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

/* ── Variables ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Dark (default) */
  --bg:        #0f0f11;
  --surface:   #161618;
  --surface2:  #1c1c1f;
  --border:    rgba(255,255,255,.07);
  --primary:   #5e6ad2;
  --primary-h: #6872e5;
  --success:   #30a46c;
  --error:     #e5484d;
  --warning:   #f76b15;
  --info:      #0090ff;
  --text:      #ededef;
  --text-muted:#818189;
  --radius:    7px;
  --shadow:    0 0 0 1px rgba(0,0,0,.25), 0 8px 24px rgba(0,0,0,.18);
  --sidebar-w: 212px;
  --row-hover: rgba(255,255,255,.03);
  --row-border: rgba(255,255,255,.04);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:        #ffffff;
    --surface:   #fafafa;
    --surface2:  #f0f0f3;
    --border:    rgba(0,0,0,.08);
    --text:      #1c1c1e;
    --text-muted:#6f6e77;
    --shadow:    0 0 0 1px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
    --row-hover: rgba(0,0,0,.025);
    --row-border: rgba(0,0,0,.05);
  }
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.sidebar-logo {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 9px;
}
.sidebar-logo .logo-icon {
  width: 28px; height: 28px;
  background: var(--primary);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}
.sidebar-logo .logo-text {
  font-weight: 600; font-size: 14px; letter-spacing: -.1px;
}
.sidebar-logo .logo-text span { color: var(--primary); }

nav { flex: 1; padding: 8px 6px; }

nav a {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border-radius: 5px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  transition: color .1s, background .1s;
  cursor: pointer;
  margin-bottom: 1px;
}
nav a:hover { color: var(--text); background: var(--row-hover); }
nav a.active { color: var(--primary); background: rgba(94,106,210,.1); }
nav a .nav-icon { font-size: 15px; width: 16px; height: 16px; text-align: center; flex-shrink: 0; }

.sidebar-status {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}
.status-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  margin-right: 6px; background: var(--text-muted); vertical-align: middle;
}
.status-dot.connected    { background: var(--success); box-shadow: 0 0 5px var(--success); }
.status-dot.needs_code,
.status-dot.needs_password,
.status-dot.authenticating { background: var(--warning); }
.status-dot.error        { background: var(--error); }

/* ── Main content ───────────────────────────────────────────────────────── */
#main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#topbar {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  flex-shrink: 0;
}
#topbar h1 { font-size: 15px; font-weight: 600; letter-spacing: -.1px; }
#topbar .topbar-actions { display: flex; gap: 6px; }

#content { flex: 1; padding: 24px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  padding: 6px 14px; border-radius: 6px; border: none; cursor: pointer;
  font-size: 12px; font-weight: 500; transition: all .1s; display: inline-flex;
  align-items: center; gap: 5px; text-decoration: none; font-family: inherit;
  letter-spacing: -.01em;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-h); }
