/* ============================================================
   TWIN-EWC — Global Stylesheet v3
   Palette: Navy #1a2f5e · Green #4a7c3f · Gold #f5b93e
            Blue #3a7fc1 · Red #d94f3d
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  --navy-900: #0e1d3a;
  --navy-800: #1a2f5e;
  --navy-700: #223a72;
  --navy-600: #2b4a8c;
  --navy-500: #3a5fa8;
  --navy-400: #3a7fc1;
  --navy-300: #6fa3d8;
  --navy-200: #aec9eb;
  --navy-100: #d8e8f7;
  --navy-50:  #eef5fb;

  --green-700: #2e5228;
  --green-600: #3a6633;
  --green-500: #4a7c3f;
  --green-400: #5e9a51;
  --green-200: #b2d4ab;
  --green-50:  #eaf4e8;

  --gold-500: #f5b93e;
  --gold-400: #f8ca65;
  --gold-100: #fef3cc;

  --red-500:  #d94f3d;

  --ice-50:         #f5f8fc;
  --text-primary:   #0e1d3a;
  --text-secondary: #3d5275;
  --text-muted:     #7090b0;
  --border:         #c0d4e8;
  --border-light:   #deeaf6;
  --surface:        #ffffff;
  --surface-alt:    #f5f8fc;

  --shadow-sm: 0 1px 3px rgba(14,29,58,.08), 0 1px 2px rgba(14,29,58,.06);
  --shadow-md: 0 4px 12px rgba(14,29,58,.12), 0 2px 4px rgba(14,29,58,.06);
  --shadow-lg: 0 10px 30px rgba(14,29,58,.16);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --nav-h: 60px;
  --drawer-w: 280px;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--ice-50);
  color: var(--text-primary);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
button { cursor: pointer; font: inherit; border: none; background: none; }
input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

/* ============================================================
   SPLASH SCREEN
   ============================================================ */
#splash {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--navy-800);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 40px;
  transition: opacity .6s ease, visibility .6s ease;
}
#splash.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.splash-emblem {
  width: 200px; height: 200px;
  border-radius: 32px;
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  box-shadow: 0 0 0 1px rgba(255,255,255,.1),
              0 0 60px rgba(58,127,193,.5);
  animation: splash-glow 2.2s ease-in-out infinite alternate;
}
.splash-emblem img {
  width: 100%; height: 100%;
  object-fit: contain;
}
.splash-bar-track {
  width: 200px; height: 3px;
  background: rgba(255,255,255,.12);
  border-radius: 99px; overflow: hidden;
}
.splash-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--navy-400), var(--gold-500));
  border-radius: 99px;
  animation: splash-load 2s ease-out forwards;
}
@keyframes splash-load { to { width: 100%; } }
@keyframes splash-glow {
  from { box-shadow: 0 0 30px rgba(58,127,193,.3), 0 0 0 1px rgba(255,255,255,.08); }
  to   { box-shadow: 0 0 80px rgba(58,127,193,.65), 0 0 0 1px rgba(255,255,255,.14); }
}

/* ============================================================
   TOP NAVIGATION — DESKTOP
   ============================================================ */
#topnav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--nav-h);
  background: var(--navy-800);
  display: flex; align-items: center;
  padding: 0 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,.3);
}

/* Brand */
.nav-brand {
  display: flex; align-items: center; gap: 10px;
  margin-right: 20px; flex-shrink: 0; text-decoration: none;
}
.nav-brand-logo {
  width: 36px; height: 36px; border-radius: 7px;
  background: #fff; overflow: hidden; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; padding: 3px;
}
.nav-brand-logo img { width: 100%; height: 100%; object-fit: contain; }
.nav-brand-text {
  font-size: .92rem; font-weight: 800; letter-spacing: .12em; color: #fff;
  white-space: nowrap;
}
.nav-brand-text em { color: var(--gold-500); font-style: normal; }

