:root {
  --bg: #f7f5f8;
  --panel: #ffffff;
  --ink: #1d1a22;
  --muted: #6f6878;
  --line: #e7e2ea;
  --brand: #d6336c;
  --brand-ink: #ffffff;
  --brand-soft: #fbe3ec;
  --ok: #2f9e66;
  --bad: #d9480f;
  --warn: #e8a317;
  --shadow: 0 1px 2px rgba(20, 10, 30, .06), 0 8px 24px rgba(20, 10, 30, .06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141217;
    --panel: #1d1a22;
    --ink: #efeaf2;
    --muted: #a39cab;
    --line: #2f2a36;
    --brand: #f06595;
    --brand-ink: #1a0b12;
    --brand-soft: #3a1a28;
    --ok: #51cf8a;
    --bad: #ff8a50;
    --warn: #ffc94d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.45 Inter, system-ui, -apple-system, Segoe UI, sans-serif;
}
.muted { color: var(--muted); font-weight: 400; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 10px; }
.err { color: var(--bad); font-size: 13px; margin: 6px 0; white-space: pre-wrap; }
.okmsg { color: var(--ok); font-size: 13px; margin: 6px 0; }
.okmsg a { color: inherit; }
.spacer { flex: 1; }

.logo {
  display: inline-block; width: 22px; height: 22px; border-radius: 7px; vertical-align: -5px;
  background: radial-gradient(circle at 30% 110%, #fdf497 0%, #fd5949 45%, #d6249f 60%, #285aeb 95%);
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: -.01em; white-space: nowrap; }

.btn {
  font: inherit; font-weight: 600; border-radius: 9px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.conn { font-size: 12px; color: var(--muted); padding: 4px 10px; border-radius: 99px; background: var(--bg); }
.conn.ok { color: var(--ok); }
.conn.bad { color: var(--bad); }

/* layout */
.layout { display: grid; grid-template-columns: 280px 1fr; gap: 20px; padding: 20px; }
.side section { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 16px; }
.side h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.count { background: var(--bg); color: var(--ink); border-radius: 99px; padding: 0 8px; font-size: 12px; }
.count.bad { color: var(--bad); }
.cards { display: flex; flex-direction: column; gap: 8px; max-height: 52vh; overflow: auto; }
.card {
  display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 10px; cursor: grab;
  border: 1px solid var(--line); background: var(--panel);
}
.card:hover { border-color: var(--brand); }
.card img, .card .noimg { width: 44px; height: 55px; object-fit: cover; border-radius: 6px; flex: none; background: var(--bg); }
.card .t { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .s { font-size: 11px; color: var(--muted); }
.card.failed { border-color: var(--bad); }
.empty-note { color: var(--muted); font-size: 13px; padding: 6px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 14px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.dot.scheduled { background: var(--brand); }
.dot.published { background: var(--ok); }
.dot.failed { background: var(--bad); }
.dot.publishing { background: var(--warn); }

/* calendar */
.cal-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.fc { --fc-border-color: var(--line); --fc-page-bg-color: var(--panel); --fc-neutral-bg-color: var(--bg);
      --fc-today-bg-color: var(--brand-soft); --fc-button-bg-color: var(--panel); --fc-button-text-color: var(--ink);
      --fc-button-border-color: var(--line); --fc-button-hover-bg-color: var(--bg); --fc-button-hover-border-color: var(--muted);
      --fc-button-active-bg-color: var(--brand); --fc-button-active-border-color: var(--brand);
      --fc-list-event-hover-bg-color: var(--bg); --fc-event-bg-color: transparent; --fc-event-border-color: transparent; }
.fc .fc-button-primary:not(:disabled).fc-button-active { color: var(--brand-ink); }
.fc .fc-toolbar-title { font-size: 18px; font-weight: 700; }
.fc .fc-button { font-weight: 600; text-transform: capitalize; border-radius: 8px; }
.fc .fc-daygrid-day.fc-day-past { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.fc a { color: inherit; text-decoration: none; }
.fc-event { cursor: pointer; }
.ev {
  display: flex; gap: 6px; align-items: center; width: 100%; overflow: hidden; padding: 3px;
  border-radius: 7px; border-left: 3px solid var(--brand); background: var(--brand-soft); color: var(--ink);
}
.ev img { width: 26px; height: 32px; object-fit: cover; border-radius: 4px; flex: none; }
.ev .tx { min-width: 0; font-size: 11.5px; line-height: 1.25; }
.ev .tm { font-weight: 700; }
.ev .cp { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ev.published { border-left-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--panel)); }
.ev.failed { border-left-color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, var(--panel)); }
.ev.publishing { border-left-color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, var(--panel)); }
.fc-timegrid-event .ev { height: 100%; align-items: flex-start; }

/* modal */
dialog { border: none; border-radius: 16px; padding: 0; background: var(--panel); color: var(--ink); box-shadow: var(--shadow);
         width: min(920px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(15, 8, 20, .45); }
.modal-body { margin: 0; display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; }
.x { margin-left: auto; font-size: 24px; line-height: 1; background: none; border: none; color: var(--muted); cursor: pointer; }
.pill { font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--bg); text-transform: capitalize; }
.pill.scheduled { background: var(--brand-soft); color: var(--brand); }
.pill.published { color: var(--ok); }
.pill.failed { color: var(--bad); }
.modal-grid { display: grid; grid-template-columns: 320px 1fr; gap: 24px; padding: 20px; overflow: auto; }
.fields label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 12px; }
.fields input, .fields textarea {
  display: block; width: 100%; margin-top: 6px; font: inherit; font-weight: 400; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; resize: vertical;
}
.fields input:focus, .fields textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.capmeta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin: -6px 0 12px; }
.capmeta .over { color: var(--bad); font-weight: 600; }
.modal-foot { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }

.phone { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--panel); }
.phone-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-size: 13px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: radial-gradient(circle at 30% 110%, #fdf497 0%, #fd5949 45%, #d6249f 60%, #285aeb 95%); }
.phone-media { aspect-ratio: 4 / 5; background: var(--bg); display: flex; overflow-x: auto; scroll-snap-type: x mandatory; }
.phone-media > * { flex: 0 0 100%; width: 100%; height: 100%; object-fit: cover; scroll-snap-align: start; }
.phone-media .empty { display: grid; place-items: center; color: var(--muted); }
.dots { display: flex; justify-content: center; gap: 4px; padding: 6px 0 0; min-height: 12px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--brand); }
.phone-cap { padding: 6px 10px 12px; margin: 0; font-size: 12.5px; white-space: pre-wrap; max-height: 110px; overflow: auto; }
.file-btn { display: block; text-align: center; margin-top: 10px; padding: 9px; border: 1px dashed var(--muted); border-radius: 9px; cursor: pointer; font-weight: 600; }
.file-btn input { display: none; }
.file-btn:hover { border-color: var(--brand); color: var(--brand); }

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

/* login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: min(360px, 100%); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.login-card input { font: inherit; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.login-card p { margin: 0 0 6px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
  .side { order: 2; }
  .cards { max-height: none; }
  .modal-grid { grid-template-columns: 1fr; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .conn { order: 5; width: 100%; text-align: center; }
  .fc .fc-toolbar { flex-wrap: wrap; gap: 8px; }
}
