:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --line: #e2e2dc;
  --ink: #1d1f1e;
  --ink-2: #4a4f4c;
  --muted: #7b807d;
  --accent: #256c5a;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe9;
  --danger: #b4342b;
  --warn: #a8660a;
  --warn-soft: #fbf0dc;
  --ok-soft: #e2efe9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 1px rgba(0,0,0,.03);
  color-scheme: light;
}
/* tmavý režim: podle systému, pokud uživatel nezvolil světlý; nebo vynuceně */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141615;
    --surface: #1c1f1e;
    --surface-2: #232726;
    --line: #2f3432;
    --ink: #e8ebe9;
    --ink-2: #b9bfbc;
    --muted: #868d8a;
    --accent: #5bb39a;
    --accent-ink: #0d1a16;
    --accent-soft: #1f3530;
    --danger: #ef7a70;
    --warn: #e2a64b;
    --warn-soft: #3a2f1c;
    --ok-soft: #1f3530;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141615;
  --surface: #1c1f1e;
  --surface-2: #232726;
  --line: #2f3432;
  --ink: #e8ebe9;
  --ink-2: #b9bfbc;
  --muted: #868d8a;
  --accent: #5bb39a;
  --accent-ink: #0d1a16;
  --accent-soft: #1f3530;
  --danger: #ef7a70;
  --warn: #e2a64b;
  --warn-soft: #3a2f1c;
  --ok-soft: #1f3530;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: 1rem; margin: 0 0 .75rem; font-weight: 620; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.25rem;
  padding: 0 1.25rem; height: 54px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
  overflow-x: auto; white-space: nowrap;
}
.brand { font-weight: 700; color: var(--ink); font-size: 1.05rem; }
.topbar nav, .topbar-right { display: flex; gap: .15rem; }
.topbar-right { margin-left: auto; }
.topbar nav a, .topbar-right a {
  color: var(--ink-2); padding: .4rem .65rem; border-radius: 7px; font-size: .93rem;
}
.topbar nav a:hover, .topbar-right a:hover { background: var(--surface-2); text-decoration: none; }
.theme-toggle { font: inherit; background: none; border: 0; cursor: pointer; color: var(--ink-2); padding: .4rem .65rem; border-radius: 7px; font-size: .93rem; }
.theme-toggle:hover { background: var(--surface-2); }
.topbar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { max-width: 1280px; margin: 0 auto; padding: 1.25rem 1.25rem 4rem; }

.page-head { display: flex; align-items: center; flex-wrap: wrap; gap: .75rem 1.25rem; margin-bottom: 1.1rem; }
.page-head > .btn:last-child, .page-head > .actions:last-child { margin-left: auto; }

