/* Freelance Tracker — calm, Apple-style interface (light + dark) */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f2f2f4;
  --fill: rgba(118, 118, 128, .12);
  --fill-strong: rgba(118, 118, 128, .2);
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --sep: rgba(60, 60, 67, .12);
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-soft: rgba(0, 113, 227, .1);
  --green: #248a3d;
  --red: #d70015;
  --orange: #c93400;
  --purple: #8944ab;
  --dot-green: #34c759;
  --dot-red: #ff3b30;
  --dot-orange: #ff9500;
  --dot-blue: #007aff;
  --dot-purple: #af52de;
  --c-rev: #0071e3;
  --c-dir: #ff9f0a;
  --c-ovh: #c7c7cc;
  --c-net: #34c759;
  --sidebar-bg: rgba(246, 246, 248, .82);
  --shadow: 0 1px 1px rgba(0, 0, 0, .02), 0 2px 12px rgba(0, 0, 0, .04);
  --shadow-pop: 0 12px 40px rgba(0, 0, 0, .14), 0 2px 8px rgba(0, 0, 0, .06);
  --r: 18px;
  --r-sm: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --fill: rgba(118, 118, 128, .24);
    --fill-strong: rgba(118, 118, 128, .32);
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #8d8d93;
    --sep: rgba(84, 84, 88, .55);
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --accent-soft: rgba(10, 132, 255, .18);
    --green: #30d158;
    --red: #ff453a;
    --orange: #ff9f0a;
    --purple: #bf5af2;
    --dot-green: #30d158;
    --dot-red: #ff453a;
    --dot-orange: #ff9f0a;
    --dot-blue: #0a84ff;
    --dot-purple: #bf5af2;
    --c-rev: #0a84ff;
    --c-dir: #ff9f0a;
    --c-ovh: #636366;
    --c-net: #30d158;
    --sidebar-bg: rgba(28, 28, 30, .78);
    --shadow: none;
    --shadow-pop: 0 12px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000; --surface: #1c1c1e; --surface-2: #2c2c2e; --fill: rgba(118,118,128,.24); --fill-strong: rgba(118,118,128,.32);
  --text: #f5f5f7; --text-2: #a1a1a6; --text-3: #8d8d93; --sep: rgba(84,84,88,.55);
  --accent: #0a84ff; --accent-hover: #409cff; --accent-soft: rgba(10,132,255,.18);
  --green: #30d158; --red: #ff453a; --orange: #ff9f0a; --purple: #bf5af2;
  --dot-green: #30d158; --dot-red: #ff453a; --dot-orange: #ff9f0a; --dot-blue: #0a84ff; --dot-purple: #bf5af2;
  --c-rev: #0a84ff; --c-dir: #ff9f0a; --c-ovh: #636366; --c-net: #30d158;
  --sidebar-bg: rgba(28,28,30,.78); --shadow: none; --shadow-pop: 0 12px 40px rgba(0,0,0,.5); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.47 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-feature-settings: "cv11", "ss01";
  letter-spacing: -.008em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body.modal-open { overflow: hidden; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 30px; font-weight: 700; letter-spacing: -.025em; }
