/* LJ hub – shared styles. Light and dark follow the phone/PC setting. */
:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --line: #dddcd5;
  --ink: #141413;
  --ink-2: #52514e;
  --ink-3: #85847e;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e3eefb;
  --good: #1d7a43;
  --good-soft: #e2f3e8;
  --warn: #9a6200;
  --warn-soft: #fbf0d9;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --s1: #2a78d6;   /* chart: fully recorded */
  --s2: #eb6834;   /* chart: pay only */
  --s3: #1baf7a;   /* chart: estimated / second measure */
  --grid: #e6e5df;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 19, .06), 0 2px 8px rgba(20, 20, 19, .04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --line: #34332f;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-3: #8f8e86;
    --accent: #3987e5;
    --accent-soft: #1b2c42;
    --good: #5cc98a;
    --good-soft: #17301f;
    --warn: #e5b04a;
    --warn-soft: #34290f;
    --bad: #f08a83;
    --bad-soft: #3a1a18;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --grid: #2b2a27;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 var(--font);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
@media (min-width: 900px) { body { padding-bottom: 32px; } }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.45rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.tiny { font-size: .78rem; color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-in {
  max-width: 1180px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand svg { width: 30px; height: 30px; flex: none; }
.crumb { color: var(--ink-2); font-weight: 600; }
.crumb::before { content: "/"; margin-right: 10px; color: var(--ink-3); font-weight: 400; }
.topnav { margin-left: auto; display: none; gap: 4px; }
.topnav a {
  padding: 7px 12px; border-radius: 999px; color: var(--ink-2); font-weight: 500;
}
.topnav a:hover { background: var(--surface-2); text-decoration: none; }
.topnav a.on { background: var(--accent-soft); color: var(--accent); }
@media (min-width: 900px) { .topnav { display: flex; } }
.top-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
@media (min-width: 900px) { .top-right { margin-left: 8px; } }
.iconbtn {
  width: 36px; height: 36px; border-radius: 999px; display: grid; place-items: center;
  color: var(--ink-2); border: 1px solid var(--line); background: var(--surface);
}
.iconbtn:hover { background: var(--surface-2); text-decoration: none; }
.iconbtn svg { width: 18px; height: 18px; }

/* ---------- bottom tab bar (phone) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
@media (min-width: 900px) { .tabbar { display: none; } }
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .7rem; color: var(--ink-3); padding: 4px 0; font-weight: 500;
}
.tabbar a:hover { text-decoration: none; }
.tabbar a.on { color: var(--accent); }
.tabbar svg { width: 22px; height: 22px; }
.tabbar .plus {
  width: 48px; height: 48px; border-radius: 16px; background: var(--accent); color: #fff;
  display: grid; place-items: center; margin-top: -18px; box-shadow: 0 4px 14px rgba(42, 120, 214, .35);
}
.tabbar .plus svg { width: 26px; height: 26px; }

/* ---------- layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 18px 16px 28px; }
.narrow { max-width: 640px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: 1fr; }
.g3 { grid-template-columns: 1fr; }
@media (min-width: 720px) { .g2 { grid-template-columns: 1fr 1fr; } .g3 { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1000px) { .g3 { grid-template-columns: 1fr 1fr 1fr; } }
.span2 { grid-column: 1 / -1; }
@media (min-width: 1000px) { .span2 { grid-column: span 2; } }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card h2 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card h2 small { font-weight: 400; font-size: .8rem; color: var(--ink-3); }
.section-title { margin: 26px 0 10px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 600; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.kpi .label { font-size: .78rem; color: var(--ink-2); font-weight: 500; }
.kpi .value { font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .78rem; color: var(--ink-3); margin-top: 2px; }
.kpi.hero { grid-column: 1 / -1; background: var(--accent); color: #fff; border-color: transparent; }
.kpi.hero .label, .kpi.hero .sub { color: rgba(255, 255, 255, .85); }
.kpi.hero .value { font-size: 2.2rem; }
@media (min-width: 720px) { .kpi.hero { grid-column: span 2; } }

/* ---------- forms ---------- */
label { display: block; font-size: .82rem; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); vertical-align: middle; }
.field { margin-bottom: 14px; }
.fields { display: grid; gap: 0 12px; grid-template-columns: 1fr 1fr; }
.fields .full { grid-column: 1 / -1; }
.hint { font-size: .78rem; color: var(--ink-3); margin-top: 4px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; color: var(--ink); font-size: .9rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 14px 2px; margin: 0 0 14px; }
legend { padding: 0 6px; font-weight: 700; font-size: .85rem; }
.calc { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-weight: 600; margin-bottom: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; border-radius: 10px; padding: 10px 16px; min-height: 44px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }

/* ---------- pills, filters ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters select { width: auto; min-height: 38px; padding: 6px 10px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface); }
.seg a { padding: 7px 12px; font-size: .85rem; color: var(--ink-2); }
.seg a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg a:hover { text-decoration: none; }
.pill { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--accent-soft); color: var(--accent); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---------- flash ---------- */
.flash { border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-weight: 500; }
.flash.ok { background: var(--good-soft); color: var(--good); }
.flash.error { background: var(--bad-soft); color: var(--bad); }
.note { background: var(--warn-soft); color: var(--ink); border-radius: 10px; padding: 12px 14px; font-size: .9rem; }
.note.info { background: var(--accent-soft); }
.note strong { color: inherit; }

/* ---------- tables & lists ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .75rem; color: var(--ink-3); font-weight: 600; padding: 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
.total-row td { font-weight: 700; border-top: 2px solid var(--line); }

.list { display: grid; gap: 8px; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; color: var(--ink);
}
.item:hover { text-decoration: none; border-color: var(--accent); }
.item .t { font-weight: 600; }
.item .m { font-size: .8rem; color: var(--ink-2); }
.item .amt { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.item .flags { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text, .chart text.lbl { fill: var(--ink-3); font-size: 11px; font-family: var(--font); }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--line); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .hl, .chart .hl.on { opacity: 1; }
.tip {
  position: absolute; pointer-events: none; z-index: 5; background: var(--ink); color: var(--surface);
  font-size: .78rem; padding: 7px 10px; border-radius: 8px; white-space: nowrap; opacity: 0; transition: opacity .1s;
  transform: translate(-50%, calc(-100% - 10px)); line-height: 1.35;
}
.tip b { font-weight: 700; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--ink-2); margin-bottom: 8px; }
.empty { color: var(--ink-3); font-size: .9rem; padding: 26px 0; text-align: center; }

/* ---------- stat rows ---------- */
.stat-rows { display: grid; gap: 0; }
.stat-rows > div { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.stat-rows > div:last-child { border-bottom: 0; }
.stat-rows span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

.records { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
@media (min-width: 720px) { .records { grid-template-columns: repeat(3, 1fr); } }
.record { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.record .k { font-size: .75rem; color: var(--ink-2); }
.record .v { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.record .d { font-size: .75rem; color: var(--ink-3); }

.meter { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; display: flex; gap: 2px; }
.meter span { display: block; height: 100%; }

/* ---------- home tiles ---------- */
.hero-home { padding: 8px 0 18px; }
.hero-home h1 { font-size: 1.8rem; }
.tiles { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .tiles { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1000px) { .tiles { grid-template-columns: 1fr 1fr 1fr; } }
.tile {
  display: flex; flex-direction: column; gap: 12px; color: var(--ink); min-height: 190px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 18px; box-shadow: var(--shadow);
  transition: transform .12s, border-color .12s;
}
.tile:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-2px); }
.tile .logo { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; }
.tile .logo svg { width: 32px; height: 32px; }
.tile h2 { margin: 0; font-size: 1.2rem; }
.tile .lines { font-size: .88rem; color: var(--ink-2); display: grid; gap: 2px; }
.tile .go { margin-top: auto; font-weight: 600; color: var(--accent); font-size: .9rem; }
.tile.soon { opacity: .75; border-style: dashed; box-shadow: none; }
.tile.soon:hover { transform: none; border-color: var(--line); }
.tile.soon .go { color: var(--ink-3); }

.auth { max-width: 380px; margin: 8vh auto 0; }
.auth .brand { justify-content: center; margin-bottom: 22px; font-size: 1.2rem; }
.auth .brand svg { width: 48px; height: 48px; }

.open-block { border: 2px solid var(--accent); }
.loading { opacity: .6; pointer-events: none; }

/* ---------- select & delete several blocks ---------- */
.item .pick { display: none; }
.selecting .item { grid-template-columns: auto 1fr auto; cursor: pointer; }
.selecting .item .pick { display: block; grid-row: 1 / span 2; pointer-events: none; }
.selecting .item .flags { grid-column: 2 / -1; }
.item.chosen { border-color: var(--bad); background: var(--bad-soft); }
.selbar {
  display: none; position: fixed; left: 50%; transform: translateX(-50%); z-index: 40;
  bottom: calc(84px + env(safe-area-inset-bottom)); width: min(560px, calc(100% - 24px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18); align-items: center; gap: 8px;
}
.selbar.on { display: flex; }
.selbar #selcount { flex: 1; text-align: center; color: var(--ink-2); }
@media (min-width: 900px) { .selbar { bottom: 20px; } }