/* Desktop links */
.nav-links {
  display: flex; align-items: center; gap: 2px;
  flex: 1; overflow: hidden;
}
.nav-link {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: var(--radius-sm);
  color: var(--navy-200); font-size: .82rem; font-weight: 500;
  letter-spacing: .02em; white-space: nowrap;
  transition: background .18s, color .18s;
  border-bottom: 2px solid transparent;
}
.nav-link:hover  { background: var(--navy-700); color: #fff; }
.nav-link.active { background: var(--navy-700); color: #fff; border-bottom-color: var(--green-400); }
.nav-link svg    { width: 15px; height: 15px; flex-shrink: 0; }

/* Desktop install button */
.nav-install {
  display: inline-flex; align-items: center; gap: 7px;
  margin-left: 12px; flex-shrink: 0;
  padding: 7px 16px; border-radius: var(--radius-sm);
  background: var(--gold-500); color: var(--navy-800);
  font-size: .82rem; font-weight: 700; letter-spacing: .04em;
  white-space: nowrap; border: none; cursor: pointer;
  animation: install-pulse 2.8s ease-in-out infinite;
  transition: background .18s, transform .15s, box-shadow .18s, opacity .18s;
}
.nav-install:hover {
  background: var(--gold-400); transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(245,185,62,.45); animation: none;
}
.nav-install:active { transform: translateY(0); }
.nav-install svg { width: 14px; height: 14px; }
.nav-install[hidden] { display: none !important; }

@keyframes install-pulse {
  0%, 100% { box-shadow: 0 0 0 0   rgba(245,185,62,.45); }
  50%       { box-shadow: 0 0 0 8px rgba(245,185,62,.0);  }
}

/* Hamburger button — mobile only */
.nav-hamburger {
  display: none;
  flex-direction: column; justify-content: center; align-items: center;
  gap: 5px; width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  margin-left: auto; flex-shrink: 0;
  background: transparent; border: none; cursor: pointer;
  transition: background .18s;
}
.nav-hamburger:hover { background: var(--navy-700); }
.nav-hamburger span {
  display: block; width: 22px; height: 2px;
  background: #fff; border-radius: 99px;
  transition: transform .28s cubic-bezier(.4,0,.2,1), opacity .28s;
  transform-origin: center;
}
/* X state */
.nav-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger.open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.nav-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ============================================================
   MOBILE DRAWER
   ============================================================ */
.nav-overlay {
  display: block;
  position: fixed; inset: 0; z-index: 290;
  background: rgba(14,29,58,.55);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .28s ease;
}
.nav-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.nav-drawer {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--drawer-w); z-index: 300;
  background: var(--navy-900);
  display: flex; flex-direction: column;
  transform: translateX(calc(-1 * var(--drawer-w)));
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  box-shadow: 4px 0 24px rgba(0,0,0,.4);
}
.nav-drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.drawer-logo {
  width: 44px; height: 44px; border-radius: 10px;
  background: #fff; padding: 4px; object-fit: contain; flex-shrink: 0;
}
.drawer-title {
  font-size: 1rem; font-weight: 800; letter-spacing: .12em; color: #fff;
}
.drawer-title em { color: var(--gold-500); font-style: normal; }

.drawer-links {
  flex: 1; overflow-y: auto; padding: 12px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.drawer-link {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  color: var(--navy-200); font-size: .9rem; font-weight: 500;
  transition: background .18s, color .18s;
  border-left: 3px solid transparent;
}
.drawer-link:hover  { background: var(--navy-800); color: #fff; }
.drawer-link.active {
  background: var(--navy-700); color: #fff;
  border-left-color: var(--green-400);
}
.drawer-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.drawer-footer {
  padding: 16px 10px 24px;
  border-top: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.drawer-install-btn {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  padding: 13px 18px; border-radius: var(--radius-sm);
  background: var(--gold-500); color: var(--navy-800);
  font-size: .9rem; font-weight: 700; letter-spacing: .04em;
  border: none; cursor: pointer;
  animation: install-pulse 2.8s ease-in-out infinite;
  transition: background .18s, box-shadow .18s;
}
.drawer-install-btn:hover {
  background: var(--gold-400); animation: none;
  box-shadow: 0 4px 14px rgba(245,185,62,.4);
}
.drawer-install-btn svg { width: 18px; height: 18px; }
.drawer-install-btn[hidden] { display: none !important; }

/* ============================================================
   PAGE LAYOUT
   ============================================================ */
#app { padding-top: var(--nav-h); min-height: 100dvh; }

.page {
  display: none; min-height: calc(100dvh - var(--nav-h));
  padding: 32px 24px; max-width: 1280px; margin: 0 auto;
  animation: fade-in .25s ease;
}
.page.active { display: block; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

.page-header { margin-bottom: 28px; }
.page-title {
  font-size: 1.5rem; font-weight: 700; color: var(--navy-800);
  letter-spacing: -.01em; line-height: 1.2;
}
.page-subtitle { font-size: .87rem; color: var(--text-secondary); margin-top: 4px; }

/* ---------- Card ---------- */
.card {
  background: var(--surface); border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm); padding: 24px;
}

/* ============================================================
   MAPPING PAGE
   ============================================================ */
.mapping-toolbar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.search-box { flex: 1; min-width: 200px; position: relative; }
.search-box input {
  width: 100%; padding: 9px 12px 9px 38px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-primary); font-size: .875rem;
  transition: border-color .18s, box-shadow .18s;
}
.search-box input:focus {
  outline: none; border-color: var(--navy-400);
  box-shadow: 0 0 0 3px rgba(58,127,193,.15);
}
.search-box svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; stroke: var(--text-muted); pointer-events: none;
}
.mapping-meta { font-size: .8rem; color: var(--text-muted); white-space: nowrap; }

.table-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border-light); }
.data-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.data-table thead th {
  background: var(--navy-800); color: var(--navy-100);
  padding: 11px 14px; text-align: left; font-weight: 600;
  font-size: .78rem; letter-spacing: .06em; text-transform: uppercase;
  white-space: nowrap; cursor: pointer; user-select: none;
  transition: background .15s;
}
.data-table thead th:hover { background: var(--navy-700); }
.data-table thead th .sort-icon { display: inline-block; margin-left: 5px; opacity: .45; font-style: normal; }
.data-table thead th.asc  .sort-icon::after { content: ' ↑'; opacity: 1; }
.data-table thead th.desc .sort-icon::after { content: ' ↓'; opacity: 1; }
.data-table thead th:not(.asc):not(.desc) .sort-icon::after { content: ' ↕'; }
.data-table tbody tr { border-bottom: 1px solid var(--border-light); transition: background .12s; }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--navy-50); }
.data-table tbody td { padding: 10px 14px; color: var(--text-primary); }
.table-empty { text-align: center; padding: 48px 24px; color: var(--text-muted); font-size: .9rem; }

