:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --text: #1d2420;
  --muted: #6b736e;
  --line: #e5e1d8;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --accent-soft: #e2efe9;
  --danger: #b4412f;
  --danger-soft: #f7e4df;
  --closed: #efece5;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121614;
    --card: #1b211e;
    --text: #e9ece9;
    --muted: #98a19c;
    --line: #2a322e;
    --accent: #5fb39a;
    --accent-text: #0d1311;
    --accent-soft: #1f3a31;
    --danger: #ef8a76;
    --danger-soft: #3a211c;
    --closed: #181d1a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #121614; --card: #1b211e; --text: #e9ece9; --muted: #98a19c; --line: #2a322e;
  --accent: #5fb39a; --accent-text: #0d1311; --accent-soft: #1f3a31;
  --danger: #ef8a76; --danger-soft: #3a211c; --closed: #181d1a; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 15px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 22px 4px 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }
.num { font-variant-numeric: tabular-nums; }

.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.login-card { max-width: 340px; text-align: center; display: grid; gap: 12px; justify-items: center; }
.login-card h1 { font-size: 28px; }
.login-card p { margin: 0; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand img { border-radius: 7px; }

main { max-width: 640px; margin: 0 auto; padding: 8px 16px calc(96px + env(safe-area-inset-bottom)); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; max-width: 160px; border: 0; background: none; padding: 6px 0 4px;
  display: grid; justify-items: center; gap: 1px; font-size: 12px; color: var(--muted); border-radius: 10px; cursor: pointer;
}
.tabbar .ico { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--accent); font-weight: 600; }
.tabbar button.active .ico { filter: none; opacity: 1; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.card.pad { padding: 16px; }

.hero { padding: 20px 18px; display: grid; gap: 4px; margin-top: 12px; }
.hero .label { color: var(--muted); font-size: 14px; }
.hero .big { font-size: 40px; font-weight: 700; letter-spacing: -.02em; }
.hero .sub { font-size: 14px; color: var(--muted); }
.private-tag { display: inline-block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--closed); border-radius: 6px; padding: 2px 6px; margin-left: 6px; vertical-align: middle; }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.stack { flex-direction: column; gap: 2px; font-size: 13px; padding: 10px 6px; }
.btn.stack .ico { font-size: 20px; }
.link { border: 0; background: none; padding: 4px; cursor: pointer; font-size: 14px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list li.tap { cursor: pointer; }
.list .main { flex: 1; min-width: 0; }
.list .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { font-size: 13px; color: var(--muted); }
.list .amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list .amt.in { color: var(--accent); }
.month-head { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 4px 8px; }
.month-head h2 { margin: 0; }
.month-head .tot { font-weight: 600; font-variant-numeric: tabular-nums; }
.empty { padding: 20px 16px; color: var(--muted); text-align: center; }

/* calendar */
.cal { padding: 12px; }
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head div { text-align: center; font-size: 12px; color: var(--muted); padding-bottom: 6px; }
.cal-cell {
  position: relative; aspect-ratio: 1 / 1; border-radius: 10px; border: 0; padding: 0;
  display: grid; place-items: center; font-size: 15px; font-variant-numeric: tabular-nums;
  background: var(--closed); color: var(--muted); cursor: pointer;
}
.cal-cell.open { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.cal-cell.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-cell.blank { background: none; cursor: default; opacity: .35; }
.cal-cell .mon { position: absolute; top: 3px; font-size: 9px; font-weight: 600; }
.cal-cell .dots { position: absolute; bottom: 5px; left: 0; right: 0; display: flex; justify-content: center; gap: 3px; }
.cal-cell .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal-cell .dots i.mine { background: var(--danger); }
.cal-month { font-weight: 600; margin: 4px 4px 10px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); padding: 10px 4px 0; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--closed); }
.legend .l-open::before { background: var(--accent-soft); }
.legend .l-booked::before { background: var(--accent); border-radius: 50%; width: 7px; height: 7px; }
.legend .l-mine::before { background: var(--danger); border-radius: 50%; width: 7px; height: 7px; }

.door { display: grid; gap: 10px; padding: 18px; margin-top: 12px; }
.door .code { font-size: 38px; font-weight: 700; letter-spacing: .12em; text-align: center; font-variant-numeric: tabular-nums; padding: 8px 0; }

/* admin */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 14px; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.toggle-row { display: flex; gap: 6px; }
.toggle { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 6px 10px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.toggle.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 600; }

