/* ══════════════════════════════════════════════════════════════
   HANSA Assets — Investment Planning Dashboard
   Design System: Mantine UI 7.x tokens
   ══════════════════════════════════════════════════════════════ */

/* ── Mantine tokens ─────────────────────────────────────────── */
:root {
  --blue:      #228be6;
  --blue-h:    #1c7ed6;
  --blue-0:    #e7f5ff;
  --blue-1:    #d0ebff;
  --blue-lt:   rgba(34,139,230,.1);
  --gray-0:    #f8f9fa;
  --gray-1:    #f1f3f5;
  --gray-2:    #e9ecef;
  --gray-3:    #dee2e6;
  --gray-4:    #ced4da;
  --gray-5:    #adb5bd;
  --gray-6:    #868e96;
  --gray-7:    #495057;
  --gray-8:    #343a40;
  --gray-9:    #212529;
  --white:     #ffffff;
  --body-bg:   #f8f9fa;
  --text:      #212529;
  --text-dim:  #495057;
  --text-muted:#868e96;
  --border:    #dee2e6;
  --radius:    4px;
  --radius-sm: 2px;
  --radius-md: 8px;
  --shadow-xs: 0 1px 3px rgba(0,0,0,.05),0 1px 2px rgba(0,0,0,.1);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.05),rgba(0,0,0,.05) 0 10px 15px -5px,rgba(0,0,0,.04) 0 7px 7px -5px;
  --font:      -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
  --font-mono: ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,'Liberation Mono','Courier New',monospace;
  --nav-w:     220px;
  --hdr-h:     56px;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.55;
       background: var(--body-bg); color: var(--text);
       -webkit-font-smoothing: antialiased; }

/* ── Shell ──────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr;
         grid-template-rows: var(--hdr-h) 1fr; min-height: 100vh; }

/* ── Header ─────────────────────────────────────────────────── */
.hdr {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  height: var(--hdr-h);
  position: sticky; top: 0; z-index: 100;
}
.hdr-left { display: flex; align-items: center; gap: 10px; }
.hdr-icon { width: 24px; height: 24px; opacity: .75; }
.hdr-title { font-size: 20px; font-weight: 700; color: var(--gray-9); letter-spacing: -.3px; }
.hdr-right { display: flex; align-items: center; gap: 10px; }
.logo-jedco { height: 24px; width: auto; }
.logo-daco  { height: 22px; width: auto; }
.logo-thc   { height: 20px; width: auto; }
.hdr-sep { width: 1px; height: 20px; background: var(--border); margin: 0 2px; }
.hdr-av {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; font-family: var(--font);
}

/* ── Nav ─────────────────────────────────────────────────────── */
.nav {
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto; overflow-x: hidden;
  position: sticky; top: var(--hdr-h);
  height: calc(100vh - var(--hdr-h));
}
.nav-scroll { flex: 1; overflow-y: auto; padding: 8px 0; }

/* User block */
.nav-user { padding: 12px 12px 10px; border-bottom: 1px solid var(--border); }
.nav-user-row { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.nav-av {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; flex-shrink: 0;
}
.nav-uname { font-size: 13px; font-weight: 600; color: var(--gray-9); }
.nav-badge {
  font-size: 9px; font-weight: 700; letter-spacing: .08em;
  background: var(--blue); color: #fff;
  padding: 1px 5px; border-radius: 3px;
}
.nav-email { font-size: 11px; color: var(--text-muted); margin-bottom: 8px;
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-btn {
  width: 100%; padding: 5px 10px; border-radius: var(--radius);
  font-family: var(--font); font-size: 12px; font-weight: 500;
  cursor: pointer; transition: background .1s, border-color .1s;
}
.nav-btn-outline {
  background: transparent; color: var(--blue);
  border: 1px solid var(--blue);
  margin-bottom: 6px;
}
.nav-btn-outline:hover { background: var(--blue-0); }
.nav-btn-filled {
  background: var(--blue); color: #fff; border: 1px solid var(--blue);
}
.nav-btn-filled:hover { background: var(--blue-h); }

/* Airport switcher */
.airport-switcher {
  padding: 8px 12px 6px;
  border-bottom: 1px solid var(--border);
}
.switcher-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-muted); margin-bottom: 6px;
}
.switcher-btns { display: flex; gap: 6px; }
.switcher-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 6px 4px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--white);
  cursor: pointer; transition: all .15s; font-family: var(--font);
}
.switcher-btn:hover { border-color: var(--blue); background: var(--blue-0); }
.switcher-btn.active { border-color: var(--blue); background: var(--blue); }
.sw-code { font-size: 12px; font-weight: 800; color: var(--gray-8); line-height: 1; }
.sw-name { font-size: 9px; color: var(--text-muted); margin-top: 2px; }
.switcher-btn.active .sw-code,
.switcher-btn.active .sw-name { color: rgba(255,255,255,.9); }

