@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ===========================================================
   schdl — monochrome neo-brutalist theme (Twenty CRM-inspired)
   =========================================================== */
:root {
  --ink: #171717; --ink-soft: #3F3F3F; --muted: #6B6B6B; --faint: #9A9A9A;
  --bg: #F6F6F5; --surface: #FFFFFF; --line: #E6E6E4; --border: #171717; --hover: #F0F0EF;
  --radius: 6px; --radius-sm: 4px;
  --shadow-hard: 3px 3px 0 var(--ink);
  --shadow-hard-sm: 2px 2px 0 var(--ink);
  --sidebar-w: 232px;
  --ui: "Inter", ui-sans-serif, system-ui, sans-serif;
  --st-draft:#9A9A9A; --st-scheduled:#4C6FB5; --st-published:#3E9460; --st-failed:#C2483B; --st-partial:#B5862F; --st-publishing:#7A5BB0;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--ui); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums;
}
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .18s; }
@media (prefers-reduced-motion: reduce) { *, ::before, ::after { animation: none !important; transition: none !important; } ::view-transition-group(*){ animation: none !important; } }

h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 16px; }
h2 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 28px 0 12px; }
a { color: var(--ink); text-decoration: none; }
a:hover { text-decoration: underline; }
strong { font-weight: 600; }
p { margin: 0 0 12px; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); position: sticky; top: 0; align-self: flex-start;
  height: 100vh; background: var(--surface); border-right: 1.5px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 12px; gap: 4px;
}
.sidebar .ws { display: flex; align-items: center; gap: 9px; font-weight: 700; padding: 6px 8px 14px; font-size: 14px; }
.sidebar .ws .mark { width: 22px; height: 22px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); display: grid; place-items: center; font-weight: 800; font-size: 12px; background: var(--ink); color: #fff; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: var(--radius-sm); color: var(--ink-soft); font-weight: 500; transition: background .12s; }
.sidebar nav a:hover { background: var(--hover); text-decoration: none; }
.sidebar nav a.active { background: var(--hover); color: var(--ink); font-weight: 600; }
.sidebar nav a svg { width: 16px; height: 16px; flex: 0 0 16px; }
.sidebar .spacer { flex: 1; }
.sidebar .new-post { margin: 10px 0; }
.sidebar .foot { border-top: 1px solid var(--line); padding-top: 10px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; }
.sidebar .foot .email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content { flex: 1; min-width: 0; padding: 28px 32px 80px; max-width: 1100px; }

/* ---------- Buttons (neo-brutalist) ---------- */
button, input[type="submit"], .btn, .button_to button {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 7px 13px; cursor: pointer; box-shadow: var(--shadow-hard-sm);
  transition: transform .06s, box-shadow .06s, background .12s;
}
button:hover, .btn:hover, .button_to button:hover { background: var(--hover); }
button:active, input[type="submit"]:active, .btn:active, .button_to button:active { transform: translate(2px,2px); box-shadow: 0 0 0 var(--ink); }
.btn-primary, input[type="submit"], button[name="commit_action"][value="schedule"] {
  background: var(--ink); color: #fff; box-shadow: var(--shadow-hard);
}
.btn-primary:hover, input[type="submit"]:hover, button[name="commit_action"][value="schedule"]:hover { background: #000; }
.btn-link { border: none; box-shadow: none; background: none; padding: 4px 6px; color: var(--muted); font-weight: 500; }
.btn-link:hover { background: none; color: var(--ink); text-decoration: underline; transform: none; }
form.button_to { display: inline; margin: 0; }

/* ---------- Forms ---------- */
form { margin: 0 0 16px; }
form > div { margin-bottom: 14px; }
label, legend { display: block; font-weight: 600; font-size: 12px; color: var(--ink-soft); margin-bottom: 5px; }
fieldset { border: 1.5px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 14px; box-shadow: var(--shadow-hard-sm); }
fieldset legend { padding: 0 6px; }
fieldset label { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); margin: 6px 0 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="datetime-local"], input[type="time"], textarea, select {
  display: block; width: 100%; max-width: 460px; font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--border); border-radius: var(--radius); padding: 9px 11px; transition: box-shadow .1s;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: none; box-shadow: var(--shadow-hard-sm); }
