:root {
  --bg: #f3f6f5;
  --surface: #ffffff;
  --surface-2: #e9efed;
  --text: #13201d;
  --muted: #5b6b67;
  --border: #d9e2df;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --in: #15803d;
  --in-ink: #ffffff;
  --out: #c2410c;
  --out-ink: #ffffff;
  --warn-bg: #fff4dc;
  --warn-text: #7a3e00;
  --danger: #b42318;
  --ok: #15803d;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(16 24 22 / 6%), 0 6px 18px rgb(16 24 22 / 6%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1513;
    --surface: #15201d;
    --surface-2: #1d2a27;
    --text: #e6eeec;
    --muted: #9aaba6;
    --border: #2a3935;
    --accent: #2dd4bf;
    --accent-ink: #062b27;
    --in: #22c55e;
    --in-ink: #052e14;
    --out: #fb923c;
    --out-ink: #3b1503;
    --warn-bg: #3a2a0c;
    --warn-text: #fcd9a1;
    --danger: #f87171;
    --ok: #4ade80;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

h1, h2 { margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 1.05rem; }
p { margin: 0 0 12px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg);
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
}

.sync {
  font-size: 0.8rem;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--warn-text);
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 4px 16px calc(env(safe-area-inset-bottom) + 32px);
}

.view { display: flex; flex-direction: column; gap: 16px; }

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

.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.row > input.grow { width: auto; flex: 1 1 160px; }
.row > .field { margin-bottom: 0; }
.error { color: var(--danger); font-weight: 500; }
.hero-title { font-size: 1.6rem; margin-bottom: 8px; }

/* gumbi */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.9rem; }
.btn.wide { width: 100%; }
#settings-back { align-self: flex-start; padding-left: 0; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.link-btn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* polja */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 0.9rem; color: var(--muted); }
input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input:focus-visible, .btn:focus-visible, .punch:focus-visible, .icon-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* glavni gumb */
.punch-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 8px; }
.status-text { margin: 0; color: var(--muted); text-align: center; min-height: 1.45em; }

.punch {
  width: min(64vw, 240px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--in);
  color: var(--in-ink);
  font: inherit;
  font-size: 2rem;
  font-weight: 700;
  box-shadow: 0 10px 30px rgb(21 128 61 / 28%);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease;
}
.punch[data-next="out"] { background: var(--out); color: var(--out-ink); box-shadow: 0 10px 30px rgb(194 65 12 / 28%); }
.punch:active { transform: scale(0.96); }
.punch:disabled { opacity: 0.6; }
.timer { font-size: 1rem; font-weight: 600; font-variant-numeric: tabular-nums; opacity: 0.9; min-height: 1.45em; }

/* ploščice */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.tile-label { font-size: 0.8rem; color: var(--muted); }
.tile-value { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.tile-sub, .tile-extra { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.tile-extra { font-weight: 600; }
.tile-extra.plus { color: var(--ok); }
.tile-extra.minus { color: var(--danger); }

.banner { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; }
.banner p { margin: 0; flex: 1; }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }

/* seznami */
.list { list-style: none; margin: 0 0 12px; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .grow small { display: block; color: var(--muted); }

.problems { background: var(--warn-bg); color: var(--warn-text); border-radius: 14px; padding: 12px 14px 4px; }
.problems .list li { border-color: rgb(122 62 0 / 20%); }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.section-head h2 { margin: 0; }

.day { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; margin-bottom: 8px; overflow: hidden; }
.day-head { display: flex; justify-content: space-between; padding: 10px 14px 4px; font-weight: 600; }
.day-head .muted { font-weight: 500; font-variant-numeric: tabular-nums; }
.shift {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 0;
  border-top: 1px solid var(--border);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.day-head + .shift { border-top: 0; }
.shift .grow small { display: block; color: var(--muted); }
.badge { font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--warn-bg); color: var(--warn-text); white-space: nowrap; }
.badge.live { background: var(--in); color: var(--in-ink); }

.norm-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
.norm-grid label { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 0.8rem; color: var(--muted); }
.norm-grid input { padding: 8px 2px; text-align: center; }

code {
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

/* dialogi */
dialog {
  width: min(92vw, 440px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
#link-value { margin: 4px 0 8px; }

/* obvestilo */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border-radius: 12px;
  background: #1f2a28;
  color: #f4f7f6;
  box-shadow: 0 8px 24px rgb(0 0 0 / 25%);
}
.toast-action { border: 0; background: none; color: #5eead4; font: inherit; font-weight: 700; cursor: pointer; padding: 4px; }

@media (max-width: 360px) {
  .tiles { grid-template-columns: 1fr; }
}
