/* Työvuorokirjaus — mobile first (360 px), scaled up with min-width queries. */

:root {
    --bg: #f3f4f1;
    --surface: #ffffff;
    --surface-2: #f8f8f6;
    --ink: #17202a;
    --ink-2: #4b5563;
    --ink-3: #6b7280;
    --line: #e2e3df;
    --brand: #13294b;
    --brand-ink: #ffffff;
    --accent: #1d5fd1;
    --go: #15803d;
    --go-ink: #ffffff;
    --stop: #b42318;
    --warn: #b45309;
    --warn-bg: #fff7e6;
    --ok-bg: #ecfdf3;
    --err-bg: #fef3f2;
    --radius: 12px;
    --radius-s: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --gutter: 16px;
    --tap: 44px;
    font-size: 16px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
}

body.menu-open, body.modal-open { overflow: hidden; }

a { color: var(--accent); }

h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }

.muted { color: var(--ink-3); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* --- top bar + hamburger ------------------------------------------------ */

.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 12px;
    min-height: 56px; padding: 0 var(--gutter);
    background: var(--brand); color: var(--brand-ink);
}
.topbar__brand { color: inherit; text-decoration: none; font-weight: 700; letter-spacing: .01em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__toggle {
    width: var(--tap); height: var(--tap); margin-right: -10px;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: 0; color: inherit; cursor: pointer; border-radius: var(--radius-s);
}
.topbar__toggle:focus-visible { outline: 2px solid #fff; }
.topbar__toggle svg { width: 26px; height: 26px; }

.nav {
    position: fixed; inset: 56px 0 0 auto; width: min(320px, 86vw);
    background: var(--surface); color: var(--ink);
    transform: translateX(100%); transition: transform .2s ease;
    overflow-y: auto; padding: 8px 0 24px; box-shadow: -8px 0 24px rgba(0,0,0,.18); z-index: 40;
}
.nav.is-open { transform: none; }
.nav__backdrop { position: fixed; inset: 56px 0 0 0; background: rgba(15, 23, 42, .4); z-index: 35; }
.nav a, .nav__group-title {
    display: flex; align-items: center; min-height: var(--tap); padding: 0 20px;
    color: var(--ink); text-decoration: none;
}
.nav a[aria-current="page"] { background: #e8eefb; color: var(--accent); font-weight: 600; }
.nav__group-title { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); min-height: 32px; margin-top: 8px; }
.nav__user { padding: 8px 20px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.nav__user strong { display: block; }

@media (min-width: 1360px) {
    .topbar__toggle, .nav__backdrop { display: none; }
    .nav {
        position: static; transform: none; width: auto; box-shadow: none; padding: 0;
        background: transparent; color: inherit; display: flex; align-items: center; overflow: visible;
    }
    .nav a { color: #dbe4f3; min-height: 56px; padding: 0 12px; }
    .nav a[aria-current="page"] { background: rgba(255,255,255,.12); color: #fff; }
    .nav__group-title, .nav__user { display: none; }
}

/* --- page ------------------------------------------------------------------ */

.page { max-width: 1180px; margin: 0 auto; padding: 16px var(--gutter) 48px; }
.page__head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 16px; }
.page__head h1 { margin: 0; flex: 1 1 auto; }

.card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card--flush { padding: 0; overflow: hidden; }

.grid { display: grid; gap: 16px; }
@media (min-width: 720px) { .grid--2 { grid-template-columns: 1fr 1fr; } .grid--3 { grid-template-columns: repeat(3, 1fr); } }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi__label { font-size: .8rem; color: var(--ink-3); }
.kpi__value { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi__sub { font-size: .8rem; color: var(--ink-2); }

/* --- notices ------------------------------------------------------------- */

.notice { padding: 12px 14px; border-radius: var(--radius-s); margin: 0 0 16px; border: 1px solid transparent; }
.notice--ok { background: var(--ok-bg); border-color: #abefc6; }
.notice--error { background: var(--err-bg); border-color: #fecdca; }
.notice--warn { background: var(--warn-bg); border-color: #fedf89; }
.notice--info { background: #eff4ff; border-color: #c7d7fe; }

/* --- buttons & forms ------------------------------------------------------ */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: var(--tap); padding: 0 16px; border-radius: var(--radius-s);
    border: 1px solid var(--line); background: var(--surface); color: var(--ink);
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid #9ec0ff; outline-offset: 1px; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: #174fb0; }
.btn--go { background: var(--go); border-color: var(--go); color: var(--go-ink); }
.btn--stop { background: var(--stop); border-color: var(--stop); color: #fff; }
.btn--ghost { background: transparent; }
.btn--small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

label { display: block; font-weight: 600; font-size: .9rem; }
input, select, textarea {
    display: block; width: 100%; margin-top: 4px; min-height: var(--tap);
    padding: 8px 12px; border: 1px solid #cfd2cc; border-radius: var(--radius-s);
    background: #fff; color: var(--ink); font: inherit; font-size: 16px; font-weight: 400;
}
input[type="checkbox"], input[type="radio"] { display: inline-block; width: 20px; height: 20px; min-height: 0; margin: 0 8px 0 0; vertical-align: middle; }
input[type="color"] { padding: 2px; width: 64px; }
.check { display: flex; align-items: center; font-weight: 500; min-height: var(--tap); }
.stack > * + * { margin-top: 12px; }
.form-grid { display: grid; gap: 12px; }
@media (min-width: 720px) { .form-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; } }
.hint { font-weight: 400; font-size: .8rem; color: var(--ink-3); margin-top: 2px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-s); padding: 12px; margin: 0; }
legend { font-weight: 600; padding: 0 4px; }

details.fold { border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); margin-bottom: 12px; }
details.fold > summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; padding: 0 14px; font-weight: 600; list-style: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: "▸"; margin-left: auto; transition: transform .15s; }
details.fold[open] > summary::after { transform: rotate(90deg); }
details.fold > .fold__body { padding: 0 14px 14px; }

/* --- tables → cards under 720 px ----------------------------------------- */

.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-size: .8rem; color: var(--ink-3); font-weight: 600; background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tfoot td { font-weight: 700; }

@media (max-width: 719px) {
    .table--cards thead { display: none; }
    .table--cards, .table--cards tbody, .table--cards tr, .table--cards td, .table--cards tfoot { display: block; width: 100%; }
    .table--cards tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
    .table--cards td { border: 0; padding: 4px 14px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
    .table--cards td::before { content: attr(data-label); color: var(--ink-3); font-size: .85rem; text-align: left; font-weight: 500; }
    .table--cards td.num { text-align: right; }
    .table--cards td[data-label=""]::before { content: none; }
}
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* --- chips, badges -------------------------------------------------------- */

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #eef0ec; color: var(--ink-2); white-space: nowrap; }
.badge--confirmed { background: #dcfae6; color: #085d3a; }
.badge--open { background: #fef0c7; color: #93370d; }
.badge--running { background: #d1e9ff; color: #1849a9; }
.badge--returned, .badge--missing { background: #fee4e2; color: #912018; }
.badge--locked, .badge--approved { background: #e0e7ff; color: #3538cd; }
.badge--draft { background: #fef0c7; color: #93370d; }
.badge--absent, .badge--planned { background: #f2f4f7; color: #475467; }
.badge--manual { background: #fdead7; color: #93370d; }
.app-promo { margin: 0 0 12px; }
.app-steps { margin: 0; padding-left: 1.2em; }
.app-steps li + li { margin-top: 6px; }
.app-login__msg { min-height: 1.4em; }
.t-manual { color: #b54708; font-style: italic; text-decoration: underline dotted; text-underline-offset: 3px; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; margin-right: 6px; background: var(--ink-3); }

/* --- timeline bars -------------------------------------------------------- */

.bar { position: relative; height: 22px; border-radius: 6px; background: #eceee9; overflow: hidden; }
.bar__seg { position: absolute; top: 0; bottom: 0; }
.bar--tall { height: 34px; }
.bar__legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .82rem; color: var(--ink-2); margin-top: 6px; }
.bar__axis { display: flex; justify-content: space-between; font-size: .72rem; color: var(--ink-3); margin-top: 2px; }

/* --- worker shift screen ------------------------------------------------- */

.clock { text-align: center; padding: 8px 0 4px; }
.clock__state { font-size: .95rem; color: var(--ink-2); }
.clock__mode { font-size: 1.6rem; font-weight: 800; margin: 2px 0; }
.clock__timer { font-size: 2.4rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.clock__since { font-size: .85rem; color: var(--ink-3); }
.clock__break { margin-top: .35rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink-2, #334155); }
.clock__break--over { color: #b91c1c; }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.mode-btn {
    min-height: 64px; border-radius: var(--radius); border: 2px solid var(--line);
    background: var(--surface); font: inherit; font-weight: 700; font-size: 1.02rem; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--ink);
}
.mode-btn small { font-weight: 500; color: var(--ink-3); font-size: .75rem; }
.mode-btn[aria-pressed="true"] { color: #fff; border-color: transparent; }
.mode-btn[aria-pressed="true"] small { color: rgba(255,255,255,.85); }
.mode-btn:disabled { opacity: .6; }

.bigbtn { width: 100%; min-height: 64px; font-size: 1.15rem; border-radius: var(--radius); }
.loc { font-size: .82rem; color: var(--ink-3); text-align: center; margin-top: 8px; }
.loc--bad { color: var(--warn); }

.today-list { list-style: none; margin: 0; padding: 0; }
.today-list li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .95rem; }
.today-list li:last-child { border-bottom: 0; }
.today-list .t { font-variant-numeric: tabular-nums; color: var(--ink-2); min-width: 100px; }

/* --- days list ------------------------------------------------------------ */

.day { border-top: 1px solid var(--line); padding: 12px 0; }
.day:first-child { border-top: 0; }
.day__head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.day__date { font-weight: 700; min-width: 70px; }
.day__sum { margin-left: auto; font-variant-numeric: tabular-nums; font-size: .92rem; }
.day__note { font-size: .88rem; margin-top: 6px; }
.segs { list-style: none; margin: 8px 0 0; padding: 0; font-size: .9rem; }
.segs li { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; padding: 4px 0; }
.segs .t { font-variant-numeric: tabular-nums; color: var(--ink-2); }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 16px; -webkit-overflow-scrolling: touch; }
.tabs a { white-space: nowrap; padding: 0 14px; min-height: var(--tap); display: inline-flex; align-items: center; text-decoration: none; color: var(--ink-2); border-bottom: 3px solid transparent; font-weight: 600; }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }

.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav strong { min-width: 130px; text-align: center; }

/* --- calendar ------------------------------------------------------------- */

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal__dow { font-size: .72rem; color: var(--ink-3); text-align: center; }
.cal__day { min-height: 64px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; font-size: .75rem; background: var(--surface); overflow: hidden; }
.cal__day--blank { background: transparent; border: 0; }
.cal__day--work { border-left: 4px solid var(--accent); }
.cal__day--oncall { border-left: 4px solid #7c3aed; }
.cal__day--off, .cal__day--holiday { background: #f2f4f7; }
.cal__day--today { outline: 2px solid var(--accent); }
.cal__n { font-weight: 700; }
@media (min-width: 720px) { .cal__day { min-height: 84px; font-size: .82rem; } }

/* --- map ------------------------------------------------------------------- */

.map {
    position: relative; z-index: 0; isolation: isolate; /* keeps Leaflet's 400–1000 z-index panes under the top bar and menu */
    width: 100%; max-width: 100%; height: 320px; overflow: hidden;
    border-radius: var(--radius); border: 1px solid var(--line); background: #e5e7eb;
}
@media (min-width: 720px) { .map { height: 440px; } }

.map-modal {
    width: calc(100vw - 2 * var(--gutter)); max-width: 720px; padding: 0;
    border: 0; border-radius: var(--radius); box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
.map-modal::backdrop { background: rgba(15, 23, 42, .55); }
.map-modal__head { display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 16px; border-bottom: 1px solid var(--line); }
.map-modal__title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-modal__close { width: var(--tap); height: var(--tap); border: 0; background: transparent; font-size: 1.6rem; line-height: 1; cursor: pointer; border-radius: var(--radius-s); }
.map-modal .map { height: min(60vh, 440px); border: 0; border-radius: 0; }
.map-modal__foot { padding: 10px 16px; }

/* --- auth pages ------------------------------------------------------------ */

body.bare { display: flex; min-height: 100vh; align-items: flex-start; justify-content: center; padding: 48px var(--gutter); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.auth-card h1 { font-size: 1.3rem; }
.auth-card__brand { font-weight: 800; color: var(--brand); margin-bottom: 16px; font-size: 1.1rem; }

@media print {
    .topbar, .nav, .btn, .no-print { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; border: 0; }
}

.mode-btn { --mode-color: #2563eb; border-left: 6px solid var(--mode-color); }
.mode-btn[aria-pressed="true"] { background: var(--mode-color); }

.mt { margin-top: 12px; }
.card__title-pad { padding: 16px 16px 0; }

@media (max-width: 719px) {
    .table--cards td:empty { display: none; }
    .table--cards td.cell-title { font-weight: 700; text-align: left; }
    .table--cards .hide-mobile { display: none; }
}

@media (max-width: 719px) {
    .table--cards td > .bar { flex: 1 1 auto; min-width: 0; margin-left: 12px; }
}