h2 { font-size: 17px; font-weight: 600; letter-spacing: -.015em; }
h3 { font-size: 17px; font-weight: 600; }
h4 { font-size: 13px; font-weight: 600; margin: 22px 0 6px; color: var(--text-2); }
p { margin: 6px 0; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.ic { width: 18px; height: 18px; flex: none; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--text-3); }
.num, .kpi-value, .big, .fc-row b, .fc-net b, .summary b, .mini-list .right { font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--sidebar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-right: 1px solid var(--sep);
  padding: 22px 10px 14px;
}
.brand { padding: 2px 12px 20px; }
.brand b { display: block; font-size: 15px; font-weight: 600; letter-spacing: -.015em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand small { display: block; color: var(--text-3); font-size: 12px; margin-top: 1px; }
.logo {
  width: 64px; height: 64px; border-radius: 16px;
  display: grid; place-items: center; margin: 0 auto 18px;
  background: linear-gradient(180deg, #3a3a3c, #1d1d1f); color: #fff;
  font-size: 30px; font-weight: 600;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .18);
}
.nav { display: flex; flex-direction: column; gap: 1px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px; border-radius: 8px;
  color: var(--text); font-size: 13.5px; font-weight: 500;
}
.nav a .ic { width: 17px; height: 17px; color: var(--accent); }
.nav a:hover { background: var(--fill); }
.nav a.active { background: var(--fill-strong); font-weight: 600; }
.sync { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--text-3); padding: 10px 12px 0; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dot-green); flex: none; }
.dot.busy { background: var(--dot-orange); }
.dot.bad { background: var(--dot-red); }

.main { min-width: 0; }
.topbar { display: none; }
.view { max-width: 1120px; margin: 0 auto; padding: 40px 40px 80px; }
.scrim { display: none; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head p { margin: 4px 0 0; color: var(--text-2); font-size: 15px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.period { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 16px; border-radius: 980px;
  border: 0; background: var(--fill); color: var(--text);
  font: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, transform .1s;
}
.btn:hover { background: var(--fill-strong); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { background: transparent; color: var(--red); }
.btn.danger:hover { background: rgba(255, 59, 48, .1); }
.btn.small { height: 28px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; height: 44px; font-size: 15px; border-radius: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn .ic { width: 15px; height: 15px; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 8px; border: 0; background: transparent;
  color: var(--text-3); display: inline-grid; place-items: center; cursor: pointer; font-size: 20px; line-height: 1;
  transition: background-color .15s, color .15s;
}
.icon-btn:hover { background: var(--fill); color: var(--text); }
.icon-btn.danger:hover { color: var(--red); }
.icon-btn.go { color: var(--accent); }
.icon-btn .ic { width: 16px; height: 16px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-align: left; }
.link:hover { text-decoration: underline; }
.link.strong { font-weight: 600; color: var(--text); }
.link.strong:hover { color: var(--accent); text-decoration: none; }
:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 1px; }
.btn:focus-visible, .icon-btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); }

.input {
  height: 34px; padding: 0 12px; border-radius: var(--r-sm);
  border: 1px solid transparent; background: var(--fill); color: var(--text);
  font: inherit; font-size: 14px; min-width: 0; width: 100%;
  transition: box-shadow .15s, background-color .15s;
}
select.input { padding-right: 28px; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2386868b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; }
textarea.input { height: auto; padding: 8px 12px; resize: vertical; }
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.period .input, .filters .input { width: auto; }
.filters { display: flex; gap: 8px; margin: 0 0 14px; flex-wrap: wrap; }
.filters input[type=search] { flex: 1; min-width: 200px; max-width: 320px; }

/* segmented control */
.tabs {
  display: inline-flex; gap: 2px; padding: 2px; margin-bottom: 14px;
  background: var(--fill); border-radius: 9px; max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: transparent; color: var(--text); font: inherit; font-size: 13px; font-weight: 500;
  padding: 5px 14px; border-radius: 7px; cursor: pointer; white-space: nowrap; transition: background-color .15s;
}
.tab:hover:not(.active) { background: var(--fill); }
.tab.active { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); font-weight: 600; }
:root[data-theme="dark"] .tab.active { background: #636366; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tab.active { background: #636366; } }
.count { margin-left: 4px; color: var(--text-3); font-weight: 500; font-size: 12px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border-radius: var(--r);
  box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 20px;
}
.card > h2 { margin-bottom: 8px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid2 > .card { margin-bottom: 20px; }
.welcome { padding: 48px 32px; text-align: center; }
.welcome h2 { font-size: 24px; letter-spacing: -.02em; margin-bottom: 8px; }
.welcome p { max-width: 520px; margin: 0 auto; font-size: 15px; }
.welcome .row-actions { justify-content: center; margin-top: 22px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.notice {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  padding: 12px 16px; margin-bottom: 20px; font-size: 13.5px; color: var(--text-2);
}
.notice::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dot-orange); flex: none; }
.notice.soft::before { background: var(--dot-blue); }
.notice b { color: var(--text); }
.danger-zone h2 { color: var(--text); }

/* KPI strip — one card, four columns */
.kpis {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow);
  margin-bottom: 20px; overflow: hidden;
}
.kpi { padding: 20px 22px; min-width: 0; position: relative; }
.kpi + .kpi::before { content: ""; position: absolute; left: 0; top: 20px; bottom: 20px; width: 1px; background: var(--sep); }
.kpi-label { color: var(--text-2); font-size: 13px; font-weight: 500; }
.kpi-value { font-size: 28px; font-weight: 600; margin: 6px 0 4px; letter-spacing: -.025em; overflow-wrap: anywhere; line-height: 1.15; }
.kpi-sub { color: var(--text-3); font-size: 12px; }
.kpi.pos .kpi-value { color: var(--green); }
.kpi.neg .kpi-value { color: var(--red); }
.help { display: none; }