/* ============================================================
   REPORTS / TOOLKIT
   ============================================================ */
.nc-toolbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: .84rem; font-weight: 600; transition: all .18s; cursor: pointer;
}
.btn-primary { background: var(--navy-600); color: #fff; border: none; }
.btn-primary:hover { background: var(--navy-500); box-shadow: var(--shadow-sm); }
.btn-ghost { background: transparent; color: var(--navy-600); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--navy-50); border-color: var(--navy-400); }
.btn svg { width: 15px; height: 15px; }

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}
.file-card {
  background: var(--surface); border: 1px solid var(--border-light);
  border-radius: var(--radius-md); padding: 20px 14px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  cursor: pointer; transition: all .2s; text-align: center;
}
.file-card:hover { border-color: var(--navy-400); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.file-card.folder { background: var(--green-50); border-color: var(--green-200); }
.file-card.folder:hover { border-color: var(--green-500); }
.file-icon { font-size: 2.2rem; line-height: 1; }
.file-name { font-size: .78rem; font-weight: 500; color: var(--text-primary); word-break: break-word; line-height: 1.3; }
.file-size { font-size: .7rem; color: var(--text-muted); }
.file-dl-hint {
  font-size: .68rem; color: var(--navy-400); font-weight: 600;
  opacity: 0; transition: opacity .18s;
  letter-spacing: .03em;
}
.file-card:hover .file-dl-hint { opacity: 1; }
.file-card.file { cursor: pointer; }
.file-card.file:hover { background: var(--navy-50); }

.nc-loader, .nc-empty, .nc-error {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 64px 24px; gap: 12px; color: var(--text-muted); font-size: .9rem;
}
.nc-error { color: var(--red-500); }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border); border-top-color: var(--navy-500);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.breadcrumb { display: flex; align-items: center; gap: 4px; font-size: .82rem; flex-wrap: wrap; flex: 1; }
.breadcrumb-item { color: var(--navy-500); cursor: pointer; }
.breadcrumb-item:hover { text-decoration: underline; }
.breadcrumb-sep { color: var(--text-muted); }
.breadcrumb-item.current { color: var(--text-primary); cursor: default; font-weight: 500; }
.breadcrumb-item.current:hover { text-decoration: none; }

