:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --text: #16161a;
  --muted: #6e6e76;
  --border: #e4e4e8;
  --soft: #f0f0f2;
  --primary: #16161a;
  --primary-text: #ffffff;
  --org: #1d4ed8;
  --org-soft: #e8eefc;
  --danger: #b42318;
  --note: #8a5a00;
  --note-soft: #fdf6e7;
  --note-border: #f0dcb0;
  --focus: #2563eb;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e10;
    --surface: #17171a;
    --text: #ededf0;
    --muted: #9a9aa3;
    --border: #2a2a2f;
    --soft: #202024;
    --primary: #ededf0;
    --primary-text: #0e0e10;
    --org: #8fb0ff;
    --org-soft: #1b2440;
    --danger: #ff8a7a;
    --note: #f5c46b;
    --note-soft: #2a2416;
    --note-border: #4a3d1f;
    --focus: #8fb0ff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
p { margin: 0; }
a { color: inherit; }

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

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 14px; }
.note { color: var(--note); font-size: 14px; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s, background-color 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover:not(:disabled) { opacity: 0.88; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--soft); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--soft); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 14px; }

.link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}
.link:hover { color: var(--text); }
.link.danger:hover { color: var(--danger); }

/* ---------- login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-box { width: 100%; max-width: 360px; text-align: center; display: grid; gap: 16px; justify-items: center; }
.login-box h1 { font-size: 28px; font-weight: 650; }
.login-box p { color: var(--muted); }

/* ---------- top bar ---------- */

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand { font-weight: 650; font-size: 16px; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tab {
  background: none;
  border: 0;
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--soft); color: var(--text); font-weight: 500; }
.account { display: flex; align-items: center; gap: 14px; font-size: 14px; white-space: nowrap; }

.banner {
  max-width: 1120px;
  margin: 16px auto 0;
  padding: 12px 16px;
  border: 1px solid var(--note-border);
  border-radius: var(--radius);
  background: var(--note-soft);
  font-size: 14px;
}
@media (max-width: 1152px) { .banner { margin: 16px 16px 0; } }

/* ---------- layout ---------- */

.main { max-width: 1120px; margin: 0 auto; padding: 24px 16px 80px; }
.narrow { max-width: 680px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stack { display: grid; gap: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }

.compose-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 440px); gap: 24px; align-items: start; }
@media (max-width: 900px) { .compose-grid { grid-template-columns: minmax(0, 1fr); } }

.composer { display: grid; gap: 14px; }

textarea, select, input[type="text"], input[type="url"], input[type="time"], input[type="datetime-local"] {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
textarea { resize: vertical; line-height: 1.55; min-height: 120px; }
textarea:focus, select:focus, input:focus { outline: none; border-color: var(--focus); }
select { padding-right: 8px; }

.field { display: grid; gap: 6px; font-size: 14px; font-weight: 500; }

.segmented { display: inline-flex; background: var(--soft); border-radius: 999px; padding: 3px; width: fit-content; max-width: 100%; }
.segmented button {
  background: none;
  border: 0;
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  padding: 5px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.segmented button.is-active { background: var(--surface); color: var(--text); font-weight: 500; box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); }
.segmented button:disabled { opacity: 0.45; cursor: default; }

.ai-box { border: 1px solid var(--border); border-radius: 8px; background: var(--soft); }
.ai-box summary {
  cursor: pointer;
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 500;
  list-style-position: inside;
  border-radius: 8px;
}
.ai-box[open] summary { padding-bottom: 4px; }
.ai-body { display: grid; gap: 10px; padding: 6px 12px 12px; }
.ai-body textarea { min-height: 72px; }
.ai-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }

.meta-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; margin-top: -6px; }

.image-row { display: grid; gap: 10px; }
.image-row > label { width: fit-content; }
.image-box { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.thumb-slot img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; display: block; border: 1px solid var(--border); }