.btn-ghost    { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover    { color: var(--text); border-color: rgba(255,255,255,.15); background: var(--surface2); }
.btn-danger   { background: transparent; color: var(--error); border: 1px solid rgba(229,72,77,.3); }
.btn-danger:hover   { background: var(--error); color: #fff; border-color: var(--error); }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover  { filter: brightness(1.08); }
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

@media (prefers-color-scheme: light) {
  .btn-ghost:hover { border-color: rgba(0,0,0,.18); }
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

/* ── Stat cards ──────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.stat-card-info { padding: 16px 18px 12px; }

.stat-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.stat-label {
  font-size: 11px; color: var(--text-muted); font-weight: 500;
  text-transform: uppercase; letter-spacing: .5px;
}

/* Per-card period segmented control */
.card-period-bar {
  display: flex;
  gap: 1px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px;
}
.card-period-btn {
  background: none; border: none; color: var(--text-muted);
  border-radius: 3px; padding: 2px 6px; font-size: 10px; font-weight: 600;
  cursor: pointer; letter-spacing: .3px; transition: all .1s; font-family: inherit;
}
.card-period-btn:hover { color: var(--text); }
.card-period-btn.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
}

@media (prefers-color-scheme: light) {
  .card-period-btn.active { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
}

.stat-value { font-size: 28px; font-weight: 700; line-height: 1; letter-spacing: -.5px; }
.stat-value.success { color: var(--success); }
.stat-value.error   { color: var(--error); }
.stat-value.primary { color: var(--primary); }
.stat-sublabel { font-size: 11px; color: var(--text-muted); margin-top: 5px; }

/* ── Automation list ─────────────────────────────────────────────────────── */
.auto-list { display: flex; flex-direction: column; gap: 8px; }

.auto-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color .1s;
}
.auto-item:hover { border-color: rgba(94,106,210,.4); }
.auto-item.disabled { opacity: .5; }

.auto-type-badge {
  padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500;
  white-space: nowrap; flex-shrink: 0; letter-spacing: .1px;
}
.badge-scheduled  { background: rgba(94,106,210,.12); color: var(--primary); }
.badge-auto_reply { background: rgba(0,144,255,.12);  color: var(--info); }
.badge-react_dm   { background: rgba(229,72,77,.10);  color: var(--error); }

.auto-info { flex: 1; min-width: 0; }
.auto-name { font-weight: 600; font-size: 13px; margin-bottom: 1px; }
.auto-meta { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.auto-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* Toggle */
.toggle { position: relative; width: 36px; height: 20px; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  position: absolute; inset: 0;
  background: var(--border); border-radius: 10px; transition: background .15s;
  border: 1px solid var(--border);
}
.toggle-thumb {
  position: absolute; width: 14px; height: 14px; top: 3px; left: 3px;
  background: var(--text-muted); border-radius: 50%; transition: transform .15s, background .15s;
}
.toggle input:checked ~ .toggle-track { background: var(--primary); border-color: var(--primary); }
.toggle input:checked ~ .toggle-thumb { transform: translateX(16px); background: #fff; }

/* ── Log table ───────────────────────────────────────────────────────────── */
.log-filters { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.log-table { width: 100%; border-collapse: collapse; min-width: 600px; }
.log-table th {
  text-align: left; padding: 8px 12px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .4px;
  color: var(--text-muted); border-bottom: 1px solid var(--border);
  font-weight: 500;
}
.log-table td {
  padding: 9px 12px; border-bottom: 1px solid var(--row-border);
  vertical-align: middle; font-size: 12px;
}
.log-table tr:last-child td { border-bottom: none; }
.log-table tr:hover td { background: var(--row-hover); }

.type-icon { font-size: 14px; display: flex; align-items: center; }

.log-preview {
  font-family: 'SF Mono', 'Fira Code', ui-monospace, monospace;
  font-size: 11px; color: var(--text-muted);
  max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.log-trigger  { color: var(--text); }
.log-response { color: var(--text-muted); margin-top: 2px; }

.log-detail-btn {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  font-size: 13px; padding: 2px 4px; line-height: 1;
}
.log-detail-btn:hover { color: var(--text); }

.ts { color: var(--text-muted); font-size: 11px; white-space: nowrap; display: flex; align-items: center; gap: 5px; }
.ts-link { text-decoration: none; }
.ts-link:hover { color: var(--primary); }

.status-dot {
  flex-shrink: 0; width: 6px; height: 6px; border-radius: 50%; display: inline-block;
}
.status-dot.success { background: var(--success); }
.status-dot.error   { background: var(--error); box-shadow: 0 0 4px var(--error); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px; overflow-y: auto;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; width: 100%; max-width: 860px;
  box-shadow: var(--shadow); animation: slideIn .12s ease;
}
@keyframes slideIn { from { transform: translateY(-12px); opacity: 0; } }

.modal-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h2 { font-size: 15px; font-weight: 600; }
.modal-close {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  font-size: 18px; line-height: 1; padding: 3px 6px; border-radius: 4px;
}
.modal-close:hover { color: var(--text); background: var(--surface2); }

.modal-body { padding: 22px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; align-items: center; gap: 8px;
}
.modal-footer span { font-size: 11px; color: var(--text-muted); margin-right: auto; }

/* ── Form ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }

label {
  display: block; font-size: 11px; font-weight: 500; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .4px; margin-bottom: 5px;
}

input[type=text], input[type=password], input[type=tel],
select, textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; color: var(--text);
  font-size: 13px; outline: none; font-family: inherit;
  transition: border-color .1s;
}
input[type=text]:focus, input[type=password]:focus, input[type=tel]:focus,
select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(94,106,210,.12);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
select option { background: var(--surface2); color: var(--text); }
textarea { resize: vertical; min-height: 80px; }

.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Rich text editor ────────────────────────────────────────────────────── */
.editor-wrap { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.editor-toolbar {
  background: var(--surface2); border-bottom: 1px solid var(--border);
  padding: 5px 7px; display: flex; gap: 2px; flex-wrap: wrap;
}
.tb-btn {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  padding: 3px 7px; border-radius: 4px; font-size: 12px; font-weight: 600;
  transition: all .1s; font-family: inherit;
}
.tb-btn:hover { color: var(--text); background: var(--border); }

.editor-panes { display: grid; grid-template-columns: 1fr 1fr; }
.editor-pane { position: relative; }
.editor-pane-label {
  position: absolute; top: 6px; right: 10px;
  font-size: 9px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px;
  pointer-events: none;
}
.editor-pane textarea {
  border: none; border-radius: 0; resize: none; min-height: 180px; height: auto;
  border-right: 1px solid var(--border); font-family: 'SF Mono', ui-monospace, monospace;
  font-size: 12px; overflow-y: hidden; background: var(--surface);
}
.editor-pane textarea:focus { outline: none; box-shadow: none; border-color: var(--border); }
.preview-pane {
  padding: 10px 14px; font-size: 13px; min-height: 180px;
  overflow-y: auto; background: var(--surface2); color: var(--text);
}
.preview-pane b, .preview-pane strong { color: var(--text); font-weight: 700; }
.preview-pane i, .preview-pane em { font-style: italic; }
.preview-pane code {
  background: var(--row-border); padding: 1px 5px;
  border-radius: 3px; font-family: ui-monospace, monospace; font-size: 11px;
}
.preview-pane pre {
  background: var(--surface); border: 1px solid var(--border);
  padding: 10px; border-radius: 5px; font-size: 11px; overflow-x: auto; margin: 6px 0;
}
.preview-pane a { color: var(--primary); }
.preview-pane s { color: var(--text-muted); }
.preview-pane tg-emoji {
  display: inline-flex; align-items: center;
  background: rgba(94,106,210,.12); border: 1px solid rgba(94,106,210,.25);
  border-radius: 4px; padding: 0 4px; font-size: 17px;
  vertical-align: middle; cursor: default; line-height: 1.3;
}
.tg-emoji-preview {
  width: 22px; height: 22px;
  vertical-align: middle;
  display: inline-block;
  object-fit: contain;
}

/* ── Custom-emoji picker ─────────────────────────────────────────────────── */
#emoji-picker {
  position: absolute;
  z-index: 2000;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ep-tabs {
  display: flex;
  gap: 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  scrollbar-width: none;
  flex-shrink: 0;
}
.ep-tabs::-webkit-scrollbar { display: none; }
.ep-tab {
  flex-shrink: 0;
  padding: 6px 10px;
  font-size: 11px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.ep-tab:hover { color: var(--text); }
.ep-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.ep-grid-wrap {
  overflow-y: auto;
  max-height: 240px;
  padding: 6px;
}
.ep-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.ep-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  padding: 4px;
  transition: background .1s;
}
.ep-cell:hover { background: var(--border); }
.ep-cell img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  display: block;
}
.ep-cell span {
  font-size: 20px;
  line-height: 1;
}
.ep-loading {
  padding: 20px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}
.ep-error { color: var(--danger); }

/* ── Settings ────────────────────────────────────────────────────────────── */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.settings-section h3 { font-size: 14px; font-weight: 600; margin-bottom: 14px; }

.auth-status-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-radius: 6px; background: var(--surface2); margin-bottom: 14px;
}
.auth-status-row .status-label { flex: 1; font-weight: 500; }
.auth-step { margin-top: 10px; display: flex; gap: 8px; }
.auth-step input { flex: 1; }

/* ── Alert / Toast ───────────────────────────────────────────────────────── */
.alert {
  padding: 9px 12px; border-radius: 6px; font-size: 12px;
  margin-bottom: 12px; display: flex; align-items: center; gap: 7px;
}
.alert-error   { background: rgba(229,72,77,.1);  border: 1px solid rgba(229,72,77,.2);  color: var(--error); }
.alert-success { background: rgba(48,164,108,.1); border: 1px solid rgba(48,164,108,.2); color: var(--success); }
.alert-info    { background: rgba(0,144,255,.1);  border: 1px solid rgba(0,144,255,.2);  color: var(--info); }

#toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 16px;
  box-shadow: var(--shadow); font-size: 12px; max-width: 300px;
  animation: slideUp .12s ease; pointer-events: all;
}
.toast.success { border-color: rgba(48,164,108,.4); }
.toast.error   { border-color: rgba(229,72,77,.4); }
@keyframes slideUp { from { transform: translateY(8px); opacity: 0; } }

/* ── Detail panel ────────────────────────────────────────────────────────── */
.detail-panel {
  background: var(--surface2); border-radius: 5px; padding: 10px 12px;
  font-family: 'SF Mono', ui-monospace, monospace; font-size: 11px; color: var(--text-muted);
  white-space: pre-wrap; word-break: break-all;
  margin-top: 6px; display: none;
}
.detail-panel.open { display: block; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 10px; opacity: .3; display: flex; align-items: center; justify-content: center; }
.empty-state p { font-size: 13px; }

/* ── Checkbox ────────────────────────────────────────────────────────────── */
.checkbox-label {
  display: flex; align-items: center; gap: 7px; cursor: pointer;
  font-size: 13px; color: var(--text); text-transform: none; letter-spacing: 0; font-weight: 400;
}
.checkbox-label input[type=checkbox] { width: auto; accent-color: var(--primary); }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Misc ────────────────────────────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px;
}
.section-header h2 { font-size: 14px; font-weight: 600; letter-spacing: -.1px; }

.tag {
  display: inline-block; padding: 2px 7px; border-radius: 4px; font-size: 10px;
  background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border);
}
.loading { color: var(--text-muted); font-size: 13px; padding: 40px; text-align: center; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Channel tag-input ───────────────────────────────────────────────────── */
.ch-box {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  min-height: 40px; padding: 5px 8px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; cursor: text; transition: border-color .1s;
}
.ch-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(94,106,210,.12); }
.ch-text-input {
  border: none; background: transparent; outline: none;
  color: var(--text); font-size: 13px; flex: 1; min-width: 160px; font-family: inherit;
}
.ch-text-input::placeholder { color: var(--text-muted); }

.channel-tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 6px 2px 7px; border-radius: 4px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 11px; font-weight: 500; white-space: nowrap; flex-shrink: 0;
}
.channel-tag.ok       { border-color: rgba(48,164,108,.4); background: rgba(48,164,108,.08); }
.channel-tag.bad      { border-color: rgba(229,72,77,.4);  background: rgba(229,72,77,.08); }
.channel-tag.warn     { border-color: rgba(247,107,21,.4); background: rgba(247,107,21,.08); }
.channel-tag.checking { opacity: .6; }
.channel-tag-icon  { font-size: 10px; flex-shrink: 0; }
.channel-tag-name  { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.channel-tag-hint  { font-size: 10px; color: var(--text-muted); cursor: help; }
.channel-tag-remove {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  font-size: 14px; line-height: 1; padding: 0 1px; flex-shrink: 0; margin-left: 1px;
}
.channel-tag-remove:hover { color: var(--error); }

/* ── Keyword token input ─────────────────────────────────────────────────── */
.kw-box {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  min-height: 40px; padding: 5px 8px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; cursor: text; transition: border-color .1s;
}
.kw-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(94,106,210,.12); }
.kw-text-input {
  border: none; background: transparent; outline: none;
  color: var(--text); font-size: 13px; flex: 1; min-width: 120px; font-family: inherit;
}
.kw-text-input::placeholder { color: var(--text-muted); }
.kw-token {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 6px 2px 8px; border-radius: 4px;
  background: rgba(94,106,210,.15); border: 1px solid rgba(94,106,210,.3);
  color: var(--text); font-size: 12px; font-weight: 500; white-space: nowrap;
}
.kw-token-remove {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  font-size: 14px; line-height: 1; padding: 0 1px; flex-shrink: 0;
}
.kw-token-remove:hover { color: var(--error); }

/* ── Channel available list ──────────────────────────────────────────────── */
.ch-list {
  border: 1px solid var(--border); border-radius: 6px;
  margin-top: 5px; max-height: 200px; overflow-y: auto; display: none;
}
.ch-list.visible { display: block; }
.ch-list-header {
  padding: 5px 10px; font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .4px;
  background: var(--surface2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1; font-weight: 500;
}
.ch-list-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; cursor: pointer; font-size: 12px;
  border-bottom: 1px solid var(--row-border); transition: background .08s;
}
.ch-list-item:last-child { border-bottom: none; }
.ch-list-item:hover { background: var(--row-hover); }
.ch-list-item.is-added { opacity: .4; pointer-events: none; }
.ch-li-icon  { font-size: 14px; flex-shrink: 0; }
.ch-li-name  { flex: 1; font-weight: 500; }
.ch-li-id    { font-size: 10px; color: var(--text-muted); font-family: ui-monospace, monospace; }
.ch-li-badge { font-size: 10px; font-weight: 600; color: var(--primary); opacity: 0; transition: opacity .1s; flex-shrink: 0; }
.ch-list-item:hover .ch-li-badge { opacity: 1; }
.ch-list-item.is-added .ch-li-badge { opacity: 1; color: var(--success); font-size: 12px; }
.ch-list-item.is-pinned { background: rgba(94,106,210,.04); }
.ch-list-item.is-pinned .ch-li-name { color: var(--primary); }

/* ── Default-channels checklist ──────────────────────────────────────────── */
.def-ch-search { margin-bottom: 7px; }
.def-ch-list { border: 1px solid var(--border); border-radius: 6px; max-height: 240px; overflow-y: auto; }
.def-ch-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 12px; cursor: pointer;
  border-bottom: 1px solid var(--row-border); transition: background .08s; user-select: none;
}
.def-ch-item:last-child { border-bottom: none; }
.def-ch-item:hover { background: var(--row-hover); }
.def-ch-item input[type=checkbox] { width: 14px; height: 14px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.def-ch-item .dc-icon  { font-size: 14px; flex-shrink: 0; }
.def-ch-item .dc-name  { flex: 1; font-size: 12px; font-weight: 500; }
.def-ch-item .dc-id    { font-size: 10px; color: var(--text-muted); font-family: ui-monospace, monospace; }
.def-ch-empty { padding: 20px; text-align: center; color: var(--text-muted); font-size: 12px; }
.def-ch-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.def-ch-selected-count { font-size: 11px; color: var(--text-muted); }

/* ── Cron ────────────────────────────────────────────────────────────────── */
.cron-description {
  font-size: 11px; margin-top: 4px; padding: 5px 9px;
  border-radius: 5px; background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-muted); transition: color .12s;
}
.cron-description.valid   { color: var(--success); border-color: rgba(48,164,108,.25); }
.cron-description.invalid { color: var(--error);   border-color: rgba(229,72,77,.25); }