input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--ink); }
fieldset input[type="text"] { max-width: 380px; margin-bottom: 6px; }

/* ---------- Top bar within content ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.topbar h1 { margin: 0; }
.topbar .actions { display: flex; gap: 8px; }

/* ---------- Cards / lists ---------- */
.card, .post-card {
  position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow-hard-sm); transition: transform .1s, box-shadow .1s;
}
.post-card:hover { transform: translate(-1px,-1px); box-shadow: var(--shadow-hard); }
.post-card .text { font-weight: 500; flex: 1 1 220px; min-width: 0; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.post-card .channels { font-size: 12px; color: var(--muted); }
.post-card .when, .when { font-size: 12px; color: var(--muted); white-space: nowrap; }
a.post-card { color: inherit; text-decoration: none; }
a.post-card:hover { text-decoration: none; }

/* ---------- Status badge + dot ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; text-transform: capitalize; padding: 3px 9px; border: 1.5px solid var(--border); border-radius: 999px; background: var(--surface); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.status-draft .badge::before, .badge.status-draft::before { background: var(--st-draft); }
.status-scheduled .badge::before { background: var(--st-scheduled); }
.status-published .badge::before { background: var(--st-published); }
.status-failed .badge::before { background: var(--st-failed); }
.status-partially_published .badge::before { background: var(--st-partial); }
.status-publishing .badge::before, .status-pending .badge::before { background: var(--st-publishing); }

/* ---------- Dashboard ---------- */
.counts { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 6px; }
.count { display: inline-flex; align-items: baseline; gap: 7px; font-size: 12.5px; font-weight: 600; color: var(--ink); background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 8px 13px; box-shadow: var(--shadow-hard-sm); }
.needs-attention { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 4px 16px 14px; margin-bottom: 24px; box-shadow: var(--shadow-hard-sm); }
.channel-warning { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 13px; padding: 9px 0; border-top: 1px dashed var(--faint); }

/* ---------- Posts index ---------- */
.targets { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 6px; }
.targets .target { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; font-size: 13px; color: var(--muted); }
.targets .target .error { color: var(--st-failed); font-size: 12px; }
ul.list { list-style: none; padding: 0; margin: 0; }
ul.list > li { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow-hard-sm); }
ul.list > li .text { font-weight: 600; display: block; margin-bottom: 4px; }
li .button_to, li > a { margin-right: 8px; }

/* ---------- Posts view switcher ---------- */
.view-switcher { display: inline-flex; border: 1.5px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-hard-sm); margin-bottom: 16px; }
.view-switcher a { padding: 7px 16px; font-size: 13px; font-weight: 600; color: var(--muted); background: var(--surface); border-right: 1.5px solid var(--border); }
.view-switcher a:last-child { border-right: none; }
.view-switcher a.active { background: var(--ink); color: var(--surface); }

/* ---------- Posts filter bar ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.filters .filter-q { padding: 7px 11px; border: 1.5px solid var(--border); border-radius: var(--radius); min-width: 200px; }
.filters select { padding: 7px 11px; border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--surface); }

/* ---------- Posts grid ---------- */
.post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.post-grid .post-card { margin-bottom: 0; flex-direction: column; align-items: flex-start; gap: 8px; }
/* Don't let the text stretch vertically (column flex) — size to content and show more lines. */
.post-grid .post-card .text { flex: 0 0 auto; width: 100%; -webkit-line-clamp: 8; line-height: 1.45; }
.post-grid .post-card .badge { margin-top: 2px; }
.calendar-nav { margin-bottom: 14px; }
.empty { color: var(--muted); }

