:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #f0ece3;
  --ink: #1f1d1a;
  --muted: #6b665d;
  --line: #dfd9cd;
  --accent: #b4241c;
  --accent-ink: #ffffff;
  --accent-soft: #f8e4e0;
  --ok: #2d6a3e;
  --warn: #8a5a00;
  --panel: #f2efe6;
  --shadow: 0 1px 2px rgb(50 40 20 / 8%), 0 8px 24px rgb(50 40 20 / 7%);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #171614;
    --surface: #211f1c;
    --surface-2: #2c2a26;
    --ink: #f1ede4;
    --muted: #a8a297;
    --line: #38352f;
    --accent: #e0584e;
    --accent-ink: #1d0f0d;
    --accent-soft: #43211d;
    --ok: #7fc794;
    --warn: #e0b45c;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, p { margin: 0; }
h2 { font-size: 16px; font-weight: 650; }
small { color: var(--muted); display: block; font-size: 13px; margin-top: 5px; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1320px; margin: 0 auto; padding: 16px 24px;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.brand-mark { display: inline-grid; grid-template-columns: repeat(3, 6px); gap: 2px; }
.brand-mark span { height: 18px; border-radius: 1.5px; background: var(--ink); }
.brand-mark span:nth-child(2) { background: var(--accent); }
.brand-mark span:nth-child(3) { background: var(--line); }

.layout {
  display: grid; grid-template-columns: minmax(0, 828px) minmax(340px, 1fr); gap: 20px; align-items: start;
  max-width: 1320px; margin: 0 auto; padding: 0 24px 40px;
}
.preview-column, .settings-column { display: grid; gap: 16px; min-width: 0; }

.panel-frame {
  position: relative; margin: 0; padding: 14px; border-radius: 16px;
  background: #24221f; box-shadow: var(--shadow);
}
.panel-frame img {
  display: block; width: 100%; height: auto; aspect-ratio: 5 / 3; background: var(--panel);
  border-radius: 2px; image-rendering: auto;
}
.preview-empty {
  position: absolute; inset: 14px; display: grid; place-items: center; color: #6b665d;
  background: var(--panel); border-radius: 2px;
}
.preview-meta { color: var(--muted); font-size: 13px; min-height: 19px; padding: 0 4px; margin-top: -6px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: 0 1px 2px rgb(50 40 20 / 5%);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; min-height: 36px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 0 0 16px; }
.facts dt { color: var(--muted); font-size: 12.5px; }
.facts dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 7px 14px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; font-size: 14px; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.button:hover { background: var(--surface-2); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button.primary:hover { filter: brightness(.93); background: var(--accent); }
.button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.button.ghost:hover { background: var(--surface-2); color: var(--ink); }
.button.wide { width: 100%; min-height: 44px; }
.button:disabled { opacity: .55; cursor: default; }
:is(.button, input, summary, .icon-button):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-size: 13px; font-weight: 600;
}
.status-pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-pill.ok i { background: var(--ok); }
.status-pill.busy i { background: var(--warn); }
.status-pill.off i { background: var(--accent); }

.calendar-list, .pick-list { list-style: none; margin: 0; padding: 0; }
.calendar-item { padding: 12px 0; border-top: 1px solid var(--line); }
.calendar-item:first-child { border-top: 0; padding-top: 0; }
.calendar-item:last-child { padding-bottom: 0; }
.calendar-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.calendar-name { font-weight: 650; overflow-wrap: anywhere; }
.calendar-sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.calendar-sub.error { color: var(--accent); }
.calendar-controls { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 9px; }
.interval { display: inline-flex; align-items: center; gap: 9px; max-width: 100%; font-size: 14px; font-weight: 400; }
.interval select {
  min-width: 0; max-width: 100%; min-height: 32px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--bg); color: var(--ink); font: inherit;
}
.interval select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-button {
  flex: none; width: 32px; height: 32px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-button:hover { background: var(--accent-soft); color: var(--accent); }
.icon-button svg { width: 17px; height: 17px; }

.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.switch { display: inline-flex; align-items: center; gap: 9px; font-size: 14px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 34px; height: 20px; margin: 0; cursor: pointer; }
.switch span {
  position: relative; flex: none; width: 34px; height: 20px; border-radius: 10px; background: var(--line); transition: background .15s;
}
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 30%); transition: transform .15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.empty { display: grid; gap: 3px; padding: 18px; text-align: center; color: var(--muted); background: var(--surface-2); border-radius: 9px; }
.empty strong { color: var(--ink); }