/* forecast */
.forecast { display: grid; grid-template-columns: repeat(3, 1fr); }
.fc { padding: 2px 22px; position: relative; }
.forecast .fc:first-child { padding-left: 0; }
.forecast .fc:last-child { padding-right: 0; }
.forecast .fc + .fc::before { content: ""; position: absolute; left: 0; top: 4px; bottom: 4px; width: 1px; background: var(--sep); }
.fc-title { font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 8px; }
.fc-row, .fc-net { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; font-size: 13.5px; }
.fc-row span, .fc-net span { color: var(--text-2); }
.fc-row b { font-weight: 500; }
.fc-net { border-top: 1px solid var(--sep); margin-top: 8px; padding-top: 10px; }
.fc-net b { font-size: 19px; font-weight: 600; letter-spacing: -.02em; }
.card > .muted.small { margin-top: 14px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.detail-grid .fc { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
.detail-grid .fc::before { display: none; }

.stat h2 { font-size: 13px; font-weight: 500; color: var(--text-2); letter-spacing: 0; }
.stat .big { font-size: 28px; font-weight: 600; margin: 6px 0 2px; letter-spacing: -.025em; }
.stat p { font-size: 13px; }
.stat .link { font-size: 13px; }

.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--sep); }
.mini-list li:first-child { border-top: 0; padding-top: 2px; }
.mini-list b { font-weight: 500; }
.mini-list small { display: block; color: var(--text-3); font-size: 12px; margin-top: 1px; }
.mini-list .right { text-align: right; white-space: nowrap; }

