/* ============================================================
   WinD Income — global UI (light only, "ocean-deep" palette).
   Shell + dashboard + management pages. Kept in sync with
   Theme/WinDTheme.cs (MudBlazor palette).
   ============================================================ */

:root {
  --wind-font: "Roboto", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}

html, body { height: 100%; }
body {
  margin: 0;
  background: #e8ecf3;
  font-family: var(--wind-font);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Tokens (global so overlay dialogs can use them too) ---------- */
:root {
  --accent:#234f8f; --accent-strong:#173657; --accent-soft:#e5ecf5; --accent-contrast:#ffffff;
  --bg:#e8ecf3; --surface:#ffffff; --surface-2:#eef2f8; --border:#d9e0ea;
  --ink:#15202f; --ink-muted:#53617a; --ink-faint:#8792a5; --ring:#234f8f55;
  --c1:#234f8f; --c2:#5a8ac6; --c3:#d99a3c; --c4:#7f8ca0;

  --good:#128a5b; --good-soft:#e4f1ea;
  --warn:#b9720a; --warn-soft:#f8eeda;
  --bad:#c73f3f;  --bad-soft:#f7e6e6;

  /* dark sidebar */
  --side-bg:#17253d; --side-ink:#eaf0f8; --side-muted:#9fb0ca; --side-faint:#74839e;
  --side-border:#28384f; --side-active:#243855; --side-accent:#6fa1db;

  --r-sm:9px; --r:13px; --r-lg:18px; --r-pill:999px;
  --shadow-sm: 0 1px 2px rgba(20,30,50,.06), 0 1px 3px rgba(20,30,50,.05);
  --shadow-md: 0 8px 24px -8px rgba(20,30,50,.18), 0 2px 6px rgba(20,30,50,.06);

  --sidebar-w:246px; --sidebar-w-collapsed:76px;
}

.wind-app {
  color: var(--ink);
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  transition: grid-template-columns .22s ease;
  line-height: 1.45;
}
.wind-app.collapsed { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }
@media (prefers-reduced-motion: reduce) { .wind-app, .wind-app * { transition: none !important; } }

.wind-app *, .wind-app *::before, .wind-app *::after { box-sizing: border-box; }

/* ---------- Sidebar ---------- */
.side {
  background: var(--side-bg); color: var(--side-ink);
  border-right: 1px solid var(--side-border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: 18px 14px; gap: 6px; overflow: hidden;
  transition: transform .24s ease;
}
.nav-backdrop { display: none; }
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 6px 8px 16px; margin-bottom: 6px;
  border-bottom: 1px solid var(--side-border); white-space: nowrap;
}
.brand-mark {
  flex: none; width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(140deg, var(--accent), var(--accent-strong));
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 17px;
  box-shadow: var(--shadow-sm);
}
.brand-name { font-weight: 750; font-size: 1.02rem; letter-spacing: -.01em; }
.brand-sub { font-size: .72rem; color: var(--side-faint); font-weight: 500; margin-top: -2px; }
.wind-app.collapsed .brand-text { display: none; }
.wind-app.collapsed .brand { justify-content: center; padding: 6px 0 16px; }

.wind-nav { display: flex; flex-direction: column; gap: 3px; }
.nav-label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--side-faint); font-weight: 650; padding: 12px 12px 5px;
}
.wind-app.collapsed .nav-label { opacity: 0; }

.nav-item {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--r-sm);
  color: var(--side-muted); font-weight: 550; font-size: .925rem;
  cursor: pointer; white-space: nowrap; border: 1px solid transparent; text-decoration: none;
}
.nav-item:hover { background: color-mix(in srgb, var(--side-ink) 10%, transparent); color: var(--side-ink); }
.nav-item.active { background: var(--side-active); color: var(--side-ink); font-weight: 650; }
.nav-item.active::before {
  content: ""; position: absolute; left: 2px; top: 9px; bottom: 9px;
  width: 3px; border-radius: 3px; background: var(--side-accent);
}
.nav-item .ic { flex: none; width: 20px; height: 20px; stroke-width: 1.9; }
.wind-app.collapsed .nav-item { justify-content: center; padding: 10px 0; }
.wind-app.collapsed .nav-item .lbl { display: none; }

.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--side-border); }
.user-chip { display: flex; align-items: center; gap: 11px; padding: 8px; border-radius: var(--r-sm); white-space: nowrap; }
.side .avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  background: var(--side-active); color: var(--side-ink);
  display: grid; place-items: center; font-weight: 700; font-size: .85rem;
}
.user-name { font-size: .86rem; font-weight: 650; color: var(--side-ink); }
.user-role { font-size: .72rem; color: var(--side-faint); }
.wind-app.collapsed .user-text { display: none; }
.wind-app.collapsed .user-chip { justify-content: center; padding: 8px 0; }

