:root {
  --bg-canvas: #eef2f6;
  --bg-surface: #ffffff;
  --navy-950: #090d16;
  --navy-900: #0f172a;
  --indigo-700: #1d4ed8;
  --indigo-600: #2563eb;
  --teal-600: #0d9488;
  --teal-700: #0f766e;
  --border-subtle: #e2e8f0;
  --border-grid: #334155;
  --sum-bg: #eff6ff;
  --sum-text: #1e40af;
  --diag-bg: #fef3c7;
  --diag-text: #92400e;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --shadow-lg: 0 20px 25px -5px rgba(15, 23, 42, 0.08), 0 8px 10px -6px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "Noto Sans Myanmar", "Pyidaungsu", sans-serif;
  background: var(--bg-canvas);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.app-header {
  background: linear-gradient(120deg, var(--navy-950) 0%, #172554 55%, #1e3a8a 100%);
  color: #ffffff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  box-shadow: 0 4px 20px rgba(9, 13, 22, 0.25);
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6 0%, #0d9488 100%);
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.28);
}

.logo-symbol {
  font-weight: 800;
  font-size: 18px;
  color: #ffffff;
  letter-spacing: -0.5px;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand-text h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.live-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.18);
  color: #6ee7b7;
  border: 1px solid rgba(110, 231, 183, 0.35);
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 12px;
  color: #cbd5e1;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-select {
  background: rgba(15, 23, 42, 0.75);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

.mode-select:hover {
  border-color: rgba(255, 255, 255, 0.5);
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.btn-lang {
  background: linear-gradient(135deg, var(--teal-600), var(--teal-700));
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.35);
}

.btn-lang:hover {
  filter: brightness(1.08);
}

.btn-glass {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(6px);
}

.btn-glass:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12px;
}

.btn-xs {
  padding: 3px 9px;
  font-size: 11px;
}

/* Dashboard KPI Strip */
.dashboard-strip {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  z-index: 20;
}

.kpi-cards {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.kpi-card {
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 6px 14px;
  display: flex;
  flex-direction: column;
  min-width: 115px;
}

.kpi-card.highlight {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.kpi-card.status-card.ok {
  background: #ecfdf5;
  border-color: #6ee7b7;
}

.kpi-card.status-card.ok .kpi-value {
  color: #047857;
}

.kpi-card.status-card.warn {
  background: #fffbeb;
  border-color: #fcd34d;
}

.kpi-card.status-card.warn .kpi-value {
  color: #b45309;
}

.kpi-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-secondary);
}

.kpi-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 1px;
}

/* Quick Presets & Zoom */
.quick-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.presets {
  display: flex;
  align-items: center;
  gap: 5px;
}

.preset-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-right: 2px;
}

.chip {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #1e293b;
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}

.chip:hover {
  background: #2563eb;
  border-color: #2563eb;
  color: #ffffff;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.zoom-pill {
  background: #e2e8f0;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  color: #0f172a;
}