.legend { display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.sw.rev { background: var(--c-rev); }
.sw.dir { background: var(--c-dir); }
.sw.ovh { background: var(--c-ovh); }
.sw.net { background: var(--c-net); }

/* chart — Apple Health style */
.chart-card { padding-bottom: 14px; }
.chart-head { margin-bottom: 14px; min-height: 76px; }
.chart-kicker { font-size: 13px; font-weight: 500; color: var(--text-2); transition: color .2s; }
.chart-total { font-size: 34px; font-weight: 600; letter-spacing: -.03em; line-height: 1.15; margin: 2px 0 6px; font-variant-numeric: tabular-nums; }
.chart-total.neg { color: var(--red); }
.chart { position: relative; touch-action: pan-y; -webkit-user-select: none; user-select: none; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--sep); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .grid.zero { stroke-dasharray: none; }
.chart .axis { fill: var(--text-3); font-size: 11px; font-family: inherit; transition: fill .2s, font-weight .2s; }
.chart .axis.month.on { fill: var(--text); font-weight: 600; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .guide { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 2 3; opacity: 0; transition: opacity .2s; }
.chart .col.on .guide { opacity: .7; }
.chart .bar {
  transform-box: fill-box; transform-origin: 50% 100%;
  animation: barGrow .9s cubic-bezier(.22, 1, .36, 1) both;
  animation-delay: calc(var(--i, 0) * 45ms);
  transition: opacity .25s ease;
}
.chart .b-rev { fill: var(--c-rev); }
.chart .b-dir { fill: var(--c-dir); }
.chart .b-ovh { fill: var(--c-ovh); }
.chart.focus .col:not(.on) .bar { opacity: .28; }
.chart .net-line {
  fill: none; stroke: var(--c-net); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 1; stroke-dashoffset: 1;
  animation: lineDraw 1.2s .35s cubic-bezier(.65, 0, .35, 1) forwards;
}
.chart .stop-a { stop-color: var(--c-net); stop-opacity: .22; }
.chart .stop-b { stop-color: var(--c-net); stop-opacity: 0; }
.chart .net-area { opacity: 0; animation: fadeIn .9s 1s ease forwards; pointer-events: none; }
.chart .net-dot {
  fill: var(--surface); stroke: var(--c-net); stroke-width: 2.5; pointer-events: none;
  opacity: 0; transform-box: fill-box; transform-origin: center; transform: scale(.4);
  transition: opacity .2s, transform .3s cubic-bezier(.34, 1.56, .64, 1);
}
.chart .net-dot.on { opacity: 1; transform: scale(1); }
@keyframes barGrow { from { transform: scaleY(0); } }
@keyframes lineDraw { to { stroke-dashoffset: 0; } }
@keyframes fadeIn { to { opacity: 1; } }

/* ---------- tables ---------- */
.summary { display: flex; gap: 20px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); margin: 0 4px 12px; }
.summary b { color: var(--text); font-weight: 600; }
.summary b.pos { color: var(--green); }
.summary b.neg { color: var(--red); }
.table-wrap { background: var(--surface); border-radius: var(--r); overflow-x: auto; box-shadow: var(--shadow); padding: 4px 0; }
.card .table-wrap { box-shadow: none; border-radius: 0; margin: 0 -8px; padding: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 500; color: var(--text-3);
  padding: 10px 14px 8px; border-bottom: 1px solid var(--sep); white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--sep); vertical-align: top; }
.table th:first-child, .table td:first-child { padding-left: 22px; }
.table th:last-child, .table td:last-child { padding-right: 18px; }
.card .table th:first-child, .card .table td:first-child { padding-left: 8px; }
.card .table th:last-child, .card .table td:last-child { padding-right: 8px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color .12s; }
.table tbody tr:hover { background: color-mix(in srgb, var(--fill) 45%, transparent); }
.table b { font-weight: 500; }
.table .num { text-align: right; white-space: nowrap; }
.table .act { text-align: right; white-space: nowrap; width: 1%; }
.table .act .cell { opacity: .55; transition: opacity .15s; }
.table tr:hover .act .cell, .table .act .cell:focus-within { opacity: 1; }
.table .sub { display: block; color: var(--text-3); font-size: 12px; font-weight: 400; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.table .num .sub { max-width: none; }

/* status: dot + label */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; white-space: nowrap; color: var(--text-2); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); flex: none; }
.badge.ok { color: var(--text); }
.badge.ok::before { background: var(--dot-green); }
.badge.warn::before { background: var(--dot-orange); }
.badge.info::before { background: var(--dot-blue); }
.badge.bad::before { background: var(--dot-red); }
.badge.up::before { background: var(--dot-purple); }
.badge.outline { color: var(--red); font-size: 12px; margin-left: 6px; }
.badge.outline::before { display: none; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11.5px; font-weight: 500; background: var(--fill); color: var(--text-2); white-space: nowrap; vertical-align: 1px; }
.tag.soft { background: transparent; padding: 0; }

.empty { text-align: center; padding: 56px 16px; background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); color: var(--text-2); font-size: 15px; }
.empty .btn { margin-top: 14px; }

