:root {
  --bg: #f6f3ee;
  --surface: #fffdf9;
  --surface-2: #efebe4;
  --line: #e2dcd2;
  --text: #24221f;
  --muted: #7a746b;
  --accent: #2f6f73;
  --accent-ink: #ffffff;
  --zsani: #d9694e;
  --zsani-soft: #fbe9e3;
  --lacko: #3b8a8f;
  --lacko-soft: #e2f1f0;
  --pool: #8c857a;
  --done: #3f9a5a;
  --done-bg: #dff1e3;
  --done-ink: #2c6b3e;
  --today: rgba(47, 111, 115, 0.07);
  --danger: #b8432f;
  --shadow: 0 1px 2px rgba(40, 30, 20, .08), 0 2px 6px rgba(40, 30, 20, .05);
  --shadow-lift: 0 8px 22px rgba(40, 30, 20, .18);
  --radius: 10px;
  --label-w: 84px;
  --topbar-h: 52px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181c;
    --surface: #1f2228;
    --surface-2: #262a31;
    --line: #30353d;
    --text: #e9e6e1;
    --muted: #9a958d;
    --accent: #5fb3b6;
    --accent-ink: #0f1a1b;
    --zsani: #ef8a70;
    --zsani-soft: #3a2621;
    --lacko: #6cc0c4;
    --lacko-soft: #1d3233;
    --pool: #8a857d;
    --done: #63c07d;
    --done-bg: #1e3524;
    --done-ink: #9fdcae;
    --today: rgba(95, 179, 182, 0.08);
    --danger: #ef7a66;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lift: 0 10px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16181c; --surface: #1f2228; --surface-2: #262a31; --line: #30353d; --text: #e9e6e1;
  --muted: #9a958d; --accent: #5fb3b6; --accent-ink: #0f1a1b; --zsani: #ef8a70; --zsani-soft: #3a2621;
  --lacko: #6cc0c4; --lacko-soft: #1d3233; --pool: #8a857d; --done: #63c07d; --done-bg: #1e3524;
  --done-ink: #9fdcae; --today: rgba(95, 179, 182, 0.08); --danger: #ef7a66; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

/* ---------- Fejléc ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand { font-weight: 700; letter-spacing: .2px; }
.nav { display: flex; align-items: center; gap: 6px; }
.range { font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.sync { width: 9px; height: 9px; border-radius: 50%; background: var(--done); flex: none; transition: background .2s; }
.sync.busy { background: #d6a43a; }
.sync.err { background: var(--danger); }

.iconbtn {
  width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 20px; line-height: 1; display: inline-grid; place-items: center;
}
.iconbtn:hover, .pill:hover { background: var(--surface-2); }
.pill {
  height: 34px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600;
}
.primary {
  height: 36px; padding: 0 18px; border-radius: 9px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.danger { height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid transparent; background: none; color: var(--danger); font-weight: 600; }
.danger:hover { border-color: var(--danger); }

/* ---------- Tábla ---------- */
.board {
  height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top));
  display: grid;
  grid-template-rows: auto 1fr 1fr 1fr;
  min-height: 0;
}
.row {
  display: grid;
  grid-template-columns: var(--label-w) repeat(var(--cols, 7), minmax(0, 1fr));
  min-height: 0;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }

.dayhead { background: var(--surface); }
.dayhead > div {
  padding: 7px 10px;
  border-left: 1px solid var(--line);
  font-weight: 600;
  display: flex; align-items: baseline; gap: 6px;
}
.dayhead .dname { text-transform: capitalize; }
.dayhead .ddate { color: var(--muted); font-weight: 500; font-size: 12.5px; }
.dayhead .today { background: var(--today); color: var(--accent); }
.dayhead .today .ddate { color: var(--accent); }

.label {
  display: flex; align-items: center; justify-content: center;
  writing-mode: vertical-rl; transform: rotate(180deg);
  font-weight: 700; letter-spacing: 1px; text-transform: uppercase; font-size: 12.5px;
  border-right: 1px solid var(--line);
  gap: 8px;
}
.label .count { writing-mode: horizontal-tb; transform: rotate(180deg); font-size: 11px; font-weight: 600; color: var(--muted); }
.band.pool .label { color: var(--pool); background: var(--surface-2); }
.band.zsani .label { color: var(--zsani); background: var(--zsani-soft); }
.band.lacko .label { color: var(--lacko); background: var(--lacko-soft); }

.poolbody { grid-column: 2 / -1; display: flex; flex-direction: column; min-height: 0; padding: 10px 12px 0; gap: 10px; }
.addform { display: flex; gap: 8px; max-width: 560px; }
.addform input {
  flex: 1; height: 38px; padding: 0 12px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface);
}
.addform input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.addform button { width: 44px; font-size: 20px; }