/* ---------- Main / topbar ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(9px);
  border-bottom: 1px solid var(--border);
}
.icon-btn {
  flex: none; width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-muted);
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { color: var(--ink); background: var(--surface-2); }
.page-title { font-size: 1.18rem; font-weight: 720; letter-spacing: -.02em; }
.page-crumb { font-size: .76rem; color: var(--ink-faint); font-weight: 500; }
.spacer { flex: 1; }
.logout-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 10px; text-decoration: none;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--ink-muted); font-weight: 600; font-size: .85rem;
}
.logout-btn:hover { color: var(--ink); background: var(--surface-2); }

.content {
  padding: 22px 28px 44px; display: flex; flex-direction: column; gap: 20px; width: 100%;
  /* clamp sideways overflow (hidden info popups, chart edges) so phones can't pan the page horizontally */
  overflow-x: clip;
}

/* ---------- Filters ---------- */
.filterbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.range-chip {
  display: inline-flex; align-items: center; gap: 9px; padding: 8px 14px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  font-size: .86rem; font-weight: 600; color: var(--ink);
}
.range-chip svg { color: var(--accent); }
.filter-right { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filter-right .lab { font-size: .8rem; color: var(--ink-muted); font-weight: 600; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-pill); padding: 3px; }
.seg button {
  border: 0; background: transparent; cursor: pointer; font: inherit;
  padding: 6px 15px; border-radius: var(--r-pill); font-size: .83rem; font-weight: 600; color: var(--ink-muted);
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.seg.wrap { flex-wrap: wrap; }

/* year dropdown in the filter bar */
.ysel {
  appearance: none; -webkit-appearance: none; font: inherit; font-size: .83rem; font-weight: 600; color: var(--ink);
  background: var(--surface) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7684' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 34px 7px 16px; cursor: pointer; outline: none; box-shadow: var(--shadow-sm);
  transition: border-color .12s ease, background-color .12s ease;
}
.ysel:hover { background-color: var(--surface-2); }
.ysel:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

/* custom year dropdown: the OPTIONS PANEL itself is rounded (native <select> popups can't be styled) */
.ydd { position: relative; }
.ydd-backdrop { position: fixed; inset: 0; z-index: 79; }
.ydd-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 80;
  min-width: 150px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-md);
  display: flex; flex-direction: column; gap: 2px;
}
.ydd-item {
  border: 0; background: transparent; cursor: pointer; font: inherit;
  text-align: left; padding: 8px 12px; border-radius: 9px;
  font-size: .85rem; font-weight: 600; color: var(--ink-muted);
}
.ydd-item:hover { background: var(--surface-2); color: var(--ink); }
.ydd-item.on { background: var(--accent-soft); color: var(--accent-strong); }

.chipbar { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: var(--r-pill);
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-muted);
  font-size: .8rem; font-weight: 600; cursor: pointer; font-family: inherit;
}
.chip:hover { background: var(--surface-2); color: var(--ink); }
.chip.on { background: var(--accent-soft); color: var(--accent-strong); border-color: color-mix(in srgb, var(--accent) 22%, transparent); }
.chip .bbadge { width: 9px; height: 9px; border-radius: 3px; }