/* ---------- modal (sheet) ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .28);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 16px; overflow-y: auto;
  animation: fade .18s ease;
}
.modal-card {
  width: 100%; max-width: 480px; background: var(--surface); color: var(--text);
  border-radius: 20px; box-shadow: var(--shadow-pop);
  max-height: calc(100vh - 32px); display: flex; flex-direction: column;
  animation: pop .22s cubic-bezier(.2, .9, .3, 1.1);
}
:root[data-theme="dark"] .modal-card { background: #2c2c2e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .modal-card { background: #2c2c2e; } }
.modal-card.wide { max-width: 680px; }
.modal-card form { display: flex; flex-direction: column; min-height: 0; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px 6px; }
.modal-head h3 { font-size: 19px; font-weight: 600; letter-spacing: -.02em; }
.modal-body { padding: 12px 22px 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px 18px; border-top: 1px solid var(--sep); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@media (prefers-reduced-motion: reduce) { .modal, .modal-card { animation: none; } }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full, .form-grid > .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.hint { color: var(--text-3); font-size: 12px; margin: 0; }
.check { display: flex; align-items: center; gap: 8px; height: 34px; font-weight: 400; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.pay-box { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--sep); }
.pay-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.pay-head b { font-weight: 600; font-size: 14px; }
.pay-row { display: grid; grid-template-columns: 1.1fr 1fr .9fr 30px; gap: 8px; margin-bottom: 8px; align-items: center; }
.pay-box .hint { margin-top: 4px; }

/* ---------- gate ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.gate-card { width: 100%; max-width: 340px; text-align: center; display: flex; flex-direction: column; gap: 10px; }
.gate-card h1 { font-size: 26px; }
.gate-card > p.muted { margin: 0 0 12px; font-size: 14px; }
.gate-card .input { height: 44px; border-radius: 12px; font-size: 16px; text-align: center; }
.gate-msg { min-height: 1.2em; margin: 0; font-size: 13px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 16px);
  background: rgba(29, 29, 31, .92); color: #f5f5f7; padding: 11px 18px; border-radius: 14px;
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  font-size: 13.5px; font-weight: 500; opacity: 0; pointer-events: none; transition: .25s cubic-bezier(.2, .9, .3, 1);
  z-index: 60; max-width: calc(100vw - 32px); box-shadow: var(--shadow-pop);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--red); color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi:nth-child(3)::before { display: none; }
  .kpi:nth-child(n+3) { border-top: 1px solid var(--sep); }
  .view { padding: 32px 28px 80px; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; width: 270px;
    background: var(--surface);
    transform: translateX(-100%); transition: transform .25s cubic-bezier(.2, .9, .3, 1);
  }
  body.menu-open .sidebar { transform: none; box-shadow: var(--shadow-pop); }
  body.menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .25); z-index: 30; }
  .topbar {
    display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 20;
    height: 50px; padding: 0 8px;
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--sep);
  }
  .topbar .icon-btn { color: var(--accent); font-size: 22px; }
  .topbar b { font-size: 16px; font-weight: 600; }
  .view { padding: 20px 16px 80px; }
  .grid2, .detail-grid { grid-template-columns: 1fr; gap: 0; }
  .forecast { grid-template-columns: 1fr; }
  .forecast .fc { padding: 12px 0; }
  .forecast .fc + .fc::before { left: 0; right: 0; top: 0; bottom: auto; width: auto; height: 1px; }
  .detail-grid { gap: 10px; }
}
@media (max-width: 720px) {
  h1 { font-size: 28px; }
  .page-head { align-items: stretch; flex-direction: column; margin-bottom: 18px; }
  .head-actions .btn { flex: 1; }
  .period, .period .input { width: 100%; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi { padding: 16px; }
  .kpi-value, .stat .big { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; }
  .filters input[type=search] { max-width: none; }
  .tabs { display: flex; }
  .tab { flex: 1; padding: 6px 10px; }

  /* tables become grouped lists */
  .table-wrap { background: transparent; box-shadow: none; overflow: visible; padding: 0; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { background: var(--surface); border-radius: 14px; padding: 10px 16px; margin-bottom: 10px; box-shadow: var(--shadow); }
  .card .table tr { box-shadow: none; background: var(--surface-2); }
  .table td, .table th:first-child, .table td:first-child, .table td:last-child,
  .card .table td:first-child, .card .table td:last-child {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    border: 0; padding: 5px 0; text-align: right;
  }
  .table td::before { content: attr(data-label); color: var(--text-2); font-size: 13px; text-align: left; flex: none; }
  .table td[data-label=""]::before { content: none; }
  .table td .cell { min-width: 0; }
  .table .act { width: 100%; justify-content: flex-end; border-top: 1px solid var(--sep); margin-top: 6px; padding-top: 8px; }
  .table .act .cell { opacity: 1; }
  .table .sub { max-width: 60vw; margin-left: auto; }
  .table tbody tr:hover { background: var(--surface); }
  .pay-row { grid-template-columns: 1fr 1fr; }
}
@media print {
  .sidebar, .topbar, .head-actions, .act, .tabs, .filters { display: none !important; }
  .app { display: block; }
  .card, .kpis, .table-wrap { box-shadow: none; break-inside: avoid; }
}