/* ---------- Calendar ---------- */
/* The :nth-child(7n) right-border removal assumes the grid is exactly 7 .cal-head
   cells followed by day cells, so every Saturday column lands on a multiple of 7. */
/* Fixed-height rows keep every week the same size regardless of how many/long the
   cards are (content-sized grid rows would otherwise stretch the densest week). */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: auto; grid-auto-rows: 192px; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-hard); }
.cal-head { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 11px; background: var(--bg); border-bottom: 1.5px solid var(--border); border-right: 1px solid var(--line); }
.cal-head:nth-child(7n) { border-right: none; }
.cal-day { overflow: hidden; padding: 7px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cal-day:nth-child(7n) { border-right: none; }
.cal-day.other-month { background: #FBFBFA; }
.cal-day.other-month .day { color: var(--faint); }
.cal-day.drag-over { background: #EEF1FF; outline: 2px solid var(--ink); outline-offset: -2px; }
.cal-item.is-draggable { cursor: grab; }
.cal-item.dragging { opacity: .45; }
.calendar .day { font-size: 11px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
.calendar .post-card { padding: 5px 7px; margin-bottom: 5px; box-shadow: none; border-width: 1.5px; font-size: 11px; gap: 5px; }
.calendar .post-card .text { font-size: 11px; flex-basis: 100%; }
.calendar .post-card .channels, .calendar .post-card .when { display: none; }
.calendar .more { font-size: 10.5px; color: var(--muted); font-weight: 600; }

/* ---------- Queue board ---------- */
.queue-board { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; }
.queue-column { flex: 1 1 240px; min-width: 220px; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-hard); }
.queue-column h2 { margin: 0 0 4px; font-size: 13px; text-transform: none; letter-spacing: -.01em; color: var(--ink); font-weight: 700; }
.queue-column .slots { font-size: 11px; color: var(--faint); margin-bottom: 12px; }
.queue-column ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.queue-column li { border: 1.5px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; box-shadow: var(--shadow-hard-sm); }

/* ---------- Channels ---------- */
.connect-buttons { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 22px; }
.connect-option { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-hard-sm); flex: 1 1 200px; }
.channel-list { list-style: none; padding: 0; margin: 0; }
.channel-list .channel { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow-hard-sm); }
.channel-list .channel .handle { color: var(--muted); font-size: 13px; }
.channel-list .channel > *:nth-child(3) { margin-right: auto; }

/* ---------- Queue slots ---------- */
.slot-list { list-style: none; padding: 0; margin: 0 0 22px; }
.slot-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 11px 14px; margin-bottom: 8px; box-shadow: var(--shadow-hard-sm); }