/* ---------- Cards / panels ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.panel { padding: 18px 20px 20px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.panel-title { font-size: 1rem; font-weight: 680; letter-spacing: -.01em; }
.panel-sub { font-size: .78rem; color: var(--ink-faint); font-weight: 500; }

/* Info tooltip on panels */
.info { position: relative; display: inline-flex; align-items: center; margin-left: 7px; vertical-align: middle; outline: none; }
.info-i {
  width: 19px; height: 19px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 800; font-style: italic; line-height: 1;
  font-family: Georgia, "Times New Roman", serif;
  text-transform: none; letter-spacing: 0;   /* stay lowercase "i" even inside uppercased table headers */
  cursor: help; user-select: none;
  transition: background .12s ease, color .12s ease, transform .12s ease;
}
.info:hover .info-i, .info:focus-visible .info-i { background: var(--accent); color: #fff; transform: scale(1.08); }
.info-pop {
  position: absolute; top: calc(100% + 8px); left: -4px; z-index: 60;
  width: max-content; max-width: 300px;
  background: var(--ink); color: #fff;
  padding: 10px 13px; border-radius: 11px; font-size: .78rem; font-weight: 500; line-height: 1.55;
  letter-spacing: 0; text-transform: none;
  box-shadow: var(--shadow-md);
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .14s ease, transform .14s ease; pointer-events: none; white-space: normal;
}
.info-pop b { color: #fff; font-weight: 700; }
.info-pop::before { content: ""; position: absolute; bottom: 100%; left: 12px; border: 6px solid transparent; border-bottom-color: var(--ink); }
.info:hover .info-pop, .info:focus .info-pop, .info:focus-within .info-pop { opacity: 1; visibility: visible; transform: translateY(0); }
@media (prefers-reduced-motion: reduce) { .info-pop { transition: none; } }

/* basis tag: marks whether a figure is whole-shop ("cả quán") or shareholder ("cổ đông") */
.basis {
  display: inline-block; margin-left: 8px; padding: 1.5px 9px; border-radius: 999px;
  font-size: .66rem; font-weight: 700; letter-spacing: .01em; vertical-align: middle;
  white-space: nowrap;
}
.basis.shop { background: var(--surface-2); color: var(--ink-muted); border: 1px solid var(--border); }
.basis.sh { background: var(--accent-soft); color: var(--accent-strong); }

/* a secondary chart tucked under the main one in the same panel (shares its filter chips) */
.sub-chart-head {
  margin-top: 16px; padding-top: 13px; border-top: 1px dashed var(--border);
  margin-bottom: 2px; font-size: .82rem; font-weight: 650; color: var(--ink);
}

/* shop health chip (comparison page) */
.hchip {
  display: inline-block; padding: 2.5px 10px; border-radius: 999px;
  font-size: .74rem; font-weight: 700; white-space: nowrap;
}
.hchip.good { background: var(--good-soft, #e3f2ea); color: var(--good); }
.hchip.warn { background: var(--warn-soft); color: var(--warn); }
.hchip.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- Branch lifecycle panel ---------- */
.life-head { font-size: .82rem; font-weight: 650; color: var(--ink); margin-bottom: 4px; }
.tbl td.cur-year { background: var(--accent-soft); color: var(--accent-strong); font-weight: 700; }
.mini-mo { color: var(--ink-faint); font-size: .72rem; font-weight: 500; }

/* ---------- Click-through chart detail tables (dialog) ---------- */
.chart-wrap.tbl-trigger { cursor: pointer; }
.dlg-table-scroll { max-height: 65vh; overflow: auto; }
.dlg-table-scroll .tbl thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }

/* ---------- Share trades on the branch card ---------- */
.branch-btns { display: flex; gap: 8px; }
.branch-btns .btn { flex: 1; justify-content: center; }
.xfer-list { display: flex; flex-direction: column; gap: 4px; padding-top: 10px; border-top: 1px dashed var(--border); }
.xfer-head { font-size: .72rem; color: var(--ink-faint); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; }
.xfer-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 10px; border-radius: var(--r); background: var(--surface-2);
}
.xfer-txt { font-size: .78rem; color: var(--ink-muted); }
.xfer-txt b { color: var(--ink); font-weight: 650; }

/* ---------- Dilution (nhường/nhận %) ---------- */
.dilution-total {
  margin: 10px 0 2px; padding: 10px 13px; border-radius: var(--r);
  background: var(--bad-soft); color: var(--bad); font-size: .85rem;
}
.dilution-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.dilution-row {
  display: flex; align-items: flex-start; gap: 10px; padding: 9px 11px;
  border-radius: var(--r); background: var(--surface-2);
}
.dil-ic { flex: none; font-size: .8rem; line-height: 1.5; }
.dil-ic.gave { color: var(--bad); }
.dil-ic.got { color: var(--good); }
.dil-body { display: flex; flex-direction: column; gap: 1px; font-size: .86rem; color: var(--ink); }
.dil-sub { font-size: .76rem; color: var(--ink-muted); }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpis-3 { grid-template-columns: repeat(3, 1fr); }
.sh-link { display: inline-flex; text-decoration: none; color: inherit; }
.sh-link:hover .nm { color: var(--accent); }
.kpi { padding: 18px 18px 14px; display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-ic { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-strong); }
.kpi-ic.warn { background: var(--warn-soft); color: var(--warn); }
.kpi-ic.good { background: var(--good-soft); color: var(--good); }
.kpi-label { font-size: .78rem; color: var(--ink-muted); font-weight: 600; }
.kpi-val { font-size: 1.6rem; font-weight: 770; letter-spacing: -.025em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-unit { font-size: .9rem; font-weight: 600; color: var(--ink-muted); margin-left: 2px; }
.trend { display: inline-flex; align-items: center; gap: 5px; align-self: flex-start; padding: 3px 9px; border-radius: var(--r-pill); font-size: .76rem; font-weight: 650; }
.trend.up { background: var(--good-soft); color: var(--good); }
.trend.flat { background: var(--surface-2); color: var(--ink-muted); }
.trend.warn { background: var(--warn-soft); color: var(--warn); }
.kpi-spark { position: absolute; right: 12px; bottom: 12px; width: 96px; height: 34px; opacity: .9; }

/* ---------- Layout grids ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-32 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; }
.grid-entry { display: grid; grid-template-columns: 430px 1fr; gap: 18px; align-items: start; }
.table-scroll { overflow-x: auto; }

/* ---------- Charts ---------- */
.chart-wrap { width: 100%; margin-top: 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; }
.legend .li { display: inline-flex; align-items: center; gap: 7px; font-size: .82rem; color: var(--ink-muted); font-weight: 600; cursor: pointer; border: 0; background: transparent; font-family: inherit; padding: 2px; border-radius: 6px; }
.legend .li:hover { color: var(--ink); }
.legend .li .dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend .li.off { color: var(--ink-faint); }
.legend .li.off .dot { filter: grayscale(1); opacity: .45; }
.legend .li.off .nm { text-decoration: line-through; text-decoration-thickness: 1.5px; }

/* Donut */
.donut-row { display: flex; align-items: center; gap: 24px; margin-top: 6px; flex-wrap: wrap; }
.donut { position: relative; width: 168px; height: 168px; border-radius: 50%; flex: none; }
.donut::after { content: ""; position: absolute; inset: 30px; background: var(--surface); border-radius: 50%; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; z-index: 1; }
.donut-center .t { font-size: .72rem; color: var(--ink-faint); font-weight: 600; }
.donut-center .v { font-size: 1.15rem; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.donut-legend { display: flex; flex-direction: column; gap: 11px; flex: 1; min-width: 180px; }
.dl-row { display: flex; align-items: center; gap: 10px; font-size: .86rem; }
.dl-row .dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.dl-row .nm { font-weight: 600; }
.dl-row .amt { margin-left: auto; color: var(--ink-muted); font-variant-numeric: tabular-nums; font-weight: 600; }
.dl-row .pc { color: var(--ink-faint); font-size: .78rem; width: 40px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Tables (custom) ---------- */
.tbl { width: 100%; border-collapse: collapse; margin-top: 8px; }
.tbl th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); font-weight: 650; padding: 9px 12px; border-bottom: 1px solid var(--border); }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--ink-muted); }
.tbl th.sortable.active { color: var(--accent); }
.sort-caret { margin-left: 4px; font-size: .85em; }
.tbl th.th-sh { text-transform: none; letter-spacing: 0; }
.th-pct { color: var(--ink-faint); font-weight: 500; margin-left: 4px; }
.pre-join { color: var(--ink-faint); }
.th-note { color: var(--ink-faint); font-weight: 500; margin-left: 5px; text-transform: none; letter-spacing: 0; }
.tbl td { padding: 12px; border-bottom: 1px solid var(--border); font-size: .88rem; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--surface-2); }
/* Bottom-line rows in a running-total table: the figures the reader came for. */
.tbl tbody tr.row-strong td { background: var(--surface-2); font-size: 1rem; border-top: 1px solid var(--border); }
/* Drill-down row: a nested table sits flush inside its parent row, quieter than it. */
.tbl tbody tr.row-sub > td { background: var(--surface-2); padding: 0 12px 10px 0; }
.tbl tbody tr.row-sub:hover { background: none; }
.tbl .tbl-sub { margin-top: 0; }
.tbl .tbl-sub th { padding: 6px 12px; font-size: .68rem; border-bottom: 1px solid var(--border); }
.tbl .tbl-sub td { padding: 7px 12px; font-size: .82rem; border-bottom: 0; }
.tbl .tbl-sub tbody tr:hover { background: none; }
.tbl tr.row-total td { font-weight: 700; background: var(--surface-2); }
.num { text-align: center; font-variant-numeric: tabular-nums; }
.tbl th.num { text-align: center; }
/* amounts that must not break across lines (payer balances on /cong-no) */
.tbl-money td.num { white-space: nowrap; }
.bname { display: inline-flex; align-items: center; gap: 9px; font-weight: 600; }
.bbadge { width: 9px; height: 9px; border-radius: 3px; flex: none; display: inline-block; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--r-pill); font-size: .75rem; font-weight: 650; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.sec { background: var(--surface-2); color: var(--ink-muted); }
.roi-tag { font-weight: 700; color: var(--accent-strong); font-variant-numeric: tabular-nums; }
.bar-mini { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; display: flex; }
.bar-mini > i { display: block; height: 100%; background: var(--accent); }
.bar-mini > i:first-child { border-radius: 99px 0 0 99px; }
.bar-mini > i:last-child { border-radius: 0 99px 99px 0; }
.bar-mini > i.seg-warn { background: var(--warn); }
.pct-warn { font-size: .78rem; font-weight: 650; color: var(--warn); white-space: nowrap; font-variant-numeric: tabular-nums; }

