:root {
  --bg: #f1f5f9; --card: #ffffff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --accent: #0f766e; --accent-text: #ffffff; --pos: #15803d; --neg: #b91c1c; --warn: #b45309;
  --field: #ffffff; --shadow: 0 1px 3px rgba(15, 23, 42, .08);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b1220; --card: #141d2f; --text: #e5eaf3; --muted: #93a1b8; --line: #243049;
  --accent: #2dd4bf; --accent-text: #04201c; --pos: #4ade80; --neg: #f87171; --warn: #fbbf24;
  --field: #0f1728; --shadow: none;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --card: #141d2f; --text: #e5eaf3; --muted: #93a1b8; --line: #243049;
    --accent: #2dd4bf; --accent-text: #04201c; --pos: #4ade80; --neg: #f87171; --warn: #fbbf24;
    --field: #0f1728; --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; color: var(--muted); font-weight: 600; }

.shell { max-width: 640px; margin: 0 auto; min-height: 100dvh; padding: 0 16px calc(84px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 12px; padding: calc(12px + env(safe-area-inset-top)) 0 12px; }
.topbar h1 { font-size: 1.2rem; flex: 1; }
.topbar select { max-width: 55%; }
.stack { display: grid; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: .9rem; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }
.num { font-variant-numeric: tabular-nums; }
.big { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; }

input, select, textarea { background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; min-height: 42px; width: 100%; }
input[type="checkbox"] { width: 20px; min-height: 20px; height: 20px; accent-color: var(--accent); }
input[type="color"] { padding: 2px; width: 52px; }
input[type="time"] { width: auto; }
label.field { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 10px; }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 14px; min-height: 42px; cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--neg); }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: .88rem; }
.btn:disabled { opacity: .5; }
.btn.icon { padding: 0; width: 42px; font-size: 1.2rem; }

