:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #f8f6f1;
  --text: #2b2b24;
  --muted: #6d6a5f;
  --border: #e2ddd0;
  --primary: #4f7a3a;
  --primary-ink: #ffffff;
  --primary-soft: #e6efdf;
  --danger: #b3392b;
  --danger-soft: #fbe7e4;
  --warn: #b7791f;
  --warn-soft: #fcf1dc;
  --info: #3b6ea5;
  --info-soft: #e3edf8;
  --shadow: 0 1px 3px rgba(40, 35, 20, .08), 0 4px 16px rgba(40, 35, 20, .05);
  --radius: 12px;
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1c18;
    --surface: #25271f;
    --surface-2: #2d3026;
    --text: #ecebe3;
    --muted: #a4a293;
    --border: #3a3d31;
    --primary: #7fb164;
    --primary-ink: #13200c;
    --primary-soft: #2f3d26;
    --danger: #ef7f70;
    --danger-soft: #45261f;
    --warn: #e7b35a;
    --warn-soft: #3f3320;
    --info: #85b3e6;
    --info-soft: #22303f;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* --- Logowanie --- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: 100%; max-width: 360px; background: var(--surface); padding: 28px 24px; border-radius: 16px; box-shadow: var(--shadow); }
.login-box h1 { text-align: center; margin: 4px 0 20px; }
.login-logo { font-size: 44px; text-align: center; }