/* ---------- cards & grids ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card.flush { padding: 0; overflow-x: auto; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; padding: .9rem 1.1rem .2rem; }
.card.notice { background: var(--warn-soft); border-color: transparent; }
.grid-work { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 1rem; align-items: start; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.grid-work > *, .grid-2 > * { min-width: 0; }
.page-head select { width: auto; max-width: 100%; }
@media (max-width: 900px) {
  .grid-work, .grid-2 { grid-template-columns: 1fr; }
}

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem 1.1rem; display: flex; flex-direction: column; gap: .15rem; color: var(--ink); box-shadow: var(--shadow);
}
a.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile b { font-size: 1.5rem; font-weight: 650; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.tile.warn { border-color: var(--warn); }
.lbl { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }

/* ---------- forms ---------- */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--ink-2); font-weight: 550; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 7px; padding: .5rem .6rem; width: 100%; min-width: 0;
}
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
::placeholder { color: var(--muted); opacity: .6; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .85rem 1rem; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid h3 { margin: 0; }
.form-stack { display: flex; flex-direction: column; gap: .8rem; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.inline-form { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.inline-form .grow { flex: 1; min-width: 180px; width: auto; }
.inline-form select { width: auto; }
form.inline { display: inline-flex; }
.narrow { max-width: 640px; }
fieldset.fx { border: 1px dashed var(--line); border-radius: 8px; display: flex; gap: .75rem; align-items: end; flex-wrap: wrap; padding: .7rem .8rem; margin: 0; }
fieldset.fx label { flex: 1; min-width: 130px; }
.w-num { width: 110px; }
.w-mid { width: 170px; }
.w-unit { width: 80px; }
.w-full { width: 100%; }

.actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.actions.col { flex-direction: column; align-items: stretch; }
.push-right { margin-left: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  font: inherit; font-weight: 560; font-size: .92rem; cursor: pointer;
  padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); white-space: nowrap;
}
.btn:hover { border-color: var(--ink-2); text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.07); border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-small { padding: .3rem .6rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
.danger, button.danger, .btn.danger { color: var(--danger); }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; background: var(--ok-soft); }
.flash-err { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .55rem .8rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface); }
.table th a.sort { color: inherit; display: inline-block; white-space: nowrap; }
.table th a.sort:hover { color: var(--ink); text-decoration: none; }
.table th.sorted, .table th.sorted a.sort { color: var(--accent); }
.export-links { font-size: .88rem; color: var(--muted); white-space: nowrap; }
a.export-links { color: var(--accent); }
[hidden] { display: none !important; }
.date-mini { width: auto; padding: .15rem .3rem; font-size: .82rem; }
.row-actions form { display: inline-flex; gap: .3rem; align-items: center; }
.table tbody tr:hover { background: var(--surface-2); }
.table tfoot td { font-weight: 600; border-bottom: 0; background: var(--surface-2); }
.table.compact td { padding: .35rem .4rem; }
.table.compact input { padding: .3rem .45rem; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.empty { color: var(--muted); text-align: center; padding: 2rem 1rem !important; }
.strike td { text-decoration: line-through; color: var(--muted); }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions form { display: inline; }
.row-actions a, .row-actions button { margin-left: .5rem; font-size: 1.05rem; }

.work-table tr.day-cont td { border-top: 0; }
.work-table tr.day-first td { border-top: 1px solid var(--line); }
.work-table td { border-bottom: 0; }
.work-table tr.weekend td:first-child b { color: var(--warn); }
.work-table tr.editing { background: var(--accent-soft); }

/* ---------- chips / status ---------- */
.chip { display: inline-block; padding: .2rem .6rem; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); font-size: .82rem; border: 1px solid var(--line); }
a.chip:hover { text-decoration: none; border-color: var(--ink-2); }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.tiny { font-size: .7rem; padding: 0 .4rem; vertical-align: 1px; }
.filters { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
.filters .sep { width: 1px; height: 18px; background: var(--line); margin: 0 .3rem; }
.status { display: inline-block; font-size: .78rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }
.st-paid, .st-invoiced { background: var(--ok-soft); color: var(--accent); }
.st-issued, .st-open { background: var(--warn-soft); color: var(--warn); }
.st-late { background: color-mix(in srgb, var(--danger) 15%, var(--surface)); color: var(--danger); }
.st-cancelled { text-decoration: line-through; }

/* ---------- work entry ---------- */
.month-nav { display: flex; align-items: center; gap: .3rem; }
.month-nav form { display: inline; }
.month-nav input { width: auto; padding: .35rem .5rem; }
.entry-form { display: flex; flex-direction: column; gap: .75rem; }
.entry-row { display: flex; gap: .6rem; align-items: end; flex-wrap: wrap; }
.f-date { flex: 0 0 160px; }
.f-time { flex: 0 0 82px; }
.f-hours { flex: 0 0 82px; }
.f-time input, .f-hours input { text-align: center; font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.summary dl { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; margin: 0 0 1rem; }
.summary dt { color: var(--muted); font-size: .88rem; }
.summary dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.summary dd.big { font-size: 1.35rem; font-weight: 650; }
.adj-form { display: flex; gap: .4rem; margin: .5rem 0; }

/* ---------- items / invoice form ---------- */
.filters-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .7rem; }
.filters-bar select, .filters-bar input { width: auto; }
.filters-bar input[type=search] { flex: 1; min-width: 160px; }
.bulk-bar {
  position: sticky; top: 62px; z-index: 5; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  background: var(--accent-soft); border-radius: var(--radius); padding: .6rem .8rem; margin-bottom: .8rem;
}
.bulk-bar select, .bulk-bar input { width: auto; padding: .3rem .5rem; }
.calc-preview { font-size: .9rem; color: var(--ink-2); background: var(--surface-2); border-radius: 8px; padding: .55rem .75rem; }
.calc-preview:empty { display: none; }
.lines-table td { padding: .35rem .4rem; vertical-align: middle; }
.lines-table input { padding: .4rem .5rem; }
.lines-table td:first-child input, .lines-table td:nth-child(4) input { text-align: right; }
.lines-table .sum-row td { background: var(--surface); font-weight: 500; }
.lines-table .sum-row.total td { font-size: 1.1rem; font-weight: 700; }

/* ---------- 3D calc ---------- */
.calc h3 { margin-top: 1rem; }
.calc h3:first-of-type { margin-top: .5rem; }
.tpl-bar { display: flex; gap: .6rem; align-items: end; }
.tpl-bar label { flex: 1; }
.params { margin-top: 1rem; border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; }
.params summary { cursor: pointer; font-weight: 600; margin-bottom: .6rem; }
.tpl-actions { display: flex; gap: .5rem; margin-top: .8rem; flex-wrap: wrap; align-items: center; }
.tpl-actions input { width: 220px; }
.calc-result { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; margin-top: 1rem; }
.calc-result > div { background: var(--surface-2); border-radius: 8px; padding: .6rem .75rem; display: flex; flex-direction: column; }
.calc-result b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.calc-result .hl { background: var(--accent-soft); }
.calc-result .hl b { color: var(--accent); }
.formula { margin: .6rem 0 0; }

/* ---------- stats bar chart ---------- */
.bars { display: flex; gap: 2px; align-items: stretch; height: 220px; padding-top: .5rem; }
.bar-col { flex: 1; display: flex; flex-direction: column; position: relative; outline: none; min-width: 0; }
.bar-track { flex: 1; display: flex; align-items: flex-end; justify-content: center; border-bottom: 1px solid var(--line); }
.bar { width: min(36px, 70%); background: var(--accent); border-radius: 4px 4px 0 0; min-height: 0; transition: filter .1s; }
.bar-col:hover .bar, .bar-col:focus .bar { filter: brightness(1.15); }
.bar-lbl { text-align: center; font-size: .75rem; color: var(--muted); padding-top: .3rem; }
.bar-tip {
  display: none; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); border-radius: 8px; padding: .5rem .7rem; font-size: .8rem;
  white-space: nowrap; flex-direction: column; gap: .1rem; z-index: 3; pointer-events: none;
}
.bar-col:hover .bar-tip, .bar-col:focus .bar-tip { display: flex; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 1rem; }

@media (max-width: 640px) {
  main { padding: 1rem 16px 4rem; }
  .topbar { padding: 0 16px; gap: .75rem; }
  .f-date { flex: 1 1 100%; }
  .f-time, .f-hours { flex: 1 1 60px; }
  .btn-now { flex: 1 1 100%; }
  .work-table .row-actions a, .work-table .row-actions button { margin-left: .25rem; }
  .table th, .table td { padding: .5rem; }
}
