/* ==========================================================================
   DESIGN SYSTEM & CSS VARIABLES
   ========================================================================== */
:root {
  --bg-main: #0b0f19;
  --bg-sidebar: #111827;
  --bg-card: #1f2937;
  --bg-card-hover: #283548;
  --bg-surface: #162032;
  
  --border-color: #374151;
  --border-subtle: #243044;
  --border-focus: #3b82f6;

  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --primary-500: #3b82f6;
  --primary-600: #2563eb;
  --primary-glow: rgba(59, 130, 246, 0.25);
  
  --accent-red: #ef4444;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.35);

  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Table dynamic vars */
  --cell-size: 44px;
  --cell-font-size: 14px;
  --grid-line-color: #3b82f6;
  --number-color: #0f172a;
}

/* ==========================================================================
   RESET & BASE STYLES
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font-body);
  background-color: var(--bg-main);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   APP LAYOUT
   ========================================================================== */
.app-layout {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ==========================================================================
   SIDEBAR
   ========================================================================== */
.sidebar {
  width: 380px;
  min-width: 340px;
  max-width: 440px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 20;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), width 0.3s ease;
  box-shadow: var(--shadow-lg);
}

.sidebar.collapsed {
  transform: translateX(-100%);
  width: 0;
  min-width: 0;
  border-right: none;
  visibility: hidden;
}

.sidebar-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  background: linear-gradient(180deg, rgba(31, 41, 55, 0.4) 0%, rgba(17, 24, 39, 0.8) 100%);
}

.logo-wrapper {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.logo-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary-500), #1d4ed8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 0 15px var(--primary-glow);
}

.logo-wrapper h1 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
  line-height: 1.2;
}

.badge-tag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-green);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.sidebar-scrollable {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.sidebar-scrollable::-webkit-scrollbar {
  width: 6px;
}
.sidebar-scrollable::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-scrollable::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}
.sidebar-scrollable::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ==========================================================================
   CONTROL SECTIONS & GROUPS
   ========================================================================== */
.control-section {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.control-section.highlight-section {
  border-color: rgba(59, 130, 246, 0.35);
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.7) 0%, rgba(22, 32, 50, 0.9) 100%);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
}

.section-title svg {
  color: var(--primary-500);
}

