:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --sunken: #efede6;
  --ink: #1c1b18;
  --muted: #68665f;
  --line: #e2dfd5;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0eb;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --ok: #1f6f5c;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 8px 24px rgb(0 0 0 / 0.06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141513;
    --surface: #1d1f1c;
    --sunken: #181a17;
    --ink: #ecebe6;
    --muted: #a09e96;
    --line: #2f322d;
    --accent: #5cc2a5;
    --accent-ink: #0d1f1a;
    --accent-soft: #1f332d;
    --danger: #f2948c;
    --danger-soft: #3a1f1c;
    --ok: #5cc2a5;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
h3 { font-size: 15px; font-weight: 600; }
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* layout */
.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100%; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 20px 14px;
  display: flex; flex-direction: column; gap: 18px; border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; padding: 0 6px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 8px; background: none; cursor: pointer; text-align: left;
}
.nav button:hover { background: var(--sunken); }
.nav button[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav .count.bad { background: var(--danger); color: var(--surface); padding: 0 7px; border-radius: 99px; }
.nav .gap { height: 14px; }
.main { padding: 28px clamp(16px, 4vw, 48px) 80px; max-width: 980px; width: 100%; outline: none; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.section { margin-top: 32px; }
.section > h2 { margin-bottom: 10px; }

/* controls */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 7px 13px; cursor: pointer; font-weight: 550; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn.ghost:hover { background: var(--sunken); color: var(--ink); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.side .new { padding: 10px; }
input[type="text"], input[type="password"], input[type="time"], input[type="datetime-local"], textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
textarea { resize: vertical; min-height: 130px; line-height: 1.45; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 550; }
.seg { display: inline-flex; background: var(--sunken); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 13px; border-radius: 7px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); font-weight: 600; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty h3 { color: var(--ink); margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }
.notice { background: var(--accent-soft); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; }
.notice.warn { background: var(--danger-soft); }

.day { margin: 26px 0 10px; display: flex; align-items: baseline; gap: 8px; }
.day:first-child { margin-top: 0; }
.day b { font-size: 15px; }
.post { display: grid; grid-template-columns: 84px minmax(0, 1fr) auto; gap: 14px; align-items: start; }
.post-time { font-weight: 600; font-variant-numeric: tabular-nums; }
.post-time span { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.post-text { white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.post-actions { display: flex; gap: 2px; flex-wrap: wrap; justify-content: flex-end; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 2px;
  border: 1px solid var(--line); border-radius: 99px; font-size: 13px; text-decoration: none; color: inherit;
}
.chip.published { border-color: var(--ok); }
.chip.failed { border-color: var(--danger); color: var(--danger); }
.chip .st { font-size: 12px; color: var(--muted); }
.chip.failed .st { color: inherit; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.thumb { position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; background: var(--sunken); border: 1px solid var(--line); }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .vid { position: absolute; left: 4px; bottom: 4px; font-size: 10px; background: rgb(0 0 0 / 0.65); color: #fff; padding: 0 5px; border-radius: 4px; }
.thumb .x {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; border: 0;
  background: rgb(0 0 0 / 0.65); color: #fff; cursor: pointer; line-height: 1; font-size: 13px;
}
.err { margin-top: 10px; background: var(--danger-soft); border-radius: 8px; padding: 9px 11px; font-size: 13px; display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.err p { overflow-wrap: anywhere; }

/* avatar */
.av {
  position: relative; flex: none; width: 24px; height: 24px; border-radius: 50%;
  background: var(--pc); color: #fff; display: inline-grid; place-items: center; font-size: 11px;
}
.av b { font-weight: 650; }
.av img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.av i { position: absolute; right: -2px; bottom: -2px; width: 9px; height: 9px; border-radius: 50%; background: var(--pc); border: 2px solid var(--surface); }
.av.lg { width: 40px; height: 40px; font-size: 16px; }
.av.lg i { width: 13px; height: 13px; }

/* calendar */
.cal { 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; }
.cal .dow { background: var(--bg); padding: 6px 8px; font-size: 12px; color: var(--muted); font-weight: 600; }
.cal .cell { background: var(--surface); min-height: 96px; padding: 5px; display: flex; flex-direction: column; gap: 3px; cursor: pointer; border: 0; text-align: left; }
.cal .cell:hover { background: var(--sunken); }
.cal .cell.out { background: var(--bg); }
.cal .cell.out .num { opacity: 0.45; }
.cal .num { font-size: 12px; font-variant-numeric: tabular-nums; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; }
.cal .today .num { background: var(--accent); color: var(--accent-ink); font-weight: 650; }
.ev { display: block; width: 100%; font-size: 11.5px; padding: 2px 5px; border-radius: 5px; background: var(--accent-soft); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 0; text-align: left; cursor: pointer; }
.ev.sent { background: var(--sunken); color: var(--muted); }
.ev.failed { background: var(--danger-soft); color: var(--danger); }

/* channels */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.prov { display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer; padding: 12px; }
.prov:hover { border-color: var(--muted); }
.prov .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--pc); flex: none; }
.chan { display: flex; align-items: center; gap: 12px; }
.chan .grow { flex: 1; min-width: 0; }
.chan .grow div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
code { background: var(--sunken); padding: 1px 6px; border-radius: 5px; font-size: 13px; overflow-wrap: anywhere; }

/* dialog */
.dialog { border: 0; border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.d-head, .d-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; }
.d-head { border-bottom: 1px solid var(--line); }
.d-foot { border-top: 1px solid var(--line); flex-wrap: wrap; }
.d-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.pick { display: flex; flex-wrap: wrap; gap: 6px; }
.pick button { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px 4px 4px; border: 1px solid var(--line); border-radius: 99px; background: none; cursor: pointer; opacity: 0.6; }
.pick button[aria-pressed="true"] { opacity: 1; border-color: var(--accent); background: var(--accent-soft); }
.issues { margin: 0; padding: 10px 12px 10px 28px; background: var(--danger-soft); border-radius: 8px; font-size: 13px; }
.counter { font-size: 12px; color: var(--muted); text-align: right; margin-top: -10px; }
.counter.over { color: var(--danger); font-weight: 600; }
.addmedia { width: 64px; height: 64px; border: 1px dashed var(--muted); border-radius: 8px; background: none; cursor: pointer; font-size: 22px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: min(520px, calc(100vw - 32px)); opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 50; white-space: pre-line; }
.toast.show { opacity: 1; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(340px, 100%); }

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: fixed; inset: auto 0 0 0; height: auto; z-index: 20; flex-direction: row; align-items: center;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--surface); border-right: 0; border-top: 1px solid var(--line); gap: 6px;
  }
  .brand, .nav .gap, .nav .count:not(.bad) { display: none; }
  .nav { flex-direction: row; flex: 1; overflow-x: auto; }
  .nav button { padding: 8px 9px; font-size: 13px; width: auto; gap: 5px; white-space: nowrap; }
  .side .new { order: 2; padding: 8px 12px; }
  .main { padding: 18px 16px 110px; }
  .post { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .post-time span { display: inline; margin-left: 8px; }
  .post-actions { justify-content: flex-start; }
  .cal .cell { min-height: 64px; padding: 3px; }
  .ev { font-size: 10px; padding: 1px 3px; }
  .toast { bottom: 84px; }
}
