/* ==========================================================================
   Expense Manager — Design System ("Modern", dark-first)
   Tokens + base + core component classes. Values are pulled verbatim from
   docs/design/DESIGN.md and docs/design/modern-dashboard.html.
   ========================================================================== */

:root {
  --accent: #2DD4BF;
  --accent-2: #22D3EE;
  --pos: #34D399;
  --neg: #FB7185;
  --blue: #60A5FA;
  --amber: #FBBF24;
  --violet: #A78BFA;
  --pink: #F472B6;
  --slate: #94A3B8;
  --sans: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", monospace;
  --r: 16px;
  --r-sm: 10px;
}

html[data-theme="dark"] {
  --bg: #0A0C10;
  --g1: rgba(45, 212, 191, 0.10);
  --g2: rgba(34, 211, 238, 0.06);
  --surface: #12161D;
  --surface-2: #181E27;
  --surface-h: #1C232E;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.12);
  --text: #EAEEF5;
  --text-2: #98A2B3;
  --text-3: #5C6675;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 14px 40px -16px rgba(0, 0, 0, 0.7);
  --chip-pos: rgba(52, 211, 153, 0.14);
  --chip-neg: rgba(251, 113, 133, 0.14);
  --accent-soft: rgba(45, 212, 191, 0.13);
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #F6F7F9;
  --g1: rgba(13, 148, 136, 0.10);
  --g2: rgba(8, 145, 178, 0.05);
  --surface: #FFFFFF;
  --surface-2: #F3F5F8;
  --surface-h: #EEF1F5;
  --line: rgba(12, 18, 28, 0.08);
  --line-2: rgba(12, 18, 28, 0.14);
  --text: #0E141B;
  --text-2: #5A6573;
  --text-3: #98A2B3;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 12px 32px -18px rgba(16, 24, 40, 0.28);
  --chip-pos: rgba(5, 150, 105, 0.12);
  --chip-neg: rgba(225, 29, 72, 0.10);
  --accent: #0D9488;
  --accent-2: #0891B2;
  --pos: #059669;
  --neg: #E11D48;
  --blue: #2563EB;
  --amber: #D97706;
  --violet: #7C3AED;
  --pink: #DB2777;
  --slate: #64748B;
  --accent-soft: rgba(13, 148, 136, 0.10);
  color-scheme: light;
}

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

html {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  line-height: 1.5;
  letter-spacing: -0.011em;
  transition: background 0.4s, color 0.4s;
}

h1, h2, h3 {
  letter-spacing: -0.02em;
}

a {
  color: var(--accent);
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

::selection {
  background: var(--accent-soft);
}

/* atmospheric corner glow */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(680px 380px at 16% -6%, var(--g1), transparent 70%),
    radial-gradient(560px 340px at 96% 4%, var(--g2), transparent 72%);
}

/* ---- app shell ----------------------------------------------------------- */
.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

/* sidebar */
.side {
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px;
}

.brand .mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  color: #04201d;
  font-weight: 700;
  font-size: 17px;
  box-shadow: 0 6px 18px -6px var(--accent);
}

.brand .name {
  font-weight: 600;
  font-size: 15px;
}

.brand .name span {
  color: var(--text-3);
  font-weight: 400;
  display: block;
  font-size: 11px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav .lbl {
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 0 10px 8px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: 0.15s;
}

.nav a svg {
  width: 17px;
  height: 17px;
  opacity: 0.85;
}

.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav a.on {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav a.on svg {
  opacity: 1;
}

.side .foot {
  margin-top: auto;
}

.imp {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px;
  border-radius: var(--r-sm);
  border: 1px dashed var(--line-2);
  font-size: 12px;
  color: var(--text-2);
}

.imp .ring {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--neg);
  box-shadow: 0 0 0 3px var(--chip-neg);
}

/* topbar */
.main {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 30px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  z-index: 5;
}

.search {
  flex: 1;
  max-width: 360px;
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  color: var(--text-3);
  font-size: 13px;
}

.search svg {
  width: 15px;
  height: 15px;
}

.search .k {
  margin-left: auto;
  font-size: 11px;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  padding: 1px 6px;
}

.tb-spacer {
  flex: 1;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-2);
}

.live .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--pos);
  animation: pulse 2.2s infinite;
}