/* Nav items */
.ni {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 14px;
  font-family: var(--font); font-size: 13.5px; font-weight: 500;
  color: var(--text-dim); background: none; border: none; cursor: pointer;
  text-decoration: none; text-align: left; transition: background .1s, color .1s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ni:hover { background: var(--gray-0); color: var(--gray-9); }
.ni[data-active] { color: var(--blue); }

.ni-ic { width: 18px; display: flex; align-items: center; justify-content: center;
          flex-shrink: 0; color: inherit; }
.ni-lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.ni-chv { width: 14px; height: 14px; flex-shrink: 0; color: var(--text-muted);
           transition: transform .2s; }
.ni-grp.open > button > .ni-chv { transform: rotate(180deg); }

.ni-kids { display: none; }
.ni-grp.open > .ni-kids { display: block; }

/* Child nav items — indented, with left blue border on active */
.ni-child {
  display: block; width: 100%;
  padding: 7px 14px 7px 42px;
  font-family: var(--font); font-size: 13px; font-weight: 400;
  color: var(--text-dim); background: none; border: none; cursor: pointer;
  text-align: left; text-decoration: none;
  transition: background .1s, color .1s;
  position: relative;
}
.ni-child:hover { background: var(--gray-0); color: var(--gray-9); }
.ni-child[data-active] {
  color: var(--blue); font-weight: 500;
  background: var(--blue-0);
  border-left: 2px solid var(--blue);
  padding-left: 40px;
}

.badge-pro {
  font-size: 9px; font-weight: 700; background: var(--blue-0);
  color: var(--blue); padding: 1px 4px; border-radius: 3px;
  border: 1px solid var(--blue-1); margin-left: 4px;
}

/* Nav footer */
.nav-footer {
  padding: 10px 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--white);
}
.refresh-btn {
  width: 100%; padding: 7px; border-radius: var(--radius);
  font-family: var(--font); font-size: 12px; font-weight: 500;
  color: var(--gray-7); background: var(--gray-1);
  border: 1px solid var(--border); cursor: pointer; margin-bottom: 8px;
}
.refresh-btn:hover { background: var(--gray-2); }

.theme-row { display: flex; gap: 4px; margin-bottom: 10px; }
.theme-btn {
  flex: 1; padding: 4px 0; border-radius: var(--radius);
  font-family: var(--font); font-size: 11px; font-weight: 500;
  color: var(--gray-6); background: var(--gray-1);
  border: 1px solid var(--border); cursor: pointer;
}
.theme-btn:hover { color: var(--gray-9); background: var(--gray-2); }

.conn-row { display: flex; align-items: flex-start; gap: 8px; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: #40c057;
             margin-top: 4px; flex-shrink: 0; }