.stamp-wrap { display: grid; place-items: center; padding: 10px 0 4px; gap: 14px; }
.stamp { width: 190px; height: 190px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); font-size: 1.25rem; font-weight: 700; box-shadow: 0 8px 28px rgba(15, 118, 110, .35); cursor: pointer; display: grid; place-items: center; line-height: 1.2; text-align: center; padding: 20px; }
.stamp:active { transform: scale(.97); }
.stamp.out { background: #dc2626; color: #fff; box-shadow: 0 8px 28px rgba(220, 38, 38, .3); }
.stamp.pause { background: #d97706; color: #fff; }
.stamp small { display: block; font-size: .8rem; font-weight: 500; opacity: .9; }
.clock { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.pair { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.pair .btn { min-width: 140px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.punch { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.punch:first-child { border-top: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; }
.dot.out { background: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat .label { font-size: .8rem; color: var(--muted); }
.stat .value { font-size: 1.3rem; white-space: nowrap; font-weight: 700; font-variant-numeric: tabular-nums; }

.monthnav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.monthnav strong { text-align: center; flex: 1; }

.day { display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: center; padding: 10px 6px; border-top: 1px solid var(--line); cursor: pointer; border-radius: 8px; }
.day:first-child { border-top: 0; }
.day:active { background: var(--bg); }
.day .d { font-weight: 700; font-variant-numeric: tabular-nums; }
.day .d span { display: block; font-size: .75rem; font-weight: 500; color: var(--muted); }
.day.off .d, .day.off { color: var(--muted); }
.day.today { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.tag { display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); margin-right: 4px; }

table.data { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.data th, table.data td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
table.data th { font-size: .82rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
table.data td.copy { cursor: pointer; }
table.data td.copy:active { background: var(--bg); }
table.data tr.off td { color: var(--muted); }
.th-btn { display: grid; gap: 4px; }

.nav { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.nav-inner { display: flex; width: 100%; max-width: 640px; }
.nav a { flex: 1; text-align: center; padding: 9px 0 8px; color: var(--muted); text-decoration: none; font-size: .72rem; display: grid; gap: 2px; justify-items: center; }
.nav a.active { color: var(--accent); font-weight: 700; }
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: 92dvh; background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
dialog::backdrop { background: rgba(2, 6, 23, .55); }
.sheet { padding: 16px; display: grid; gap: 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.sched { display: grid; grid-template-columns: 1fr; gap: 4px; }
.sched > label { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-weight: 600; }
.sched > label:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.sched .times { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.sched .times input { width: 104px; }
.sched .times input.brk { width: 70px; }

.login { max-width: 420px; margin: 0 auto; padding: calc(40px + env(safe-area-inset-top)) 16px 40px; display: grid; gap: 16px; }
.login img { width: 72px; height: 72px; border-radius: 18px; }
.err { color: var(--neg); font-size: .92rem; min-height: 1.3em; }

#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 20; max-width: 90vw; font-size: .92rem; }
#toast.show { opacity: 1; transform: translateX(-50%); }
.banner { background: color-mix(in srgb, var(--warn) 15%, var(--card)); border: 1px solid var(--warn); border-radius: 10px; padding: 8px 12px; font-size: .9rem; }

.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }

.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; }
  #app, #toast { display: none !important; }
  .print-only { display: block; }
  .print-only h1 { font-size: 16pt; margin-bottom: 4pt; }
  .print-only table { width: 100%; border-collapse: collapse; font-size: 10pt; }
  .print-only th, .print-only td { border: 1px solid #999; padding: 3pt 5pt; text-align: left; }
}
details > summary { cursor: pointer; font-weight: 600; }
table.data th, table.data td { padding: 7px 5px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; border-radius: 8px; padding: 7px 0; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.active { background: var(--accent); color: var(--accent-text); }
.range-inputs { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.range-inputs input { flex: 1 1 0; width: 0; min-width: 0; padding: 6px 6px; font-size: .9rem; }
.weeksum { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; padding: 8px 6px; margin: 2px 0 6px; border-radius: 8px; background: var(--bg); font-size: .88rem; color: var(--muted); }
.tag.warn { color: var(--warn); border-color: var(--warn); }
.photos { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.photo { position: relative; }
.photo img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; display: block; }
.photo .btn { position: absolute; top: 2px; right: 2px; min-height: 26px; padding: 0 7px; }
.add-photo { align-self: center; }
.photo-full { max-width: 100%; max-height: 75dvh; border-radius: 8px; display: block; margin: 0 auto; }
.sched .times .sub { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--muted); font-size: .85rem; }
[hidden] { display: none !important; }
.small { font-size: .82rem; }
.back { text-decoration: none; display: grid; place-items: center; color: var(--text); }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.tile { display: grid; justify-items: center; gap: 6px; text-decoration: none; color: var(--text); font-size: .8rem; text-align: center; }
.tile-icon { width: 58px; height: 58px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; color: var(--accent); }
.tile-icon svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.progress { height: 10px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; width: 100%; }
.progress .bar { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.progress .bar.done { background: var(--pos); }
.timeline { display: grid; gap: 0; margin-top: 6px; }
.tl-punch { display: flex; align-items: center; gap: 10px; }
.tl-dot { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.tl-dot.in { color: var(--pos); } .tl-dot.out { color: var(--neg); }
.tl-gap { margin-left: 14px; border-left: 2px solid var(--accent); padding: 8px 0 8px 22px; font-size: .88rem; color: var(--muted); }
.tl-gap.pause { border-left-style: dashed; border-color: var(--warn); }
.chip { border: 1px solid var(--c, var(--line)); color: var(--c, var(--text)); background: transparent; border-radius: 99px; padding: 4px 12px; font-size: .85rem; cursor: pointer; }
.chip.on { background: var(--c, var(--accent)); color: #fff; }
details.group { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
details.group > summary { cursor: pointer; font-weight: 600; }
.group-body { margin-top: 10px; }
.rule { gap: 6px; } .rule input[type="number"], .rule input:not([type]) { min-height: 36px; padding: 6px 8px; }
.list-row { display: grid; gap: 2px; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid var(--line); padding: 10px 4px; cursor: pointer; color: var(--text); }
.list-row:first-child { border-top: 0; }
.list-row.static { cursor: default; }
.year-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 10px; width: 100%; background: none; border: 0; border-top: 1px solid var(--line); padding: 11px 4px; cursor: pointer; text-align: left; color: var(--text); align-items: center; }
.year-row:first-child { border-top: 0; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-head { text-align: center; font-size: .75rem; color: var(--muted); padding: 4px 0; }
.cal-cell { min-height: 62px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 4px; display: grid; align-content: start; gap: 1px; text-align: left; font-size: .7rem; cursor: pointer; position: relative; }
.cal-cell.empty { visibility: hidden; }
.cal-cell.off { background: color-mix(in srgb, var(--line) 55%, transparent); color: var(--muted); }
.cal-cell.holiday, .cal-key.holiday { background: color-mix(in srgb, var(--neg) 22%, var(--card)); }
.cal-cell.vacation, .cal-key.vacation { background: color-mix(in srgb, var(--warn) 25%, var(--card)); }
.cal-cell.absence_excused, .cal-cell.absence_unexcused, .cal-cell.free, .cal-cell.comp_time, .cal-key.absence_excused { background: color-mix(in srgb, #8b5cf6 22%, var(--card)); }
.cal-key.off { background: color-mix(in srgb, var(--line) 55%, transparent); }
.cal-cell.today { outline: 2px solid var(--accent); }
.cal-day { font-weight: 700; font-size: .8rem; }
.cal-worked { font-variant-numeric: tabular-nums; }
.cal-diff { font-variant-numeric: tabular-nums; }
.cal-warn { position: absolute; top: 3px; right: 4px; color: var(--warn); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: .8rem; color: var(--muted); }
.cal-key { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--line); }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.gallery-item { border: 0; padding: 0; background: none; display: grid; gap: 4px; color: var(--muted); font-size: .78rem; cursor: pointer; }
.gallery-item img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.tag-row { border-top: 1px solid var(--line); padding: 8px 0; } .tag-row:first-child { border-top: 0; }
.tag-row > summary { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.url { word-break: break-all; font-size: .8rem; background: var(--bg); padding: 6px 8px; border-radius: 8px; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.preview { max-height: 50dvh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; }
.sched .times input.tgt { width: 76px; }
@media print {
  .print-only .summary { margin-top: 8pt; font-weight: 600; }
  .print-only .signature { display: flex; gap: 40pt; margin-top: 40pt; }
  .print-only .signature div { flex: 1; border-top: 1px solid #000; padding-top: 4pt; font-size: 9pt; }
}