.schedule-presets { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 7px; }
.preset-chip {
  padding: 3px 9px; border-radius: 4px; font-size: 11px; font-weight: 500;
  background: var(--surface2); border: 1px solid var(--border);
  cursor: pointer; transition: all .1s; color: var(--text-muted);
}
.preset-chip:hover { border-color: var(--primary); color: var(--primary); background: rgba(94,106,210,.08); }

/* ── Image upload ────────────────────────────────────────────────────────── */
.img-upload-area { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; min-height: 40px; }
.img-grid { display: flex; flex-wrap: wrap; gap: 8px; }

.img-add-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 8px 12px; border-radius: var(--radius);
  border: 1px dashed var(--border); cursor: pointer;
  color: var(--text-muted); font-size: 12px; height: 76px;
  transition: all .12s; user-select: none;
}
.img-add-btn:hover { border-color: var(--primary); color: var(--primary); background: rgba(94,106,210,.05); }

.img-thumb {
  position: relative; width: 104px; height: 76px;
  border-radius: 6px; overflow: hidden;
  border: 1px solid var(--border); cursor: grab;
  user-select: none; flex-shrink: 0; transition: opacity .12s, box-shadow .12s;
}
.img-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.img-thumb.dragging { opacity: .35; }
.img-thumb.drag-over { box-shadow: 0 0 0 2px var(--primary); border-color: var(--primary); }
.img-thumb.uploading { background: var(--surface2); display: flex; align-items: center; justify-content: center; cursor: default; }