/* --- Układ --- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--primary); color: var(--primary-ink);
}
.topbar h1 { font-size: 19px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .icon-btn { color: inherit; font-size: 30px; line-height: 1; padding: 0 6px 4px 0; }
.topbar .call-btn { background: rgba(255,255,255,.18); color: inherit; border: 0; white-space: nowrap; }
@media (prefers-color-scheme: dark) { .topbar .call-btn { background: rgba(0,0,0,.18); } }

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; 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(--border);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600;
}
.nav a span { font-size: 21px; line-height: 1; filter: grayscale(1); opacity: .8; }
.nav a.active { color: var(--primary); }
.nav a.active span { filter: none; opacity: 1; }

.view { padding: 16px; padding-bottom: calc(var(--nav-h) + 90px); max-width: 1100px; margin: 0 auto; }

@media (min-width: 900px) {
  .nav { top: 0; bottom: 0; right: auto; width: 200px; height: auto; flex-direction: column; justify-content: flex-start;
         padding-top: 70px; border-top: 0; border-right: 1px solid var(--border); }
  .nav a { flex: 0; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 12px 20px; font-size: 15px; }
  .topbar { z-index: 30; }
  .view { margin-left: 200px; padding: 24px; padding-bottom: 100px; }
  #app .view { max-width: calc(1100px + 200px); }
}

.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); z-index: 25;
  width: 58px; height: 58px; border-radius: 50%; border: 0; font-size: 30px;
  background: var(--primary); color: var(--primary-ink); box-shadow: 0 4px 14px rgba(0,0,0,.25); cursor: pointer;
}
@media (min-width: 900px) { .fab { bottom: 28px; right: 28px; } }

/* --- Elementy --- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.card h3 { margin: 0 0 10px; font-size: 16px; }
.card + .card, .section + .section { margin-top: 14px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 8px; }
.section-title h2 { font-size: 16px; margin: 0; }
.grid { display: grid; gap: 14px; }
@media (min-width: 700px) { .grid.two { grid-template-columns: 1fr 1fr; } }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }

.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-top: 1px solid var(--border); text-decoration: none; color: inherit; }
.item:first-child { border-top: 0; }
a.item:hover, button.item:hover { background: var(--surface-2); }
button.item { width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; font: inherit; cursor: pointer; }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: 13px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.empty { padding: 18px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge.wstepna { background: var(--warn-soft); color: var(--warn); }
.badge.potwierdzona { background: var(--info-soft); color: var(--info); }
.badge.zameldowana { background: var(--primary-soft); color: var(--primary); }
.badge.wymeldowana { background: var(--surface-2); color: var(--muted); }
.badge.anulowana { background: var(--danger-soft); color: var(--danger); text-decoration: line-through; }
.badge.ok { background: var(--primary-soft); color: var(--primary); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--muted); padding: 4px 8px; }

/* --- Formularze --- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; font-size: 16px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
input[type=checkbox] { display: inline; width: auto; margin: 0 6px 0 0; }
input[type=color] { height: 44px; padding: 4px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.form { display: grid; gap: 12px; }
.form .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .cols3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.form fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin: 0; display: grid; gap: 12px; }
.form legend { font-weight: 700; padding: 0 6px; }
.hint { font-size: 13px; margin-top: 4px; }
.hint.bad { color: var(--danger); }
.hint.ok { color: var(--primary); }
.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar input, .searchbar select { margin: 0; }
.chips { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.chip { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); font: inherit; font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer; color: var(--text); }
.chip.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

/* --- Kalendarz --- */
.cal-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.cal-toolbar .label { font-weight: 700; flex: 1; min-width: 140px; }
.cal-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); -webkit-overflow-scrolling: touch; }
.cal { display: grid; position: relative; min-width: max-content; }
.cal .rh, .cal .dh, .cal .cell { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.cal .rh { position: sticky; left: 0; z-index: 3; background: var(--surface); padding: 8px; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; min-height: 48px; }
.cal .dh { text-align: center; font-size: 11px; padding: 4px 0; color: var(--muted); background: var(--surface); }
.cal .dh b { display: block; font-size: 15px; color: var(--text); }
.cal .dh.we, .cal .cell.we { background: var(--surface-2); }
.cal .dh.today b { color: var(--primary-ink); background: var(--primary); border-radius: 50%; width: 26px; height: 26px; line-height: 26px; margin: 0 auto; }
.cal .cell { cursor: pointer; min-height: 48px; }
.cal .cell:hover { background: var(--primary-soft); }
.cal .corner { position: sticky; left: 0; z-index: 4; background: var(--surface); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.cal .bar {
  z-index: 2; border-radius: 8px; padding: 4px 8px; font-size: 12px; font-weight: 600; color: #fff;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: pointer; text-decoration: none; align-self: stretch;
  display: flex; align-items: center; margin: 6px 1px; background: #3b6ea5;
}
.cal .bar:hover { filter: brightness(1.1); }
.cal .bar.wstepna { background-color: #c98a1e; background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.25) 0 6px, transparent 6px 12px); }
.cal .bar.potwierdzona { background-color: #3b6ea5; }
.cal .bar.zameldowana { background-color: #4f7a3a; }
.cal .bar.wymeldowana { background-color: #8a877b; }
.cal .bar.cut-start { margin-left: 2px; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.cal .bar.cut-end { margin-right: 2px; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 10px; }

/* --- Szczegóły --- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.money-summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 600px) { .money-summary { grid-template-columns: repeat(3, 1fr); } }
.money-summary div { background: var(--surface-2); border-radius: 10px; padding: 10px; }
.money-summary b { display: block; font-size: 18px; }
.money-summary span { font-size: 12px; color: var(--muted); }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--primary); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.note-item { display: flex; gap: 10px; align-items: flex-start; }
.note-item.done .note-text { text-decoration: line-through; color: var(--muted); }
.note-text { white-space: pre-wrap; }

/* --- Arkusz --- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 94vh; display: flex; flex-direction: column;
  border-radius: 18px 18px 0 0; box-shadow: 0 -4px 24px rgba(0,0,0,.2); animation: up .18s ease-out;
}
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 18px; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; padding: 14px 16px 6px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 90px); transform: translateX(-50%); z-index: 60;
  background: #2b2b24; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 480px) {
  .topbar .call-btn span { display: none; }
  .topbar .call-btn { font-size: 20px; padding: 6px 10px; }
  .form .cols3 { grid-template-columns: 1fr 1fr; }
}

/* Przełączniki: status rezerwacji i status płatności */
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-opt { flex: 1 1 auto; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.seg-opt:hover { background: var(--surface-2); }
.seg-opt.active { cursor: default; }
.pay-seg .seg-opt { flex: 1 1 0; white-space: normal; min-height: 44px; }
.seg-opt.active.wstepna, .seg-opt.active.czeka { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.seg-opt.active.potwierdzona, .seg-opt.active.zaliczka { background: var(--info-soft); color: var(--info); border-color: var(--info); }
.seg-opt.active.zameldowana, .seg-opt.active.oplacona { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.seg-opt.active.wymeldowana { background: var(--surface-2); color: var(--text); border-color: var(--muted); }
.seg-opt.active.anulowana { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
