:root {
  --bg: #f5f3ef; --surface: #ffffff; --surface2: #faf8f5; --ink: #1d1b20; --muted: #6b6872;
  --line: #e7e2db; --accent: #d6451f; --accent-ink: #ffffff; --accent-soft: #fbe9e3;
  --good: #1f8a5b; --good-soft: #e1f3ea; --warn: #a96a0c; --warn-soft: #fbf0d9; --bad: #c0322b; --bad-soft: #fbe4e2;
  --shadow: 0 1px 2px rgba(30,20,10,.05), 0 6px 20px rgba(30,20,10,.05);
  --radius: 14px; --nav-h: 62px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0e0e11; --surface: #17171b; --surface2: #1e1e23; --ink: #f2f0f5; --muted: #9c98a5;
  --line: #2a2a31; --accent: #ff7a50; --accent-ink: #1c0d07; --accent-soft: #3a2016;
  --good: #4cc790; --good-soft: #14291f; --warn: #e5a94a; --warn-soft: #302612; --bad: #ff7b72; --bad-soft: #3a1b19;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.3);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e11; --surface: #17171b; --surface2: #1e1e23; --ink: #f2f0f5; --muted: #9c98a5;
    --line: #2a2a31; --accent: #ff7a50; --accent-ink: #1c0d07; --accent-soft: #3a2016;
    --good: #4cc790; --good-soft: #14291f; --warn: #e5a94a; --warn-soft: #302612; --bad: #ff7b72; --bad-soft: #3a1b19;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 750; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.hide { display: none !important; }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 20px 14px; display: flex; flex-direction: column; gap: 6px;
  border-right: 1px solid var(--line); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 800; font-size: 20px; letter-spacing: -.02em; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; }
.logo svg { width: 18px; height: 18px; stroke: var(--accent-ink); }
.nav a, .nav button {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px; color: var(--muted);
  text-decoration: none; font-weight: 550; border: 0; background: none; width: 100%; cursor: pointer; text-align: left;
}
.nav a:hover, .nav button:hover { background: var(--surface2); color: var(--ink); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 19px; height: 19px; flex: none; }
.nav .badge { margin-left: auto; }
.side .spacer { flex: 1; }
.main { padding: 28px clamp(16px, 3vw, 40px) 60px; max-width: 1180px; width: 100%; margin: 0 auto; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.top .sub { color: var(--muted); margin-top: 3px; }
.tabbar { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 18px 14px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)); }
  h1 { font-size: 22px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 0; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600; border-radius: 10px; position: relative; }
  .tabbar a.on { color: var(--accent); }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar .dot { position: absolute; top: 3px; left: calc(50% + 7px); width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }
  .mobile-only { display: inline-flex !important; }
}
.mobile-only { display: none; }