.img-thumb-spinner { color: var(--text-muted); font-size: 18px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.img-order {
  position: absolute; bottom: 4px; left: 4px;
  font-size: 9px; font-weight: 600; color: #fff;
  background: rgba(0,0,0,.6); padding: 1px 4px; border-radius: 3px; pointer-events: none;
}
.img-remove-btn {
  position: absolute; top: 4px; right: 4px;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0,0,0,.7); border: none; color: #fff;
  font-size: 12px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .1s;
}
.img-thumb:hover .img-remove-btn { opacity: 1; }
.img-remove-btn:hover { background: var(--error); }

/* ── Upcoming posts ──────────────────────────────────────────────────────── */
.upcoming-card { padding: 0; overflow: hidden; }

.upcoming-row {
  display: grid;
  grid-template-columns: 200px 1fr auto auto;
  align-items: center; gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--row-border);
  cursor: pointer; transition: background .08s;
}
.upcoming-row:last-child { border-bottom: none; }
.upcoming-row:hover { background: var(--row-hover); }

.upcoming-when { display: flex; flex-direction: column; gap: 2px; }
.upcoming-abs  { font-size: 12px; font-weight: 500; color: var(--text); }
.upcoming-rel  { font-size: 11px; color: var(--primary); }

.upcoming-name  { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upcoming-chans { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.upcoming-jitter { font-size: 10px; }

.upcoming-imminent { background: rgba(94,106,210,.05); }
.upcoming-imminent .upcoming-rel { color: var(--warning); font-weight: 600; }

.imminent-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--warning); margin-right: 3px;
  vertical-align: middle; animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; } 50% { opacity: .4; }
}