.schedule-row { display: grid; grid-template-columns: auto minmax(0, 240px) auto; justify-content: start; gap: 12px; align-items: center; font-size: 14px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding-top: 4px; }
@media (max-width: 520px) {
  .actions .btn { flex: 1 1 100%; }
  .schedule-row { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .image-box { grid-template-columns: 64px minmax(0, 1fr); }
  .image-box .link { grid-column: 2; justify-self: start; }
}

/* ---------- preview ---------- */

.preview-col { display: grid; gap: 10px; position: sticky; top: 80px; }
@media (max-width: 900px) { .preview-col { position: static; } }
.eyebrow { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.preview { padding: 16px 0 0; overflow: hidden; }
.preview-head { display: flex; gap: 10px; align-items: center; padding: 0 16px 12px; }
.avatar {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  background: var(--soft);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 15px;
}
.avatar.is-org { border-radius: 8px; background: var(--org-soft); color: var(--org); }
.pv-name { font-weight: 600; font-size: 14px; }
.pv-sub { font-size: 12px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.pv-text { padding: 0 16px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.pv-text.is-placeholder { color: var(--muted); }
.pv-text.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.pv-more { display: block; margin: 2px 16px 0 auto; font-size: 14px; }
.pv-image { margin-top: 12px; }
.pv-image img { display: block; width: 100%; max-height: 520px; object-fit: cover; }
.preview > :last-child:not(.pv-image) { margin-bottom: 16px; }
.preview .pv-more { margin-bottom: 16px; }

/* ---------- lists ---------- */

.list-section { margin-top: 36px; display: grid; gap: 12px; }
.count { font-weight: 500; color: var(--muted); margin-left: 4px; }
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
}
.item:not(:has(.item-thumb)) { grid-template-columns: minmax(0, 1fr) auto; }
.item-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.item-body { display: grid; gap: 6px; min-width: 0; }
.item-meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 13px; }
.item-title { font-weight: 600; }
.item-text {
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.item-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.empty { background: none; border: 1px dashed var(--border); border-radius: var(--radius); padding: 14px 16px; font-size: 14px; }
@media (max-width: 640px) {
  .item, .item:not(:has(.item-thumb)) { grid-template-columns: minmax(0, 1fr); }
  .item-thumb { display: none; }
  .item-actions { justify-content: flex-start; }
}

.badge { font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 999px; background: var(--soft); }
.badge.is-org { background: var(--org-soft); color: var(--org); }

.watch-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 8px; }
.watch-form #watch-note { grid-column: 1 / -1; }
.watch-form .btn { grid-column: 1 / -1; justify-self: end; }
@media (max-width: 520px) { .watch-form { grid-template-columns: minmax(0, 1fr); } }
.watch-list { margin-top: 16px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--primary);
  color: var(--primary-text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.18);
}

/* ---------- plan, inbox, stats ---------- */

.tab-count:not(:empty) {
  margin-left: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-text);
}

.stack-lg { display: grid; gap: 20px; }
.stack-sm { display: grid; gap: 8px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.field-label { font-size: 14px; font-weight: 500; }
.check { display: flex; gap: 10px; align-items: center; font-size: 15px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); }
.rationale { color: var(--muted); border-top: 1px solid var(--border); padding-top: 6px; }

.slot-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.slot-row { display: grid; grid-template-columns: minmax(0, 1.2fr) 132px minmax(0, 1.4fr) auto; gap: 8px; align-items: center; }
@media (max-width: 520px) {
  .slot-row { grid-template-columns: minmax(0, 1fr) 132px; }
  .slot-row select:nth-of-type(2) { grid-column: 1; }
}
#slot-add { justify-self: start; }

.plan-run { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.topic.is-used .item-text { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--border); }

.inbox-item { grid-template-columns: minmax(0, 1fr); }
.inbox-comment { white-space: pre-wrap; overflow-wrap: anywhere; }
.inbox-item textarea { min-height: 112px; }
.inbox-actions { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.inbox-actions select { width: auto; max-width: 220px; height: 32px; padding-top: 0; padding-bottom: 0; font-size: 14px; }

.stats-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.stats-summary { font-size: 16px; margin-bottom: 16px; max-width: 760px; }
.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.stats-table th, .stats-table td { padding: 12px 16px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.stats-table thead th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.stats-table tbody tr:last-child td { border-bottom: 0; }
.stats-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats-cell { min-width: 260px; display: grid; gap: 4px; }
.stats-text { color: var(--text); text-decoration: none; }
.stats-text:hover { text-decoration: underline; }
.issues { margin-top: 14px; font-size: 14px; color: var(--muted); }
.issues summary { cursor: pointer; }
.issues ul { margin: 8px 0 0; padding-left: 18px; }
.stats-foot { margin-top: 14px; max-width: 760px; }

.mobile-footer { display: none; }

@media (max-width: 640px) {
  .topbar-inner { gap: 12px; }
  .brand, .account { display: none; }
  .mobile-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px 40px;
    margin-top: -48px;
    font-size: 14px;
  }
}