/* ---- primitives ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card > .head, .head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .g2, .g3 { grid-template-columns: minmax(0, 1fr); } .grid { gap: 12px; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 15px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600; text-decoration: none; color: var(--ink); white-space: nowrap;
  transition: transform .12s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { background: var(--surface2); border-color: color-mix(in srgb, var(--ink) 20%, var(--line)); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 90%, #000); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: none; }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn svg { width: 17px; height: 17px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn { width: 38px; height: 38px; padding: 0; border-radius: 10px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .lbl { font-size: 12.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input[type=search], input[type=url], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface2); min-width: 0;
  transition: border-color .15s, background .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
textarea { min-height: 76px; resize: vertical; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); flex: none; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; width: 100%; height: 100%; }
.chip span {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface2); font-weight: 560; font-size: 14px; transition: all .12s ease; user-select: none;
}
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip input:active + span { transform: scale(.96); }

.tag { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; background: var(--surface2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.tag.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tag.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.tag.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 11.5px; font-weight: 700; display: inline-grid; place-items: center; }

.seg { display: inline-flex; padding: 3px; background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 8px; font-weight: 600; cursor: pointer; color: var(--muted); font-size: 13px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.banner { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 12px; background: var(--bad-soft); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); }
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.banner.info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.banner svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }

/* ---- stats / charts ---- */
.kpi .v { font-size: 32px; font-weight: 780; letter-spacing: -.02em; line-height: 1.1; margin-top: 6px; }
.kpi .l { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi .s { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 38%) 1fr auto; gap: 10px; align-items: center; font-size: 13.5px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 9px; background: var(--surface2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; min-width: 3px; transition: width .5s cubic-bezier(.2,.8,.2,1); }
.bar-row.alt .bar-fill { background: color-mix(in srgb, var(--accent) 55%, var(--muted)); }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .bar { fill: var(--accent); transition: opacity .15s; }
.chart .bar:hover { opacity: .75; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .val { fill: var(--ink); font-weight: 650; }

/* ---- lists / tables ---- */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); cursor: pointer; background: var(--surface); transition: background .12s; }
.item:first-child { border-top: 0; }
.item:hover { background: var(--surface2); }
.item .date { width: 54px; flex: none; text-align: center; line-height: 1.15; }
.item .date b { display: block; font-size: 20px; font-weight: 750; }
.item .date span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; font-weight: 650; letter-spacing: .04em; }
.item .main-t { font-weight: 650; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item .meta { color: var(--muted); font-size: 13px; margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.item.static { cursor: default; }
.avatar { width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 750; color: var(--accent); background: var(--accent-soft); font-size: 15px; }
.empty { text-align: center; color: var(--muted); padding: 34px 16px; }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; font-size: 16px; }
.filters { display: grid; grid-template-columns: 1.6fr repeat(5, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 900px) { .filters { grid-template-columns: 1fr 1fr; } .filters .search { grid-column: 1 / -1; } }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; white-space: nowrap; }
table.t td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.clickable { cursor: pointer; }
table.t tr.clickable:hover td { background: var(--surface2); }
.scroll-x { overflow-x: auto; }
.scroll-y { max-height: 520px; overflow: auto; }
td input[type=text] { padding: 6px 9px; border-radius: 8px; }

/* ---- calendar ---- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal .dow { padding: 8px; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface2); }
.cal .day { min-height: 98px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); cursor: pointer; display: flex; flex-direction: column; gap: 3px; background: var(--surface); min-width: 0; }
.cal .day:hover { background: var(--surface2); }
.cal .day.out { background: var(--surface2); opacity: .55; }
.cal .day .n { font-size: 12.5px; font-weight: 650; color: var(--muted); width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; }
.cal .day.today .n { background: var(--accent); color: var(--accent-ink); }
.cal .ev { font-size: 12px; padding: 2px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal .ev.planned { background: transparent; border: 1px dashed var(--accent); }
.cal .ev.cancelled { opacity: .5; text-decoration: line-through; }
.cal .more { font-size: 11.5px; color: var(--muted); padding-left: 4px; }
@media (max-width: 640px) { .cal .day { min-height: 62px; padding: 3px; } .cal .ev { font-size: 0; height: 7px; padding: 0; border-radius: 99px; } .cal .ev.planned { border-width: 1px; } .cal .dow { padding: 6px 2px; font-size: 10px; text-align: center; } }

/* ---- dialog ---- */
dialog { border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--ink); width: min(680px, calc(100vw - 20px)); max-height: calc(100vh - 24px); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10,8,14,.55); backdrop-filter: blur(3px); }
dialog[open] { animation: pop .18s cubic-bezier(.2,.9,.3,1.1); }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.dlg { display: flex; flex-direction: column; max-height: calc(100vh - 24px); }
.dlg-h { padding: 18px 22px 8px; display: flex; justify-content: space-between; align-items: center; }
.dlg-b { padding: 8px 22px 18px; overflow: auto; display: flex; flex-direction: column; gap: 16px; }
.dlg-f { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; align-items: center; background: var(--surface2); border-radius: 0 0 18px 18px; }
@media (max-width: 560px) { dialog { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 18px 18px 0 0; max-height: 94vh; } .dlg { max-height: 94vh; } .dlg-f { padding-bottom: calc(14px + env(safe-area-inset-bottom)); } }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px); opacity: 0; pointer-events: none; background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 14px; transition: all .25s cubic-bezier(.2,.9,.3,1.1); z-index: 100; max-width: calc(100vw - 30px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 860px) { #toast { bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); } }

/* ---- auth ---- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1000px 500px at 20% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.auth .card { width: min(400px, 100%); padding: 30px; }
.auth .brand { justify-content: center; padding: 0 0 6px; font-size: 26px; }
.auth .logo { width: 38px; height: 38px; border-radius: 11px; }
.auth .logo svg { width: 22px; height: 22px; }
.err { color: var(--bad); font-size: 13.5px; min-height: 18px; }
.copybox { display: flex; gap: 8px; }
.copybox input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.sep { height: 1px; background: var(--line); margin: 4px 0; }
.drop { border: 2px dashed var(--line); border-radius: 14px; padding: 26px; text-align: center; color: var(--muted); cursor: pointer; transition: all .15s; background: var(--surface2); }
.drop:hover, .drop.over { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.tl { position: relative; padding-left: 22px; }
.tl::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl .pt { position: relative; padding: 0 0 14px; }
.tl .pt::before { content: ""; position: absolute; left: -22px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }
.tl .pt.planned::before { background: var(--surface); border: 2px solid var(--accent); }
.tl .pt.flag::before { background: var(--bad); }
.sticky-bar { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 12px 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.fab { display: none; position: fixed; right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); width: 54px; height: 54px; border-radius: 50%; padding: 0; z-index: 19; box-shadow: 0 8px 24px rgba(214,69,31,.45); }
.fab svg { width: 26px; height: 26px; }
@media (max-width: 860px) { .fab { display: inline-flex; } #toast { bottom: calc(var(--nav-h) + 84px + env(safe-area-inset-bottom)); } }
@media (max-width: 860px) { .top .btn.primary[data-act="add"] { display: none; } }

.card.flush.scroll-y { overflow: auto; }
.hide-names input.nm:not(:focus) { -webkit-text-security: disc; }
@media (min-width: 861px) { .mobile-only { display: none !important; } }