/* Main Sheet Viewport */
.sheet-viewport {
  flex: 1;
  overflow: auto;
  padding: 24px;
  background-color: #f1f5f9;
  background-image:
    radial-gradient(#cbd5e1 1px, transparent 1px),
    radial-gradient(#e2e8f0 1px, #f8fafc 1px);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
}

.sheet-card {
  display: inline-block;
  background: #ffffff;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  border: 1px solid #cbd5e1;
  overflow: hidden;
}

.sheet-card-header {
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.sheet-meta {
  display: flex;
  align-items: center;
  gap: 7px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.dot.red { background: #ef4444; }
.dot.yellow { background: #f59e0b; }
.dot.green { background: #10b981; }

.sheet-title {
  margin-left: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
}

.sheet-timing {
  font-size: 11.5px;
  font-weight: 600;
  color: #0d9488;
}

.table-scroll {
  padding: 18px;
}

/* Magic Table */
table.magic-table {
  border-collapse: collapse;
  table-layout: fixed;
  background: #ffffff;
  font-variant-numeric: tabular-nums;
}

table.magic-table td {
  width: var(--cell-w, 60px);
  height: var(--cell-h, 39px);
  border: 1.5px solid var(--border-grid);
  text-align: center;
  vertical-align: middle;
  font-size: var(--cell-fs, 14px);
  font-weight: 500;
  padding: 2px 4px;
  transition: background 0.1s ease, color 0.1s ease;
}

table.magic-table td.core-cell {
  background: #ffffff;
  color: #0f172a;
}

table.magic-table td.core-cell.diag-cell {
  background: #f8fafc;
  font-weight: 600;
}

table.magic-table td.core-cell:hover {
  background: #2563eb;
  color: #ffffff;
  font-weight: 700;
}

table.magic-table td.sum-border {
  background: var(--sum-bg);
  color: var(--sum-text);
  font-weight: 700;
}

table.magic-table td.corner-diag {
  background: var(--diag-bg);
  color: var(--diag-text);
  font-weight: 800;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 13, 22, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  place-items: center;
  z-index: 100;
  padding: 16px;
}

.modal-backdrop.active {
  display: grid;
}

/* Classic VBA UserForm */
.vba-userform {
  width: 440px;
  max-width: 92vw;
  background: #ece9d8;
  border: 2px solid #0054e3;
  border-radius: 8px 8px 6px 6px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.vba-titlebar {
  background: linear-gradient(180deg, #0997ff 0%, #0053ee 8%, #0050ee 40%, #06f 88%, #003dd7 100%);
  color: #ffffff;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
}

.vba-close {
  background: #e0433e;
  color: #ffffff;
  border: 1px solid #ffffff;
  border-radius: 4px;
  width: 22px;
  height: 22px;
  font-weight: bold;
  cursor: pointer;
}

.vba-body {
  padding: 24px;
  background: #f0f0f0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.vba-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.vba-label {
  font-size: 15.5px;
  font-weight: 700;
  color: #000000;
  text-align: center;
  line-height: 1.45;
  flex: 1;
}

.vba-textbox {
  width: 98px;
  height: 46px;
  background: #ffffff;
  border: 2px inset #9a9a9a;
  font-size: 20px;
  font-weight: 700;
  text-align: center;
}

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

.vba-ok-btn {
  width: 120px;
  height: 40px;
  background: linear-gradient(180deg, #ffffff 0%, #e1e1e1 100%);
  border: 1px solid #707070;
  border-radius: 4px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.vba-ok-btn:hover {
  border-color: #0054e3;
  background: linear-gradient(180deg, #f2f8ff 0%, #d8e8ff 100%);
}

/* Guide Modal */
.guide-dialog {
  width: 840px;
  max-width: 95vw;
  max-height: 88vh;
  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.guide-header {
  background: linear-gradient(120deg, #0f172a, #1e3a8a);
  color: #ffffff;
  padding: 16px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.guide-header h2 {
  margin: 0;
  font-size: 17px;
}

.guide-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-close-modal {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  padding: 6px 11px;
  font-size: 14px;
}

.guide-content {
  padding: 24px 28px;
  overflow-y: auto;
  line-height: 1.8;
  font-size: 14.5px;
  color: #1e293b;
}

.guide-section {
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e2e8f0;
}

.guide-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.guide-section h3 {
  margin: 0 0 10px 0;
  color: #1d4ed8;
  font-size: 16px;
}

.formula-box {
  background: #eff6ff;
  border-left: 4px solid #2563eb;
  padding: 12px 16px;
  border-radius: 8px;
  font-family: Consolas, monospace;
  font-weight: 700;
  color: #1e3a8a;
  margin: 12px 0;
}

.color-legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  font-size: 13px;
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1.5px solid #334155;
  flex-shrink: 0;
}

/* Verification Drawer */
.test-drawer {
  background: #0f172a;
  color: #e2e8f0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
  font-family: Consolas, monospace;
  font-size: 12px;
  border-top: 2px solid #2563eb;
}

.test-drawer.open {
  max-height: 240px;
  overflow-y: auto;
  padding: 12px 24px;
}

.test-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  color: #93c5fd;
  font-weight: 700;
}

.pass { color: #34d399; }
.warn-log { color: #fbbf24; }
