:root {
  /* Sync brand: charcoal ink + Sync red */
  --paper: #F5F5F7;
  --surface: #FFFFFF;
  --ink: #1C1C22;
  --muted: #5E5E6A;
  --line: #E1E1E6;
  --accent: #E02833;
  --accent-hover: #C3142A;
  --accent-ink: #FFFFFF;
  --done: #2D7A4B;
  --done-bg: #E8F3EC;
  --critical: #A86200;
  --critical-bg: #FFF3DD;
  --danger: #B3261E;
  --radius: 8px;
  --font: "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141418;
    --surface: #1D1D23;
    --ink: #EDEDF0;
    --muted: #9C9CA8;
    --line: #2E2E36;
    --accent: #F2474F;
    --accent-hover: #FF5F66;
    --accent-ink: #FFFFFF;
    --done: #63C08A;
    --done-bg: #16261D;
    --critical: #E5A33D;
    --critical-bg: #2D2414;
    --danger: #F08A82;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--paper);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- top bar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 24px; min-height: 56px; flex-wrap: wrap;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; letter-spacing: -0.02em; color: var(--ink); text-decoration: none; }
.brand img { width: 32px; height: 32px; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a {
  color: var(--muted); text-decoration: none; padding: 16px 10px 14px;
  border-bottom: 2px solid transparent;
}
.nav a:hover { color: var(--ink); }
.nav a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 500; }
.who { display: flex; align-items: center; gap: 12px; font-size: 14px; }

main { max-width: 1080px; margin: 0 auto; padding: 28px 20px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin-top: 4px; }

/* ---------- controls ---------- */
button, .btn {
  font: inherit; font-weight: 500; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: var(--radius); text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--muted); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover, .btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 400; }
button:disabled { opacity: .45; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type=text], input[type=password], input[type=search], input[type=date], input[type=time], input:not([type]), select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 64px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.narrow { max-width: 520px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 8px 12px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--ink); font-weight: 500; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 13px; font-weight: 500; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
td.num, th.num { text-align: right; }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty p + * { margin-top: 12px; }

.progress { display: flex; align-items: center; gap: 10px; min-width: 140px; }
.bar { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.full > i { background: var(--done); }

.badge { display: inline-block; font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.completed { color: var(--done); border-color: var(--done); }
.badge.cancelled { color: var(--danger); border-color: var(--danger); }
.badge.in_progress { color: var(--ink); border-color: var(--ink); }

/* ---------- run / checklist ---------- */
.run-head { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: start; margin-bottom: 24px; }
.run-meta { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 10px; font-size: 14px; color: var(--muted); }
.run-meta b { color: var(--ink); font-weight: 500; }
.run-progress { font-size: 40px; font-weight: 700; line-height: 1; text-align: right; }
.run-progress small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); margin-top: 6px; }
.run-bar { height: 4px; background: var(--line); margin-bottom: 28px; border-radius: 2px; overflow: hidden; }
.run-bar > i { display: block; height: 100%; background: var(--done); transition: width .25s ease; }

.section-title { font-size: 14px; font-weight: 600; color: var(--muted); margin: 28px 0 8px; }
.section-title:first-child { margin-top: 0; }

.steps { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.step {
  display: grid; grid-template-columns: 44px 32px 1fr; gap: 12px; align-items: start;
  padding: 14px 16px; border-bottom: 1px solid var(--line); border-left: 3px solid transparent;
}
.step:last-child { border-bottom: 0; }
.step.critical { border-left-color: var(--critical); }
.step.checked { background: var(--done-bg); }
.step-no { font-size: 20px; font-weight: 600; color: var(--muted); text-align: right; line-height: 28px; }
.step.checked .step-no { color: var(--done); }
.tick {
  width: 28px; height: 28px; border-radius: 4px; border: 2px solid var(--muted);
  background: var(--surface); padding: 0; display: grid; place-items: center; cursor: pointer;
}
.tick svg { width: 18px; height: 18px; opacity: 0; }
.step.checked .tick { background: var(--done); border-color: var(--done); }
.step.checked .tick svg { opacity: 1; stroke: var(--surface); }
.tick:disabled { cursor: default; opacity: 1; }
.step-title { font-weight: 500; line-height: 28px; }
.step.checked .step-title { color: var(--muted); }
.step-details { white-space: pre-wrap; color: var(--muted); font-size: 14px; margin-top: 2px; }
.step-flag { display: inline-block; margin-left: 8px; font-size: 12px; font-weight: 600; color: var(--critical); background: var(--critical-bg); padding: 1px 8px; border-radius: 999px; vertical-align: 2px; }
.step-sign { font-size: 13px; color: var(--done); margin-top: 4px; }

.run-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 24px; align-items: center; }

