/* One stylesheet. Colours, sizes and radii are named once here and used by name below. */

:root {
  --page: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --ink: #1d2524;
  --ink-2: #5b6765;
  --line: #dcd9d0;
  --accent: #0f6b57;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe9;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;

  --draft: #b26a00;
  --draft-soft: #fdf0d5;
  --approved: #0f6b57;
  --approved-soft: #dcefe9;
  --publishing: #1c5fb8;
  --publishing-soft: #e1ecfb;
  --published: #4b5563;
  --published-soft: #e9ebee;
  --failed: #b3261e;
  --failed-soft: #fbe9e7;
  --off: #7a8483;
  --off-soft: #eeeeec;

  --radius: 10px;
  --radius-small: 6px;
  --gap: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #121716;
    --surface: #1b2221;
    --surface-2: #242d2b;
    --ink: #e8ecea;
    --ink-2: #9aa6a3;
    --line: #313c3a;
    --accent: #4fc3a5;
    --accent-ink: #06231c;
    --accent-soft: #173a32;
    --danger: #ff8a80;
    --danger-soft: #3d1f1c;

    --draft: #f2b441;
    --draft-soft: #3a2c0d;
    --approved: #4fc3a5;
    --approved-soft: #173a32;
    --publishing: #7fb2f5;
    --publishing-soft: #172a45;
    --published: #aab3b1;
    --published-soft: #2a3231;
    --failed: #ff8a80;
    --failed-soft: #3d1f1c;
    --off: #8b9694;
    --off-soft: #262d2c;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
}

h1, h2, h3, p, ul, dl, dd { margin: 0; }
ul { padding: 0; list-style: none; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.muted { color: var(--ink-2); }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; }
.stack { display: grid; gap: var(--gap); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.centred {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
}
.centred h1 { font-size: 1.6rem; }
.centred p { max-width: 36ch; }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* -- controls --------------------------------------------------------------- */

button, select, input, textarea { font: inherit; color: inherit; }

.button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}
.button:hover { border-color: var(--ink-2); }
.button:disabled { opacity: 0.5; cursor: default; }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.button.danger { color: var(--danger); border-color: var(--danger); }
.button.quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.button.icon { width: 38px; padding: 0; font-size: 1.2rem; line-height: 1; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: grid; gap: 4px; }
.field > span { font-size: 0.85rem; color: var(--ink-2); }
.field.inline { display: block; }
select, input[type="text"], input[type="password"], input[type="datetime-local"], textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
}
textarea { resize: vertical; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

.segmented { display: flex; border: 1px solid var(--line); border-radius: var(--radius-small); overflow: hidden; }
.segmented button { min-height: 36px; padding: 0 14px; border: 0; background: var(--surface); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* -- the page --------------------------------------------------------------- */

#app { max-width: 1280px; margin: 0 auto; padding: 0 16px 48px; display: grid; gap: 16px; }

.bar { display: flex; align-items: center; gap: var(--gap); padding: 14px 0 2px; flex-wrap: wrap; }
.brandmark { letter-spacing: -0.01em; }
.bar select { width: auto; min-width: 150px; }
.who { font-size: 0.9rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  gap: 10px;
}
.panel.danger { border-color: var(--failed); background: var(--failed-soft); }
.panel-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.rows { display: grid; }
.account { padding: 8px 0; }
.account-what { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 10px; }
.account-name { font-weight: 600; overflow-wrap: anywhere; }
.account-id { font-size: 0.88rem; overflow-wrap: anywhere; }
.account-problem { flex-basis: 100%; color: var(--danger); font-size: 0.88rem; overflow-wrap: anywhere; }
.row-item { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line); }
.row-main {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 130px 220px 1fr;
  gap: 4px 14px;
  align-items: center;
  padding: 10px 4px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.row-main:hover .row-what { text-decoration: underline; }
.row-when { font-variant-numeric: tabular-nums; font-weight: 600; }
.row-where { display: flex; gap: 6px; align-items: center; min-width: 0; }
.row-where .muted, .row-what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-note { grid-column: 1 / -1; color: var(--draft); font-size: 0.85rem; }

.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; }

/* Each state: its colour and the soft one behind it. Rejected and cancelled share the quiet pair. */
.state-draft { --state: var(--draft); --state-soft: var(--draft-soft); }
.state-approved { --state: var(--approved); --state-soft: var(--approved-soft); }
.state-publishing { --state: var(--publishing); --state-soft: var(--publishing-soft); }
.state-published { --state: var(--published); --state-soft: var(--published-soft); }
.state-failed { --state: var(--failed); --state-soft: var(--failed-soft); }
.state-rejected, .state-cancelled { --state: var(--off); --state-soft: var(--off-soft); }
.badge { background: var(--state-soft); color: var(--state); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--state); }

/* -- the calendar ----------------------------------------------------------- */