.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 90px; gap: 12px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 10px; }
label { display: block; font-size: 13.5px; font-weight: 600; }
input:not([type=checkbox]) {
  display: block; width: 100%; min-height: 38px; margin-top: 5px; padding: 7px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg); color: var(--ink); font: inherit; font-weight: 400;
}
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; }
.style-picker { grid-column: 1 / -1; }
#style-options { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.style-option { position: relative; display: block; cursor: pointer; }
.style-option input { position: absolute; opacity: 0; }
.style-option > span {
  display: grid; place-items: center; height: 46px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
}
.style-option input:checked + span { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.style-option input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.person-chip {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 5px; border-radius: 5px;
  font-size: 13px; font-weight: 700; line-height: 1; border: 2px solid transparent;
}
.person-chip.s0 { background: #1c1b1a; border-color: #1c1b1a; color: #fff; }
.person-chip.s1 { background: #f2efe6; border-color: #1c1b1a; color: #1c1b1a; }
.person-chip.s2 { background: #b4241c; border-color: #b4241c; color: #fff; }
.person-chip.s3 { background: #f2efe6; border-color: #b4241c; color: #b4241c; }
.chip-preview { display: inline-flex; padding: 5px 7px; background: var(--panel); border-radius: 7px; }

.notice { padding: 9px 12px; border-radius: 8px; background: var(--surface-2); font-size: 14px; }
.notice.error { background: var(--accent-soft); color: var(--ink); margin-bottom: 12px; }

dialog {
  width: min(480px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(25 20 12 / 45%); }
dialog h2 { font-size: 18px; margin-bottom: 14px; }
dialog p { color: var(--muted); }
details { margin-top: 14px; }
summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#add-error { margin: 14px 0 0; }
.pick-intro { margin-bottom: 10px; }
.pick-list { display: grid; gap: 2px; max-height: 260px; overflow: auto; margin-bottom: 14px; }
.pick-list label {
  display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 7px; font-weight: 500; font-size: 14.5px; cursor: pointer;
}
.pick-list label:hover { background: var(--surface-2); }
.pick-list input { width: 17px; height: 17px; accent-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 20; max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 9px; background: var(--ink); color: var(--bg); font-weight: 550; box-shadow: var(--shadow);
}

.login-page { display: grid; place-items: center; padding: 16px; }
.login {
  display: grid; gap: 12px; width: min(380px, 100%); padding: 32px; text-align: center; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.login .brand-mark { justify-self: center; grid-template-columns: repeat(3, 9px); gap: 3px; }
.login .brand-mark span { height: 28px; }
.login h1 { font-size: 26px; letter-spacing: -.02em; }
.login > p:not(.notice) { color: var(--muted); margin-bottom: 10px; }

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 0 16px 28px; }
  .topbar { padding: 12px 16px; }
  .panel-frame { padding: 7px; border-radius: 10px; }
  .preview-empty { inset: 7px; }
}

@media (max-width: 520px) {
  .facts { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .facts > div { display: flex; justify-content: space-between; gap: 12px; }
  .facts dd { margin: 0; text-align: right; }
  .card { padding: 15px; }
  .card-head { flex-wrap: wrap; }
  .form-grid.two { grid-template-columns: minmax(0, 1fr); }
  .status-pill span { display: none; }
  .status-pill { padding: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
