:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --text: #22201c;
  --muted: #6f6a60;
  --line: #e2ddd1;
  --accent: #2f5d50;
  --accent-text: #ffffff;
  --home: #dcefdc;
  --home-ink: #1f5a2a;
  --work: #dbe6f6;
  --work-ink: #1e4278;
  --vacation: #fbe3c4;
  --vacation-ink: #7a4310;
  --warn: #b3261e;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171a18;
    --surface: #212522;
    --text: #ece8df;
    --muted: #a19b8f;
    --line: #343a36;
    --accent: #6fb39c;
    --accent-text: #0f1a16;
    --home: #1f3a25;
    --home-ink: #b5e3bd;
    --work: #1f2f47;
    --work-ink: #b9cff0;
    --vacation: #47321a;
    --vacation-ink: #f5cf9c;
    --warn: #ff8a80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

a { color: var(--accent); }

button, input, textarea { font: inherit; color: inherit; }

.narrow { max-width: 480px; margin: 0 auto; padding: 16px; }
.center { text-align: center; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--warn); }
.logo { text-align: center; font-size: 28px; margin: 32px 0 16px; }

textarea { font-family: ui-monospace, monospace; font-size: 13px; word-break: break-all; resize: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

label { font-weight: 600; font-size: 14px; }

input[type=password], input[type=text], input[type=date], textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
}

.primary, .secondary {
  min-height: 48px;
  border-radius: 10px;
  border: 0;
  padding: 0 18px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.primary { background: var(--accent); color: var(--accent-text); }
.secondary { background: transparent; border: 1px solid var(--line); }
.danger { color: var(--warn); }
.link { background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 4px; }

.choose { display: grid; gap: 12px; margin: 16px 0; }
.choose-btn {
  display: block;
  text-align: center;
  padding: 28px 16px;
  font-size: 22px;
  font-weight: 700;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  text-decoration: none;
}

/* --- webapp: nabídka instalace, režim na ploše ------------------------------- */
.install {
  max-width: 608px;
  margin: 12px auto 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--accent);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
}
@media (max-width: 640px) { .install { margin: 12px 16px 0; } }
.install-text { margin: 0; grid-column: 1 / -1; font-size: 14px; }
.install-go { width: auto; }
.install-close { justify-self: end; grid-column: 2; }
.install-go:not([hidden]) + .install-close { grid-column: auto; }

/* Na ploše (standalone) není prohlížečová lišta – hlavičku odsadíme od výřezu a notche. */
@media (display-mode: standalone) {
  body { padding-top: 0; }
  .top { padding-top: calc(10px + env(safe-area-inset-top)); }
  html, body { overscroll-behavior-y: none; }
}

/* --- hlavička a lišta ------------------------------------------------------ */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); display: flex; align-items: center; gap: 6px; }
.brand img { border-radius: 6px; }
.logo-icon { border-radius: 16px; margin-bottom: 4px; }
.whoami { font-weight: 600; }
.nav { justify-self: end; text-decoration: none; padding: 8px 0; }

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  max-width: 640px;
  margin: 12px auto 4px;
  padding: 0 16px;
}
.btn.icon {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-decoration: none;
  font-size: 22px;
  color: var(--text);
}
.seg {
  flex: 1;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
}
.seg a {
  flex: 1;
  text-align: center;
  padding: 11px 4px;
  text-decoration: none;
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
}
.seg a.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }

/* --- dny -------------------------------------------------------------------- */
.days { max-width: 640px; margin: 0 auto; padding: 8px 16px 16px; display: grid; gap: 8px; }

.month { font-size: 15px; margin: 14px 0 0; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.weekend {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px dashed var(--line);
  padding-top: 2px;
  margin: 2px 0;
}

.day {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 8px;
  align-items: stretch;
  padding: 6px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid transparent;
}
.day.is-today { border-color: var(--accent); border-left-color: var(--accent); }
.day.nobody-home { border-left-color: var(--warn); }
.day.nobody-home .date::after { content: "nikdo doma"; font-size: 10px; color: var(--warn); line-height: 1.1; text-align: center; }

.date { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
.date b { font-size: 17px; }
.date span { font-size: 13px; color: var(--muted); }
.date em { font-style: normal; font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; }

.cells { display: grid; grid-template-columns: 1.25fr 1fr; gap: 6px; }

.cell {
  position: relative;
  min-height: 60px;
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform .08s ease, background-color .15s ease;
}
.cell:active { transform: scale(.97); }
.cell[data-state=home] { background: var(--home); color: var(--home-ink); }
.cell[data-state=work] { background: var(--work); color: var(--work-ink); }
.cell[data-state=vacation] { background: var(--vacation); color: var(--vacation-ink); }
.cell[data-sync="1"]::after { content: "📅"; position: absolute; top: 5px; right: 7px; font-size: 13px; }
.cell[data-explicit="1"] { box-shadow: inset 0 0 0 2px currentColor; }

.who { font-size: 12px; font-weight: 600; opacity: .75; }
.st { font-size: 16px; font-weight: 700; }
.cell.is-me .st { font-size: 18px; }
.note { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.note:empty { display: none; }

.hint { max-width: 640px; margin: 0 auto; padding: 0 16px; text-align: center; font-size: 13px; color: var(--muted); }

/* --- šablona ---------------------------------------------------------------- */
.tpl { width: 100%; border-collapse: separate; border-spacing: 6px; }
.tpl th { text-align: left; font-size: 14px; }
.tpl thead th { text-align: center; }
.tpl .cell { width: 100%; align-items: center; }

/* --- detail dne (spodní panel) ---------------------------------------------- */
.sheet {
  border: 0;
  padding: 0;
  margin: auto auto 0;
  width: 100%;
  max-width: 560px;
  border-radius: 18px 18px 0 0;
  background: var(--surface);
  color: var(--text);
}
.sheet::backdrop { background: rgb(0 0 0 / .4); }
.sheet form { display: grid; gap: 10px; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet-title { margin: 0 0 4px; font-size: 18px; }
.states { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.states label { font-weight: 600; }
.states input { position: absolute; opacity: 0; pointer-events: none; }
.states span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
}
.states input:checked + span { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.states input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }

/* --- patička a toast -------------------------------------------------------- */
.foot {
  max-width: 640px;
  margin: 16px auto 24px;
  padding: 0 16px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.sync-status.is-error { color: var(--warn); }

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