/* ── Spam risk ───────────────────────────────────────────────────────────── */
.risk-card { padding: 18px; }
.risk-summary {
  display: flex; align-items: center; gap: 18px;
  margin-bottom: 20px; padding-bottom: 18px; border-bottom: 1px solid var(--border);
}
.risk-gauge { flex-shrink: 0; }
.risk-level { font-size: 18px; font-weight: 700; margin-bottom: 5px; letter-spacing: -.2px; }
.risk-desc  { font-size: 11px; color: var(--text-muted); line-height: 1.55; max-width: 480px; }

.risk-factors { display: flex; flex-direction: column; gap: 14px; }
.risk-factor-top {
  display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px;
}
.risk-factor-label { font-size: 12px; font-weight: 500; }
.risk-factor-value { font-size: 11px; color: var(--text-muted); }
.risk-bar-track {
  height: 3px; background: var(--surface2); border-radius: 2px; overflow: hidden; margin-bottom: 4px;
}
.risk-bar-fill { height: 100%; border-radius: 2px; transition: width .5s ease, background .5s ease; }
.risk-factor-detail { font-size: 11px; color: var(--text-muted); }

/* ── Gallery ─────────────────────────────────────────────────────────────── */
.album-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px;
}
.album-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: default;
  transition: border-color .12s;
}
.album-card:hover { border-color: rgba(94,106,210,.4); }

