/* Calendar: cool paper, navy ink, amber reserved for "now" and reminders. */
:root {
  --paper: #eef1f5;
  --surface: #ffffff;
  --ink: #1b2a41;
  --muted: #5d6b7e;
  --line: #d6dce4;
  --soft: #e3e8ef;
  --amber: #e3a21a;
  --amber-soft: #fbefd3;
  --danger: #b4232f;
  --ok: #1f7a4d;
  --focus: #2f6fd6;
  --radius-s: 6px;
  --radius-m: 10px;
  --title-font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
  --body-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar-w: 264px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111823;
    --surface: #18212f;
    --ink: #e4e9f0;
    --muted: #9aa7b8;
    --line: #2c3748;
    --soft: #222c3c;
    --amber: #f0b43a;
    --amber-soft: #3a3020;
    --danger: #f07178;
    --ok: #5cc795;
    --focus: #7aa7ff;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.45 var(--body-font);
  font-variant-numeric: tabular-nums;
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin-top: 1.25rem; }
p { margin: 0 0 .75rem; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }
.small, .hint { font-size: .85rem; }
.hint { color: var(--muted); display: block; font-weight: 400; margin-top: .2rem; }
.spacer { flex: 1; }

/* ---------- form controls ---------- */
label { display: block; font-weight: 600; font-size: .9rem; }
label.inline { display: inline-flex; align-items: center; gap: .35rem; font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: .45rem .55rem; width: 100%; margin-top: .25rem; font-weight: 400;
}
label.inline input, label.inline select { width: auto; margin-top: 0; }
input.num, label.inline input.num, .reminder input.num { width: 5.5rem; }
input[type="checkbox"], input[type="radio"] { width: auto; margin: 0; accent-color: var(--ink); }
input[type="color"] { padding: .1rem; height: 2.4rem; width: 4rem; }
textarea { resize: vertical; }
.checkbox-row { display: flex; align-items: center; gap: .5rem; align-self: end; padding-bottom: .55rem; }
.stack > * + * { margin-top: .9rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; border-radius: var(--radius-s);
  padding: .5rem .9rem; border: 1px solid transparent; cursor: pointer;
  text-decoration: none; background: none; color: var(--ink); min-height: 2.4rem;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--surface); }
.btn-outline { border-color: var(--line); background: var(--surface); }
.btn-quiet { padding-inline: .6rem; }
.btn-quiet:hover, .btn-outline:hover { background: var(--soft); }
.btn-danger { color: var(--danger); border-color: var(--line); }
.btn-block { width: 100%; }
.icon-btn {
  font: inherit; font-size: 1.4rem; line-height: 1; width: 2.4rem; height: 2.4rem;
  border: 1px solid transparent; border-radius: var(--radius-s); background: none; color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: var(--soft); }

.notice {
  border-left: 3px solid var(--ink); background: var(--soft);
  padding: .55rem .75rem; border-radius: 0 var(--radius-s) var(--radius-s) 0;
}
.notice-error { border-color: var(--danger); }
.notice-ok { border-color: var(--ok); }

/* ---------- login / invite ---------- */
.auth-page { display: grid; place-items: center; padding: 1rem; }
.auth-card {
  width: min(380px, 100%); background: var(--surface); padding: 2rem 1.75rem;
  border-radius: var(--radius-m); border: 1px solid var(--line);
}
.auth-title, .period-title {
  font-family: var(--title-font); font-weight: 800; letter-spacing: -.02em;
}
.auth-title { font-size: 2.1rem; margin-bottom: 1.25rem; }
.auth-title::after {
  content: ""; display: block; width: 2.2rem; height: .3rem; margin-top: .4rem;
  background: var(--amber); border-radius: 3px;
}

/* ---------- app layout ---------- */
.app-page { overflow: hidden; }
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100vh; height: 100dvh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 1rem; display: flex; flex-direction: column; gap: 1rem; overflow-y: auto;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.brand { font-family: var(--title-font); font-weight: 800; font-size: 1.2rem; }
.sidebar-heading { font-size: .9rem; color: var(--muted); font-weight: 600; margin-bottom: .4rem; }
.sidebar-foot { margin-top: auto; display: flex; flex-wrap: wrap; gap: .25rem; border-top: 1px solid var(--line); padding-top: .75rem; }
.search input { margin: 0; }
.search-results { display: flex; flex-direction: column; gap: .15rem; max-height: 40vh; overflow-y: auto; }
.search-result {
  text-align: left; font: inherit; color: inherit; background: none; border: 0; cursor: pointer;
  padding: .4rem .5rem; border-radius: var(--radius-s); border-left: 4px solid var(--c, var(--ink));
}
.search-result:hover { background: var(--soft); }
.search-result small { display: block; color: var(--muted); }