/* ---------- Modal (dialog + frame) ---------- */
dialog.modal { padding: 0; border: none; background: transparent; max-width: min(940px, 94vw); width: 100%; }
dialog.modal::backdrop { background: rgba(23,23,23,.38); animation: backdrop-in .18s ease; }
dialog.modal .modal-card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); box-shadow: 6px 6px 0 var(--ink); animation: modal-in .18s cubic-bezier(.2,.8,.2,1); }
dialog.modal .modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1.5px solid var(--border); }
dialog.modal .modal-head h1 { margin: 0; font-size: 16px; }
dialog.modal .modal-body { padding: 18px; max-height: 78vh; overflow: auto; }
dialog.modal .composer { display: grid; grid-template-columns: 1fr; gap: 18px; align-items: start; }
@media (min-width: 760px) { dialog.modal .modal-card.wide .composer { grid-template-columns: 1.2fr 1fr; } }
.composer .pane-editor input, .composer .pane-editor textarea, .composer .pane-editor select { max-width: 100%; }
.composer .pane-editor fieldset input[type="text"] { max-width: 100%; }
.composer .pane-preview { border: 1.5px dashed var(--faint); border-radius: var(--radius); padding: 12px; min-height: 120px; display: flex; flex-direction: column; gap: 10px; }
.preview-hint { color: var(--muted); font-size: 13px; margin: 0; }
.preview-card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; box-shadow: var(--shadow-hard-sm); }
.preview-head { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.preview-text { font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.preview-text .muted { color: var(--faint); }
.preview-count { margin-top: 8px; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.preview-count.over { color: var(--st-failed); font-weight: 700; }
.thread-label { font-size: 11px; font-weight: 700; color: var(--st-scheduled); margin-bottom: 8px; }
.thread-seg { border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 8px; }
.thread-seg:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
.thread-seg .preview-text { font-size: 13px; }
.thread-seg .preview-count { margin-top: 4px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Flash toasts ---------- */
.flashes { position: fixed; top: 16px; right: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 11px 14px; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: 13px; font-weight: 500; background: var(--surface); box-shadow: var(--shadow-hard); min-width: 220px; animation: toast-in .2s ease; }
.flash-notice { border-left: 5px solid var(--st-published); }
.flash-alert { border-left: 5px solid var(--st-failed); }
.error { color: var(--st-failed); font-size: 13px; }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* ---------- Auth (standalone, no shell) ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth .auth-card { width: 360px; max-width: 100%; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-hard); padding: 28px 26px; }
.auth h1 { text-align: center; }
.auth form { margin: 0; }
.auth input { max-width: 100%; }
.auth input[type="submit"] { width: 100%; margin-top: 4px; }

/* ---------- List entrance stagger ---------- */
.stagger > * { animation: rise .28s ease both; }
.stagger > *:nth-child(1){animation-delay:.02s}.stagger > *:nth-child(2){animation-delay:.06s}.stagger > *:nth-child(3){animation-delay:.10s}.stagger > *:nth-child(4){animation-delay:.14s}.stagger > *:nth-child(5){animation-delay:.18s}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
/* ---------- Post detail modal ---------- */
.post-detail { display: flex; flex-direction: column; gap: 12px; }
.post-detail .detail-text { font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.detail-target { border: 1.5px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow-hard-sm); }
.detail-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.detail-head .handle { color: var(--muted); font-size: 13px; }
.detail-target .when { font-size: 12px; color: var(--muted); }
.detail-target .thread-ids { font-size: 11px; color: var(--st-scheduled); font-weight: 700; margin-top: 4px; }
.detail-target .metrics { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: 12.5px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.detail-target .metrics.muted { color: var(--faint); }

::selection { background: var(--ink); color: #fff; }

/* ---------- Composer: randomize time ---------- */
.random-sched { border: 1.5px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-top: 14px; background: var(--surface); box-shadow: var(--shadow-hard-sm); }
.random-sched summary { cursor: pointer; font-size: 13px; font-weight: 700; color: var(--ink); }
.random-sched .hint { font-size: 12px; color: var(--muted); margin: 8px 0 12px; }
.random-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; max-width: 460px; }
.random-grid label { display: flex; flex-direction: column; gap: 4px; margin: 0; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
/* Match date + time fields to one compact size (the global rule only sizes time inputs). */
.random-sched input[type="date"], .random-sched input[type="time"] { display: block; width: 100%; max-width: none; margin: 0; padding: 7px 9px; font-size: 13px; }

/* ---------- Composer: media thumbnails ---------- */
.media-existing, .media-previews { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.media-thumb { display: inline-flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); margin: 0; }
.media-existing img, .media-previews img { width: 64px; height: 64px; object-fit: cover; border: 1.5px solid var(--border); border-radius: var(--radius-sm); display: block; }

/* ---------- Bank ---------- */
.bank-list { display: grid; gap: 12px; margin-top: 16px; }
.bank-card { border: 1.5px solid var(--border); padding: 12px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-hard-sm); }
.bank-card .bank-actions { display: flex; gap: 8px; margin-top: 8px; }
.bank-status { margin: 12px 0; }
.bank-status pre { white-space: pre-wrap; }
