/* ============================================================
   Nelabs Design System — Excel → Dashboard
   Brand: #1A56DB primary · #0F2E6B navy · #E8F0FE · #F7F9FF
   Fonts: Satoshi (display) + Inter (UI)
   ============================================================ */

:root {
  /* Brand */
  --navy:        #0F2E6B;
  --navy-deep:   #0B2152;
  --primary:     #1A56DB;
  --primary-600: #1A56DB;
  --primary-700: #1648BD;
  --primary-800: #12399A;
  --blue-100:    #E8F0FE;
  --blue-50:     #F3F7FF;

  /* Surfaces */
  --bg:          #F7F9FF;
  --surface:     #FFFFFF;
  --border:      #E3EAF6;
  --border-soft: #EEF3FB;

  /* Text */
  --text:        #0B1B3F;
  --text-2:      #33456F;
  --muted:       #5A6B8C;
  --muted-2:     #8A98B8;

  /* Semantic */
  --success:     #10B981;
  --success-bg:  #E7F8F1;
  --danger:      #E4573D;
  --danger-bg:   #FDEBE7;
  --warn:        #F59E0B;
  --warn-bg:     #FEF4E2;

  /* Elevation */
  --shadow-xs:   0 1px 2px rgba(11, 27, 63, 0.05);
  --shadow-sm:   0 2px 8px rgba(11, 27, 63, 0.06);
  --shadow-md:   0 8px 24px rgba(11, 27, 63, 0.08);
  --shadow-lg:   0 20px 48px rgba(11, 27, 63, 0.10);

  /* Shape */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 16px;

  /* Type */
  --font-display: 'Satoshi', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-ui:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-num:     'JetBrains Mono', 'IBM Plex Mono', ui-monospace, SFMono-Regular, monospace;

  --sidebar-w: 264px;
  --topbar-h: 68px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
svg { display: block; }

/* ---------- App shell ---------- */
#app { min-height: 100vh; }

#sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 50;
  background: linear-gradient(180deg, var(--navy-deep) 0%, var(--navy) 55%, var(--primary-800) 130%);
  color: #fff;
  display: flex; flex-direction: column;
  transition: transform 0.3s var(--ease);
}

.brand { padding: 20px 20px 18px; display: flex; flex-direction: column; gap: 12px; }
.brand-logo-tile {
  background: #FFFFFF; border-radius: 14px;
  padding: 10px 16px; align-self: flex-start; line-height: 0;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22), inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}
.brand-logo-tile .brand-mark { height: 34px; width: auto; display: block; }
.brand-sub { font-size: 11px; color: rgba(255, 255, 255, 0.62); letter-spacing: 0.4px; }

#nav { padding: 6px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 11px 12px;
  background: transparent; border: 0; border-radius: var(--r-sm);
  color: rgba(255, 255, 255, 0.78); font-size: 13.5px; font-weight: 500;
  text-align: left; transition: background 0.18s, color 0.18s;
}
.nav-item svg { width: 19px; height: 19px; fill: currentColor; flex: none; }
.nav-item:hover { background: rgba(255, 255, 255, 0.09); color: #fff; }
.nav-item.active {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  box-shadow: inset 3px 0 0 #fff, 0 1px 0 rgba(255,255,255,0.08);
  font-weight: 600;
}

.sidebar-section { margin-top: 18px; padding: 0 12px; flex: 1; overflow-y: auto; }
.sidebar-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: 1.1px; text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45); padding: 0 12px 8px;
}
.wb-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--r-sm);
  color: rgba(255, 255, 255, 0.8); font-size: 12.5px;
  border: 1px solid rgba(255,255,255,0.08); background: rgba(255,255,255,0.04);
  margin-bottom: 6px;
}
.wb-item .wb-ic {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  display: grid; place-items: center; font-size: 11px; font-weight: 800;
  background: rgba(255, 255, 255, 0.14); color: #fff;
}
.wb-item .wb-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.wb-item .wb-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.wb-item .wb-sheets { font-size: 10.5px; color: rgba(255, 255, 255, 0.5); }

.sidebar-footer {
  margin: 12px; padding: 12px 14px; border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.07); border: 1px solid rgba(255,255,255,0.09);
  font-size: 11.5px; color: rgba(255, 255, 255, 0.65);
  display: flex; align-items: center; justify-content: space-between;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: #34D399; box-shadow: 0 0 0 3px rgba(52,211,153,0.25); display: inline-block; margin-right: 7px; }