.calendar-list { list-style: none; margin: 0 0 .25rem; padding: 0; }
.calendar-list li { display: flex; align-items: center; gap: .5rem; padding: .2rem 0; }
.calendar-list label { display: flex; align-items: center; gap: .5rem; font-weight: 400; flex: 1; min-width: 0; cursor: pointer; }
.calendar-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatch-check { appearance: none; width: 1.05rem; height: 1.05rem; border-radius: 4px; border: 2px solid var(--c); flex: none; }
.swatch-check:checked { background: var(--c); }
.calendar-list .edit { font-size: .85rem; padding: .15rem .4rem; min-height: 0; color: var(--muted); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
  padding: .9rem 1.25rem .6rem;
}
.period-title { font-size: clamp(1.6rem, 3.2vw, 2.6rem); margin: 0; flex: 1; min-width: 10ch; }
.toolbar-controls { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.nav-buttons { display: flex; align-items: center; gap: .15rem; }
.view-switch { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; background: var(--surface); }
.view-switch button {
  font: inherit; font-weight: 600; font-size: .9rem; color: var(--muted); background: none;
  border: 0; padding: .45rem .75rem; cursor: pointer; border-left: 1px solid var(--line);
}
.view-switch button:first-child { border-left: 0; }
.view-switch button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.calendar-host { flex: 1; min-height: 0; padding: 0 1.25rem 1rem; }

.offline-banner {
  margin: 0; padding: .5rem 1.25rem; background: var(--amber-soft); border-bottom: 2px solid var(--amber);
  font-weight: 600;
}
.offline .requires-online { display: none !important; }

/* ---------- FullCalendar theming ---------- */
.fc {
  --fc-border-color: var(--line);
  --fc-page-bg-color: var(--surface);
  --fc-neutral-bg-color: var(--soft);
  --fc-today-bg-color: var(--amber-soft);
  --fc-now-indicator-color: var(--amber);
  --fc-list-event-hover-bg-color: var(--soft);
  --fc-highlight-color: rgba(227, 162, 26, .18);
  --fc-event-border-color: transparent;
  height: 100%;
  background: var(--surface);
  border-radius: var(--radius-m);
}
.fc .fc-scrollgrid { border-radius: var(--radius-m); overflow: hidden; }
.fc .fc-col-header-cell-cushion, .fc .fc-daygrid-day-number { color: var(--ink); text-decoration: none; }
.fc .fc-day-today .fc-daygrid-day-number {
  background: var(--amber); color: #1b2a41; border-radius: 999px; min-width: 1.8em; text-align: center; font-weight: 700;
}
.fc .fc-multimonth { border: 0; }
.fc .fc-multimonth-title { font-family: var(--title-font); font-weight: 800; font-size: 1.1rem; text-align: left; padding-left: .75rem; }
.fc .fc-list-day-cushion { background: var(--soft); }
.fc .fc-event { cursor: pointer; }
.fc .fc-list-event-title a, .fc .fc-list-day-text, .fc .fc-list-day-side-text { color: var(--ink); text-decoration: none; }

/* ---------- dialogs ---------- */
.dialog {
  border: 1px solid var(--line); border-radius: var(--radius-m); padding: 0;
  background: var(--surface); color: var(--ink);
  width: min(640px, calc(100vw - 1.5rem)); max-height: calc(100dvh - 1.5rem);
}
.dialog-small { width: min(420px, calc(100vw - 1.5rem)); }
.dialog::backdrop { background: rgba(17, 24, 35, .45); }
.dialog-body { padding: 1.1rem 1.25rem 1.25rem; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.dialog-head h2 { margin: 0; font-family: var(--title-font); font-weight: 800; font-size: 1.4rem; }
.dialog-foot { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: 1.1rem; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem 1rem; }
.span-2 { grid-column: span 2; }
.group { border: 1px solid var(--line); border-radius: var(--radius-m); margin: 1rem 0 0; padding: .6rem .9rem .9rem; }
.group legend { font-weight: 700; padding: 0 .3rem; }
.repeat-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.repeat-row > select { width: auto; margin: 0; }
.weekday-picker { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .7rem; }
.weekday-picker label {
  font-weight: 600; font-size: .85rem; border: 1px solid var(--line); border-radius: 999px;
  padding: .3rem .65rem; cursor: pointer; display: inline-flex; gap: .3rem; align-items: center;
}
.weekday-picker label:has(input:checked) { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.weekday-picker input { position: absolute; opacity: 0; pointer-events: none; }
.weekday-picker label:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.radio-stack { display: flex; flex-direction: column; gap: .35rem; margin-top: .7rem; }
.radio-stack label { font-weight: 400; display: flex; gap: .45rem; align-items: center; }
#repeat-custom-wrap { margin-top: .7rem; }
#repeat-custom { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.repeat-ends { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; margin-top: .8rem; }
.repeat-ends > span { font-weight: 600; font-size: .9rem; }

.reminder-list { list-style: none; padding: 0; margin: .25rem 0 .5rem; display: flex; flex-direction: column; gap: .6rem; }
.reminder {
  border-left: 3px solid var(--amber); background: var(--paper); border-radius: 0 var(--radius-s) var(--radius-s) 0;
  padding: .55rem .65rem; display: flex; flex-wrap: wrap; gap: .45rem .75rem; align-items: center;
}
.reminder select, .reminder input { width: auto; margin: 0; }
.reminder .when { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.reminder .channels { display: flex; gap: .7rem; flex-wrap: wrap; }
.reminder .channels label { font-weight: 400; display: inline-flex; gap: .3rem; align-items: center; }
.reminder .remove { margin-left: auto; }
.reminder .warn { flex-basis: 100%; font-size: .82rem; color: var(--muted); margin: 0; }

.choice-buttons { display: flex; flex-direction: column; gap: .5rem; margin-top: .75rem; }

.tabs { display: flex; flex-wrap: wrap; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tabs button {
  font: inherit; font-weight: 600; font-size: .9rem; background: none; border: 0; color: var(--muted);
  padding: .5rem .6rem; cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--amber); }
.channel-row { display: grid; grid-template-columns: 1fr auto; gap: .25rem .75rem; align-items: end; }
.channel-row .channel-status { grid-column: 1 / -1; margin: 0; font-size: .85rem; color: var(--muted); }
.channel-status.ready::before { content: "● "; color: var(--ok); }
.channel-status.not-ready::before { content: "○ "; }
.log-list { list-style: none; padding: 0; margin: 0 0 .5rem; }
.log-list li { padding: .45rem 0; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: .25rem .75rem; }
.log-list .when { color: var(--muted); font-size: .85rem; min-width: 9rem; }
.log-list .status-sent { color: var(--ok); }
.log-list .status-failed, .log-list .status-skipped { color: var(--danger); }
.log-list .error { flex-basis: 100%; font-size: .82rem; color: var(--muted); }

.toast {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 1000;
  background: var(--ink); color: var(--surface); padding: .6rem 1rem; border-radius: var(--radius-s);
  max-width: calc(100vw - 2rem); font-weight: 600;
}
.toast.error { background: var(--danger); color: #fff; }

/* ---------- admin ---------- */
.admin { max-width: 860px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.admin-head .period-title { flex: none; }
.admin-section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; }
.inline-form label select { width: auto; }
.new-link { display: flex; gap: .5rem; align-items: end; margin-top: .9rem; }
.new-link label { flex: 1; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .85rem; color: var(--muted); }
.tag { font-size: .78rem; border: 1px solid var(--line); border-radius: 999px; padding: .05rem .45rem; margin-right: .2rem; white-space: nowrap; }
.tag.on { border-color: var(--ok); color: var(--ok); }

/* ---------- small screens ---------- */
.only-mobile { display: none; }
.scrim { display: none; }
@media (max-width: 820px) {
  .only-mobile { display: inline-block; }
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(85vw, 320px); z-index: 50;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(17, 24, 35, .4); }
  .toolbar { padding: .6rem .75rem .5rem; }
  .toolbar-controls { width: 100%; justify-content: space-between; }
  .view-switch button { padding: .45rem .55rem; }
  .calendar-host { padding: 0 .5rem .5rem; }
  .field-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
