/* Always dark. */
:root {
  --bg: #111113;
  --surface: #1c1c1e;
  --surface-2: #26262a;
  --text: #f2f2f4;
  --muted: #9a9aa1;
  --line: #2f2f34;
  --accent: #7983f5;
  --accent-text: #ffffff;
  --danger: #ff5c5c;
  --today: #ff6961;
  --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  --rail: 200px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); }

button, .button, input, select, textarea { font: inherit; color: inherit; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 32px; padding: 4px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; text-decoration: none;
}
button:hover, .button:hover { background: var(--surface-2); }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible,
.button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.primary:hover { background: var(--accent); filter: brightness(1.08); }
.danger { color: var(--danger); }
.icon-btn { width: 32px; padding: 0; font-size: 18px; }

/* sign-in / notice pages */
.notice { max-width: 420px; margin: 15vh auto; padding: 32px 24px; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.notice h1 { font-size: 26px; margin-bottom: 8px; }
.notice code { font-size: 13px; }

/* shell: section rail + content */
.shell { display: flex; min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh; width: var(--rail); flex: none;
  display: flex; flex-direction: column; gap: 4px; padding: 20px 12px;
  background: var(--surface); border-right: 1px solid var(--line);
}
.brand { font-size: 17px; font-weight: 700; padding: 0 10px 16px; letter-spacing: -.01em; }
.rail a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.rail a:hover { background: var(--surface-2); color: var(--text); }
.rail a[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.rail a[aria-current="page"] svg { stroke: var(--accent); }
.rail svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; flex: none; }
.rail-spacer { flex: 1; }
.user { display: flex; align-items: center; gap: 8px; padding: 8px 10px; flex-wrap: wrap; }
.user img { width: 28px; height: 28px; border-radius: 50%; }
.user #userName { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user button { min-height: 28px; padding: 2px 10px; }

.content { flex: 1; min-width: 0; padding: 24px 28px 40px; max-width: 1280px; }
.status { padding: 8px 12px; margin-bottom: 12px; border-radius: 8px; background: var(--surface-2); }
.status[data-kind="error"] { color: var(--danger); }

.section-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.section-head .heading { flex: 1; min-width: 180px; }
.section-head h1 { font-size: 24px; letter-spacing: -.01em; }
.section-head p { margin: 2px 0 0; }
.nav { display: flex; gap: 4px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.card h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 10px; }

/* overview */
.overview-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; align-items: start; }
.overview-grid > .card { position: sticky; top: 24px; }
.week { display: flex; flex-direction: column; gap: 10px; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.day.today { border-color: color-mix(in srgb, var(--today) 55%, var(--line)); }
.day.past { opacity: .6; }
.day.past:hover, .day.past:focus-within { opacity: 1; }
.day-head { display: flex; align-items: center; gap: 8px; }
.day-head h3 { flex: 1; display: flex; align-items: baseline; gap: 8px; font-size: 15px; }
.day.today .dname { color: var(--today); }
.ddate { font-weight: 400; font-size: 13px; }
.badge { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 10px;
  background: color-mix(in srgb, var(--today) 22%, transparent); color: var(--today); align-self: center; }
.day-head .add { width: 28px; min-height: 28px; font-size: 16px; border-color: transparent; background: transparent; color: var(--muted); }
.day-head .add:hover { background: var(--surface-2); color: var(--text); }
.day .agenda-list { margin-top: 8px; }
.empty-day { margin: 6px 0 0; }

.reminder-list, .agenda-list { list-style: none; margin: 0; padding: 0; }
.reminder-list li { display: flex; flex-direction: column; padding: 6px 0 6px 10px;
  border-left: 3px solid var(--c, var(--accent)); margin-bottom: 6px; }
#reminderStatus { margin: 4px 0 10px; }

.agenda-item { width: 100%; justify-content: flex-start; align-items: flex-start; gap: 12px; text-align: left;
  padding: 7px 10px; margin-bottom: 4px; border: 0; border-left: 3px solid var(--c);
  border-radius: 6px; background: var(--surface-2); }
.agenda-item:hover { background: color-mix(in srgb, var(--c) 14%, var(--surface-2)); }
.agenda-item .when { width: 130px; flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.agenda-item .what { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.agenda-item .what strong { font-weight: 500; }
.repeat-badge { flex: none; }

/* calendar: whose-calendar chips */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { border-radius: 999px; padding: 4px 14px; gap: 8px; color: var(--muted); }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.chip[aria-pressed="true"] { color: var(--text); border-color: var(--c, var(--accent));
  background: color-mix(in srgb, var(--c, var(--accent)) 18%, var(--surface)); }

/* calendar: month grid */
.month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--line); gap: 1px; }
.dow { background: var(--surface); padding: 6px 8px; font-size: 12px; color: var(--muted); text-align: right; }
.cell { background: var(--surface); min-height: 112px; padding: 4px; display: flex; flex-direction: column;
  gap: 2px; cursor: pointer; min-width: 0; }
.cell:hover { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
.cell.other { background: var(--bg); }
.cell.other .num { color: var(--muted); }
.num { align-self: flex-end; min-height: 26px; min-width: 26px; padding: 0 6px; border: 0; border-radius: 13px;
  background: transparent; font-size: 13px; }
.cell.today .num { background: var(--today); color: #fff; font-weight: 600; }
.pill { justify-content: flex-start; min-height: 22px; padding: 1px 6px; border: 0; border-radius: 5px;
  font-size: 12px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;
  background: transparent; border-left: 3px solid var(--c); }
.pill:hover { background: color-mix(in srgb, var(--c) 15%, transparent); }
.pill.all-day { background: color-mix(in srgb, var(--c) 22%, transparent); border-left-width: 0; }
.pill .t { color: var(--muted); font-variant-numeric: tabular-nums; }
.more { justify-content: flex-start; min-height: 20px; padding: 0 6px; border: 0; background: transparent;
  font-size: 12px; color: var(--muted); }

/* reminders */
.reminders-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.reminders-grid .side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 24px; }
.settings { display: flex; flex-direction: column; gap: 16px; }
.settings .card { display: flex; flex-direction: column; gap: 12px; }
.settings .card.paused { opacity: .5; }
.settings hr { border: 0; border-top: 1px solid var(--line); margin: 2px 0; width: 100%; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; cursor: pointer; }
.switch-row > span:first-child { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.switch-row.compact { padding: 6px 0; }
.switch-list { display: flex; flex-direction: column; }
.switch-list .switch-row + .switch-row { border-top: 1px solid var(--line); }
.cal-name { flex-direction: row !important; align-items: center; gap: 10px !important; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; display: inline-block; }
input[role="switch"] {
  appearance: none; flex: none; width: 40px; height: 24px; margin: 0; border-radius: 12px; cursor: pointer;
  background: var(--line); position: relative; transition: background .15s;
}
input[role="switch"]::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
input[role="switch"]:checked { background: var(--accent); }
input[role="switch"]:checked::after { transform: translateX(16px); }
input[role="switch"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.settings label.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.settings .row.inline { align-items: flex-end; flex-wrap: wrap; }
.settings .row.inline label:not(.check) { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); width: 180px; }
.settings .row.inline label.check { padding-bottom: 8px; }
.settings .row.off { opacity: .45; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { display: flex; flex-direction: column; gap: 2px; }
.chip.on { color: var(--text); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  padding: 2px 4px 2px 12px; cursor: default; min-height: 32px; display: inline-flex; align-items: center; border: 1px solid var(--accent); }
.chip-x { width: 24px; min-height: 24px; padding: 0; border: 0; border-radius: 50%; background: transparent; font-size: 16px; color: var(--muted); }
.chip-x:hover { background: var(--surface-2); color: var(--text); }
select.chip-add { width: auto; min-height: 32px; border-radius: 999px; padding: 2px 12px; background: var(--surface); }
.chips .none { align-self: center; }
.save-state { color: var(--muted); }
.save-state[data-kind="ok"] { color: #63da38; }
.save-state[data-kind="error"] { color: var(--danger); }
.rem-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.reminder-list li.dim { opacity: .5; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { display: flex; flex-direction: column; padding: 6px 0; border-top: 1px solid var(--line); }
.history li:first-child { border-top: 0; }
.preview-label { margin: 4px 0 -4px; }
.dm-preview { background: #313338; border-radius: 8px; padding: 12px; }
.embed { border-left: 4px solid var(--c); background: #2b2d31; border-radius: 4px; padding: 10px 14px;
  display: flex; flex-direction: column; gap: 6px; max-width: 440px; color: #dbdee1; }
.embed-title { font-weight: 600; color: #00a8fc; }
.embed-name { font-weight: 600; font-size: 12px; color: #f2f3f5; }
.embed-foot { font-size: 11px; color: #949ba4; }

/* per-event Discord rule (editor) and Event rules list */
.discord-rule { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 12px; margin: 0;
  display: flex; flex-direction: column; gap: 8px; }
.discord-rule legend { padding: 0 6px; font-size: 12px; color: var(--muted); }
#eventForm .discord-rule label.check { font-size: 13px; }
.discord-rule #ruleHint { margin: 0; }
.discord-rule #ruleHint:empty { display: none; }
.rule-row { flex-direction: row !important; align-items: center; justify-content: space-between; gap: 8px; }
.rule-text { display: flex; flex-direction: column; min-width: 0; }
.rule-row button { min-height: 28px; padding: 2px 10px; flex: none; }

/* dialogs */
dialog { width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 20px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h2 { font-size: 18px; margin-bottom: 12px; }
#eventForm { display: flex; flex-direction: column; gap: 10px; }
#eventForm label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); flex: 1; min-width: 0; }
#eventForm label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
#eventForm label.time { flex: 0 0 130px; }
input:not([type="checkbox"]), select, textarea {
  width: 100%; min-height: 36px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); font-size: 15px; }
textarea { resize: vertical; }
.row { display: flex; gap: 10px; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.spacer { flex: 1; }
#dayList { max-height: 50vh; overflow: auto; }

/* tablet: reminders card drops below the week */
@media (max-width: 1000px) {
  .overview-grid { grid-template-columns: minmax(0, 1fr); }
  .overview-grid > .card { position: static; }
  .reminders-grid { grid-template-columns: minmax(0, 1fr); }
  .reminders-grid .side { position: static; }
}

/* phone: rail becomes a bottom tab bar */
@media (max-width: 700px) {
  .shell { display: block; padding-bottom: 64px; }
  .rail {
    position: fixed; inset: auto 0 0 0; top: auto; height: 60px; width: auto; z-index: 10;
    flex-direction: row; align-items: stretch; padding: 0 8px; gap: 0;
    border-right: 0; border-top: 1px solid var(--line);
  }
  .brand, .rail-spacer { display: none; }
  .rail a { flex: 1; flex-direction: column; justify-content: center; gap: 2px; font-size: 11px; padding: 6px; border-radius: 0; background: transparent !important; }
  .rail a[aria-current="page"] { color: var(--accent); }
  .user { padding: 0 4px; flex-wrap: nowrap; }
  .user #userName { display: none; }
  .content { padding: 16px 16px 24px; }
  .section-head h1 { font-size: 20px; }
  .section-head .heading { flex-basis: 100%; }
  .cell { min-height: 76px; padding: 2px; }
  .dow { text-align: center; padding: 4px 0; }
  .num { align-self: center; }
  .pill { font-size: 11px; padding: 0 3px; min-height: 18px; }
  .pill .t { display: none; }
  .agenda-item { flex-direction: column; gap: 2px; }
  .agenda-item .when { width: auto; }
  .row { flex-wrap: wrap; }
  #eventForm label.time { flex: 1 0 120px; }
}