/* ============================================================
   ANALYTICS TOOLS
   ============================================================ */
.analytics-layout {
  display: grid; grid-template-columns: 1fr 340px;
  gap: 24px; align-items: start;
}
@media (max-width: 900px) { .analytics-layout { grid-template-columns: 1fr; } }

.radar-title { font-size: .8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 16px; letter-spacing: .06em; text-transform: uppercase; }
.radar-wrap { width: 100%; aspect-ratio: 1/1; max-width: 420px; margin: 0 auto; }
#radarCanvas { width: 100%; height: 100%; }

.score-badge {
  background: linear-gradient(135deg, var(--navy-800), var(--navy-600));
  color: #fff; border-radius: var(--radius-md); padding: 18px 20px;
  text-align: center; margin-top: 20px;
}
.score-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; color: var(--navy-200); }
.score-value { font-size: 3rem; font-weight: 800; letter-spacing: -.02em; line-height: 1; margin: 6px 0 2px; }
.score-max { font-size: .8rem; color: var(--navy-300); }
.score-bar-track { margin-top: 12px; height: 6px; background: var(--navy-700); border-radius: 99px; overflow: hidden; }
.score-bar-fill { height: 100%; background: linear-gradient(90deg, var(--green-500), var(--gold-500)); border-radius: 99px; transition: width .4s ease; }

.params-card .card-title { font-size: .8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 20px; letter-spacing: .06em; text-transform: uppercase; }
.param-row { margin-bottom: 18px; }
.param-label { font-size: .82rem; font-weight: 600; color: var(--text-primary); margin-bottom: 8px; display: flex; justify-content: space-between; }
.param-label span.param-val { font-size: .88rem; font-weight: 700; color: var(--navy-500); min-width: 30px; text-align: right; }
.param-controls { display: flex; align-items: center; gap: 10px; }
.param-slider {
  flex: 1; -webkit-appearance: none; appearance: none; height: 5px; border-radius: 99px;
  background: linear-gradient(90deg, var(--navy-500) 0%, var(--navy-500) var(--pct,50%), var(--border) var(--pct,50%), var(--border) 100%);
  cursor: pointer; outline: none;
}
.param-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--navy-600); border: 2px solid #fff; box-shadow: var(--shadow-sm);
  cursor: pointer; transition: background .15s;
}
.param-slider::-webkit-slider-thumb:hover { background: var(--navy-400); }
.param-slider::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--navy-600); border: 2px solid #fff; box-shadow: var(--shadow-sm);
}
.param-number {
  width: 56px; padding: 5px 8px; text-align: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: .85rem; font-weight: 600; color: var(--navy-800); transition: border-color .18s;
}
.param-number:focus { outline: none; border-color: var(--navy-400); box-shadow: 0 0 0 3px rgba(58,127,193,.15); }

/* ============================================================
   DASHBOARD EMPTY
   ============================================================ */
.dashboard-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 50vh; gap: 14px; color: var(--text-muted);
}
.dashboard-empty svg { width: 56px; height: 56px; stroke: var(--navy-200); }
.dashboard-empty p { font-size: .95rem; }

/* ============================================================
   RESPONSIVE — MOBILE
   ============================================================ */
@media (max-width: 768px) {
  /* Hide desktop links and install btn, show hamburger */
  .nav-links     { display: none !important; }
  .nav-install   { display: none !important; }
  .nav-hamburger { display: flex; }
  /* Prevent body scroll when drawer open */
  body.drawer-open { overflow: hidden; }

  .page { padding: 20px 14px; }
  .page-title { font-size: 1.2rem; }
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--navy-200); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--navy-300); }