/* ---------- motion ---------- */
.view.enter > * { animation: rise .55s cubic-bezier(.22, 1, .36, 1) both; }
.view.enter > *:nth-child(2) { animation-delay: .04s; }
.view.enter > *:nth-child(3) { animation-delay: .08s; }
.view.enter > *:nth-child(4) { animation-delay: .12s; }
.view.enter > *:nth-child(5) { animation-delay: .16s; }
.view.enter > *:nth-child(6) { animation-delay: .2s; }
.view.enter > *:nth-child(n+7) { animation-delay: .24s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.modal.closing { animation: fadeOut .18s ease forwards; pointer-events: none; }
.modal.closing .modal-card { animation: popOut .18s ease forwards; }
@keyframes fadeOut { to { opacity: 0; } }
@keyframes popOut { to { opacity: 0; transform: translateY(6px) scale(.98); } }

.nav a { transition: background-color .2s ease, color .2s ease; }
.kpi, .card, .table-wrap { transition: box-shadow .25s ease; }
.toast { transition: opacity .3s ease, transform .4s cubic-bezier(.34, 1.4, .64, 1); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
  .chart .net-line { stroke-dashoffset: 0; }
}

/* ---------- iOS-style refinements ---------- */
.notice { display: block; position: relative; padding-left: 32px; line-height: 1.5; }
.notice::before { position: absolute; left: 16px; top: 18px; }
.notice .link { margin-left: 4px; white-space: nowrap; }

@media (max-width: 900px) {
  /* small title appears in the bar once the large title scrolls away */
  .topbar b { opacity: 0; transform: translateY(4px); transition: opacity .25s ease, transform .25s ease; }
  body.scrolled .topbar b { opacity: 1; transform: none; }
  .topbar { border-bottom-color: transparent; transition: border-color .25s ease; }
  body.scrolled .topbar { border-bottom-color: var(--sep); }
}
@media (max-width: 720px) {
  /* forms open as a bottom sheet */
  .modal { place-items: end center; padding: 0; }
  .modal-card, .modal-card.wide {
    max-width: none; border-radius: 22px 22px 0 0; max-height: 94vh;
    animation: sheetUp .38s cubic-bezier(.22, 1, .36, 1);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-head { padding-top: 22px; position: relative; }
  .modal-head::before { content: ""; position: absolute; top: 8px; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: 3px; background: var(--fill-strong); }
  .modal.closing .modal-card { animation: sheetDown .2s ease forwards; }
  .modal-foot .btn { flex: 1; height: 44px; font-size: 15px; }
  .input { height: 40px; font-size: 16px; } /* 16px stops iOS zooming into fields */
}
@keyframes sheetUp { from { transform: translateY(100%); } }
@keyframes sheetDown { to { transform: translateY(100%); } }

/* ---------- dashboard: primary numbers ---------- */
.hero { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.hero-card {
  background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 20px 22px 18px; min-width: 0;
}
.hero-label { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 500; color: var(--text-2); }
.hero-label i { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-3); }
.hero-card.in .hero-label i { background: var(--dot-green); }
.hero-card.out .hero-label i { background: var(--dot-orange); }
.hero-card.net .hero-label i { background: var(--dot-blue); }
.hero-card.soft .hero-label i { background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-3); }
.hero-card.in.soft .hero-label i { box-shadow: inset 0 0 0 1.5px var(--dot-green); }
.hero-card.out.soft .hero-label i { box-shadow: inset 0 0 0 1.5px var(--dot-orange); }
.hero-card.net.soft .hero-label i { box-shadow: inset 0 0 0 1.5px var(--dot-blue); }
.hero-value { font-size: 32px; font-weight: 600; letter-spacing: -.03em; line-height: 1.15; margin: 10px 0 6px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hero-card.pos .hero-value { color: var(--green); }
.hero-card.neg .hero-value { color: var(--red); }
.hero-sub { font-size: 12.5px; color: var(--text-3); line-height: 1.4; }
.hero-card.net.soft { background: linear-gradient(180deg, var(--accent-soft), transparent 70%), var(--surface); }
.hero + .kpis .kpi-value { font-size: 22px; }

/* ---------- fixed expenses ---------- */
.month-nav { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 16px; background: var(--surface); border-radius: 12px; padding: 4px 6px; box-shadow: var(--shadow); }
.month-nav b { min-width: 132px; text-align: center; font-size: 15px; font-weight: 600; }
.month-nav .icon-btn { font-size: 22px; color: var(--accent); }
.amt-input { width: 130px; text-align: right; height: 32px; font-variant-numeric: tabular-nums; }
.table .num .amt-input { margin-left: auto; display: block; }
.hint-line { margin: 10px 4px 20px; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.paid-only > span { font-size: 12.5px; font-weight: 500; color: var(--text-2); }

@media (max-width: 1080px) { .hero { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px) {
  .hero { grid-template-columns: 1fr 1fr; gap: 10px; }
  .hero-card { padding: 14px 14px 12px; }
  .hero-value { font-size: 21px; margin: 6px 0 4px; }
  .hero-label { font-size: 12.5px; }
  .hero-sub { font-size: 11.5px; }
  .amt-input { width: 120px; }
  .month-nav { display: flex; justify-content: space-between; }
}
/* two columns: pair "done" with "still due" side by side */
@media (max-width: 1080px) {
  .hero-card:nth-child(1) { order: 1; } .hero-card:nth-child(4) { order: 2; }
  .hero-card:nth-child(2) { order: 3; } .hero-card:nth-child(5) { order: 4; }
  .hero-card:nth-child(3) { order: 5; } .hero-card:nth-child(6) { order: 6; }
}

/* ---------- roles: view-only logins ---------- */
body.ro [data-act^="add"], body.ro [data-act^="edit"], body.ro [data-act^="del"], body.ro [data-act^="pay"],
body.ro [data-act="toggleFixedPaid"], body.ro [data-act="resetFixedAmt"], body.ro [data-act="restore"],
body.ro [data-act="resetAll"], body.ro [data-act="importLocal"] { display: none !important; }
.amt-input:disabled { background: transparent; color: var(--text); opacity: 1; }

/* ---------- setup screen ---------- */
.gate-card.wide { max-width: 560px; text-align: left; }
.gate-card.wide h1, .gate-card.wide > p.muted { text-align: center; }
.gate-section { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 12px; }
.gate-section h3 { font-size: 15px; margin-bottom: 6px; }
.gate-section .input { height: 38px; font-size: 15px; text-align: left; }
.gate-section .muted.small { margin: 0 0 12px; }

.spacer { height: 20px; }
.role-list li small { max-width: 520px; }
.mini-list .muted { font-weight: 400; }

/* ---------- phone: thumb-friendly sizes (Apple: 44pt tap targets) ---------- */
@media (max-width: 900px), (pointer: coarse) {
  .btn { height: 44px; padding: 0 18px; font-size: 15px; }
  .btn.small { height: 36px; font-size: 14px; }
  .icon-btn { width: 44px; height: 44px; border-radius: 10px; }
  .icon-btn .ic { width: 20px; height: 20px; }
  .input, select.input { height: 44px; font-size: 16px; }
  .amt-input { height: 40px; }
  .tab { padding: 8px 14px; font-size: 14px; }
  .month-nav .icon-btn { width: 44px; height: 44px; }
  .link.small, .stat .link, .card-head .link { display: inline-block; padding: 10px 0; }
  .link.strong { padding: 4px 0; }
  .mini-list li { padding: 12px 0; }
  .tag, .count, .chart .axis, .kpi-sub, .hero-sub, .mini-list small, .table .sub { font-size: 12px; }
  .check { height: 44px; }
  .check input { width: 20px; height: 20px; }
  .table .act .cell { display: flex; gap: 4px; justify-content: flex-end; }
}

/* ---------- phone: bottom tab bar ---------- */
.tabbar { display: none; }
@media (max-width: 900px) {
  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--sep);
  }
  .tabbar a, .tabbar button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 48px; border: 0; background: none; font: inherit; font-size: 10.5px; font-weight: 500;
    color: var(--text-3); cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .tabbar .ic { width: 24px; height: 24px; }
  .tabbar .active { color: var(--accent); }
  .tabbar a:active, .tabbar button:active { transform: scale(.94); }
  .view { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .topbar .icon-btn[data-act="toggleMenu"] { display: none; }
  .topbar { padding-top: env(safe-area-inset-top); height: calc(50px + env(safe-area-inset-top)); justify-content: center; }
}
@media (max-width: 900px), (pointer: coarse) {
  .mini-list .right .link { display: inline-block; padding: 12px 0 12px 16px; }
  .table .link.strong { padding: 8px 0; }
}
@media (max-width: 720px) { .table td.act .cell { margin-left: auto; } }

/* phone: "More" sits on the right of the tab bar, so the menu slides in from the right */
@media (max-width: 900px) {
  .sidebar {
    left: auto; right: 0;
    transform: translateX(100%);
    border-right: 0; border-left: 1px solid var(--sep);
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  body.menu-open .sidebar { transform: none; }
}

/* show / hide password */
.pw-wrap { position: relative; display: block; width: 100%; }
.pw-wrap .input { padding-right: 46px; }
.pw-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 38px; height: 38px; border: 0; border-radius: 8px; background: none;
  color: var(--text-3); display: grid; place-items: center; cursor: pointer;
}
.pw-eye:hover { color: var(--text); background: var(--fill); }
.pw-eye .ic { width: 18px; height: 18px; }
.gate-card .pw-wrap .input { padding-left: 46px; } /* keep centred text visually centred */

/* ---------- install as an app ---------- */
.install-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  margin: 8px 0 4px; padding: 10px 12px; border: 0; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent);
  font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; text-align: left;
}
.install-btn:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.install-btn .ic { width: 18px; height: 18px; }
.steps { margin: 4px 0 14px; padding-left: 22px; line-height: 1.6; }
.steps li { margin-bottom: 10px; padding-left: 4px; }
.key { display: inline-block; min-width: 22px; padding: 0 6px; border-radius: 6px; background: var(--fill); text-align: center; font-weight: 600; }
.gate-card .link.install-only { align-self: center; margin-top: 4px; }