.fy { font-family: var(--font-num); font-size: 10px; color: rgba(255,255,255,0.45); }

/* ---------- Main ---------- */
#main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

#topbar {
  position: sticky; top: 0; z-index: 40; height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 28px;
  background: rgba(247, 249, 255, 0.82);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-soft);
}
#menu-btn { display: none; background: none; border: 1px solid var(--border); border-radius: 10px; padding: 8px; }
#menu-btn svg { width: 18px; height: 18px; fill: var(--text); }
.topbar-title h1 { font-family: var(--font-display); font-size: 19px; font-weight: 700; letter-spacing: -0.2px; }
.topbar-title p { font-size: 12px; color: var(--muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.file-count {
  font-family: var(--font-num); font-size: 11px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 999px;
}

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: var(--r-sm);
  font-size: 13px; font-weight: 600; border: 1px solid transparent;
  transition: all 0.18s var(--ease);
}
.btn svg { width: 15px; height: 15px; fill: currentColor; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--primary-700); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover { border-color: #C9D6EC; background: var(--blue-50); }

/* ---------- Views ---------- */
.view { padding: 26px 28px 60px; animation: fade-in 0.25s var(--ease); }
.view.hidden { display: none; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Headline KPI strip ---------- */
.kpi-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  margin-bottom: 26px;
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 18px 20px;
  box-shadow: var(--shadow-xs);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-card .k-label { font-size: 11.5px; font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi-card .k-label .k-ic { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; }
.kpi-card .k-label .k-ic svg { width: 12px; height: 12px; fill: currentColor; }
.kpi-card .k-value { font-family: var(--font-display); font-size: 26px; font-weight: 700; letter-spacing: -0.5px; margin-top: 10px; color: var(--text); }
.kpi-card .k-foot { margin-top: 6px; font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; font-family: var(--font-num); font-size: 11px; padding: 2px 7px; border-radius: 999px; }
.delta.up { color: var(--success); background: var(--success-bg); }
.delta.down { color: var(--danger); background: var(--danger-bg); }
.delta.flat { color: var(--muted); background: var(--border-soft); }
.kpi-hero { background: linear-gradient(135deg, var(--navy) 0%, var(--primary-800) 100%); border: 0; color: #fff; }
.kpi-hero .k-label, .kpi-hero .k-foot { color: rgba(255, 255, 255, 0.7); }
.kpi-hero .k-value { color: #fff; }
.kpi-hero .k-ic { background: rgba(255,255,255,0.16); }

/* ---------- Sheet sections ---------- */
.sheet-section { margin-bottom: 30px; }
.sheet-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px; padding: 0 2px;
}
.sheet-head h2 { font-family: var(--font-display); font-size: 16.5px; font-weight: 700; letter-spacing: -0.2px; }
.sheet-head .wb-badge {
  font-size: 10.5px; font-weight: 700; color: var(--primary-700);
  background: var(--blue-100); border-radius: 999px; padding: 3px 10px; letter-spacing: 0.3px;
}
.sheet-head .shape-tag {
  font-size: 10.5px; font-weight: 600; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 10px;
}
.sheet-head .sheet-meta { margin-left: auto; font-family: var(--font-num); font-size: 11px; color: var(--muted-2); }

.widget-grid { display: grid; gap: 16px; grid-template-columns: repeat(12, 1fr); }
.widget {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-xs);
  padding: 18px 20px; min-width: 0;
}
.widget.span-12 { grid-column: span 12; }
.widget.span-8 { grid-column: span 8; }
.widget.span-6 { grid-column: span 6; }
.widget.span-4 { grid-column: span 4; }
.widget h3 { font-family: var(--font-display); font-size: 13.5px; font-weight: 700; margin-bottom: 4px; }
.widget .w-sub { font-size: 11.5px; color: var(--muted); margin-bottom: 14px; }
.chart-box { position: relative; height: 250px; }
.chart-box.tall { height: 300px; }

/* stat chips */
.chip-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.chip {
  background: var(--blue-50); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 10px 12px;
}
.chip .c-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.chip .c-value { font-family: var(--font-num); font-size: 15px; font-weight: 600; margin-top: 3px; color: var(--text); }

/* ---------- Tables ---------- */
.table-wrap {
  overflow: auto; max-height: 460px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface);
}
table.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--navy); color: #fff;
  font-size: 11px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
  padding: 10px 12px; text-align: left; white-space: nowrap;
}
.data-table tbody td {
  padding: 9px 12px; border-bottom: 1px solid var(--border-soft);
  color: var(--text-2); white-space: nowrap;
}
.data-table tbody tr:nth-child(even) { background: var(--blue-50); }
.data-table tbody tr:hover { background: var(--blue-100); }
.data-table .num { font-family: var(--font-num); text-align: right; }
.data-table .total-row td { font-weight: 700; background: var(--blue-100) !important; color: var(--navy); border-top: 2px solid var(--primary); }
.data-table .mono { font-family: var(--font-num); font-size: 11.5px; }

/* ---------- Sheet viewer ---------- */
.viewer-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.vtab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: var(--r-sm);
  background: var(--surface); border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 600; color: var(--text-2);
  transition: all 0.15s var(--ease);
}
.vtab:hover { border-color: #C9D6EC; }
.vtab.active { background: var(--navy); border-color: var(--navy); color: #fff; box-shadow: var(--shadow-sm); }
.vtab .v-ic { width: 18px; height: 18px; border-radius: 5px; background: rgba(26,86,219,0.1); color: var(--primary); display: grid; place-items: center; font-size: 10px; font-weight: 800; }
.vtab.active .v-ic { background: rgba(255,255,255,0.18); color: #fff; }

.viewer-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.search-box {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 220px; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 0 12px; height: 38px;
}
.search-box svg { width: 15px; height: 15px; fill: var(--muted-2); }
.search-box input { border: 0; outline: 0; background: transparent; font: inherit; font-size: 13px; color: var(--text); width: 100%; }
.viewer-meta { font-family: var(--font-num); font-size: 11.5px; color: var(--muted); margin-left: auto; }

/* ---------- Upload ---------- */
.dropzone {
  border: 2px dashed #C3D3EF; border-radius: var(--r-lg);
  background: var(--blue-50);
  padding: 64px 32px; text-align: center; cursor: pointer;
  transition: all 0.2s var(--ease); margin-bottom: 24px;
}
.upload-logo { height: 60px; width: auto; display: block; margin: 0 auto 20px; }
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--blue-100); }
.dropzone .dz-ic { width: 54px; height: 54px; margin: 0 auto 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); display: grid; place-items: center; box-shadow: var(--shadow-sm); }
.dropzone .dz-ic svg { width: 26px; height: 26px; fill: var(--primary); }
.dropzone h2 { font-family: var(--font-display); font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.dropzone p { color: var(--muted); font-size: 13px; }
.dropzone .dz-hint { font-size: 11.5px; color: var(--muted-2); margin-top: 14px; font-family: var(--font-num); }

.upload-note {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--warn-bg); border: 1px solid #F6E3BC; color: #8A5A00;
  border-radius: var(--r-md); padding: 14px 16px; font-size: 12.5px; line-height: 1.55;
}
.upload-note svg { width: 18px; height: 18px; fill: var(--warn); flex: none; margin-top: 1px; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; top: 18px; right: 18px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: var(--r-sm); box-shadow: var(--shadow-md);
  padding: 12px 16px; min-width: 260px; max-width: 380px;
  font-size: 13px; animation: toast-in 0.3s var(--ease);
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast .t-title { font-weight: 700; margin-bottom: 2px; }
.toast .t-msg { color: var(--muted); font-size: 12px; }
@keyframes toast-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }

/* ---------- Empty / loading ---------- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state svg { width: 44px; height: 44px; fill: #C9D6EC; margin: 0 auto 14px; }
.empty-state h3 { font-family: var(--font-display); color: var(--text-2); font-size: 15px; margin-bottom: 6px; }

.skeleton { background: linear-gradient(90deg, #EDF2FA 25%, #F7FAFF 50%, #EDF2FA 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--r-md); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .widget.span-8, .widget.span-6, .widget.span-4 { grid-column: span 12; }
}
@media (max-width: 900px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  #main { margin-left: 0; }
  #menu-btn { display: block; }
  .sidebar-footer { display: none; }
}
@media (max-width: 640px) {
  .view { padding: 18px 14px 48px; }
  #topbar { padding: 0 14px; gap: 10px; }
  .topbar-title p { display: none; }
  .topbar-actions .btn-ghost span, .topbar-actions .btn-primary { }
  #btn-sample { padding: 0 10px; }
  #btn-export { padding: 0 12px; }
  .file-count { display: none; }
  .kpi-card .k-value { font-size: 22px; }
  .data-table { font-size: 11.5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ============================================================
   Interactivity — clickable dashboard layer
   ============================================================ */
.clickable { cursor: pointer; }
.kpi-card.clickable { transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), border-color 0.2s; }
.kpi-card.clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: #C9D6EC; }
.kpi-card.clickable:active { transform: translateY(0); }
.kpi-hero.clickable:hover { box-shadow: 0 12px 32px rgba(11,27,63,0.35); }