/* ---------- stats ---------- */
.grid-months th.m, .grid-months td.m { text-align: center; padding: 8px 4px; min-width: 40px; }
.cell { display: inline-grid; place-items: center; width: 34px; height: 30px; border-radius: 4px; font-size: 13px; color: var(--muted); }
.cell.h1 { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--ink); }
.cell.h2 { background: color-mix(in srgb, var(--accent) 38%, transparent); color: var(--ink); }
.cell.h3 { background: color-mix(in srgb, var(--accent) 62%, transparent); color: var(--accent-ink); font-weight: 600; }
.cell.h4 { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.total-cell { font-size: 18px; font-weight: 700; }

.figures { display: flex; gap: 40px; flex-wrap: wrap; margin-bottom: 28px; }
.figure b { display: block; font-size: 36px; font-weight: 700; line-height: 1.1; }
.figure span { font-size: 13px; color: var(--muted); }

.month-chart { display: grid; grid-template-columns: repeat(12, 1fr); gap: 8px; align-items: end; height: 180px; padding: 16px 16px 0; }
.month-chart .col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.month-chart .val { font-size: 12px; color: var(--muted); }
.month-chart .colbar { width: 100%; max-width: 36px; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.month-chart .colbar.zero { background: var(--line); }
.month-labels { display: grid; grid-template-columns: repeat(12, 1fr); gap: 8px; padding: 6px 16px 14px; font-size: 12px; color: var(--muted); text-align: center; border-top: 1px solid var(--line); }

/* ---------- template editor ---------- */
.edit-step { display: grid; grid-template-columns: 32px 1fr auto; gap: 10px; padding: 14px; border-bottom: 1px solid var(--line); }
.edit-step:last-child { border-bottom: 0; }
.edit-step.critical { border-left: 3px solid var(--critical); }
.edit-step .idx { font-weight: 600; color: var(--muted); padding-top: 8px; text-align: right; }
.edit-step .fields { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
.edit-step .fields .wide { grid-column: 1 / -1; }
.edit-step .ops { display: flex; flex-direction: column; gap: 4px; }
.edit-step .ops button { padding: 4px 8px; font-size: 13px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .panel { width: 100%; max-width: 380px; }
.login h1 { margin-bottom: 4px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-brand img { width: 48px; height: 48px; }
.login-brand span { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.login p { margin-bottom: 20px; }

/* ---------- modal + toast ---------- */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; max-width: 460px; width: calc(100% - 32px);
  background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgb(10 15 20 / .45); }
dialog h2 { margin-bottom: 10px; }
dialog .dialog-body { margin-bottom: 18px; }
dialog.critical { border-top: 4px solid var(--critical); }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }
.secret { font-size: 22px; font-weight: 600; padding: 10px 14px; background: var(--paper); border-radius: var(--radius); user-select: all; letter-spacing: .03em; margin: 10px 0; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--radius);
  font-size: 14px; display: none; max-width: calc(100% - 32px); z-index: 10;
}
#toast.show { display: block; }
#toast.error { background: var(--danger); color: #fff; }

/* ---------- attachments ---------- */
.media-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.media-btn { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; font-size: 13px; border-radius: 999px; }
.media-btn svg { width: 18px; height: 18px; color: var(--accent); }
dialog.wide { max-width: min(1100px, calc(100% - 32px)); }
.lightbox { display: block; max-width: 100%; max-height: 75vh; margin: 0 auto; border-radius: 4px; border: 1px solid var(--line); }
.media-edit { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.media-thumb { position: relative; width: 72px; height: 54px; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; background: var(--paper); }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-thumb .kind { position: absolute; left: 3px; bottom: 3px; font-size: 10px; font-weight: 700; background: var(--ink); color: var(--paper); padding: 0 4px; border-radius: 3px; }
.media-thumb button { position: absolute; right: 2px; top: 2px; padding: 0 5px; font-size: 12px; line-height: 16px; border-radius: 3px; }
.upload-btn { font-size: 13px; padding: 6px 10px; }
.upload-btn input { display: none; }

/* ---------- known issues ---------- */
.search { max-width: 420px; margin-bottom: 18px; }
.issue { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 12px; }
.issue-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.issue h2 { font-size: 17px; }
.issue .applies { font-size: 13px; color: var(--muted); margin-top: 2px; }
.issue h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 14px 0 4px; }
.error-text { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px;
  background: var(--paper); border-left: 3px solid var(--accent); padding: 10px 12px; border-radius: 4px; }
.fix-text { white-space: pre-wrap; }
.issue-foot { font-size: 12px; color: var(--muted); margin-top: 12px; }

/* ---------- stats drill-down ---------- */
a.cell { text-decoration: none; }
a.cell:hover { outline: 2px solid var(--ink); outline-offset: -2px; }
.month-chart .col { border: 0; background: none; padding: 0; cursor: pointer; font: inherit; border-radius: 4px 4px 0 0; }
.month-chart .col:hover .colbar:not(.zero) { background: var(--accent-hover); }
.month-chart .col.sel .colbar { background: var(--ink); }
.month-labels span.sel { color: var(--ink); font-weight: 700; }

/* ---------- client picker ---------- */
.combo > label > span { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.combo-list { list-style: none; margin: 4px 0 0; padding: 4px 0; max-height: 240px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.combo-list li { padding: 7px 12px; cursor: pointer; }
.combo-list li:hover, .combo-list li.on { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.combo-list li.none { color: var(--muted); cursor: default; }

/* ---------- calendar ---------- */
.cal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-head div { padding: 8px 10px; font-size: 13px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); }
.cal-day { min-height: 112px; padding: 4px 6px 8px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); cursor: pointer; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal-day:nth-child(7n) { border-right: 0; }
.cal-day:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); }
.cal-day.out { background: var(--paper); }
.cal-day.out .cal-num { color: var(--muted); opacity: .6; }
.cal-num { border: 0; background: none; padding: 2px 4px; font-weight: 600; font-size: 14px; align-self: flex-start; border-radius: 4px; }
.cal-day.today .cal-num { background: var(--accent); color: var(--accent-ink); }
.cal-long { display: none; }
.cal-entry { text-align: left; font-size: 12px; line-height: 1.35; padding: 4px 6px; border-radius: 4px; border: 1px solid var(--line);
  border-left: 3px solid var(--muted); background: var(--surface); width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 400; }
.cal-entry span { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.sched-status.completed { color: var(--done); font-weight: 600; }
.sched-status.cancelled { color: var(--danger); font-weight: 600; }
.cal-entry.mine { border-left-color: var(--accent); }
.cal-entry[draggable="true"] { cursor: grab; }
.cal-warn { display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; background: var(--danger); color: #fff;
  font-style: normal; font-weight: 700; font-size: 11px; line-height: 1; margin-right: 4px; vertical-align: 1px; }
.cal-entry.dragging { opacity: .4; }
.cal-day.drop { background: color-mix(in srgb, var(--accent) 10%, transparent); outline: 2px dashed var(--accent); outline-offset: -3px; }
.cal-entry.started { background: color-mix(in srgb, var(--critical) 10%, var(--surface)); }
.cal-entry.done { background: var(--done-bg); }
.cal-entry.done span, .cal-entry.done b { color: var(--done); }
.cal-key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line); vertical-align: -1px; margin: 0 4px 0 12px; }
.cal-key:first-child { margin-left: 0; }
.cal-key.mine { border-left: 3px solid var(--accent); }
.cal-key.started { background: color-mix(in srgb, var(--critical) 25%, var(--surface)); }
.cal-key.done { background: var(--done-bg); border-color: var(--done); }
.cal-none { margin-top: 12px; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 18px; }
dl.kv dt { color: var(--muted); font-size: 14px; }
dl.kv dd { margin: 0; font-weight: 500; }

@media (max-width: 720px) {
  .cal-head { display: none; }
  .cal-grid { display: block; }
  .cal-day { min-height: 0; border-right: 0; display: none; padding: 10px 12px; }
  .cal-day.has, .cal-day.today { display: flex; }
  .cal-day.out.has { display: flex; }
  .cal-short { display: none; }
  .cal-long { display: inline; }
  .cal-entry { white-space: normal; font-size: 14px; }
}

@media (max-width: 640px) {
  .topbar-inner { gap: 8px 16px; padding-top: 10px; }
  .who { margin-left: auto; }
  .nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; margin: 0 -10px; }
  .nav a { white-space: nowrap; padding: 10px; }
  .run-head { grid-template-columns: 1fr; }
  .run-progress { text-align: left; }
  .step { grid-template-columns: 28px 28px 1fr; padding: 12px; }
  .step-no { font-size: 15px; }
  .edit-step .fields { grid-template-columns: 1fr; }
  .figures { gap: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  .run-bar > i { transition: none; }
}
