:root {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --line: #334155;
  --late: #f97316;
  --late-bg: rgba(249, 115, 22, 0.17);
  --off: #22c55e;
  --off-bg: rgba(34, 197, 94, 0.17);
  --accent: #38bdf8;
  --btn: #2563eb;
  --err: #f87171;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --line: #cbd5e1;
    --late: #ea580c;
    --late-bg: rgba(234, 88, 12, 0.12);
    --off: #16a34a;
    --off-bg: rgba(22, 163, 74, 0.13);
    --accent: #0284c7;
    --err: #dc2626;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0 auto;
  max-width: 560px;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: 0 max(14px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

header {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 0 10px;
  background: var(--bg);
}
h1 { font-size: 1.3rem; margin: 0; }
h2.weekhead {
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--muted); margin: 18px 2px 8px;
}
h3 { font-size: 0.95rem; margin: 16px 0 6px; }

.btn {
  display: inline-block; cursor: pointer; border: 0; border-radius: 10px;
  background: var(--btn); color: #fff; font: inherit; font-weight: 600;
  padding: 9px 14px; -webkit-tap-highlight-color: transparent;
}
.btn.small { padding: 8px 12px; font-size: 0.9rem; }
.btn.danger { background: transparent; color: var(--err); border: 1px solid var(--err); }
.link { background: none; border: 0; color: var(--accent); font: inherit; padding: 10px 4px; cursor: pointer; }

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 4px; }
.summary:empty { display: none; }
.card { border-radius: 14px; padding: 12px 14px; background: var(--card); border-top: 4px solid var(--line); }
.card.c-late { background: var(--late-bg); border-top-color: var(--late); }
.card.c-off { background: var(--off-bg); border-top-color: var(--off); }
.card .k { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.card .v { font-size: 1.15rem; font-weight: 700; margin-top: 2px; }
.card .rel { font-size: 0.85rem; color: var(--muted); }

.status { margin: 8px 2px; font-size: 0.85rem; color: var(--muted); min-height: 1.2em; }
.status.err { color: var(--err); }

.row {
  display: grid; grid-template-columns: 6.2rem 1fr auto; align-items: center; gap: 10px;
  padding: 12px 12px 12px 14px; margin: 0 0 8px;
  background: var(--card); border-radius: 12px; border-left: 5px solid var(--line);
}
.row.t-weekend { border-left-color: #64748b; }
.row.t-late { background: var(--late-bg); border-left-color: var(--late); }
.row.t-off { background: var(--off-bg); border-left-color: var(--off); }
.row.t-blank, .row.t-other, .row.t-leave { border-left-style: dashed; }
.row.today { outline: 2px solid var(--accent); outline-offset: 1px; }
.row.past { opacity: 0.55; }
.dow { display: block; font-weight: 700; }
.dnum { display: block; font-size: 0.85rem; color: var(--muted); }
.times { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.chip {
  font-size: 0.78rem; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--line); color: var(--text); white-space: nowrap;
}
.t-late .chip { background: var(--late); color: #1c0d02; }
.t-off .chip { background: var(--off); color: #04210f; }

.empty { text-align: center; color: var(--muted); padding: 44px 8px; }
.actions { text-align: center; }

.settings { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 10px; }
.settings summary { cursor: pointer; color: var(--muted); padding: 8px 0; }
.settings label { display: block; margin: 12px 0; font-size: 0.9rem; color: var(--muted); }
.settings input {
  display: block; width: 100%; margin-top: 6px; padding: 10px; font: inherit;
  color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px;
}
.btnrow { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
pre {
  white-space: pre-wrap; word-break: break-word; font-size: 0.75rem; line-height: 1.5;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 320px; overflow: auto;
}

/* ---------- toolbar, shared banner ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; margin: 6px 0 4px; }
.toolbar[hidden], .sharedbar[hidden] { display: none; }
.toolbar .btn { margin-left: 0; }
.seg { display: flex; flex: 1; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; padding: 8px 6px; cursor: pointer;
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: inset 0 -3px 0 var(--accent); }
.sharedbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  margin: 2px 0 8px; padding: 8px 12px; border-radius: 10px; background: var(--card); color: var(--muted); font-size: 0.85rem;
}
.sharedbar .link { padding: 4px; font-size: 0.85rem; }
body.shared .upload, body.shared .settings { display: none; }

/* ---------- view switching ---------- */
body.view-list .calendar { display: none; }
body.view-cal #list, body.view-cal .actions { display: none; }

/* ---------- calendar (screen) ---------- */
.calhead { margin: 6px 0 10px; }
.caltitle { font-size: 1.15rem; font-weight: 700; }
.calrange { color: var(--muted); font-size: 0.85rem; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 0.78rem; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 5px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line); background: var(--card); }
.sw.t-late { background: var(--late); border-color: var(--late); }
.sw.t-off { background: var(--off); border-color: var(--off); }
.sw.t-weekend { background: var(--wknd-bg); border-color: var(--wknd); }

.cal {
  display: grid; gap: 2px;
  grid-template-columns: 2.9rem repeat(7, minmax(0, 1fr));
  grid-auto-rows: minmax(44px, auto);
}
.cal .ch {
  font-size: 0.7rem; font-weight: 700; color: var(--muted); text-align: center;
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 3px; min-height: 0;
}
.cal .wk {
  font-size: 0.68rem; font-weight: 600; color: var(--muted);
  display: flex; align-items: center; justify-content: flex-start; line-height: 1.1;
}
.cell {
  position: relative; background: var(--card); border-radius: 6px; border: 1px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 12px 1px 2px; overflow: hidden; min-width: 0;
}
.cell .dn { position: absolute; top: 2px; left: 4px; font-size: 0.6rem; color: var(--muted); line-height: 1; }
.cell .cl { font-size: 0.68rem; font-weight: 800; line-height: 1.1; }
.cell .ct { font-size: 0.55rem; color: var(--muted); line-height: 1.15; white-space: nowrap; }
.cell.empty { background: transparent; }
.cell.t-late { background: var(--late-bg); border-color: var(--late); }
.cell.t-late .cl { color: var(--late); }
.cell.t-off { background: var(--off-bg); border-color: var(--off); }
.cell.t-off .cl { color: var(--off); }
.cell.t-weekend { background: var(--wknd-bg); border-color: var(--wknd); }
.cell.today { outline: 2px solid var(--accent); outline-offset: 0; z-index: 1; }
.cell.past { opacity: 0.5; }
.calfoot { display: none; }
@media screen and (max-width: 520px) { .cell .ct { display: none; } .cell { padding-top: 14px; } }
:root { --wknd: #64748b; --wknd-bg: rgba(100, 116, 139, 0.25); }
@media (prefers-color-scheme: light) { :root { --wknd-bg: rgba(100, 116, 139, 0.16); } }

/* ---------- one sheet of A4 ---------- */
@page { size: A4 portrait; margin: 8mm; }
@media print {
  :root {
    --bg: #fff; --card: #fff; --text: #111; --muted: #444; --line: #888;
    --late: #c2410c; --late-bg: #fdba74; --off: #15803d; --off-bg: #86efac;
    --wknd: #475569; --wknd-bg: #cbd5e1; --accent: #111;
  }
  html, body { background: #fff; color: #111; }
  body { max-width: none; margin: 0; padding: 0; font-size: 10pt; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  header, .summary, .status, .toolbar, .sharedbar, .actions, .settings, #list { display: none !important; }
  .calendar { display: block !important; }

  .calwrap { height: 281mm; display: flex; flex-direction: column; }
  .calhead { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2mm 6mm; margin: 0 0 3mm; }
  .caltitle { font-size: 20pt; }
  .calrange { font-size: 11pt; color: #222; }
  .legend { margin: 0 0 0 auto; font-size: 8.5pt; color: #111; gap: 2px 10px; }
  .sw { width: 9pt; height: 9pt; border-color: #666; }

  .cal {
    flex: 1 1 auto; min-height: 0;
    max-height: calc(var(--n) * 15mm + 7mm);
    gap: 1px;
    grid-template-columns: 15mm repeat(7, minmax(0, 1fr));
    grid-template-rows: 6mm repeat(var(--n), minmax(0, 1fr));
    grid-auto-rows: auto;
  }
  .cal .ch { font-size: 9pt; color: #111; padding-bottom: 1mm; }
  .cal .wk { font-size: 8.5pt; font-weight: 700; color: #111; }
  .cell { border: 0.4pt solid #bbb; border-radius: 0; padding: 0; justify-content: center; }
  .cell.empty { border-color: #ddd; }
  .cell .dn { top: 0.6mm; left: 1mm; font-size: 6.5pt; color: #333; }
  .cell .cl { font-size: 9pt; }
  .cell .ct { display: block !important; font-size: 7pt; color: #111; }
  .cell.t-late { border: 0.8pt solid var(--late); }
  .cell.t-late .cl { color: #7c2d12; }
  .cell.t-off { border: 0.8pt solid var(--off); }
  .cell.t-off .cl { color: #14532d; font-size: 10pt; }
  .cell.today { outline: none; }
  .cell.past { opacity: 1; }
  .calfoot { display: block; flex: none; margin-top: 2mm; font-size: 7.5pt; color: #444; text-align: right; }
}