.section-title h3 {
  font-family: var(--font-heading);
  font-size: 0.88rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.section-helper {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: -0.5rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.control-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.control-group label, .group-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.value-pill {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--bg-card);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  color: var(--primary-500);
}

.num-direct-input {
  width: 65px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 3px 6px;
  text-align: right;
  transition: all 0.2s ease;
}

.num-direct-input:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

/* ==========================================================================
   DATE CARDS & DIAGONAL CONTROLS
   ========================================================================== */
.highlight-date-section {
  border-color: rgba(248, 113, 113, 0.35);
  background: linear-gradient(180deg, rgba(40, 24, 30, 0.7) 0%, rgba(26, 20, 28, 0.9) 100%);
}

.date-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.date-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.date-badge {
  font-family: var(--font-heading);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
}

.badge-d1 {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.badge-d2 {
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.date-inputs-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1.4fr;
  gap: 0.5rem;
}

.date-options-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: rgba(0, 0, 0, 0.15);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.checkbox-container-sm {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.72rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.checkbox-container-sm input {
  display: none;
}

.checkmark-sm {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.checkbox-container-sm input:checked ~ .checkmark-sm {
  background: var(--primary-500);
  border-color: var(--primary-500);
}

.checkbox-container-sm input:checked ~ .checkmark-sm::after {
  content: '';
  width: 3px;
  height: 6px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

.styled-text-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: #93c5fd;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 10px;
  outline: none;
  transition: all 0.2s;
}

.styled-text-input:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.mirror-toggles-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.mirror-toggle-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: all 0.2s ease;
  user-select: none;
}

.mirror-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.color-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-horiz { background-color: #06b6d4; }
.dot-vert  { background-color: #a855f7; }
.dot-diag  { background-color: #f59e0b; }

/* Active states for each toggle */
.mirror-toggle-btn[data-mirror="horizontal"].active {
  background: rgba(6, 182, 212, 0.2);
  border-color: #06b6d4;
  color: #67e8f9;
  box-shadow: 0 0 8px rgba(6, 182, 212, 0.3);
}

.mirror-toggle-btn[data-mirror="vertical"].active {
  background: rgba(168, 85, 247, 0.2);
  border-color: #a855f7;
  color: #d8b4fe;
  box-shadow: 0 0 8px rgba(168, 85, 247, 0.3);
}

.mirror-toggle-btn[data-mirror="diagonal"].active {
  background: rgba(245, 158, 11, 0.2);
  border-color: #f59e0b;
  color: #fde68a;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.3);
}

/* Colors quad grid */
.colors-quad-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.color-mini-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
}

.color-tag-name {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.color-picker-mini input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  cursor: pointer;
  background: none;
}
.color-picker-mini input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-picker-mini input[type="color"]::-webkit-color-swatch {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

/* Cell marked styles for mirrors */
.grid-cell.marked-cross-horiz {
  background-color: rgba(6, 182, 212, 0.2) !important;
  border-color: #06b6d4 !important;
}
.grid-cell.marked-cross-horiz::before {
  background: linear-gradient(to top right, transparent calc(50% - 1.2px), #06b6d4 calc(50% - 1.2px), #06b6d4 calc(50% + 1.2px), transparent calc(50% + 1.2px));
}
.grid-cell.marked-cross-horiz::after {
  background: linear-gradient(to bottom right, transparent calc(50% - 1.2px), #06b6d4 calc(50% - 1.2px), #06b6d4 calc(50% + 1.2px), transparent calc(50% + 1.2px));
}

.grid-cell.marked-cross-vert {
  background-color: rgba(168, 85, 247, 0.2) !important;
  border-color: #a855f7 !important;
}
.grid-cell.marked-cross-vert::before {
  background: linear-gradient(to top right, transparent calc(50% - 1.2px), #a855f7 calc(50% - 1.2px), #a855f7 calc(50% + 1.2px), transparent calc(50% + 1.2px));
}
.grid-cell.marked-cross-vert::after {
  background: linear-gradient(to bottom right, transparent calc(50% - 1.2px), #a855f7 calc(50% - 1.2px), #a855f7 calc(50% + 1.2px), transparent calc(50% + 1.2px));
}

.grid-cell.marked-cross-diag {
  background-color: rgba(245, 158, 11, 0.2) !important;
  border-color: #f59e0b !important;
}
.grid-cell.marked-cross-diag::before {
  background: linear-gradient(to top right, transparent calc(50% - 1.2px), #f59e0b calc(50% - 1.2px), #f59e0b calc(50% + 1.2px), transparent calc(50% + 1.2px));
}
.grid-cell.marked-cross-diag::after {
  background: linear-gradient(to bottom right, transparent calc(50% - 1.2px), #f59e0b calc(50% - 1.2px), #f59e0b calc(50% + 1.2px), transparent calc(50% + 1.2px));
}

.mirror-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px dashed var(--border-subtle);
}

.mirror-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.segmented-control-mini {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.mini-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 4px 2px;
  border-radius: 3px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  white-space: nowrap;
}

.mini-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.mini-btn.active {
  background: var(--accent-red);
  color: #ffffff;
  box-shadow: 0 1px 4px rgba(239, 68, 68, 0.3);
}

#date2Mirror .mini-btn.active {
  background: #d97706;
  box-shadow: 0 1px 4px rgba(217, 119, 6, 0.3);
}

.date-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.date-field label {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 600;
}

.date-input {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 6px;
  text-align: center;
  outline: none;
  transition: all 0.2s;
}

.date-input:focus {
  border-color: #f87171;
  box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.25);
}

/* Switch toggle */
.switch-toggle {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 18px;
  cursor: pointer;
}

.switch-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-round {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  transition: .3s;
  border-radius: 20px;
}

.slider-round:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 12px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-muted);
  transition: .3s;
  border-radius: 50%;
}

.switch-toggle input:checked + .slider-round {
  background-color: var(--accent-red);
  border-color: var(--accent-red);
}

.switch-toggle input:checked + .slider-round:before {
  transform: translateX(16px);
  background-color: #ffffff;
}

/* DIAGONALS SVG OVERLAY */
.diagonals-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  overflow: visible;
}

/* ==========================================================================
   SLIDERS & INPUTS
   ========================================================================== */
.styled-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-card);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  transition: background 0.2s;
}

.styled-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary-500);
  cursor: pointer;
  box-shadow: 0 0 8px var(--primary-glow);
  transition: transform 0.15s ease, background-color 0.15s;
  border: 2px solid #fff;
}

.styled-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  background: var(--primary-600);
}

.range-bounds {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.input-with-unit {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.unit-text {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  min-width: 38px;
  text-align: right;
}

.custom-select-wrapper {
  position: relative;
}

.styled-select {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.8rem;
  padding: 7px 10px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

.styled-select:focus {
  border-color: var(--primary-500);
}

/* ==========================================================================
   SEGMENTED CONTROLS
   ========================================================================== */
.segmented-control, .segmented-control-2 {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 3px;
}

.segmented-control {
  flex-direction: column;
}

.segmented-control-2 {
  flex-direction: row;
}

.segment-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all 0.2s ease;
}

.segment-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.segment-btn.active {
  background: var(--primary-500);
  color: #fff;
  box-shadow: 0 2px 8px var(--primary-glow);
}

/* ==========================================================================
   PRESET CARDS
   ========================================================================== */
.presets-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
}

.preset-card {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.8rem;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
}

.preset-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.preset-card.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--primary-500);
  box-shadow: 0 0 10px var(--primary-glow);
}

