:root {
  --navy: #00126b;
  --blue: #3860b2;
  --blue-hover: #2c4d94;
  --bg: #f0f0f0;
  --card: #fff;
  --text: #1b1b1b;
  --muted: #666;
  --line: #d9dce6;
  --green: #22a745;
  --red: #c0392b;
  --amber: #ffbf00;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, 'Open Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { margin: 0 0 .5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
a { color: var(--blue); }
[hidden] { display: none !important; }

/* ---- Runko ---- */
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; gap: .75rem; padding: .5rem 1rem; position: sticky; top: 0; z-index: 10; }
.topbar img { height: 40px; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .85rem; opacity: .9; text-align: right; }
.topbar button { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4); border-radius: 6px; padding: .3rem .6rem; cursor: pointer; font: inherit; font-size: .85rem; }
nav.tabs { background: #fff; border-bottom: 1px solid var(--line); display: flex; overflow-x: auto; padding: 0 .5rem; position: sticky; top: 56px; z-index: 9; }
nav.tabs a { padding: .8rem 1rem; text-decoration: none; color: var(--muted); white-space: nowrap; border-bottom: 3px solid transparent; font-weight: 600; }
nav.tabs a.active { color: var(--navy); border-bottom-color: var(--blue); }
main { max-width: 760px; margin: 0 auto; padding: 1rem; }
main.wide { max-width: 1000px; }
.card { background: var(--card); border-radius: var(--radius); padding: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,.12); margin-bottom: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: .75rem; }

/* ---- Lomakkeet ---- */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
input, select, textarea {
  width: 100%; font: inherit; padding: .55rem .6rem; border: 1px solid #b9bfd0; border-radius: 6px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; }
textarea { min-height: 4.5rem; resize: vertical; }
input[type=checkbox] { width: auto; }
.field { margin-bottom: .75rem; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; }
button.btn, a.btn {
  display: inline-block; font: inherit; font-weight: 600; text-decoration: none; text-align: center;
  background: var(--blue); color: #fff; border: 0; border-radius: 8px; padding: .75rem 1.1rem; cursor: pointer; min-height: 44px;
}
button.btn:hover, a.btn:hover { background: var(--blue-hover); }
button.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--blue); border: 1px solid var(--blue); }
.btn.secondary:hover { background: #eef2fb; }
.btn.danger { background: var(--red); }
.btn.small { padding: .35rem .7rem; min-height: 0; font-size: .85rem; }
.btn.block { display: block; width: 100%; }

/* ---- Leimasin ---- */
.clock-head { text-align: center; }
.clock-head .time { font-size: 1.6rem; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: .5rem; }
.clock-head .time svg { width: 28px; height: 28px; }
.clock-head .time.edited svg { color: #e0a800; }
.ring { display: block; margin: .5rem auto; width: 160px; height: 160px; }
.actions { display: flex; flex-direction: column; gap: .6rem; margin-top: .5rem; }
.actions .btn { font-size: 1.1rem; padding: 1rem; }
.status-pill { display: inline-block; padding: .15rem .6rem; border-radius: 99px; font-size: .8rem; font-weight: 600; background: #e7eaf7; color: var(--navy); }
.status-pill.pause { background: #fff3cd; color: #7a5b00; }
.status-pill.edited { background: #fff3cd; color: #7a5b00; }
.banner { padding: .75rem 1rem; border-radius: 8px; background: #fff3cd; color: #5c4500; margin-bottom: 1rem; }
.confirm { border: 2px solid var(--red); }

/* ---- Tilastot ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,.12); padding: .75rem; text-align: center; }
.stat h3 { font-size: .9rem; color: var(--muted); font-weight: 600; }
.stat svg { width: 110px; height: 110px; }
.stat .sub { font-size: .8rem; color: var(--muted); }
.flexbox { text-align: center; font-size: 2rem; font-weight: 700; }
.pos { color: var(--green); } .neg { color: var(--red); }

/* ---- Taulukot ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f4f6fc; }
tr.selected { background: #e7eaf7; }
.presets { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .75rem; }
.presets button { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: .35rem .8rem; cursor: pointer; font: inherit; font-size: .85rem; }
.presets button:hover { background: #eef2fb; }

/* ---- Kirjautuminen ---- */
.login { max-width: 380px; margin: 8vh auto 0; padding: 1rem; }
.login .logo { background: var(--navy); border-radius: var(--radius) var(--radius) 0 0; padding: 1rem; text-align: center; }
.login .logo img { max-width: 100%; height: 48px; }
.login .card { border-radius: 0 0 var(--radius) var(--radius); }
.divider { text-align: center; color: var(--muted); font-size: .85rem; margin: .8rem 0; }
.error { color: var(--red); font-size: .9rem; margin-top: .5rem; }

/* ---- Dialogi ja ilmoitukset ---- */
dialog { border: 0; border-radius: var(--radius); padding: 1.25rem; width: min(520px, calc(100vw - 2rem)); box-shadow: 0 8px 32px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0,0,0,.45); }
#toasts { position: fixed; left: 0; right: 0; bottom: 1rem; display: flex; flex-direction: column; align-items: center; gap: .5rem; pointer-events: none; z-index: 100; padding: 0 1rem; }
.toast { background: #222; color: #fff; padding: .7rem 1rem; border-radius: 8px; max-width: 560px; box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.toast.err { background: var(--red); }

@media (max-width: 520px) {
  main { padding: .75rem; }
  .topbar .who { display: none; }
}