.cell { border-left: 1px solid var(--line); min-height: 0; display: flex; flex-direction: column; }
.cell.today { background: var(--today); }
.cell:first-of-type { border-left: 0; }

.list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overscroll-behavior: contain;
}
.list.pool-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  align-content: start;
  padding: 0 0 12px;
}
.list:empty::after {
  content: attr(data-empty);
  color: var(--muted); opacity: .55; font-size: 12px;
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  padding: 10px; text-align: center;
}
.list.pool-list:empty::after { grid-column: 1 / -1; }

/* ---------- Kártya ---------- */
.card {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 8px 9px 8px 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--pool);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: grab;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background .15s, border-color .15s, opacity .15s;
}
.card:active { cursor: grabbing; }
.band.zsani .card { border-left-color: var(--zsani); }
.band.lacko .card { border-left-color: var(--lacko); }
.card .title { flex: 1; min-width: 0; overflow-wrap: anywhere; padding-top: 2px; }
.card .note { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chk {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--surface);
  display: grid; place-items: center; padding: 0;
  font-size: 13px; font-weight: 800; color: transparent;
}
.chk:hover { border-color: var(--done); color: var(--done); }

.card.done { background: var(--done-bg); border-color: var(--done); border-left-color: var(--done) !important; }
.card.done .title { color: var(--done-ink); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.card.done .chk { background: var(--done); border-color: var(--done); color: #fff; }

.sortable-ghost { opacity: .35; }
.sortable-chosen { box-shadow: var(--shadow-lift); }
.sortable-drag { transform: rotate(1.5deg); }
.dragging .list { outline: 1px dashed transparent; }
.dragging .list:hover { outline-color: var(--accent); outline-offset: -4px; border-radius: 8px; }

/* ---------- Dialógus ---------- */
.dlg {
  border: 1px solid var(--line); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--text);
  width: min(460px, calc(100vw - 32px));
  box-shadow: var(--shadow-lift);
}
.dlg.narrow { width: min(340px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(20, 18, 15, .45); }
.dlg form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { margin: 0; font-size: 17px; outline: none; }
.fld { display: flex; flex-direction: column; gap: 6px; }
.fld > span { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.fld input, .fld textarea, #pinInput {
  width: 100%; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg);
}
.fld textarea { resize: vertical; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { height: 36px; border: 0; background: var(--surface); font-weight: 600; border-left: 1px solid var(--line); }
.seg button:first-child { border-left: 0; }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }
.seg button[data-owner="zsani"][aria-checked="true"] { background: var(--zsani); color: #fff; }
.seg button[data-owner="lacko"][aria-checked="true"] { background: var(--lacko); color: #fff; }
.dayrow { display: flex; gap: 8px; align-items: center; }
.dayrow input { flex: 1; }
.quickdays { display: flex; flex-wrap: wrap; gap: 6px; }
.quickdays button {
  height: 30px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); font-size: 12.5px;
}
.quickdays button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check input { width: 18px; height: 18px; accent-color: var(--done); }
.actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.grow { flex: 1; }
.muted { color: var(--muted); margin: 0; }
.err { color: var(--danger); margin: 0; font-weight: 600; }
[hidden] { display: none !important; }

.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-weight: 600; box-shadow: var(--shadow-lift); z-index: 50; max-width: calc(100vw - 32px);
}

/* ---------- Mobil: egy nap ---------- */
@media (max-width: 760px), (pointer: coarse) and (max-height: 520px) {
  :root { --topbar-h: 56px; }
  .topbar { gap: 8px; padding: 0 10px; }
  .brand { display: none; }
  .range { order: -1; color: var(--text); font-size: 15px; }
  .range.today { color: var(--accent); }
  .board { grid-template-rows: 1fr 1fr 1fr; touch-action: pan-y; }
  .dayhead { display: none; }
  .row { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); min-width: 0; }
  .poolbody, .cell, .list { min-width: 0; }
  .label {
    writing-mode: horizontal-tb; transform: none; justify-content: flex-start;
    padding: 6px 12px; border-right: 0; border-bottom: 1px solid var(--line); font-size: 12px;
  }
  .label .count { transform: none; }
  .poolbody { grid-column: 1; padding: 8px 8px 0; gap: 8px; }
  .list.pool-list { grid-template-columns: 1fr; padding-bottom: 8px; }
  .cell { border-left: 0; }
  .cell.today { background: none; }
  .card { padding: 10px 10px 10px 9px; font-size: 15px; }
  .chk { width: 26px; height: 26px; font-size: 15px; }
  .addform input { height: 40px; font-size: 16px; }
  .fld input, .fld textarea, #pinInput { font-size: 16px; }
}