.empty-note {
  display: flex; gap: 12px; align-items: center; padding: 14px 16px; border-radius: var(--r);
  background: var(--accent-soft); color: var(--accent-strong); font-size: .88rem; font-weight: 550;
  border: 1px solid color-mix(in srgb, var(--accent) 16%, transparent);
}

/* ---------- Page toolbar / buttons ---------- */
.pagebar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pagebar .sub { font-size: .86rem; color: var(--ink-muted); font-weight: 550; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 10px;
  border: 1px solid transparent; background: var(--accent); color: #fff; font-weight: 650;
  font-size: .88rem; cursor: pointer; font-family: inherit; box-shadow: var(--shadow-sm); text-decoration: none;
}
.btn:hover { background: var(--accent-strong); }
.btn.sec { background: var(--surface); color: var(--ink); border-color: var(--border); box-shadow: none; }
.btn.sec:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; }

/* ---------- Forms ---------- */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-top: 12px; }
.wind-field { display: flex; flex-direction: column; gap: 6px; }
.wind-field.full { grid-column: 1 / -1; }
.wind-label, .form label { font-size: .8rem; font-weight: 600; color: var(--ink-muted); }
.wind-input, .form select.input, .form input.input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  font: inherit; font-size: .9rem; color: var(--ink); width: 100%;
}
.wind-input:focus, .form .input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.wind-money { position: relative; display: flex; align-items: center; }
.wind-money .wind-input { padding-right: 30px; }
.wind-money .wind-suffix { position: absolute; right: 12px; color: var(--ink-faint); font-weight: 600; font-size: .9rem; pointer-events: none; }
.wind-hint { font-size: .74rem; color: var(--ink-faint); }
.wind-pw { position: relative; display: flex; align-items: center; }
.wind-pw .wind-input { padding-right: 44px; }
.wind-pw .wind-input::-ms-reveal { display: none; }   /* Edge's own eye would sit next to ours */
.wind-pw-toggle {
  position: absolute; right: 5px; width: 34px; height: 34px; display: grid; place-items: center;
  border: 0; border-radius: 8px; background: transparent; color: var(--ink-faint); cursor: pointer;
}
.wind-pw-toggle:hover { color: var(--ink-muted); background: var(--surface-2); }
.wind-pw-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; color: var(--ink-muted); }
.wind-pw-toggle svg { width: 18px; height: 18px; }
.wind-pw-toggle .ic-hide, .wind-pw-toggle[aria-pressed="true"] .ic-show { display: none; }
.wind-pw-toggle[aria-pressed="true"] .ic-hide { display: block; }