.data-table tbody tr { cursor: pointer; transition: background 0.12s; }

/* section collapse */
.sheet-head { cursor: pointer; user-select: none; }
.sheet-head .chev {
  margin-left: 2px; width: 22px; height: 22px; flex: none;
  color: var(--muted-2); transition: transform 0.25s var(--ease);
}
.sheet-head .chev svg { width: 18px; height: 18px; fill: currentColor; }
.sheet-section.collapsed .chev { transform: rotate(-90deg); }
.sheet-section.collapsed .widget-grid { display: none; }

/* filter chips */
.filter-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--blue-100); color: var(--primary-700);
  border: 1px solid #C9D6EC; border-radius: 999px;
  padding: 5px 12px; font-size: 12px; font-weight: 600;
  margin-bottom: 10px;
}
.filter-chip .fc-x {
  background: rgba(26,86,219,0.12); border: 0; border-radius: 50%;
  width: 18px; height: 18px; font-size: 10px; line-height: 1;
  color: var(--primary-700); cursor: pointer; display: grid; place-items: center;
  transition: background 0.15s;
}
.filter-chip .fc-x:hover { background: rgba(26,86,219,0.25); }

/* global workbook filter chip (topbar) */
#filter-chip.hidden { display: none; }
#filter-chip.filter-chip { margin-bottom: 0; }
#filter-chip .fc-x { width: 20px; height: 20px; }

/* sort arrows */
.data-table th.sortable { cursor: pointer; }
.data-table th.sortable:hover { background: var(--primary-700); }
.data-table th .arrow { opacity: 0.65; font-size: 9px; margin-left: 3px; }

/* pulse highlight when jumping to a section/table */
@keyframes pulse-highlight {
  0% { box-shadow: 0 0 0 0 rgba(26, 86, 219, 0.4); }
  100% { box-shadow: 0 0 0 22px rgba(26, 86, 219, 0); }
}
.pulse { animation: pulse-highlight 1.1s var(--ease) 2; border-color: var(--primary) !important; }

/* ---------- detail modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(11, 27, 63, 0.45);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px;
  animation: fade-in 0.18s var(--ease);
}
.modal {
  background: var(--surface); border-radius: 20px;
  width: min(580px, 100%); max-height: 86vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.25s var(--ease);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(16px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  padding: 20px 22px 14px; border-bottom: 1px solid var(--border-soft);
}
.modal-head h3 { font-family: var(--font-display); font-size: 16px; font-weight: 700; margin-top: 6px; }
.modal-head p { font-size: 12px; color: var(--muted); margin-top: 2px; }
.modal-x {
  background: var(--blue-50); border: 1px solid var(--border); cursor: pointer;
  width: 32px; height: 32px; border-radius: 9px; font-size: 14px; color: var(--muted);
  display: grid; place-items: center; transition: all 0.15s; flex: none;
}
.modal-x:hover { color: var(--text); border-color: #C9D6EC; }
.modal-body { padding: 6px 22px; overflow-y: auto; }
.modal-row {
  display: flex; justify-content: space-between; gap: 28px;
  padding: 11px 0; border-bottom: 1px solid var(--border-soft); font-size: 13px;
}
.modal-row .m-k { color: var(--muted); font-weight: 600; flex: none; }
.modal-row .m-v { font-weight: 600; text-align: right; font-family: var(--font-num); word-break: break-word; }
.modal-row.text .m-v { font-family: var(--font-ui); }
.modal-foot { padding: 14px 22px 18px; text-align: right; }
@media (max-width: 480px) {
  .modal-row { flex-direction: column; gap: 2px; }
  .modal-row .m-v { text-align: left; }
}
