:root {
  --bg: #f3f1ec; --panel: #fbfaf7; --ink: #17161a; --muted: #8a857c; --line: #e6e2d9; --soft: #ece9e2;
  --orange: #f4511e; --orange-soft: #fde6dd; --teal: #0e6e6e; --good: #12805c; --bad: #d43d12;
  --side: #141414; --side-ink: #d6d3cc; --side-act: #262626;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 10px;
  --c1: #17161a; --c2: #f4511e; --c3: #0e6e6e; --c4: #c9a227; --c5: #7a5af8; --c6: #8a857c;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 Inter, system-ui, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .err { color: var(--bad); min-height: 1em; }
.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good); } .neg { color: var(--bad); }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* logo */
.logo { display: flex; align-items: center; gap: 10px; }
.logo b { display: block; font-size: 15px; letter-spacing: .01em; }
.logo small { display: block; font-size: 10px; letter-spacing: .18em; color: var(--muted); font-weight: 600; }
.logo-mark { width: 24px; height: 8px; border-radius: 2px; background: var(--orange); position: relative; }
.logo-mark::after { content: ''; position: absolute; left: 7px; top: 3px; width: 10px; height: 2px; background: var(--side); box-shadow: -4px 0 0 -0px var(--side); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(380px, 100%); display: grid; gap: 12px; }
.login-card .logo-mark::after { background: var(--panel); box-shadow: none; }
.login-card h1 { margin: 6px 0 0; font-size: 22px; }

