:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f0f2ee;
  --text: #1b1f1d;
  --muted: #5f6b66;
  --line: #dde2dc;
  --accent: #0f5c4d;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe9;
  --red: #b42318;
  --red-soft: #fde8e6;
  --amber: #9a5b00;
  --amber-soft: #fff1d6;
  --blue: #1d4f91;
  --blue-soft: #e3edfb;
  --green: #1d7a46;
  --green-soft: #e1f4e8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513; --surface: #1a1f1d; --surface-2: #222826; --text: #e8ece9; --muted: #9aa6a1; --line: #2e3532;
    --accent: #4fb89c; --accent-ink: #0b1411; --accent-soft: #1d3a32;
    --red: #ff8a7f; --red-soft: #3a1d1a; --amber: #f2b350; --amber-soft: #3a2c12;
    --blue: #8ab4f8; --blue-soft: #1b2a40; --green: #6fd39b; --green-soft: #173225;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- układ ---------- */
.shell { min-height: 100%; }
.main { padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 20px; margin: 0; flex: 1; letter-spacing: -.01em; }
#view { padding: 16px; max-width: 1100px; margin: 0 auto; outline: none; }

.nav {
  position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--surface); border-top: 1px solid var(--line);
}
.nav .brand { display: none; }
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px; min-width: 0;
}
.nav a .ico { font-size: 19px; line-height: 1; }
.nav a.active { color: var(--accent); font-weight: 600; }
.nav a[data-view="harmonogram"] { display: none; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 232px 1fr; }
  .nav {
    position: sticky; top: 0; height: 100vh; flex-direction: column; border-top: 0; border-right: 1px solid var(--line);
    padding: 16px 12px; gap: 2px;
  }
  .nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 6px 10px 18px; }
  .nav .brand img { border-radius: 8px; }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 12px; border-radius: 10px; font-size: 15px; }
  .nav a[data-view="harmonogram"] { display: flex; }
  .nav a.active { background: var(--accent-soft); }
  .nav a .ico { width: 20px; text-align: center; font-size: 16px; }
  .main { padding-bottom: 24px; }
  #view { padding: 24px 28px; }
  .topbar { padding: 14px 28px; }
}

/* ---------- elementy ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.section { margin: 22px 0 10px; display: flex; align-items: baseline; gap: 10px; }
.section h2 { font-size: 15px; margin: 0; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); flex: 1; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { padding: 14px 16px; }
.stat .lbl { font-size: 12.5px; color: var(--muted); }
.stat .val { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12.5px; color: var(--muted); }
.stat.red .val { color: var(--red); }
.stat.amber .val { color: var(--amber); }

.list { padding: 0; margin: 0; list-style: none; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row .body { flex: 1; min-width: 0; }
.row .t { font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; }
.row .s { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .r { text-align: right; flex: none; }
.row .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row.off { opacity: .55; }
.datebox {
  flex: none; width: 46px; text-align: center; border-radius: 10px; padding: 5px 0; background: var(--surface-2); line-height: 1.1;
}
.datebox b { display: block; font-size: 17px; }
.datebox small { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.datebox.red { background: var(--red-soft); color: var(--red); }
.datebox.red small { color: var(--red); }
.datebox.amber { background: var(--amber-soft); color: var(--amber); }
.datebox.amber small { color: var(--amber); }

.pill { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; vertical-align: 1px; }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.acc { background: var(--accent-soft); color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text); min-height: 38px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
.check {
  flex: none; width: 38px; height: 38px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; font-size: 17px; color: var(--muted);
}
.check:hover { border-color: var(--green); color: var(--green); background: var(--green-soft); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px; cursor: pointer; white-space: nowrap; font-size: 13.5px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.search { flex: 1; min-width: 160px; }
input[type="text"], input[type="search"], input[type="number"], input[type="date"], input[type="month"], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 11px; min-height: 40px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
label.f { display: block; font-size: 12.5px; color: var(--muted); font-weight: 600; }
label.f > span { display: block; margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.grid2 .wide { grid-column: 1 / -1; }
.inline { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); font-weight: 500; }

.sync { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px; cursor: pointer; font-size: 13px; max-width: 55vw; }
.sync span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.sync.ok .dot { background: var(--green); }
.sync.syncing .dot { background: var(--blue); animation: pulse 1s infinite; }
.sync.error .dot { background: var(--red); }
.sync.auth .dot { background: var(--amber); }
@keyframes pulse { 50% { opacity: .3; } }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); z-index: 9; width: 56px; height: 56px;
  border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 30px; line-height: 1; cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
.fab[hidden] { display: none; }
@media (min-width: 900px) { .fab { bottom: 28px; right: 28px; } }

dialog {
  border: 0; padding: 0; border-radius: 18px; width: min(560px, calc(100vw - 20px)); max-height: calc(100dvh - 30px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(10, 15, 13, .45); }
dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 30px); }
dialog .dh { padding: 16px 18px 6px; display: flex; align-items: center; gap: 10px; }
dialog .dh h3 { margin: 0; font-size: 18px; flex: 1; }
dialog .db { padding: 8px 18px 14px; overflow: auto; }
dialog .df { padding: 12px 18px 16px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); flex-wrap: wrap; }
dialog .df .spacer { flex: 1; }
.x { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); padding: 4px 8px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); bottom: calc(var(--nav-h) + 86px + env(safe-area-inset-bottom));
  background: #1f2523; color: #fff; padding: 10px 14px; border-radius: 12px; z-index: 50; opacity: 0; pointer-events: none;
  transition: .2s; display: flex; gap: 12px; align-items: center; max-width: calc(100vw - 32px); font-size: 14px;
}
.toast.show { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
.toast button { background: none; border: 0; color: #7fe0c3; font-weight: 700; cursor: pointer; }
@media (min-width: 900px) { .toast { bottom: 28px; } }

.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 13.5px; }
table.t th, table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
table.t td:first-child, table.t th:first-child { text-align: left; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--surface-2); }
table.t tfoot td { font-weight: 700; }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.hello { padding: 20px; }
.hello h2 { margin: 0 0 6px; }
.hello p { color: var(--muted); margin: 0 0 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack > * + * { margin-top: 12px; }
.month h3 { font-size: 14px; margin: 0; padding: 12px 14px; display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); text-transform: capitalize; }
.cols { display: grid; gap: 12px; }
@media (min-width: 900px) { .cols.two { grid-template-columns: 1fr 1fr; } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; word-break: break-all; }