.live.off .dot {
  background: var(--text-3);
  animation: none;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 var(--chip-pos); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.iconbtn {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: 0.15s;
}

.iconbtn:hover {
  background: var(--surface-h);
  color: var(--text);
}

.iconbtn svg {
  width: 17px;
  height: 17px;
}

.tenant {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.tenant .av {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: linear-gradient(135deg, #475569, #1e293b);
  display: grid;
  place-items: center;
  font-size: 11px;
  color: #fff;
}

.tenant .chev {
  color: var(--text-3);
  font-size: 10px;
}

/* content + page head */
.content {
  padding: 26px 30px 56px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.pagehead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.pagehead h1 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.pagehead p {
  color: var(--text-2);
  font-size: 13px;
  margin-top: 3px;
}

.seg {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}

.seg button {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 13px;
  border-radius: 7px;
  cursor: pointer;
  transition: 0.15s;
}

.seg button.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

/* ---- card + panel -------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}

.panel {
  padding: 20px;
}

.ph {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.ph h3 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.ph .sub {
  font-size: 12px;
  color: var(--text-2);
}

.legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--text-2);
}

.legend i {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}

/* grids */
.grid2 {
  display: grid;
  grid-template-columns: 1.85fr 1fr;
  gap: 16px;
  align-items: stretch;
}

.grid2b {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: stretch;
}

/* ---- KPI cards ----------------------------------------------------------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
}

.kpi {
  padding: 16px;
}

.kpi .cap {
  font-size: 11.5px;
  color: var(--text-2);
  font-weight: 500;
}

.kpi .big {
  font-size: 23px;
  font-weight: 600;
  margin-top: 10px;
  letter-spacing: -0.03em;
}

.kpi .big.neg {
  color: var(--neg);
}

.kpi .big.posv {
  color: var(--pos);
}

.kpi .row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 9px;
}

.kpi .muted {
  font-size: 11.5px;
  color: var(--text-3);
}

/* chip */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
}

.chip.up {
  color: var(--pos);
  background: var(--chip-pos);
}

.chip.down {
  color: var(--neg);
  background: var(--chip-neg);
}

/* ---- charts -------------------------------------------------------------- */
.chart {
  width: 100%;
  height: 200px;
  display: block;
}

.gl {
  stroke: var(--line);
  stroke-width: 1;
}

.xlab {
  fill: var(--text-3);
  font-size: 10px;
  font-family: var(--sans);
}

.vlab {
  fill: var(--text-3);
  font-size: 9.5px;
  font-family: var(--mono);
}

.xaxis {
  display: flex;
  justify-content: space-between;
  margin: 6px 0 0 40px;
}

.view-all {
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
}

/* ---- donut --------------------------------------------------------------- */
.donutwrap {
  display: flex;
  align-items: center;
  gap: 22px;
}

.donut {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
  -webkit-mask: radial-gradient(transparent 55%, #000 56%);
  mask: radial-gradient(transparent 55%, #000 56%);
}

.donut .ctr {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
}

.dlegend {
  display: flex;
  flex-direction: column;
  gap: 9px;
  flex: 1;
}

.dlegend .li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 9px;
  align-items: center;
  font-size: 12.5px;
}

.dlegend .li i {
  width: 9px;
  height: 9px;
  border-radius: 3px;
}

.dlegend .li .nm {
  color: var(--text-2);
}

.dlegend .li .vl {
  font-weight: 600;
}

.li.click {
  cursor: pointer;
  padding: 3px 6px;
  margin: -3px -6px;
  border-radius: 7px;
  transition: 0.12s;
}

.li.click:hover {
  background: var(--surface-2);
}

/* ---- utilization / payoff bars ------------------------------------------- */
.ub {
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.ub:last-child {
  border-bottom: 0;
}

.ub .top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.ub .nm {
  font-size: 13.5px;
  font-weight: 500;
}

.ub .nm small {
  color: var(--text-3);
  font-weight: 400;
  margin-left: 6px;
}

.ub .pct {
  font-size: 12.5px;
  font-weight: 600;
  font-family: var(--mono);
}

.ub .track {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
  position: relative;
}

.ub .fill {
  height: 100%;
  border-radius: 4px;
  transform-origin: left;
  transform: scaleX(0);
  animation: grow 1s cubic-bezier(0.2, 0.7, 0.2, 1) forwards 0.2s;
}

@keyframes grow {
  to { transform: scaleX(var(--w)); }
}

.ub .sub {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-3);
  margin-top: 6px;
}

.danger {
  color: var(--neg) !important;
}

/* ---- budget vs actual ---------------------------------------------------- */
.bva {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.bva:last-child {
  border-bottom: 0;
}

.bva .top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 7px;
  font-size: 13px;
}

.bva .top .cat {
  font-weight: 500;
}

.bva .top .num {
  font-family: var(--mono);
  color: var(--text-2);
  font-size: 12px;
}

.bva .bar {
  height: 7px;
  border-radius: 4px;
  background: var(--surface-2);
  position: relative;
  overflow: hidden;
}

.bva .bar .act {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 4px;
  background: var(--accent);
}

.bva .bar .act.over {
  background: var(--neg);
}

/* ---- transactions row ---------------------------------------------------- */
.tx {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 11px 8px;
  border-radius: var(--r-sm);
  transition: 0.15s;
}

.tx:hover {
  background: var(--surface-2);
}

.tx .ic {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  color: var(--text-2);
  flex-shrink: 0;
}

.tx .ic svg {
  width: 16px;
  height: 16px;
}

.tx .meta {
  flex: 1;
  min-width: 0;
}

.tx .meta .d {
  font-size: 13.5px;
  font-weight: 500;
}

.tx .meta .s {
  font-size: 11.5px;
  color: var(--text-3);
}

.tx .amt {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}

.tx .amt.in {
  color: var(--pos);
}

/* ---- entrance animation -------------------------------------------------- */
.rise {
  opacity: 0;
  transform: translateY(12px);
  animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}

@keyframes rise {
  to { opacity: 1; transform: none; }
}

.s1 { animation-delay: 0.04s; }
.s2 { animation-delay: 0.09s; }
.s3 { animation-delay: 0.15s; }
.s4 { animation-delay: 0.22s; }
.s5 { animation-delay: 0.29s; }
.s6 { animation-delay: 0.36s; }
.s7 { animation-delay: 0.43s; }

/* ---- drill-down popover -------------------------------------------------- */
.popmask {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
}

.popmask.show {
  display: block;
}

.pop {
  position: fixed;
  z-index: 50;
  width: 286px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  box-shadow: 0 22px 64px -20px rgba(0, 0, 0, 0.65);
  padding: 16px;
  opacity: 0;
  transform: translateY(6px) scale(0.98);
  pointer-events: none;
  transition: 0.16s;
}

.pop.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.pop .ph2 {
  display: flex;
  align-items: center;
  gap: 9px;
}

.pop .ph2 i {
  width: 11px;
  height: 11px;
  border-radius: 3px;
}

.pop .ph2 .nm {
  font-size: 15px;
  font-weight: 600;
}

.pop .tot {
  font-family: var(--mono);
  font-size: 23px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 6px;
}

.pop .g {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
  margin: 13px 0;
  padding: 13px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.pop .st .k {
  font-size: 10px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pop .st .v {
  font-size: 14px;
  font-weight: 600;
  font-family: var(--mono);
  margin-top: 2px;
}

.pop .st .v.up {
  color: var(--neg);
}

.pop .st .v.dn {
  color: var(--pos);
}

.pop .merch {
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 12px;
}

.pop .merch b {
  color: var(--text);
  font-weight: 500;
}

.pop .acts {
  display: flex;
  gap: 8px;
}

.pop .acts button {
  flex: 1;
  height: 34px;
  border-radius: 9px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--line);
}

.pop .acts .go {
  background: var(--accent);
  border-color: var(--accent);
  color: #04201d;
}

.pop .acts .cmp {
  background: var(--surface-2);
  color: var(--text);
}

/* ---- responsive ---------------------------------------------------------- */
@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .grid2,
  .grid2b { grid-template-columns: 1fr; }
}

/* ---- auth / login -------------------------------------------------------- */
.auth-wrap {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  padding: 28px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.auth-brand .mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  color: #04201d;
  font-weight: 700;
  font-size: 19px;
  box-shadow: 0 6px 18px -6px var(--accent);
}

.auth-title {
  font-weight: 600;
  font-size: 16px;
}

.auth-sub {
  font-size: 12.5px;
  color: var(--text-2);
  margin-top: 2px;
}

.auth-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  margin: 14px 0 6px;
}

.auth-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  transition: 0.15s;
}

.auth-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-error {
  margin-top: 14px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  background: var(--chip-neg);
  color: var(--neg);
  font-size: 12.5px;
  font-weight: 500;
}

.auth-submit {
  width: 100%;
  margin-top: 20px;
  height: 42px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #04201d;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s;
}

.auth-submit:hover:not(:disabled) {
  filter: brightness(1.05);
}

.auth-submit:disabled {
  opacity: 0.6;
  cursor: default;
}

/* ---- state / placeholder ------------------------------------------------- */
.state-msg {
  color: var(--text-2);
  font-size: 13.5px;
  text-align: center;
  padding: 28px 20px;
}

.coming-soon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 24px;
  text-align: center;
}

.coming-soon .cs-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  color: #04201d;
  font-weight: 700;
  font-size: 20px;
  box-shadow: 0 6px 18px -6px var(--accent);
}

.coming-soon .cs-title {
  font-size: 16px;
  font-weight: 600;
}

.coming-soon .cs-sub {
  font-size: 13px;
  color: var(--text-2);
  max-width: 340px;
}

/* ---- blazor error ui ----------------------------------------------------- */
#blazor-error-ui {
  background: var(--surface);
  color: var(--text);
  border-top: 1px solid var(--line-2);
  bottom: 0;
  box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
  display: none;
  left: 0;
  padding: 0.6rem 1.25rem 0.7rem 1.25rem;
  position: fixed;
  width: 100%;
  z-index: 1000;
}

#blazor-error-ui .dismiss {
  cursor: pointer;
  position: absolute;
  right: 0.75rem;
  top: 0.5rem;
}

.blazor-error-boundary {
  background: var(--neg);
  padding: 1rem 1rem 1rem 1rem;
  color: #fff;
}

.blazor-error-boundary::after {
  content: "An error has occurred.";
}