/* forms + sheet */
label.field { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input[type=text], input[type=number], input[type=time], textarea, input[inputmode] {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form { display: grid; gap: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.money-input { position: relative; }
.money-input span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money-input input { padding-left: 26px; font-size: 22px; font-weight: 600; }
.receipt-pick { display: flex; align-items: center; gap: 10px; }
.receipt-pick img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }

#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 88vh; overflow-y: auto; background: var(--card); color: var(--text);
  border-radius: 18px 18px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 12px; }
#sheet h3 { font-size: 20px; margin-bottom: 4px; }
#sheet .sub { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.receipt-img { width: 100%; border-radius: 12px; border: 1px solid var(--line); display: block; }

#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 30;
  max-width: 420px; margin: 0 auto; padding: 12px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 15px; text-align: center; box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
#toast.err { background: var(--danger); color: #fff; }

@media (min-width: 700px) {
  .tabbar { justify-content: center; }
}

/* events */
.event-card { display: flex; gap: 14px; padding: 16px; margin-bottom: 10px; cursor: pointer; }
.ev-emoji { font-size: 28px; line-height: 1; width: 40px; height: 40px; display: grid; place-items: center; background: var(--accent-soft); border-radius: 12px; flex-shrink: 0; }
.ev-emoji.big { width: 52px; height: 52px; font-size: 32px; }
.ev-title { font-weight: 700; font-size: 17px; margin-bottom: 2px; }
.event-card .meta { font-size: 14px; color: var(--muted); }
.ev-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--text); }
.tag.on { background: var(--accent); color: var(--accent-text); }
.tag.muted { background: var(--closed); color: var(--muted); font-weight: 500; }
.ev-sheet-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.facts { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 6px; font-size: 15px; }
.facts a { color: var(--accent); }
.desc { white-space: pre-wrap; color: var(--text); background: var(--bg); border-radius: 12px; padding: 12px; margin: 0 0 14px; font-size: 15px; }
.stack-btns { display: grid; gap: 8px; }
.stack-btns p { margin: 0 0 4px; }
.ok-line { font-weight: 600; color: var(--accent); }
.danger-text { color: var(--danger); font-weight: 600; }
.pick { display: flex; align-items: center; gap: 12px; width: 100%; cursor: pointer; }
.pick input { width: 20px; height: 20px; accent-color: var(--accent); }
.pick .main { display: grid; }
.check { display: flex; gap: 10px; align-items: center; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.row-emoji { display: grid; grid-template-columns: 76px 1fr; gap: 10px; }
.qa { margin: 0 0 10px; font-size: 15px; }
select { width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px; }
input[type=date], input[type=number] { width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px; }

/* layout helpers (phone: everything stacks) */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 18px 4px 10px; }
.page-head h2 { margin: 0; }
.page-head .btn { min-height: 38px; padding: 8px 14px; }
.cell-items { display: none; }
.tabbar .lbl { display: contents; }

/* ---------- desktop ---------- */
@media (min-width: 960px) {
  :root { --side: 232px; }
  .topbar { padding: 0 28px; height: 61px; }
  .topbar .brand { width: calc(var(--side) - 28px); }

  /* tabs become a left sidebar */
  .tabbar {
    top: 61px; bottom: 0; right: auto; width: var(--side);
    flex-direction: column; justify-content: flex-start; gap: 2px;
    padding: 18px 12px; border-top: 0; border-right: 1px solid var(--line); background: var(--bg);
  }
  .tabbar button {
    flex: 0 0 auto; max-width: none; display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; font-size: 15px; color: var(--text); text-align: left;
  }
  .tabbar .ico { font-size: 18px; }
  .tabbar button:hover { background: var(--closed); }
  .tabbar button.active { background: var(--accent-soft); color: var(--text); }

  main { max-width: none; margin: 0 0 0 var(--side); padding: 20px 40px 56px; }
  .view { max-width: 1160px; margin: 0 auto; }
  h2 { margin-top: 26px; }

  /* two columns: wide main + sticky side */
  .cols { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 32px; align-items: start; }
  .cols .col-side { position: sticky; top: 84px; }
  #view-pot .cols, #view-events .cols.manage { grid-template-columns: 360px minmax(0, 1fr); }
  .cols .col-side > .card:first-child, .cols .col-main > :first-child { margin-top: 12px; }

  .hero .big { font-size: 46px; }
  .list li.tap:hover, .event-card:hover { background: var(--closed); }
  .event-card { transition: background .12s; }

  /* events as a grid of cards */
  .event-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
  .event-grid .event-card { margin: 0; }

  /* space: calendar left, door code + bookings right */
  .space-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; grid-template-rows: auto 1fr; grid-template-areas: "cal door" "cal book"; gap: 0 32px; align-items: start; }
  .cal-cell .mon { top: 9px; right: 8px; font-size: 11px; color: var(--muted); }
  .cols > div > h2:first-child, .cols > div > .month-head:first-child { margin-top: 18px; }
  .a-door { grid-area: door; }
  .a-cal { grid-area: cal; }
  .a-book { grid-area: book; }
  .a-door .door { margin-top: 12px; }
  .a-cal .cal { margin-top: 12px; }
  .a-cal h2:first-child { display: none; }
  .cal { padding: 18px; }
  .cal-grid { gap: 6px; }
  .cal-cell { aspect-ratio: auto; min-height: 92px; place-items: start; align-content: start; justify-items: start; padding: 8px; text-align: left; gap: 4px; display: grid; }
  .cal-cell.blank { min-height: 92px; padding: 8px; }
  .cal-cell .dnum { font-size: 14px; }
  .cal-cell .dots { display: none; }
  .cal-cell .cell-items { display: grid; gap: 3px; width: 100%; }
  .cal-cell .ci { font-size: 11px; font-weight: 600; line-height: 1.25; padding: 2px 5px; border-radius: 5px; background: var(--accent); color: var(--accent-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .cal-cell .ci.mine { background: var(--danger); color: #fff; }
  .cal-cell .ci.more { background: none; color: var(--muted); padding: 0 2px; }
  .cal-cell:hover:not(.blank) { outline: 2px solid var(--accent); outline-offset: -2px; }
  .legend .l-booked::before, .legend .l-mine::before { width: 10px; height: 10px; border-radius: 3px; }

  /* sheets become centred dialogs */
  #sheet {
    top: 50%; left: 50%; right: auto; bottom: auto; transform: translate(-50%, -50%);
    width: min(560px, 92vw); max-height: 86vh; border-radius: 18px; padding: 24px 28px 26px;
    box-shadow: 0 24px 64px rgba(0,0,0,.25); animation: pop .16s ease-out;
  }
  @keyframes pop { from { opacity: 0; transform: translate(-50%, -48%); } }
  .sheet-grip { display: none; }
  #toast { left: auto; right: 28px; bottom: 28px; margin: 0; }
}

@media (min-width: 1400px) {
  .cols { grid-template-columns: minmax(0, 1fr) 400px; }
  #view-pot .cols, #view-events .cols.manage { grid-template-columns: 400px minmax(0, 1fr); }
}