.album-thumb-grid {
  width: 100%; aspect-ratio: 1;
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
  gap: 2px; background: var(--surface2); cursor: pointer; overflow: hidden;
}
.album-thumb-cell {
  background: var(--surface2) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
}
.album-thumb-cell.video-cell { background: #111; }
.album-thumb-empty {
  grid-column: 1/-1; grid-row: 1/-1;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; opacity: .25;
}
.play-icon { font-size: 16px; opacity: .75; }

.album-card-footer { padding: 9px 11px; display: flex; align-items: center; gap: 5px; }
.album-card-name {
  flex: 1; font-weight: 500; font-size: 12px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.album-card-name:hover { color: var(--primary); }
.album-card-meta { font-size: 10px; color: var(--text-muted); white-space: nowrap; }
.album-card-actions { display: flex; gap: 3px; }

.album-card-new {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 7px; cursor: pointer;
  min-height: 170px; border-style: dashed; background: transparent;
}
.album-card-new:hover { border-color: var(--primary); color: var(--primary); }
.album-card-new-icon { font-size: 24px; opacity: .4; }
.album-card-label { font-size: 12px; color: var(--text-muted); }

/* ── Media grid ──────────────────────────────────────────────────────────── */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.media-item {
  position: relative; aspect-ratio: 1; border-radius: 6px; overflow: hidden;
  border: 1px solid var(--border); background: var(--surface2);
}
.media-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-thumb-video {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: #0d0d0d; font-size: 28px; opacity: .7;
}
.media-item-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: flex-start; justify-content: flex-end; padding: 5px;
  opacity: 0; transition: opacity .12s;
}
.media-item:hover .media-item-overlay { opacity: 1; }
.media-type-badge {
  position: absolute; bottom: 4px; left: 4px;
  font-size: 9px; font-weight: 700; letter-spacing: .4px;
  background: rgba(0,0,0,.75); color: #fff; padding: 2px 4px; border-radius: 3px;
}

/* ── Album picker ────────────────────────────────────────────────────────── */
.album-picker-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.album-picker-row select { flex: 1; min-width: 170px; }
#album-count-wrap { display: flex; align-items: center; gap: 7px; }

/* ── Status badge (kept for compatibility) ───────────────────────────────── */
.status-badge {
  display: inline-block; padding: 2px 7px; border-radius: 4px; font-size: 10px; font-weight: 500;
}
.status-badge.success { background: rgba(48,164,108,.12); color: var(--success); }
.status-badge.error   { background: rgba(229,72,77,.12);  color: var(--error); }

/* ── Lucide icon utilities ───────────────────────────────────────────────── */
svg.lucide { display: inline-block; vertical-align: middle; flex-shrink: 0; }
.logo-icon svg.lucide { width: 15px; height: 15px; color: #fff; }
nav a .nav-icon svg.lucide, nav a svg.lucide.nav-icon { width: 16px; height: 16px; }
.type-icon svg.lucide { width: 14px; height: 14px; }
.auto-type-badge svg.lucide { width: 11px; height: 11px; vertical-align: -1px; }
.channel-tag-icon svg.lucide { width: 11px; height: 11px; }
.channel-tag-hint svg.lucide { width: 11px; height: 11px; }
.ch-li-icon svg.lucide { width: 14px; height: 14px; }
.dc-icon svg.lucide { width: 14px; height: 14px; }
.ch-li-badge svg.lucide { width: 11px; height: 11px; }
.log-detail-btn svg.lucide { width: 14px; height: 14px; }
.btn svg.lucide { width: 12px; height: 12px; }
.play-icon svg.lucide { width: 16px; height: 16px; }
.album-card-new-icon svg.lucide { width: 28px; height: 28px; opacity: .4; }
.empty-icon svg.lucide { width: 38px; height: 38px; }

/* Icon color helpers */
.icon-primary { color: var(--primary); }
.icon-info    { color: var(--info); }
.icon-error   { color: var(--error); }
.icon-success { color: var(--success); }
.icon-warning { color: var(--warning); }
.icon-muted   { color: var(--text-muted); }

/* Spin for loader icons */
svg.lucide-loader, svg.lucide-loader-2 { animation: spin 1s linear infinite; }

/* ── Login page ─────────────────────────────────────────────────────────── */
.login-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  width: 340px;
  text-align: center;
  box-shadow: var(--shadow);
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.login-logo-icon {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
}

.login-logo-icon svg.lucide { width: 18px; height: 18px; color: #fff; }

.login-logo-text {
  font-weight: 700; font-size: 20px; letter-spacing: -.2px;
}
.login-logo-text span { color: var(--primary); }

.login-subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 24px;
  line-height: 1.5;
}

#google-btn-container {
  display: flex;
  justify-content: center;
}

/* ── Sidebar user section ───────────────────────────────────────────────── */
#sidebar-user-section {
  position: relative;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  cursor: pointer;
  transition: background .1s;
}
.sidebar-user:hover { background: var(--row-hover); }