.conn-row > div { font-size: 11px; font-weight: 600; color: #40c057; }
.conn-sub { font-size: 10px; color: var(--text-muted); font-weight: 400; margin-top: 1px; }

/* ── Main ────────────────────────────────────────────────────── */
.main {
  padding: 0;
  overflow: hidden;
  background: var(--body-bg);
}
.pg { height: calc(100vh - var(--hdr-h)); overflow-y: auto; padding: 20px 24px; }
.pg-hdr {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 20px; gap: 16px; flex-wrap: wrap;
}
.pg-title { font-size: 20px; font-weight: 700; color: var(--gray-9); }
.pg-hdr-r { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Badges */
.bdg { display: flex; align-items: center; gap: 6px;
       padding: 4px 10px; border-radius: 20px;
       font-size: 11.5px; font-weight: 500; white-space: nowrap; }
.bdg-blue { background: var(--blue-0); color: var(--blue); border: 1px solid #a5d8ff; }
.bdg-gray { background: var(--gray-1); color: var(--gray-6); border: 1px solid var(--border); }
.bdg-dot { width: 6px; height: 6px; border-radius: 50%; background: #40c057; }

/* ── KPI Cards ───────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-xs);
  border-top: 3px solid transparent;
}
.kpi.t0 { border-top-color: #40c057; }
.kpi.t1 { border-top-color: var(--blue); }
.kpi.t2 { border-top-color: #f59f00; }
.kpi.t3 { border-top-color: #7950f2; }
.kpi-lbl { font-size: 11px; font-weight: 600; text-transform: uppercase;
            letter-spacing: .08em; color: var(--text-muted); margin-bottom: 6px; }
.kpi-val { font-size: 26px; font-weight: 700; color: var(--gray-9);
            line-height: 1.1; margin-bottom: 4px; }
.kpi-val sup { font-size: 12px; font-weight: 500; color: var(--text-muted); margin-left: 2px; }
.kpi-sub { font-size: 11.5px; color: var(--text-muted); }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  margin-bottom: 16px;
}
.card-hdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
}
.card-hdr-dk { background: #1c2733; }
.card-hdr-dk .ctitle { color: #fff; }
.card-hdr-dk .csub { color: rgba(255,255,255,.55); }
.ctitle { font-size: 13.5px; font-weight: 600; color: var(--gray-9); }
.csub { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }

/* ── Two-col layout ──────────────────────────────────────────── */
.two-col { display: grid; grid-template-columns: 1fr 400px; gap: 12px; margin-bottom: 16px; }

/* ── Chart ───────────────────────────────────────────────────── */
.chart-pad { padding: 12px 16px 8px; }
.chart-box { height: 280px; position: relative; }
.leg-row { display: flex; flex-wrap: wrap; gap: 6px;
           padding: 4px 16px 12px; }
.leg-it {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--text-dim);
  padding: 2px 7px 2px 4px; border-radius: 3px;
  cursor: pointer; transition: background .1s;
}
.leg-it:hover { background: var(--gray-1); }
.leg-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

/* ── WPS Panel ───────────────────────────────────────────────── */
.wps-hdr {
  display: grid; grid-template-columns: 48px 90px 80px 1fr;
  gap: 0; padding: 6px 12px;
  background: var(--gray-1); border-bottom: 1px solid var(--border);
}
.wch { font-size: 10px; font-weight: 700; text-transform: uppercase;
       letter-spacing: .07em; color: var(--text-muted); }
.wch.c { text-align: center; }
.wch.r { text-align: right; padding-right: 8px; }
.wps-row {
  display: grid; grid-template-columns: 48px 90px 80px 1fr;
  align-items: center; border-bottom: 1px solid var(--gray-1);
}
.wps-row:last-child { border-bottom: none; }
.wc { font-size: 11.5px; color: var(--text-dim); padding: 5px 0; }
.wc.yr { color: #fff; font-size: 11px; font-weight: 700;
          display: flex; align-items: center; justify-content: center; height: 100%; }
.wc.wv { text-align: center; font-size: 10px; font-weight: 600;
          color: var(--gray-7); line-height: 1.4; }
.wc.bv { text-align: right; font-size: 11.5px; font-weight: 600;
          padding-right: 8px; cursor: pointer; color: var(--gray-8); }
.wc.bv:hover { color: var(--blue); text-decoration: underline; }
.wc.rt { font-size: 10.5px; color: var(--text-muted); padding: 5px 8px; line-height: 1.35; }

/* ── AIP Table ───────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; }
table.aip {
  width: 100%; border-collapse: collapse;
  font-size: 12.5px; color: var(--text-dim);
}
table.aip thead th {
  padding: 8px 10px; text-align: right;
  font-size: 11px; font-weight: 700;
  color: var(--text-muted); background: var(--gray-0);
  border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0;
  user-select: none;
}
table.aip thead th:first-child { text-align: left; }
table.aip thead th.r { text-align: right; }

/* Row levels */
table.aip tr.l0 { cursor: pointer; background: var(--white); }
table.aip tr.l0:hover { background: var(--gray-0); }
table.aip tr.l0 td { padding: 7px 10px; border-bottom: 1px solid var(--gray-1); }
table.aip tr.l0 td:first-child { font-weight: 600; }

table.aip tr.l1 { background: var(--white); cursor: pointer; }
table.aip tr.l1:hover { background: #f0f7ff; }
table.aip tr.l1 td { padding: 5px 10px; border-bottom: 1px solid var(--gray-1);
                       font-size: 12px; }

table.aip tr.l2 { background: var(--white); cursor: pointer; }
table.aip tr.l2:hover { background: var(--gray-0); }
table.aip tr.l2 td { padding: 4px 10px; border-bottom: 1px solid var(--gray-1);
                       font-size: 11.5px; }

table.aip tr.l3 td { padding: 4px 10px; border-bottom: 1px solid var(--gray-1);
                       font-size: 11px; background: var(--gray-0); }

table.aip tr.tot td {
  padding: 8px 10px; background: #1c2733; color: #fff;
  font-size: 12.5px; font-weight: 700;
}
table.aip td.m { text-align: right; }
.cs { cursor: pointer; border-radius: 3px; padding: 1px 4px; font-size: 12px;
       transition: background .12s; }
.cs:hover { background: var(--blue-0); color: var(--blue); }

/* Expand button */
.xb {
  width: 18px; height: 18px; border-radius: var(--radius-sm);
  background: none; border: 1px solid var(--border);
  color: var(--text-muted); font-size: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; margin-right: 8px; transition: all .15s;
  flex-shrink: 0; line-height: 1;
}
.xb:hover { background: var(--gray-1); border-color: var(--gray-4); }
.xb.o { background: var(--blue); border-color: var(--blue); color: #fff; transform: rotate(90deg); }

/* Facility row arrow */
.fac-arr { font-size: 10px; color: var(--text-muted); margin-right: 4px; }
.fac-lnk { font-size: 12px; font-weight: 500; color: var(--gray-7); }

/* SG badges */
.sg {
  display: inline-flex; align-items: center;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 3px;
  white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}

/* ── Drill overlay ───────────────────────────────────────────── */
.drill {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.45);
  display: none; align-items: stretch;
}
.drill.open { display: flex; }

.drill-bar {
  position: fixed; top: 0; left: 0; right: 0;
  background: #1c2733;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; height: 52px; z-index: 201;
}
.d-back {
  display: flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.15);
  color: rgba(255,255,255,.85); padding: 4px 10px;
  border-radius: var(--radius); font-size: 12.5px; font-weight: 500;
  cursor: pointer; font-family: var(--font);
}
.d-back:hover { background: rgba(255,255,255,.18); }
.d-center { flex: 1; }
.d-title { font-size: 14px; font-weight: 700; color: #fff; }
.d-meta  { font-size: 11.5px; color: rgba(255,255,255,.55); margin-top: 1px; }
.d-srch {
  padding: 6px 12px; border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.08); color: #fff;
  font-family: var(--font); font-size: 12.5px; width: 220px;
}
.d-srch::placeholder { color: rgba(255,255,255,.4); }
.d-srch:focus { outline: none; border-color: var(--blue); background: rgba(255,255,255,.12); }
.d-body {
  position: fixed; top: 52px; left: 0; right: 0; bottom: 0;
  overflow-y: auto; background: var(--white);
  padding-bottom: 24px;
}

/* Drill table */
table.d-tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.d-tbl th {
  padding: 8px 12px; text-align: left;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); background: var(--gray-0);
  border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none; white-space: nowrap;
  position: sticky; top: 0;
}
table.d-tbl th:hover { background: var(--gray-1); color: var(--gray-8); }
/* Dark header row — used in BC Builder asset table */
table.d-tbl thead tr[style*="17375E"] th,
table.d-tbl tr[style*="17375E"] th {
  color: #fff !important;
  background: #17375E !important;
}
table.d-tbl thead tr[style*="17375E"] th:hover {
  background: #1e4a7a !important;
}
table.d-tbl td {
  padding: 8px 12px; border-bottom: 1px solid var(--gray-1);
  vertical-align: middle; color: var(--text-dim);
}
table.d-tbl tr:hover td { background: var(--gray-0); }
table.d-tbl tfoot td {
  padding: 8px 12px; background: var(--gray-0);
  font-size: 12px; color: var(--text-muted); border-top: 1px solid var(--border);
}
.c-num { text-align: right; font-family: var(--font-mono); font-size: 12px; }
.c-sm  { font-size: 11.5px; color: var(--text-muted); }

/* Asset link */
.a-lnk { color: var(--blue); text-decoration: none; font-weight: 500;
           display: inline-flex; align-items: center; gap: 3px; }
.a-lnk:hover { text-decoration: underline; }
.a-ext { font-size: 10px; opacity: .6; }

/* ── Warn box ────────────────────────────────────────────────── */
.warn {
  display: flex; align-items: flex-start; gap: 10px;
  background: #fff9db; border: 1px solid #ffe066;
  border-radius: var(--radius-md); padding: 12px 14px;
  font-size: 12.5px; color: #5c4a00; margin-bottom: 16px;
}

/* ── BC rows ─────────────────────────────────────────────────── */
.bc-row:hover td { background: var(--gray-0) !important; }

/* ── Loading ─────────────────────────────────────────────────── */
.load-st {
  display: flex; align-items: center; gap: 12px; justify-content: center;
  padding: 60px; color: var(--text-muted); font-size: 14px;
}
.spin {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--blue);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --nav-w: 56px; }
  .ni-lbl, .ni-chv, .ni-kids, .nav-user, .nav-footer { display: none; }
  .ni-ic { width: 100%; justify-content: center; }
  .ni { justify-content: center; padding: 12px 0; }
}

/* ── Builder ─────────────────────────────────────────────────────────── */
.builder-bc-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}
.builder-bc-item:hover { background: var(--blue-0); }
.builder-bc-item.active { background: var(--blue); }
.builder-bc-item.active * { color: rgba(255,255,255,.9) !important; }

.builder-tab {
  padding: 9px 16px;
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.builder-tab:hover { color: var(--blue); background: var(--blue-0); }
.builder-tab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; background: #fff; }

@media print {
  .nav, .hdr, .pg-hdr, .builder-tab, .builder-bc-item { display: none !important; }
  .main { grid-column: 1 / -1; }
}