.calendar { display: grid; gap: 10px; }
.toolbar { display: flex; align-items: center; gap: var(--gap); flex-wrap: wrap; }
.toolbar h2 { font-size: 1.15rem; }

.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.day {
  min-height: 220px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.day h3 { display: flex; justify-content: space-between; align-items: baseline; color: var(--ink-2); font-weight: 600; }
.day .day-number { font-size: 1.1rem; color: var(--ink); }
.day.today { border-color: var(--accent); }
.day.today .day-number, .cell.today .day-number { color: var(--accent); font-weight: 700; }
.empty { font-size: 0.85rem; }

.card {
  display: grid;
  gap: 4px;
  justify-items: start;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--state);
  border-radius: var(--radius-small);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}
.card:hover, .chip:hover { box-shadow: var(--shadow); }
.card-top { display: flex; gap: 6px; align-items: center; font-variant-numeric: tabular-nums; }
.card-account { font-size: 0.8rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-what { font-size: 0.88rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.state-cancelled .card-what, .state-rejected .card-what { text-decoration: line-through; color: var(--ink-2); }

.month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); gap: 1px; }
.weekday { padding: 6px 8px; background: var(--surface-2); color: var(--ink-2); font-size: 0.8rem; font-weight: 600; }
.cell { min-height: 112px; padding: 4px; background: var(--surface); display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cell.outside { background: var(--page); }
.cell.outside .day-number { color: var(--ink-2); }
.cell .day-number { align-self: flex-start; min-width: 28px; height: 26px; border: 0; border-radius: 13px; background: none; cursor: pointer; }
.cell .day-number:hover { background: var(--surface-2); }

.chip {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  min-width: 0;
  padding: 3px 6px;
  border: 0;
  border-left: 3px solid var(--state);
  border-radius: 4px;
  background: var(--state-soft);
  font-size: 0.78rem;
  text-align: left;
  cursor: pointer;
}
.chip-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.chip-what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.chip .tag { background: var(--surface); }
.more { border: 0; background: none; padding: 0 6px; white-space: nowrap; color: var(--ink-2); font-size: 0.78rem; text-align: left; cursor: pointer; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--ink-2); font-size: 0.82rem; }
.legend li { display: flex; align-items: center; gap: 6px; }

/* -- one post --------------------------------------------------------------- */

dialog {
  width: min(640px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
dialog[open] { display: grid; gap: 14px; }
dialog::backdrop { background: rgb(0 0 0 / 45%); }
.dialog-head { display: flex; align-items: center; gap: 4px 10px; flex-wrap: wrap; }
.dialog-head h2 { overflow-wrap: anywhere; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 14px; }
.facts dt { color: var(--ink-2); font-size: 0.85rem; padding-top: 2px; }
.facts dd { min-width: 0; overflow-wrap: anywhere; }
.post-text { white-space: pre-wrap; }
.files { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; }

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs:empty { display: none; }
.thumbs li { position: relative; }
.thumbs img, .thumbs video {
  display: block;
  width: 104px;
  height: 104px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface-2);
}
.thumbs video { width: 185px; }
.thumbs .remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  min-height: 26px;
  border-radius: 13px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.thumbs + .files { margin-top: 6px; }
input[type="file"] { max-width: 100%; }

.callout { padding: 10px 12px; border-radius: var(--radius-small); background: var(--surface-2); }
.callout.danger { background: var(--danger-soft); color: var(--danger); }
.callout p { color: var(--ink); overflow-wrap: anywhere; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

#toasts { position: fixed; right: 16px; bottom: 16px; left: 16px; display: grid; gap: 8px; justify-items: end; pointer-events: none; z-index: 10; }
.toast {
  pointer-events: auto;
  display: flex;
  gap: 10px;
  align-items: start;
  max-width: min(480px, 100%);
  padding: 10px 6px 10px 14px;
  border-radius: var(--radius-small);
  background: var(--ink);
  color: var(--page);
  box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); color: #fff; }
.toast ul { margin-top: 4px; padding-left: 18px; list-style: disc; font-size: 0.9rem; }
.toast .button { color: inherit; }

/* -- a phone ---------------------------------------------------------------- */

@media (max-width: 820px) {
  .who { display: none; }
  .bar { gap: 8px; }
  .bar .field.inline { order: 3; width: 100%; }
  .bar select { width: 100%; }
  .more { padding: 0 2px; font-size: 0.72rem; }
  .row-main { grid-template-columns: 1fr; gap: 2px; }
  .week { grid-template-columns: 1fr; }
  .day { min-height: 0; }
  .day h3 { justify-content: flex-start; gap: 8px; }
  .cell { min-height: 64px; }
  .chip { padding: 3px 4px; }
  .chip .tag, .chip-what { display: none; }
  .toolbar h2 { order: -1; width: 100%; }
}