.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-avatar-fallback {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-avatar-fallback svg.lucide { width: 14px; height: 14px; color: var(--text-muted); }

.user-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.user-name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.user-email {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-chevron svg.lucide { width: 13px; height: 13px; color: var(--text-muted); flex-shrink: 0; }

.user-menu {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 8px; right: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  padding: 4px;
}

.user-menu-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 4px 8px 2px;
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border-radius: 4px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background .1s;
}
.user-menu-item:hover { background: var(--row-hover); }
.user-menu-item svg.lucide { width: 13px; height: 13px; color: var(--text-muted); flex-shrink: 0; }

.user-avatar-sm {
  width: 20px; height: 20px;
  border-radius: 50%;
  object-fit: cover;
}
.user-avatar-sm-fallback {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-avatar-sm-fallback svg.lucide { width: 11px; height: 11px; }

.user-menu-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.user-menu-logout { color: var(--error); }
.user-menu-logout svg.lucide { color: var(--error); }

/* ── Hamburger button (hidden on desktop) ───────────────────────────────── */
.hamburger-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 5px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.hamburger-btn:hover { background: var(--row-hover); color: var(--text); }
.hamburger-btn svg.lucide { width: 18px; height: 18px; }

/* ── Mobile backdrop ────────────────────────────────────────────────────── */
#nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 199;
}
#nav-backdrop.visible { display: block; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Sidebar becomes a slide-in drawer */
  #sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .22s ease, box-shadow .22s ease;
    box-shadow: none;
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: 6px 0 32px rgba(0,0,0,.35);
  }

  .hamburger-btn { display: flex; }

  #topbar {
    padding: 11px 14px;
    gap: 10px;
  }
  #topbar h1 { font-size: 14px; }

  #content { padding: 14px; }

  /* Forms & layouts */
  .form-row         { grid-template-columns: 1fr; }
  .editor-panes     { grid-template-columns: 1fr; }
  .stat-grid        { grid-template-columns: 1fr; }

  /* Modal slides up from bottom on mobile */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    max-width: 100%;
    border-radius: 14px 14px 0 0;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
  }
  .modal-body {
    overflow-y: auto;
    flex: 1;
  }

  /* Automation items: wrap actions below on very small screens */
  .auto-item { flex-wrap: wrap; gap: 8px; }
  .auto-actions { margin-left: auto; }

  /* Log rows: keep readable */
  .log-type-icon { display: none; }

  /* Topbar actions: smaller buttons */
  .topbar-actions .btn { padding: 5px 10px; font-size: 11px; }
  .topbar-actions .btn span { display: none; }

  /* Upcoming list */
  .upcoming-chans { max-width: 100px; }

  /* Login card full-width */
  .login-card { width: 100%; max-width: 340px; padding: 32px 24px; }
}
