:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #ece7dc;
  --ink: #1d2a27;
  --ink-2: #56645f;
  --ink-3: #8a948f;
  --line: #dfd8ca;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #dce8e2;
  --calm: #6f9d8b;
  --warn: #b5652f;
  --warn-soft: #f5e3d4;
  --work: #4a6390;
  --work-soft: #e1e7f2;
  --radius: 18px;
  --shadow: 0 1px 2px rgb(29 42 39 / 6%), 0 6px 24px rgb(29 42 39 / 6%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14211e;
    --surface: #1b2b27;
    --surface-2: #233631;
    --ink: #ecebe4;
    --ink-2: #aab8b1;
    --ink-3: #7b8b84;
    --line: #2d433d;
    --accent: #8cc2ad;
    --accent-ink: #10201c;
    --accent-soft: #24413a;
    --calm: #8cc2ad;
    --warn: #e59a68;
    --warn-soft: #3d2a1f;
    --work: #9db4e0;
    --work-soft: #25304a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

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

h1 { font-size: 28px; letter-spacing: -0.02em; margin: 0; font-weight: 650; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); margin: 28px 4px 10px; font-weight: 600; }
p { margin: 0; }

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.top .who { color: var(--ink-2); font-size: 14px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: 16px;
}
.card + .card { margin-top: 10px; }
.stack > * + * { margin-top: 10px; }

.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* Hlavní ukazatel */
.gauge { display: grid; place-items: center; padding: 22px 16px 18px; text-align: center; }
.gauge svg { width: 220px; height: 220px; display: block; }
.gauge .track { stroke: var(--surface-2); }
.gauge .bar { stroke: var(--calm); transition: stroke-dashoffset 0.6s ease; }
.gauge.over .bar { stroke: var(--warn); }
.gauge .big { font-size: 46px; font-weight: 650; letter-spacing: -0.03em; fill: var(--ink); }
.gauge .unit { font-size: 14px; fill: var(--ink-2); }
.gauge .caption { margin-top: 10px; color: var(--ink-2); font-size: 15px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.01em;
  padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2);
  white-space: nowrap;
}
.badge.personal { background: var(--accent-soft); color: var(--accent); }
.badge.client_work { background: var(--work-soft); color: var(--work); }
.badge.warn, .badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.monitor::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row > :first-child { min-width: 0; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.list > .row { padding: 12px 0; border-top: 1px solid var(--line); }
.list > .row:first-child { border-top: 0; padding-top: 0; }
.list > .row:last-child { padding-bottom: 0; }

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.kpi .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 13px; color: var(--ink-2); }

/* Ovládací prvky */
button, input, select, textarea { font: inherit; color: inherit; }
.btn {
  appearance: none; border: 0; cursor: pointer;
  min-height: 44px; padding: 10px 16px; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.warn { background: var(--warn-soft); color: var(--warn); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .chip:focus-visible { outline: 3px solid var(--calm); outline-offset: 2px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }

label { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
}
textarea { min-height: 72px; resize: vertical; }
.field + .field { margin-top: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  appearance: none; cursor: pointer; min-height: 40px; padding: 8px 14px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--bg); font-weight: 600;
}
.chip[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Plán */
.week .row { padding: 8px 0; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 20px; cursor: pointer; }
.stepper output { min-width: 68px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Historie: dny */
.days { display: grid; gap: 8px; }
.day { display: grid; grid-template-columns: 74px 1fr 64px; align-items: center; gap: 10px; font-size: 14px; }
.meter { position: relative; height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter i { position: absolute; inset: 0 auto 0 0; background: var(--calm); border-radius: 999px; }
.meter i.over { background: var(--warn); }

/* Spodní lišta */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px max(8px, calc((100vw - 560px) / 2)) calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
#tabs[hidden] { display: none; }
#tabs button {
  appearance: none; border: 0; background: none; cursor: pointer;
  min-height: 48px; border-radius: 12px; font-size: 13px; font-weight: 600; color: var(--ink-3);
}
#tabs button[aria-current=page] { color: var(--accent); background: var(--accent-soft); }

#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 76px);
  max-width: 528px; margin: 0 auto; padding: 12px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: 15px; text-align: center;
}

.login { min-height: 70vh; display: grid; align-content: center; gap: 18px; }
.login img { width: 72px; height: 72px; border-radius: 18px; }
.empty { color: var(--ink-3); font-size: 14px; padding: 4px 0; }
.note { font-size: 13px; color: var(--ink-2); padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.week .btns { margin-top: 12px; }
.card + .btn, .card + .note, .note + h2 { margin-top: 10px; }
.gauge + .note { margin-top: 10px; }

/* Okamžitá odezva na dotyk (bez čekání na dvojklep, viditelné stisknutí a „pracuji“) */
button, .chip, .btn, input, select, textarea { touch-action: manipulation; }
button { -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
.btn, .chip, .stepper button, #tabs button { transition: transform 0.08s ease, opacity 0.12s ease, background-color 0.15s ease; }
.btn:active, .chip:active, .stepper button:active, #tabs button:active { transform: scale(0.96); }
.btn[aria-busy=true] { position: relative; color: transparent; }
.btn[aria-busy=true]::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--accent-ink); border-right-color: transparent; animation: spin 0.7s linear infinite;
}
.btn.ghost[aria-busy=true]::after, .btn.warn[aria-busy=true]::after { border-color: var(--ink); border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn[aria-busy=true]::after { animation-duration: 2s; } }

.stepper button { width: 44px; height: 44px; font-size: 22px; line-height: 1; }
.stepper output { min-width: 84px; }
.savebar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; position: sticky; bottom: calc(env(safe-area-inset-bottom) + 72px); background: var(--surface); padding: 8px 0 2px; }
.dirty { color: var(--warn); font-weight: 600; }
.top .btn.small { max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* PIN klávesnice */
.pinpad { display: grid; gap: 14px; justify-items: center; }
.pindots { font-size: 28px; letter-spacing: 0.3em; min-height: 40px; color: var(--ink-2); }
.pingrid { display: grid; grid-template-columns: repeat(3, 76px); gap: 12px; }
.pinkey { width: 76px; height: 64px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); font-size: 24px; font-weight: 600; cursor: pointer; }
.pinkey:active { transform: scale(0.95); background: var(--accent-soft); }

.mood { font-size: 16px; font-weight: 600; color: var(--ink); margin-top: 6px; text-align: center; }
.card > .mood { text-align: left; margin: 0; }
.quick { margin-top: 10px; }

#tabs button { position: relative; }
#tabs button[data-badge]:not([data-badge=""])::after {
  content: attr(data-badge); position: absolute; top: 4px; right: calc(50% - 34px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--warn); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