/* shell */
.shell { display: grid; grid-template-columns: 180px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 22px 8px 14px; }
.side .logo { padding: 0 6px 20px; }
.side .logo b { color: #fff; }
.side .logo small { color: #9a958c; }
nav { display: grid; gap: 2px; flex: 1; align-content: start; overflow: auto; }
nav a { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 7px; color: var(--side-ink); text-decoration: none; font-size: 13px; font-weight: 500; }
nav a:hover { background: #1e1e1e; }
nav a.on { background: var(--side-act); color: #fff; }
nav a.cta { border: 1px solid #5a2414; color: var(--orange); margin: 8px 0; }
nav a.cta:hover { background: #1f1410; }
nav .sep { height: 8px; }
.me { display: flex; align-items: center; gap: 8px; padding: 12px 6px 0; border-top: 1px solid #262626; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--orange); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none; }
.me-txt { flex: 1; min-width: 0; }
.me-txt b { display: block; color: #fff; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-txt small { display: block; color: #9a958c; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: #9a958c; cursor: pointer; padding: 4px; }
.icon-btn:hover { color: #fff; }
.main { min-width: 0; padding: 32px 40px 48px; max-width: 1180px; width: 100%; margin: 0 auto; }
.menu-btn { display: none; }

/* page head */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.page-head .sub i { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--orange); margin: 0 8px 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* buttons & inputs */
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--orange-soft); border-color: var(--orange); }
.btn { display: inline-flex; align-items: center; gap: 7px; font: inherit; font-size: 13px; font-weight: 600; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 7px; padding: 7px 13px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c9c3b8; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

/* filters */
.filters { display: grid; gap: 12px; margin-bottom: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 12.5px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 99px; padding: 5px 11px; cursor: pointer; }
.chip:hover { border-color: #c9c3b8; }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
.period-pick { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.period-pick select, .period-pick input { font-size: 13px; padding: 6px 10px; }
.drops { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ms { position: relative; }
.ms > button { font: inherit; font-size: 13px; min-width: 124px; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 6px 30px 6px 9px; cursor: pointer; color: var(--ink); position: relative; }
.ms > button::after { content: ''; position: absolute; right: 10px; top: 11px; width: 6px; height: 6px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg); }
.ms > button.active { border-color: var(--orange); color: var(--orange); font-weight: 600; }
.ms-pop { position: absolute; top: calc(100% + 4px); left: 0; z-index: 30; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.12); width: 260px; max-height: 340px; display: grid; grid-template-rows: auto 1fr auto; }
.ms-pop input { margin: 8px; }
.ms-list { overflow: auto; padding: 0 8px; }
.ms-list label { display: flex; flex-direction: row; gap: 8px; align-items: center; color: var(--ink); font-size: 13px; padding: 4px 2px; font-weight: 400; }
.ms-foot { display: flex; justify-content: space-between; padding: 8px; border-top: 1px solid var(--line); }
.link-btn { background: none; border: 0; color: var(--orange); font: inherit; font-size: 12.5px; cursor: pointer; font-weight: 600; }

/* layout */
main { display: grid; gap: 14px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.panel h2 { margin: 0 0 12px; font-size: 14px; font-weight: 700; }
.panel h3 { font-size: 13px; margin: 14px 0 8px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.legend i.line { height: 2px; width: 12px; vertical-align: 3px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

/* KPI cards */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.kpi.span2 { grid-column: span 2; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 14px 12px; position: relative; overflow: hidden; min-width: 0; }
.kpi.hero { grid-column: span 2; background: var(--ink); border-color: var(--ink); color: #fff; }
.kpi.hero::before { content: ''; position: absolute; right: -40px; top: -55px; width: 170px; height: 170px; border-radius: 50%; border: 18px solid var(--orange); }
.kpi .lbl { color: var(--muted); font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; }
.kpi.hero .lbl { color: #bdb8ae; }
.kpi .val { font-family: var(--mono); font-size: 21px; font-weight: 600; margin: 6px 0 2px; letter-spacing: -.01em; position: relative; z-index: 1; }
.kpi.hero .val { font-size: 34px; }
.kpi .unit { font-size: 11px; color: var(--muted); }
.kpi.hero .unit { color: #bdb8ae; }
.kpi .cmp { font-size: 11px; color: var(--muted); display: grid; gap: 8px; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.kpi.hero .cmp { display: flex; gap: 16px; border-top-color: #2c2b2f; color: #9a958c; position: relative; z-index: 1; }
.kpi .cmp b { font-weight: 500; color: var(--ink); }
.kpi.hero .cmp b { color: #fff; }
.kpi.wide { grid-column: span 1; }
.chart-box { position: relative; height: 260px; }

/* tabs */
.utabs { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.utabs button { font: inherit; font-size: 13px; border: 0; background: none; color: var(--muted); padding: 8px 10px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.utabs button:hover { color: var(--ink); }
.utabs button.on { color: var(--ink); border-bottom-color: var(--orange); font-weight: 600; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button { font: inherit; font-size: 12.5px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 4px 11px; border-radius: 99px; cursor: pointer; }
.tabs button.on { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }

/* tables */
.tbl-wrap { overflow: auto; max-height: 620px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
td { font-weight: 500; }
td.num { font-weight: 400; }
th { position: sticky; top: 0; background: var(--panel); font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); cursor: pointer; user-select: none; z-index: 1; font-weight: 600; }
tbody tr:hover { background: #f5f2ec; }
tr.click { cursor: pointer; }
.share { display: flex; align-items: center; gap: 8px; justify-content: flex-start; }
.bar { height: 6px; background: var(--soft); border-radius: 3px; overflow: hidden; width: 70px; flex: none; }
.bar > i { display: block; height: 100%; background: var(--orange); border-radius: 3px; }
.share span { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.toolbar { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--soft); color: var(--ink); margin: 1px 2px; }
.tag.bad { background: var(--orange-soft); color: var(--bad); }
.pill { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--soft); text-transform: uppercase; letter-spacing: .04em; }

.modal { position: fixed; inset: 0; background: rgba(20,20,20,.45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-card { background: var(--panel); border-radius: 14px; width: min(1040px, 100%); max-height: 92vh; overflow: auto; padding: 22px; position: relative; }
.modal-x { position: absolute; right: 12px; top: 8px; border: 0; background: none; font-size: 26px; color: var(--muted); cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.inv-lines td { padding: 4px; } .inv-lines input, .inv-lines select { width: 100%; padding: 6px 7px; font-size: 12.5px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; max-width: 90vw; }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--soft); font-size: 13px; }
.notice.warn { background: var(--orange-soft); color: #8a2b0c; }

@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kpi.span2 { grid-column: span 2; } .grid2 { grid-template-columns: 1fr; } }
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; width: 220px; transform: translateX(-100%); transition: transform .2s; }
  .shell.open .side { transform: none; }
  .menu-btn { display: inline-block; font-size: 20px; background: none; border: 1px solid var(--line); border-radius: 7px; padding: 2px 10px; margin-bottom: 10px; cursor: pointer; }
  .main { padding: 16px; }
  .kpi.hero { grid-column: span 2; }
}
@media (max-width: 520px) { .kpis { grid-template-columns: 1fr; } .kpi.hero { grid-column: span 1; } }
@media print {
  body { background: #fff; }
  .side, .menu-btn, .actions, .filters .chips, .drops, .utabs, .ms, #filters select { display: none !important; }
  .shell { display: block; } .main { padding: 0; max-width: none; }
  .panel, .kpi { break-inside: avoid; } .tbl-wrap { max-height: none; overflow: visible; }
}
