:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1a2230;
  --muted: #5b6676;
  --border: #dde3ea;
  --accent: #0f766e;
  --accent-soft: #e0f2f0;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --run: #0f766e;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 14px;
  --tabbar-h: 60px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1217;
    --card: #171d25;
    --text: #e6eaf0;
    --muted: #94a0b0;
    --border: #2a333f;
    --accent: #2dd4bf;
    --accent-soft: #123a37;
    --danger: #f97066;
    --danger-soft: #3a1714;
    --run: #2dd4bf;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

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

body {
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 90px);
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--accent); color: #fff;
}
@media (prefers-color-scheme: dark) { .topbar { background: #0b3b37; } }
.topbar h1 { margin: 0; font-size: 1.15rem; font-weight: 650; }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: rgba(255,255,255,.2); }

main { max-width: 640px; margin: 0 auto; padding: 12px 16px; }

.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}
.card h2 { margin: 0 0 10px; font-size: 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card-head h2 { margin: 0; }

/* ----- Aktivní měření ----- */
.active-card { text-align: center; padding: 18px 14px; }
.active-card.running { border-color: var(--run); background: var(--accent-soft); }
.active-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.active-card.running .active-label { color: var(--run); font-weight: 600; }
.active-customer { font-size: 1.2rem; font-weight: 600; margin: 4px 0; word-break: break-word; }
.active-card.idle .active-customer { font-size: .95rem; font-weight: 400; color: var(--muted); }
.timer { font-size: 2.8rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.active-card.idle .timer { color: var(--muted); opacity: .5; }
.active-meta { color: var(--muted); font-size: .9rem; min-height: 1.2em; }
.note-input { margin-top: 10px; }
.btn.btn-stop {
  margin-top: 12px; width: 100%; padding: 14px;
  font-size: 1.1rem; font-weight: 700;
  background: var(--danger); color: #fff; border-color: var(--danger);
}

.btn-pip { margin-top: 8px; color: var(--muted); }

/* ----- Přihlášení a účty ----- */
.login-page { padding-bottom: 24px; }
.login-card { max-width: 400px; margin: 24px auto; }
.login-btn { width: 100%; margin-top: 4px; }
input[type=password] {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
.user-list { list-style: none; margin: 8px 0 0; padding: 0; }
.user-list li {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.user-list li:last-child { border-bottom: 0; }
.user-list .u-name { font-weight: 600; }
.user-list .u-tags { color: var(--muted); font-size: .8rem; margin-left: 6px; font-weight: 400; }
.user-list .u-actions { display: flex; gap: 6px; }
.user-list .disabled .u-name { text-decoration: line-through; color: var(--muted); }
.new-pass { font-family: ui-monospace, Consolas, monospace; background: var(--accent-soft); padding: 8px; border-radius: 8px;
  word-break: break-all; user-select: all; }

/* ----- Formulářové prvky ----- */
input[type=text], input[type=search], input[type=date], input[type=time], select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.field { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
.field > input, .field > select { margin-top: 4px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.check input { width: 20px; height: 20px; }

.btn {
  font: inherit;
  font-size: .95rem;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #04201d; } }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-small { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.btn-icon { width: 44px; font-size: 1.4rem; padding: 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn-row.end { justify-content: flex-end; }
.btn-row.spread { justify-content: space-between; }
.btn-row.spread span { display: flex; gap: 8px; }
.file-btn { display: inline-flex; align-items: center; }

.hint { color: var(--muted); font-size: .85rem; margin: 6px 0; }
.error { color: var(--danger); font-size: .9rem; }
code { font-size: .85em; }

/* ----- Zákazníci ----- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.chips:empty { display: none; }
.chip {
  font: inherit; font-size: .85rem;
  padding: 6px 12px;
  border-radius: 99px;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.customer-list { list-style: none; margin: 8px 0 0; padding: 0; }
.customer-list li button {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  width: 100%;
  font: inherit; text-align: left;
  color: var(--text);
  background: transparent;
  border: 0; border-bottom: 1px solid var(--border);
  padding: 12px 4px;
  min-height: 48px;
  cursor: pointer;
}
.customer-list li:last-child button { border-bottom: 0; }
.customer-list li button:hover { background: var(--accent-soft); }
.customer-list .sub { display: block; color: var(--muted); font-size: .8rem; }
.customer-list .go { color: var(--accent); font-size: .85rem; white-space: nowrap; }
.customer-list .adhoc { font-style: italic; }

/* ----- Den ----- */
.day-nav { display: flex; gap: 8px; align-items: center; }
.day-nav input { flex: 1; text-align: center; }

.summary { width: 100%; border-collapse: collapse; font-size: .95rem; }
.summary th, .summary td { padding: 6px 4px; border-bottom: 1px solid var(--border); text-align: left; }
.summary thead th { font-size: .8rem; color: var(--muted); font-weight: 500; }
.summary tfoot th { border-bottom: 0; }
.summary .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.entry-list { list-style: none; margin: 0; padding: 0; }
.entry-list li button {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  width: 100%;
  font: inherit; text-align: left; color: var(--text);
  background: transparent;
  border: 0; border-bottom: 1px solid var(--border);
  padding: 10px 4px;
  cursor: pointer;
}
.entry-list li:last-child button { border-bottom: 0; }
.entry-list .e-cust { font-weight: 600; word-break: break-word; }
.entry-list .e-dur { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.entry-list .e-time, .entry-list .e-note { color: var(--muted); font-size: .85rem; }
.entry-list .e-note { grid-column: 1 / -1; }
.entry-list .running .e-dur { color: var(--run); }

.help ul { padding-left: 18px; margin: 8px 0 0; font-size: .9rem; }
.help summary { cursor: pointer; color: var(--accent); font-size: .9rem; }

/* ----- Mikrofon ----- */
.mic {
  position: fixed;
  right: max(16px, calc(50% - 320px + 16px));
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  width: 68px; height: 68px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
  cursor: pointer;
  z-index: 6;
  display: grid; place-items: center;
}
.mic svg { width: 32px; height: 32px; fill: currentColor; }
.mic:active { transform: scale(.95); }
@media (prefers-color-scheme: dark) { .mic { color: #04201d; } }

/* ----- Tab bar ----- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1;
  font: inherit; font-size: .9rem;
  color: var(--muted);
  background: transparent; border: 0;
  cursor: pointer;
}
.tab.active { color: var(--accent); font-weight: 650; }

/* ----- Poslech ----- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0,0,0,.55);
  display: grid; place-items: center;
  padding: 16px;
}
.overlay[hidden] { display: none; }
.listen-box {
  background: var(--card); color: var(--text);
  border-radius: var(--radius);
  padding: 24px; width: min(420px, 100%);
  text-align: center;
}
.listen-text { font-size: 1.2rem; min-height: 2.8em; margin: 16px 0; word-break: break-word; }
.pulse {
  width: 64px; height: 64px; margin: 0 auto;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(.85); opacity: .7; }
  50% { transform: scale(1.05); opacity: 1; }
}

/* ----- Dialogy ----- */
dialog {
  width: min(480px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  padding: 16px;
}
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h2 { margin: 0 0 12px; font-size: 1.1rem; }

/* ----- Toast ----- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: calc(60px + env(safe-area-inset-top));
  z-index: 30;
  max-width: calc(100% - 32px);
  background: #1a2230; color: #fff;
  padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
  font-size: .95rem;
}
.toast.err { background: var(--danger); }
.toast[hidden] { display: none; }