.preset-preview {
  width: 40px;
  height: 28px;
  border-radius: 4px;
  border: 1px solid #60a5fa;
  position: relative;
  flex-shrink: 0;
  background-color: #fff;
}

/* Visual miniature icons */
.preview-p1 {
  background: repeating-linear-gradient(45deg, #dbeafe, #dbeafe 4px, #ffffff 4px, #ffffff 8px);
}
.preview-p2 {
  background: #ffffff;
  background-image: linear-gradient(#bfdbfe 1px, transparent 1px), linear-gradient(90deg, #bfdbfe 1px, transparent 1px);
  background-size: 8px 8px;
}
.preview-p3 {
  background: repeating-linear-gradient(-45deg, #dbeafe, #dbeafe 4px, #ffffff 4px, #ffffff 8px);
}

.preset-info {
  display: flex;
  flex-direction: column;
}

.preset-info strong {
  font-size: 0.82rem;
  color: var(--text-primary);
}

.preset-info span {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

/* ==========================================================================
   COLOR PICKERS & CHECKBOXES
   ========================================================================== */
.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
}

.color-picker-wrapper input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
  background: none;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}
.color-picker-wrapper input[type="color"]::-webkit-color-swatch {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.color-hex {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.checkbox-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.checkbox-container input {
  display: none;
}

.checkmark {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.2s ease;
}

.checkbox-container input:checked ~ .checkmark {
  background: var(--primary-500);
  border-color: var(--primary-500);
}

.checkbox-container input:checked ~ .checkmark::after {
  content: '';
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* ==========================================================================
   MARKER TOOLS
   ========================================================================== */
.tools-bar {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.tool-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all 0.2s;
}

.tool-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.tool-btn.active {
  border-color: var(--primary-500);
  background: rgba(59, 130, 246, 0.2);
  color: #fff;
}

.tool-preview-circle {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1.5px solid #2563eb;
  background: rgba(37, 99, 235, 0.15);
}

.tool-preview-cross {
  width: 13px;
  height: 13px;
  border: 1.5px solid #ef4444;
  background: rgba(239, 68, 68, 0.2);
  position: relative;
}
.tool-preview-cross::before, .tool-preview-cross::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
  background: #ef4444;
}
.tool-preview-cross::before { transform: translateY(-50%) rotate(45deg); }
.tool-preview-cross::after { transform: translateY(-50%) rotate(-45deg); }

.tool-preview-highlight {
  width: 13px;
  height: 13px;
  background: #fef08a;
  border-radius: 2px;
}

.tools-actions-row {
  display: flex;
  justify-content: flex-end;
}

.btn-secondary-sm {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary-sm:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
  background: rgba(239, 68, 68, 0.1);
}

/* ==========================================================================
   SIDEBAR FOOTER
   ========================================================================== */
.sidebar-footer {
  padding: 0.85rem 1.5rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: flex;
  gap: 0.6rem;
  justify-content: space-between;
}

.stat-pill {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.stat-pill strong {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-primary);
}

/* ==========================================================================
   VIEWPORT & HEADER
   ========================================================================== */
.viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
  background: radial-gradient(circle at 50% 20%, #151e2e 0%, #0b0f19 80%);
}

.topbar {
  height: 56px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(17, 24, 39, 0.7);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  z-index: 10;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.toggle-sidebar-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-sidebar-btn:hover {
  color: var(--text-primary);
  border-color: var(--primary-500);
}

.config-summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.chip {
  font-size: 0.74rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.chip-primary {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--primary-500);
  color: #93c5fd;
}

/* ZOOM CONTROLS */
.zoom-controls {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 26px;
  height: 26px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

#zoomLevel {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  font-weight: 700;
  min-width: 42px;
  text-align: center;
  color: var(--text-secondary);
}

/* ACTION BUTTONS */
.action-buttons {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-export {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-export:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.btn-primary-action {
  background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  box-shadow: 0 2px 10px var(--primary-glow);
  transition: all 0.2s;
}

.btn-primary-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--primary-glow);
  background: linear-gradient(135deg, #60a5fa, var(--primary-500));
}

/* ==========================================================================
   BOARD & TABLE STAGE
   ========================================================================== */
.board-container {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem;
  position: relative;
  background-image: 
    radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 24px 24px, 12px 12px;
  background-position: 0 0, 12px 12px;
}

.table-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
  transition: transform 0.15s ease-out;
}

/* THE PHYSICAL PAPER CARD FOR THE GRID */
.table-paper {
  background: #ffffff;
  padding: 18px;
  border-radius: 4px;
  box-shadow: 
    0 10px 30px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.05),
    0 20px 40px rgba(0, 0, 0, 0.4);
  position: relative;
}

/* ==========================================================================
   GRID STYLING (MATCHING ATTACHED SCREENSHOTS)
   ========================================================================== */
.grid-wrapper {
  display: inline-block;
  border: 2px solid var(--grid-line-color);
  background-color: #ffffff;
  position: relative;
  user-select: none;
}

.grid-table {
  border-collapse: collapse;
  border-spacing: 0;
  table-layout: fixed;
}

.grid-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  min-width: var(--cell-size);
  max-width: var(--cell-size);
  min-height: var(--cell-size);
  max-height: var(--cell-size);
  border: 1px solid #bfdbfe; /* Subtle inner grid line */
  text-align: center;
  vertical-align: middle;
  position: relative;
  padding: 0;
  font-family: var(--font-heading);
  font-size: var(--cell-font-size);
  font-weight: 700;
  color: var(--number-color);
  transition: background-color 0.15s ease;
  cursor: pointer;
}

.grid-cell:hover {
  background-color: rgba(59, 130, 246, 0.08);
}

.grid-cell.empty-cell {
  background-color: #f8fafc;
  color: transparent;
  cursor: default;
}

.grid-cell.empty-cell:hover {
  background-color: #f1f5f9;
}

/* MARKERS ON CELLS */
.cell-number-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 2;
}

/* Blue circle mark (like 25, 41, 48, 49, 66 in screenshots) */
.grid-cell.marked-blue-circle .cell-number-wrapper::before {
  content: '';
  position: absolute;
  width: calc(var(--cell-size) * 0.72);
  height: calc(var(--cell-size) * 0.72);
  border: 1.8px solid #2563eb;
  background-color: rgba(191, 219, 254, 0.4);
  border-radius: 50%;
  z-index: -1;
  animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Red cross mark (like 11, 29 in screenshots) */
.grid-cell.marked-red-cross {
  background-color: rgba(254, 202, 202, 0.5) !important;
  border-color: #ef4444 !important;
}

.grid-cell.marked-red-cross::before,
.grid-cell.marked-red-cross::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.grid-cell.marked-red-cross::before {
  background: linear-gradient(to top right, transparent calc(50% - 1.2px), #ef4444 calc(50% - 1.2px), #ef4444 calc(50% + 1.2px), transparent calc(50% + 1.2px));
}

.grid-cell.marked-red-cross::after {
  background: linear-gradient(to bottom right, transparent calc(50% - 1.2px), #ef4444 calc(50% - 1.2px), #ef4444 calc(50% + 1.2px), transparent calc(50% + 1.2px));
}

.grid-cell.marked-red-cross .cell-number-wrapper {
  color: #b91c1c;
  font-weight: 800;
}

/* Yellow highlight */
.grid-cell.marked-highlight-yellow {
  background-color: #fef08a !important;
}

/* INDEX HEADERS (WHEN ENABLED) */
.grid-cell.index-header {
  background-color: #e2e8f0;
  color: #64748b;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  font-weight: 600;
  cursor: default;
}

@keyframes popIn {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   BOTTOM BAR & CAPACITY WARNING
   ========================================================================== */
.bottom-bar {
  height: 38px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  z-index: 10;
}

.capacity-warning {
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.15);
  padding: 2px 10px;
  border-radius: 4px;
  border: 1px solid rgba(245, 158, 11, 0.3);
  font-weight: 600;
}

/* ==========================================================================
   TOAST NOTIFICATION
   ========================================================================== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #fff;
  border: 1px solid var(--border-color);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  transform: translateY(100px);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */
@media print {
  body, html {
    background: #fff !important;
    overflow: visible !important;
  }
  .sidebar, .topbar, .bottom-bar, .toast {
    display: none !important;
  }
  .app-layout {
    display: block !important;
    width: 100% !important;
    height: auto !important;
  }
  .viewport {
    background: transparent !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  .board-container {
    padding: 0 !important;
    background: none !important;
    overflow: visible !important;
  }
  .table-paper {
    box-shadow: none !important;
    padding: 0 !important;
  }
  .table-stage {
    transform: none !important;
  }
}