/* ---------- Névajánlás ---------- */
.suggest {
  position: fixed; z-index: 40; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow-lift); max-height: 50vh; overflow-y: auto;
}
.suggest li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 6px 8px 10px; border-radius: 7px; cursor: pointer;
}
.suggest li:hover, .suggest li.on { background: var(--surface-2); }
.suggest .stxt { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.suggest b { color: var(--accent); }
.suggest .sdel {
  flex: none; width: 26px; height: 26px; border: 0; border-radius: 6px;
  background: none; color: var(--muted); font-size: 17px; line-height: 1;
}
.suggest .sdel:hover { background: var(--line); color: var(--danger); }
@media (max-width: 760px), (pointer: coarse) and (max-height: 520px) { .suggest li { padding: 11px 6px 11px 12px; font-size: 16px; } }

/* ---------- Közös feladat ---------- */
:root { --shared: #7a5cc4; --shared-soft: #ece6fa; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --shared: #a990ec; --shared-soft: #2b2540; } }
:root[data-theme="dark"] { --shared: #a990ec; --shared-soft: #2b2540; }
.share {
  flex: none; width: 26px; height: 24px; margin: -1px -3px 0 0; padding: 0;
  border: 1px solid transparent; border-radius: 7px; background: none;
  display: grid; place-items: center; color: var(--muted); opacity: .45;
}
.share svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.card:hover .share, .share:focus-visible { opacity: 1; }
.share:hover { border-color: var(--line); }
.card.shared .share { opacity: 1; color: #fff; background: var(--shared); }
.band.zsani .card.shared, .band.lacko .card.shared { border-left-color: var(--shared); }
.card.shared:not(.done) { background: linear-gradient(90deg, var(--shared-soft), var(--surface) 70%); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 22px; }
#fShared { accent-color: var(--shared); }
@media (hover: none) { .share { opacity: .7; } }
@media (max-width: 760px), (pointer: coarse) and (max-height: 520px) { .share { width: 32px; height: 30px; } .share svg { width: 20px; height: 20px; } }

/* ---------- Telefon fekvő helyzetben: egy nap, a három rész egymás mellett ---------- */
@media (pointer: coarse) and (max-height: 520px) and (orientation: landscape) {
  :root { --topbar-h: 44px; }
  .topbar { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .board { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  .board { grid-template-rows: minmax(0, 1fr); grid-template-columns: repeat(3, minmax(0, 1fr)); height: calc(100dvh - var(--topbar-h)); }
  .row { border-bottom: 0; }
  .band + .band { border-left: 1px solid var(--line); }
  .label { padding: 4px 10px; }
  .addform input { height: 36px; }
  .addform button { height: 36px; }
  .card { padding: 7px 8px; font-size: 14px; }
  .chk { width: 24px; height: 24px; }
  .iconbtn, .pill { height: 32px; }
}

.addform input { min-width: 0; }
.addform button { flex: none; }

/* ---------- Álló telefon: dátum felül, alatta nagy lapozógombok ---------- */
@media (max-width: 760px) {
  :root { --topbar-h: 112px; }
  .topbar {
    position: relative;
    flex-direction: column; align-items: stretch; justify-content: center;
    gap: 8px; padding: 8px 12px;
  }
  .range { order: -1; flex: none; text-align: center; font-size: 17px; padding: 0 18px; }
  .nav { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; }
  .nav .iconbtn { width: auto; height: 50px; font-size: 42px; font-weight: 300; padding-bottom: 5px; border-radius: 12px; }
  .nav .pill { height: 50px; padding: 0 22px; font-size: 16px; border-radius: 12px; }
  .sync { position: absolute; top: 18px; right: 14px; }
}

/* ---------- Dátumválasztó a fejlécben ---------- */
.rangewrap { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.rangewrap .range { flex: 0 1 auto; }
.rangewrap:hover .range { color: var(--accent); }
.caret { color: var(--muted); font-size: 12px; flex: none; }
#jumpDate { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
@media (max-width: 760px) {
  .rangewrap { order: -1; flex: none; justify-content: center; padding: 0 18px; }
  .rangewrap .range { padding: 0; }
}
@media (pointer: coarse) and (max-height: 520px) and (orientation: landscape) {
  .rangewrap { order: -1; }
}

/* ---------- Telefon: egy sáv kinagyítása (a névre koppintva) ---------- */
.label .zoom { display: none; }
@media (max-width: 760px), (pointer: coarse) and (max-height: 520px) {
  .label.focusable { cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; }
  .label.focusable:active { filter: brightness(.96); }
  .label .zoom { display: inline; margin-left: auto; font-size: 14px; opacity: .7; }
  .board[data-focus="zsani"], .board[data-focus="lacko"] { grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); }
  .board[data-focus="zsani"] > .band:not(.zsani),
  .board[data-focus="lacko"] > .band:not(.lacko) { display: none; }
}
