/* Garmin deník – základní styly. Barvy přes custom properties, světlý/tmavý motiv dle systému. */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --border: #dde2ea;
  --text: #17202c;
  --text-muted: #5e6b7d;
  --primary: #0b6bcb;
  --primary-hover: #0958a8;
  --primary-contrast: #ffffff;
  --primary-soft: #e3effb;
  --danger: #c62f2f;
  --danger-hover: #a72525;
  --danger-soft: #fbe7e7;
  --success: #1e7d45;
  --success-soft: #e2f4e9;
  --warning: #9a6200;
  --warning-soft: #fdf1dc;
  --focus: #3d8bfd;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --radius-sm: 6px;
  --gap: 16px;
  --topbar-h: 56px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #171e27;
    --surface-2: #1f2833;
    --border: #2c3744;
    --text: #e6ebf1;
    --text-muted: #94a1b2;
    --primary: #4c9cf0;
    --primary-hover: #6aaff5;
    --primary-contrast: #07121f;
    --primary-soft: #16304d;
    --danger: #f06a6a;
    --danger-hover: #f58787;
    --danger-soft: #3a1c1f;
    --success: #4cc27b;
    --success-soft: #16301f;
    --warning: #e3a640;
    --warning-soft: #3a2c12;
    --focus: #6aaff5;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

/* --- základ --- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg, canvas { max-width: 100%; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--text-muted); }
.small { font-size: .875rem; }
.mono { font-family: var(--font-mono); }
.num { text-align: right; white-space: nowrap; }
.hidden { display: none !important; }

/* --- layout --- */
.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }
.container-narrow { max-width: 420px; }
.page-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px 16px; margin-bottom: var(--gap);
}
.page-head h1 { margin: 0; }
.stack > * + * { margin-top: var(--gap); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* --- horní lišta a navigace --- */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 16px; min-height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 700; color: var(--text); white-space: nowrap; letter-spacing: -.01em;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background: linear-gradient(135deg, var(--primary) 0%, #18a999 100%);
}
.nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.nav-link {
  padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav-link.is-active { color: var(--primary); background: var(--primary-soft); }
.nav-logout { margin: 0 0 0 8px; }
.nav-toggle {
  display: none; margin-left: auto; width: 40px; height: 40px; padding: 0;
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); cursor: pointer;
}
.nav-toggle-bar, .nav-toggle-bar::before, .nav-toggle-bar::after {
  display: block; width: 18px; height: 2px; margin: 0 auto;
  background: currentColor; border-radius: 1px; position: relative; content: "";
}
.nav-toggle-bar::before { position: absolute; top: -6px; }
.nav-toggle-bar::after { position: absolute; top: 6px; }

@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; gap: 0 12px; }
  /* bez JS zůstane navigace vidět jako řádek s posuvem; s JS se sbalí pod tlačítko */
  .nav {
    order: 3; width: 100%; margin: 0; padding-bottom: 8px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  .js .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .js .nav {
    display: none; flex-direction: column; align-items: stretch; overflow: visible;
    padding: 4px 0 12px; border-top: 1px solid var(--border);
  }
  .js .nav.is-open { display: flex; }
  .js .nav-link { padding: 10px 12px; }
  .js .nav-logout { margin: 8px 0 0; }
  .js .nav-logout .btn { width: 100%; }
}

/* --- karty --- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
  min-width: 0;
}
.card-title { font-size: 1.1rem; margin-bottom: 12px; }
.card-head {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
  gap: 4px 12px; margin-bottom: 12px;
}
.card-head .card-title { margin: 0; }
@media (max-width: 520px) { .card { padding: 16px; } }

/* --- mřížka a statistické dlaždice --- */
.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: var(--gap); }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.card .stat { background: var(--surface-2); border-color: transparent; }
.stat-label {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); font-weight: 600;
}
.stat-value { font-size: 1.5rem; font-weight: 650; line-height: 1.2; white-space: nowrap; }
.stat-unit { font-size: .85rem; font-weight: 500; color: var(--text-muted); margin-left: 3px; }
.stat-sub { font-size: .8rem; color: var(--text-muted); }

/* --- tabulky --- */
.table-wrap {
  width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.table { width: 100%; border-collapse: collapse; font-size: .925rem; }
.table th, .table td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap; vertical-align: middle;
}
.table th {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); font-weight: 600; background: var(--surface-2);
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.wrap, .table th.wrap { white-space: normal; min-width: 160px; }
.table .num { text-align: right; }
.card > .table-wrap { border: 0; border-radius: 0; margin: 0 -20px; width: calc(100% + 40px); }

/* --- tlačítka --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; min-height: 38px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; line-height: 1.2; cursor: pointer;
  text-decoration: none; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: .875rem; }
.btn-block { width: 100%; }

/* --- formuláře --- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-narrow { max-width: 420px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-weight: 550; font-size: .9rem; }
.field input, .field select, .field textarea, .input {
  width: 100%; padding: 9px 11px; min-height: 40px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
}
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus {
  outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--primary-soft);
}
.field .hint, .hint { font-size: .8rem; color: var(--text-muted); }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

/* --- odznaky --- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px;
  border-radius: 999px; font-size: .75rem; font-weight: 600; line-height: 1.5;
  background: var(--surface-2); color: var(--text-muted); white-space: nowrap;
}
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

/* --- flash zprávy --- */
.flash {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 10px 14px; margin-bottom: var(--gap); border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--surface-2);
}
.flash-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.flash-info { background: var(--primary-soft); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }
.flash-close {
  background: none; border: 0; color: inherit; font-size: 1.25rem; line-height: 1;
  cursor: pointer; padding: 0 2px; opacity: .7;
}
.flash-close:hover { opacity: 1; }

/* --- graf --- */
.chart-box { position: relative; width: 100%; aspect-ratio: 16 / 7; min-height: 220px; }
.chart-box-tall { aspect-ratio: 16 / 9; }
.chart-box > canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
@media (max-width: 520px) { .chart-box { aspect-ratio: 4 / 3; } }

/* --- prázdný stav --- */
.empty {
  text-align: center; padding: 40px 16px; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.empty-title { font-size: 1.1rem; font-weight: 600; color: var(--text); margin: 0; }
.empty .btn { margin-top: 12px; }

/* --- přihlášení --- */
.page-login .container { padding-top: 12vh; }
.login-card { padding: 28px; }
.login-brand {
  display: flex; align-items: center; gap: 10px; font-weight: 700;
  color: var(--text-muted); margin-bottom: 16px;
}

/* --- mySASY (karta v Nastavení) --- */
.mysasy-steps { margin: 8px 0 14px; padding-left: 1.3em; display: grid; gap: 6px; }
.mysasy-callback {
  display: block; margin-top: 4px; padding: 6px 8px; border-radius: 6px; background: var(--surface-2);
  font-size: .875rem; overflow-wrap: anywhere; user-select: all;
}
.stat-value--sm { font-size: 1.1rem; }
.mysasy-check { display: flex; align-items: center; gap: 6px; font-weight: 500; }
.mysasy-attr { margin: 12px 0 0; font-size: .75rem; }