.calc-row { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; padding: 13px 16px; border-radius: var(--r); background: var(--surface-2); font-weight: 600; font-size: .9rem; }
.calc-row .big { font-size: 1.2rem; font-weight: 770; color: var(--accent-strong); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.payout-total { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); font-weight: 700; font-variant-numeric: tabular-nums; }
.form-actions { display: flex; gap: 10px; margin-top: 16px; }

/* ---------- Branch cards ---------- */
.branch-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.branch-card { padding: 18px; display: flex; flex-direction: column; gap: 15px; }
.branch-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.branch-id { display: flex; gap: 12px; align-items: center; min-width: 0; }
.branch-mark { flex: none; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-weight: 750; font-size: .9rem; color: #fff; }
.branch-name { font-weight: 700; font-size: 1rem; }
.branch-loc { font-size: .76rem; color: var(--ink-faint); margin-top: 1px; }
.branch-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bstat { display: flex; flex-direction: column; gap: 2px; padding: 11px 12px; border-radius: var(--r); background: var(--surface-2); }
.bstat .l { font-size: .72rem; color: var(--ink-faint); font-weight: 600; }
.bstat .v { font-size: .95rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.branch-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.avatars { display: flex; }
.avatars .av { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--surface); margin-left: -8px; display: grid; place-items: center; font-size: .68rem; font-weight: 700; color: #fff; }
.avatars .av:first-child { margin-left: 0; }
.row-actions { display: flex; gap: 3px; }
.ico-sm { width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; color: var(--ink-faint); display: grid; place-items: center; cursor: pointer; }
.ico-sm:hover { background: var(--surface-2); color: var(--ink); }
.ico-sm.danger:hover { background: var(--bad-soft); color: var(--bad); }
.ico-sm svg { width: 17px; height: 17px; }

/* investments inside a branch card */
.inv-list { display: flex; flex-direction: column; margin-top: 2px; }
.inv-row { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-top: 1px solid var(--border); font-size: .85rem; }
.inv-who { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.inv-sub { font-size: .74rem; font-weight: 500; color: var(--ink-faint); }
.inv-row .inv-amt { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 1px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.inv-cap { font-weight: 700; color: var(--ink); }
.inv-rec { font-size: .78rem; font-weight: 600; color: var(--ink-faint); }
.inv-empty { padding: 10px 4px; font-size: .82rem; color: var(--ink-faint); border-top: 1px solid var(--border); }
.btn-xs { padding: 5px 10px; font-size: .78rem; }
.btn-xs svg { width: 14px; height: 14px; }

/* ---------- Shareholders ---------- */
.sh-name { display: flex; align-items: center; gap: 11px; }
.sh-avatar { flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); display: grid; place-items: center; font-weight: 700; font-size: .8rem; }
.sh-name .nm { font-weight: 650; }
.sh-name .sub { font-size: .74rem; color: var(--ink-faint); }
.own { display: flex; align-items: center; gap: 10px; min-width: 130px; }
.own .bar-mini { flex: 1; }
.own .pct { font-size: .82rem; font-weight: 650; font-variant-numeric: tabular-nums; width: 42px; }
.received { display: flex; flex-direction: column; gap: 5px; min-width: 160px; }
.received .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.kpi-scope { font-size: .66rem; color: var(--ink-faint); font-weight: 500; margin-left: 6px; text-transform: none; letter-spacing: 0; }
.money-warn { color: var(--warn); font-weight: 650; font-variant-numeric: tabular-nums; }
.neg { color: var(--bad) !important; font-weight: 650; }
.pos { color: var(--good) !important; font-weight: 650; }
.seg.muted { opacity: .5; }

/* ---------- Divested shareholders: faded + struck through, listed last ---------- */
.exited-name { text-decoration: line-through; }
.seg button.exited, .legend-exited { opacity: .55; text-decoration: line-through; }
.seg button.exited.on { opacity: .85; }
.tbl tbody tr.exited > td { opacity: .55; }
.inv-row.exited .inv-who, .inv-row.exited .inv-amt { opacity: .55; }
.exit-sum { padding: 14px 18px; }
.exit-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.exit-title { font-weight: 680; }
.exit-rows { display: grid; grid-template-columns: max-content max-content 1fr; gap: 6px 18px; align-items: baseline; font-size: .9rem; }
.exit-rows .l { color: var(--ink-muted); font-weight: 600; }
.exit-rows .v { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.exit-rows .s { font-size: .78rem; color: var(--ink-faint); }
.exit-rows .s .trade { display: block; }
.exit-rows .total { border-top: 1px solid var(--border); padding-top: 6px; }
.exit-rows .v.total { font-size: 1.05rem; }
.exit-line { display: flex; flex-wrap: wrap; gap: 4px 8px; padding: 8px 0 0 47px; font-size: .8rem; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
@media (max-width: 820px) {
  .exit-rows { grid-template-columns: max-content 1fr; }
  .exit-rows .s { grid-column: 1 / -1; margin-top: -4px; }
  .exit-rows .s:empty { display: none; }
  .exit-line { padding-left: 0; }
}

/* ---------- Loading / misc ---------- */
.center-load { display: grid; place-items: center; min-height: 40vh; }

/* pull-to-refresh indicator (touch devices, see wind.js) */
#ptr-indicator {
  position: fixed; top: -46px; left: 50%; transform: translateX(-50%);
  width: 38px; height: 38px; border-radius: 50%; z-index: 300;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md);
  display: grid; place-items: center; font-size: 18px; font-weight: 700; color: var(--accent);
  opacity: 0; pointer-events: none;
}
#ptr-indicator.ready { background: var(--accent); color: #fff; }
#ptr-indicator.spin { animation: spin .7s linear infinite; }

.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.load-box { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.load-txt { font-size: .85rem; color: var(--ink-muted); font-weight: 600; }
/* a card acting as a loading placeholder — centers its spinner */
.skel-panel { display: grid; place-items: center; }
.card.panel.skel-panel { min-height: 240px; }
.card.kpi.skel-panel { min-height: 96px; }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-md); padding: 32px 30px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand .brand-mark { width: 44px; height: 44px; font-size: 19px; }
.login-brand .n { font-weight: 750; font-size: 1.1rem; letter-spacing: -.01em; color: var(--ink); }
.login-brand .s { font-size: .76rem; color: var(--ink-faint); margin-top: -1px; }
.login-title { font-size: 1.15rem; font-weight: 700; margin: 0 0 18px; color: var(--ink); }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-error { background: var(--bad-soft); color: var(--bad); border-radius: var(--r); padding: 11px 14px; font-size: .85rem; font-weight: 600; margin-bottom: 14px; }
.login-remember { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--ink-muted); cursor: pointer; user-select: none; }
.login-remember input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.login-note { background: var(--warn-soft); color: var(--warn); border-radius: var(--r); padding: 12px 14px; font-size: .85rem; line-height: 1.5; }

/* ---------- Quản lý nợ: one table, rows coloured by what falls due next ---------- */
.kpis-2 { grid-template-columns: repeat(2, 1fr); }
.kpi-sub { font-size: .76rem; color: var(--ink-faint); font-weight: 550; margin-top: 4px; }
.dir-chip { display: inline-block; padding: 2px 9px; border-radius: var(--r-pill); font-size: .7rem; font-weight: 700; white-space: nowrap; }
.dir-chip.out { background: var(--bad-soft); color: var(--bad); }
.dir-chip.in { background: var(--good-soft); color: var(--good); }
.tbl tbody tr.row-link { cursor: pointer; }
/* td backgrounds win over the tr hover, so a coloured row stays coloured under the pointer */
.tbl tbody tr.due-soon > td { background: var(--warn-soft); }
.tbl tbody tr.due-now > td { background: var(--bad-soft); }
.tbl tbody tr.due-soon > td:first-child { box-shadow: inset 3px 0 0 var(--c3); }
.tbl tbody tr.due-now > td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.due-soon-text { color: var(--warn); font-weight: 700; }
.due-now-text { color: var(--bad); font-weight: 700; }
.due-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: .76rem; color: var(--ink-muted); }
.due-legend .sw { display: inline-block; width: 11px; height: 11px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; }
.due-legend .sw.soon { background: var(--warn-soft); border: 1px solid var(--c3); }
.due-legend .sw.now { background: var(--bad-soft); border: 1px solid var(--bad); }
.loan-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.loan-stats > * { min-width: 0; }
.loan-stats .l { font-size: .7rem; color: var(--ink-faint); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; }
.loan-stats .v { font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.tbl tbody tr.period-paid > td { color: var(--ink-faint); }
@media (max-width: 820px) { .loan-stats { grid-template-columns: repeat(2, 1fr); } }
.due-legend-hint { margin-left: auto; color: var(--ink-faint); }

/* ticked rows, summed in a card pinned to the corner (above the topbar, below the mobile drawer) */
.tbl th.pick-col, .tbl td.pick-col { width: 34px; padding-right: 0; cursor: default; }
.pick-col input { width: 16px; height: 16px; margin: 0; vertical-align: middle; accent-color: var(--accent); cursor: pointer; }
.pick-sum {
  position: fixed; right: 24px; bottom: 24px; z-index: 140; width: 470px; max-width: calc(100vw - 48px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-md);
  padding: 8px 8px 10px 16px; display: flex; flex-direction: column;
}
.pick-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: .82rem; color: var(--ink-muted); font-weight: 600; }
.pick-actions { display: flex; gap: 2px; }
.pick-head .ico-sm { width: 28px; height: 28px; }
/* long picks scroll between a sticky header and sticky totals */
.pick-scroll { max-height: min(55vh, 460px); overflow: auto; padding-right: 8px; }
.pick-tbl { width: 100%; border-collapse: collapse; font-size: .84rem; font-variant-numeric: tabular-nums; }
.pick-tbl th { position: sticky; top: 0; background: var(--surface); text-align: left; font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); font-weight: 650; padding: 6px 0 6px 10px; border-bottom: 1px solid var(--border); }
.pick-tbl td { padding: 7px 0 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.pick-tbl th:first-child, .pick-tbl td:first-child { padding-left: 0; }
.pick-tbl .num { text-align: right; white-space: nowrap; }
.pick-tbl tbody tr:last-child td { border-bottom: 0; }
.pick-who { font-weight: 600; }
.pick-tbl tfoot { position: sticky; bottom: 0; }
.pick-tbl tfoot td { background: var(--surface-2); font-weight: 650; border-bottom: 0; }
.pick-tbl tfoot tr:first-child td { border-top: 2px solid var(--border); }
.pick-tbl tfoot td:first-child { padding-left: 8px; color: var(--ink-muted); }
.pick-tbl tfoot td:last-child { padding-right: 8px; }
.pick-tbl tr.pick-net td { font-size: .95rem; font-weight: 750; }
.pick-sum.collapsed .pick-tbl tbody { display: none; }
.pick-tbl tr.pick-sub td { font-weight: 550; font-size: .8rem; color: var(--ink-muted); }
.pick-tbl tfoot tr.pick-sub td:first-child { padding-left: 18px; }
.pick-spacer { height: 180px; }

/* month-by-month: a month header row, then one row per thing falling due */
.cf-grid { align-items: start; }
.cf-tbl td.cf-date { white-space: nowrap; }
.cf-total { font-size: 1.15rem; font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cf-empty { margin-top: 10px; }
.tbl tbody tr.cf-month > td { background: var(--surface-2); font-weight: 700; font-size: .84rem; padding-top: 9px; padding-bottom: 9px; }
.tbl tbody tr.cf-late > td { background: var(--bad-soft); color: var(--bad); }
.cf-now { margin-left: 6px; font-size: .7rem; font-weight: 650; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; }
.cf-tbl td.cf-who b { font-weight: 600; }
.cf-due { margin-left: 6px; font-size: .76rem; }
.cf-foot { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; font-size: .8rem; color: var(--ink-muted); }
.cf-foot > div { display: flex; justify-content: space-between; gap: 12px; }
.cf-foot b { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 650; }
@media (max-width: 620px) {
  .pick-sum { left: 16px; right: 16px; bottom: 16px; width: auto; max-width: none; }
  .pick-scroll { max-height: 45vh; }
  /* a fourth column doesn't fit a phone: drop the last one (the page's own table still shows it) */
  .pick-tbl.pick-wide th:last-child, .pick-tbl.pick-wide td:last-child { display: none; }
  .pick-tbl.pick-wide tfoot td:nth-last-child(2) { padding-right: 8px; }
  .due-legend-hint { margin-left: 0; }
  /* three columns fit a phone if names wrap and the "còn N ngày" note drops under the date */
  .tbl.cf-tbl { display: table; white-space: normal; }
  .cf-due { display: block; margin-left: 0; }
}

/* ---------- Responsive ---------- */
/* grid children default to min-width:auto → wide charts/tables blow the layout out.
   Clamp every grid cell so content scrolls INSIDE its card instead. */
.kpis > *, .grid-2 > *, .grid-32 > *, .grid-entry > *, .branch-grid > * { min-width: 0; }
.chart-wrap { min-width: 0; }

@media (max-width: 1200px) {
  .branch-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  /* three cards on two columns: the odd one takes the whole row instead of half of it */
  .kpis-3 > :last-child { grid-column: 1 / -1; }
}
@media (max-width: 1080px) {
  .wind-app { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }
  .grid-2, .grid-32, .grid-entry { grid-template-columns: 1fr; }
}
/* Phones/small tablets: sidebar becomes a slide-in overlay drawer */
@media (max-width: 820px) {
  .wind-app, .wind-app.collapsed { grid-template-columns: 1fr; }
  .side {
    position: fixed; top: 0; left: 0; height: 100vh; width: var(--sidebar-w);
    z-index: 200; transform: translateX(-100%);
    box-shadow: 0 12px 40px rgba(15, 25, 45, .35);
  }
  /* nav-ready is set AFTER Blazor boots and the mobile check ran — without it the drawer
     stays hidden, so the sidebar can't flash over the page during prerender/reload */
  .wind-app.nav-ready:not(.collapsed) .side { transform: translateX(0); }
  .wind-app.collapsed .brand-text, .wind-app.collapsed .nav-item .lbl,
  .wind-app.collapsed .user-text, .wind-app.collapsed .nav-label { display: revert; }
  .wind-app.collapsed .nav-item { justify-content: flex-start; padding: 10px 12px; }
  .wind-app.collapsed .brand, .wind-app.collapsed .user-chip { justify-content: flex-start; padding-left: 8px; }
  .nav-backdrop { position: fixed; inset: 0; background: rgba(10, 18, 32, .45); z-index: 150; }
  .wind-app.nav-ready:not(.collapsed) .nav-backdrop { display: block; }
}
@media (max-width: 620px) {
  /* two compact KPI columns beat one endless stack of 8 cards */
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 12px 13px; }
  .kpi-val { font-size: .98rem; }
  .kpi-scope { display: block; margin-left: 0; }
  .content { padding: 14px 10px 40px; }
  .topbar { padding: 12px 14px; gap: 10px; }
  .form { grid-template-columns: 1fr; }
  .page-title { font-size: 1.05rem; }
  .logout-btn span { display: none; }
  .tbl { display: block; overflow-x: auto; white-space: nowrap; }
  .tbl th, .tbl td { padding: 8px 9px; font-size: .8rem; }
  .donut-row { gap: 16px; }
  .panel { padding: 14px 13px 16px; }
  .pagebar { flex-wrap: wrap; gap: 10px; }
  .filterbar { align-items: stretch; }
  .filter-right { justify-content: space-between; width: 100%; }
  .branch-stats { gap: 8px; }
  .bstat { padding: 9px 10px; }
  .bstat .v { font-size: .86rem; }
  /* shareholder rows on branch cards: let amounts wrap under the name */
  .inv-row { flex-wrap: wrap; row-gap: 4px; }
  .xfer-row .xfer-txt { white-space: normal; }
  .branch-btns { flex-wrap: wrap; }
  .branch-btns .btn { min-width: 140px; }
  /* dialogs use (almost) the full phone width */
  .mud-dialog { margin: 8px !important; max-width: calc(100vw - 16px) !important; }
  .dlg-table-scroll { max-height: 70vh; }
  .dilution-row { flex-wrap: wrap; }
}
@media (max-width: 380px) {
  .kpis { grid-template-columns: 1fr; }
}

/* ---------- MudBlazor tweaks (dialogs / snackbar keep the palette) ---------- */
.mud-dialog { border-radius: var(--r-lg) !important; }
.mud-dialog-title { font-weight: 700; }
.wind-app .mud-input-control { margin-top: 4px; }
