/* ==========================================================================
   MS Office Shapes Gallery & Editing System Styles
   ========================================================================== */
@import url('gradient.css');

/* Shapes Picker Modal */
.office-shapes-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  z-index: 1050;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.office-shapes-dialog {
  background: var(--bg-surface, #ffffff);
  border-radius: 10px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
  width: 760px;
  max-width: 95vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border-color, #cbd5e1);
  animation: shapesModalPop 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes shapesModalPop {
  0% { transform: scale(0.96); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.office-shapes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  background: var(--bg-toolbar, #f8fafc);
}

.office-shapes-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main, #0f172a);
}

.office-shapes-btn-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted, #64748b);
  cursor: pointer;
  border-radius: 4px;
  padding: 0 4px;
}

.office-shapes-btn-close:hover {
  color: #ef4444;
}

/* Preset Style Quick Selector Bar */
.office-shapes-styles-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--bg-surface, #ffffff);
  border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.office-shapes-bar-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted, #64748b);
}

.office-shapes-style-chips {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.shape-style-chip {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.shape-style-chip:hover {
  transform: scale(1.12);
}

.shape-style-chip.active {
  box-shadow: 0 0 0 2px #0f172a, 0 2px 6px rgba(0,0,0,0.25);
  transform: scale(1.1);
}

/* Gallery Content */
.office-shapes-gallery-content {
  padding: 14px 18px;
  overflow-y: auto;
  max-height: 520px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg-surface, #ffffff);
}

.office-shapes-section-title {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted, #64748b);
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-color, #f1f5f9);
  padding-bottom: 4px;
}

.office-shapes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  gap: 6px;
}

.office-shape-item-btn {
  background: var(--bg-surface, #ffffff);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.12s ease;
}

.office-shape-item-btn:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  transform: translateY(-1px);
}

.shape-item-svg-box {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shape-item-svg-box svg {
  max-width: 100%;
  max-height: 100%;
}

.shape-item-name {
  font-size: 0.65rem;
  color: var(--text-muted, #64748b);
  text-align: center;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.office-shape-item-btn:hover .shape-item-name {
  color: #1d4ed8;
  font-weight: 500;
}

/* Modal Footer */
.office-shapes-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--bg-toolbar, #f8fafc);
  border-top: 1px solid var(--border-color, #e2e8f0);
}

.office-shapes-footer-tip {
  font-size: 0.75rem;
  color: var(--text-muted, #64748b);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ==========================================================================
   Inserted Shape Container & Controls
   ========================================================================== */
.office-shape-container {
  position: relative;
  display: inline-block;
  user-select: none;
  box-sizing: border-box;
}

.doc-inline-shape {
  margin: 12px 16px 12px 0;
  vertical-align: middle;
  float: none;
}

.sheets-floating-shape {
  position: absolute;
  z-index: 35;
  cursor: move;
}

.doc-floating-shape {
  position: absolute !important;
  margin: 0 !important;
  z-index: 35;
  cursor: move;
}

.office-shape-svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Shape Text Overlay (Centrally positioned text node inside shape) */
.shape-text-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 78%;
  max-height: 80%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.3;
  word-break: break-word;
  outline: none;
  cursor: text;
  pointer-events: auto;
  user-select: text;
  padding: 4px;
}

.shape-text-overlay:focus {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 4px;
}

/* Selection outline & handles (matching Slides orange theme) */
.shape-selection-outline {
  display: none;
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border: 1.5px dashed #ea580c;
  border-radius: 1px;
  pointer-events: none;
}

.office-shape-container.selected .shape-selection-outline {
  display: block;
}

.shape-handle {
  display: none;
  position: absolute;
  width: 9px;
  height: 9px;
  background: #ffffff;
  border: 1.5px solid #ea580c;
  border-radius: 1px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  z-index: 10;
  pointer-events: auto;
}

.office-shape-container.selected .shape-handle {
  display: block;
}

/* Handle positions (Square handles centered on borders) */
.handle-nw { top: -8px; left: -8px; cursor: nwse-resize; }
.handle-n  { top: -8px; left: calc(50% - 4.5px); cursor: ns-resize; }
.handle-ne { top: -8px; right: -8px; cursor: nesw-resize; }
.handle-e  { top: calc(50% - 4.5px); right: -8px; cursor: ew-resize; }
.handle-se { bottom: -8px; right: -8px; cursor: nwse-resize; }
.handle-s  { bottom: -8px; left: calc(50% - 4.5px); cursor: ns-resize; }
.handle-sw { bottom: -8px; left: -8px; cursor: nesw-resize; }
.handle-w  { top: calc(50% - 4.5px); left: -8px; cursor: ew-resize; }

/* Rotator Handle (Circular top handle with orange stem line matching Slides) */
.shape-rotator-stem {
  display: none;
  position: absolute;
  top: -26px;
  left: 50%;
  width: 1.5px;
  height: 26px;
  background-color: #ea580c;
  pointer-events: none;
  z-index: 20;
}

.office-shape-container.selected .shape-rotator-stem {
  display: block !important;
}

.shape-handle.handle-rotator {
  display: none;
  position: absolute;
  top: -34px;
  left: calc(50% - 7px);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #ea580c;
  cursor: grab;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.1s ease, background-color 0.1s ease;
  z-index: 25;
  pointer-events: auto;
}

.office-shape-container.selected .shape-handle.handle-rotator {
  display: block !important;
}

.shape-handle.handle-rotator:hover,
.shape-handle.handle-rotator.active {
  background-color: #ffffff;
  border-color: #ea580c;
  transform: scale(1.25);
}

.shape-handle.handle-rotator:active {
  cursor: grabbing;
}

[data-theme="dark"] .shape-selection-outline {
  border-color: #f97316;
}

[data-theme="dark"] .shape-handle {
  border-color: #f97316;
}

[data-theme="dark"] .shape-rotator-stem {
  background-color: #f97316;
}

[data-theme="dark"] .shape-handle.handle-rotator {
  border-color: #f97316;
}

[data-theme="dark"] .shape-handle.handle-rotator:hover,
[data-theme="dark"] .shape-handle.handle-rotator.active {
  border-color: #f97316;
}

/* Shape Live Rotation Degree Tooltip */
.shape-rotate-tooltip {
  position: absolute;
  top: -54px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  z-index: 25;
  display: none;
  animation: formatBarFade 0.1s ease-out;
}

.shape-rotate-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -4px;
  border-width: 4px;
  border-style: solid;
  border-color: #1e293b transparent transparent transparent;
}

.office-shape-container {
  cursor: grab;
}

.office-shape-container.moving {
  cursor: grabbing !important;
  opacity: 0.75;
}

.shape-fmt-angle-indicator {
  font-size: 0.72rem;
  font-weight: 600;
  color: #ea580c;
  background: #fff7ed;
  border: 1px solid #fdba74;
  padding: 2px 6px;
  border-radius: 4px;
  user-select: none;
}

[data-theme="dark"] .shape-fmt-angle-indicator {
  color: #fb923c;
  background: rgba(249, 115, 22, 0.15);
  border-color: #ea580c;
}

/* ==========================================================================
   Floating Formatting Toolbar for Selected Shape
   ========================================================================== */
.shape-floating-format-bar {
  position: fixed;
  z-index: 1020;
  background: var(--bg-surface, #ffffff);
  border: 1px solid var(--border-color, #cbd5e1);
  border-radius: 6px;
  box-shadow: 0 10px 20px -3px rgba(0,0,0,0.18), 0 4px 6px -2px rgba(0,0,0,0.08);
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  animation: formatBarFade 0.14s ease-out;
}

@keyframes formatBarFade {
  0% { opacity: 0; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}

.shape-toolbar-handle {
  color: var(--text-muted, #94a3b8);
  font-size: 0.75rem;
  padding: 0 2px;
  cursor: grab;
}

.shape-fmt-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-main, #334155);
}

.shape-fmt-group label {
  font-size: 0.75rem;
  color: var(--text-muted, #64748b);
  cursor: pointer;
}

.shape-color-picker {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid var(--border-color, #cbd5e1);
  cursor: pointer;
  padding: 0;
  background: none;
}

.shape-color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.shape-color-picker::-webkit-color-swatch {
  border: none;
  border-radius: 3px;
}

.shape-fmt-select {
  height: 24px;
  font-size: 0.75rem;
  border-radius: 4px;
  border: 1px solid var(--border-color, #cbd5e1);
  background: var(--bg-surface, #ffffff);
  color: var(--text-main, #0f172a);
  padding: 0 4px;
  cursor: pointer;
}

.shape-fmt-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 0.8rem;
  color: var(--text-main, #334155);
  cursor: pointer;
  transition: all 0.12s ease;
}

.shape-fmt-btn:hover {
  background: var(--bg-hover, #f1f5f9);
  border-color: var(--border-color, #cbd5e1);
}

.shape-fmt-btn.btn-danger {
  color: #ef4444;
}

.shape-fmt-btn.btn-danger:hover {
  background: #fee2e2;
  border-color: #fca5a5;
}

.shape-fmt-divider {
  width: 1px;
  height: 18px;
  background-color: var(--border-color, #e2e8f0);
  margin: 0 2px;
}

/* Dark mode styling for shapes UI */
[data-theme="dark"] .office-shapes-dialog {
  background: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .office-shapes-header,
[data-theme="dark"] .office-shapes-footer {
  background: #0f172a;
  border-color: #334155;
}

[data-theme="dark"] .office-shapes-styles-bar,
[data-theme="dark"] .office-shapes-gallery-content {
  background: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .office-shapes-section-title {
  border-color: #334155;
  color: #94a3b8;
}

[data-theme="dark"] .office-shape-item-btn {
  background: #1e293b;
}

[data-theme="dark"] .office-shape-item-btn:hover {
  background: #0f172a;
  border-color: #3b82f6;
}

[data-theme="dark"] .shape-floating-format-bar {
  background: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .shape-fmt-select {
  background: #0f172a;
  border-color: #334155;
  color: #f8fafc;
}

/* ==========================================================================
   MS Office 7-Column Shape Styles Gallery (Theme Styles + Presets)
   ========================================================================== */
.office-shapes-styles-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 10px 18px;
  background: var(--bg-surface, #ffffff);
  border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.office-shapes-styles-bar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.office-shapes-toggle-styles-btn {
  background: var(--bg-toolbar, #f1f5f9);
  border: 1px solid var(--border-color, #cbd5e1);
  border-radius: 5px;
  padding: 3px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-main, #334155);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.14s ease;
}

.office-shapes-toggle-styles-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}

#office-shapes-style-chips {
  max-height: 112px;
  overflow-y: auto;
  transition: max-height 0.22s ease;
  padding: 2px;
}

#office-shapes-style-chips.expanded {
  max-height: 360px;
}

#sidebar-shapes-style-chips {
  max-height: 290px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 6px;
  background: var(--bg-toolbar, #f8fafc);
}

.ms-shape-styles-gallery {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.ms-shape-styles-cat-header {
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--text-muted, #475569);
  padding: 4px 4px 2px 4px;
  letter-spacing: 0.01em;
}

.ms-shape-styles-grid-7 {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  padding: 2px 4px 6px 4px;
}

.ms-shape-style-tile {
  position: relative;
  width: 100%;
  aspect-ratio: 1.15 / 1;
  min-width: 34px;
  min-height: 30px;
  padding: 3px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, border-color 0.1s ease, background-color 0.1s ease;
  box-sizing: border-box;
}

/* Checkerboard background for transparent & semi-transparent Presets */
.ms-shape-style-tile.ms-shape-tile-checker {
  background-color: #ffffff;
  background-image:
    linear-gradient(45deg, #d4d4d8 25%, transparent 25%),
    linear-gradient(-45deg, #d4d4d8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d4d4d8 75%),
    linear-gradient(-45deg, transparent 75%, #d4d4d8 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  border: 1px solid #cbd5e1;
}

.ms-shape-style-tile:hover {
  transform: scale(1.08);
  border-color: #94a3b8;
  z-index: 2;
}

.ms-shape-style-tile.active {
  outline: 2px solid #ea580c;
  outline-offset: 1px;
  z-index: 3;
}

.ms-shape-style-tile-inner {
  width: 100%;
  height: 100%;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Calibri, 'Segoe UI', sans-serif;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.01em;
  box-sizing: border-box;
  pointer-events: none;
  user-select: none;
}

/* Bottom "Other Theme Fills" menu item */
.ms-shape-styles-footer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  margin-top: 2px;
  border-top: 1px solid var(--border-color, #e2e8f0);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-main, #1e293b);
  cursor: pointer;
  border-radius: 0 0 6px 6px;
  transition: background 0.12s ease;
}

.ms-shape-styles-footer-item:hover {
  background: var(--bg-hover, #f1f5f9);
}

.ms-shape-styles-footer-icon {
  color: #d97706;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
}

.ms-shape-styles-footer-text {
  flex: 1;
}

.ms-shape-styles-footer-caret {
  font-size: 0.72rem;
  color: var(--text-muted, #64748b);
}

/* Floating Format Bar: Shape Styles Trigger & Popover */
.shape-fmt-styles-trigger {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px !important;
  font-weight: 600;
  font-size: 0.76rem !important;
  background: var(--bg-toolbar, #f8fafc);
  border: 1px solid var(--border-color, #cbd5e1) !important;
}

.shape-fmt-styles-abc-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 4px;
  border-radius: 3px;
  background: #4472c4;
  border: 1px solid #2f5597;
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1.1;
}

.shape-fmt-styles-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 340px;
  max-height: 410px;
  overflow-y: auto;
  background: var(--bg-surface, #ffffff);
  border: 1px solid var(--border-color, #cbd5e1);
  border-radius: 8px;
  box-shadow: 0 14px 28px -4px rgba(0, 0, 0, 0.24), 0 6px 12px -2px rgba(0, 0, 0, 0.12);
  padding: 8px;
  z-index: 1080;
  animation: formatBarFade 0.14s ease-out;
}

[data-theme="dark"] .shape-fmt-styles-popover {
  background: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .shape-fmt-styles-trigger,
[data-theme="dark"] .office-shapes-toggle-styles-btn {
  background: #0f172a;
  border-color: #334155 !important;
  color: #f8fafc;
}

[data-theme="dark"] #sidebar-shapes-style-chips {
  background: #0f172a;
  border-color: #334155;
}

[data-theme="dark"] .ms-shape-styles-cat-header {
  color: #94a3b8;
}

[data-theme="dark"] .ms-shape-styles-footer-item {
  border-color: #334155;
  color: #f8fafc;
}

[data-theme="dark"] .ms-shape-styles-footer-item:hover {
  background: #334155;
}
