:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #17212b;
  --muted: #66727f;
  --line: #dfe5ea;
  --accent: #168acd;
  --accent-dark: #0877b4;
  --success: #168a60;
  --warning: #b76511;
  --danger: #bf3b45;
  --shadow: 0 14px 40px rgba(29, 51, 72, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar { height: 68px; display: flex; align-items: center; gap: 28px; padding: 0 max(24px, calc((100vw - 1180px) / 2)); background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(14px); }
.brand { color: var(--text); font-weight: 760; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; background: linear-gradient(145deg, #1aa7ec, #0574b4); color: white; font-size: 13px; letter-spacing: .02em; }
nav { display: flex; gap: 6px; flex: 1; }
nav a { color: var(--muted); padding: 9px 13px; border-radius: 9px; font-weight: 600; }
nav a:hover, nav a[aria-current="page"] { color: var(--text); background: #edf5f9; text-decoration: none; }
.logout-form { margin-left: auto; }
.page { max-width: 1180px; margin: 0 auto; padding: 44px 24px 80px; }
.narrow-page { max-width: 760px; }
.page-heading { margin-bottom: 28px; }
.split-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.heading-actions, .form-actions, .card-actions, .stack-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack-actions { align-items: stretch; flex-direction: column; }
h1 { font-size: clamp(30px, 4vw, 44px); line-height: 1.05; margin: 5px 0 10px; letter-spacing: -.035em; }
h2 { font-size: 20px; margin: 0 0 8px; letter-spacing: -.015em; }
p { line-height: 1.6; }
.eyebrow { color: var(--accent-dark); font-size: 12px; font-weight: 800; letter-spacing: .14em; }
.muted { color: var(--muted); font-size: 14px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.metric-card, .panel, .bot-card, .form-card, .auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.metric-card { padding: 22px; min-height: 156px; display: flex; flex-direction: column; gap: 8px; }
.metric-label { color: var(--muted); font-size: 13px; font-weight: 650; }
.metric-value { font-size: 34px; line-height: 1.15; }
.small-value { font-size: 22px; }
.panel { padding: 24px; margin-top: 18px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.button { appearance: none; border: 1px solid transparent; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; padding: 10px 15px; font: inherit; font-weight: 700; cursor: pointer; line-height: 1.2; text-decoration: none; }
.button:hover { text-decoration: none; filter: brightness(.97); }
.button.primary { background: var(--accent); color: white; }
.button.secondary { background: #eaf4fa; border-color: #c9e2ef; color: #075f91; }
.button.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.button.danger { background: var(--danger); color: white; }
.button.danger-outline { background: #fff4f4; border-color: #f0c9cd; color: var(--danger); }
.button.small { padding: 7px 11px; font-size: 13px; }
.button.full { width: 100%; }
.messages { display: grid; gap: 9px; margin-bottom: 22px; }
.message, .callout { padding: 14px 17px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.message.success { border-color: #b8e0cf; background: #f0faf6; }
.message.error, .callout.warning { border-color: #efd2a9; background: #fff8ed; }
.message.info { border-color: #c8e1ef; background: #f2f9fd; }
.callout { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.callout p { margin: 4px 0 0; }
.compact-callout { display: block; }
.status-line { margin-top: auto; display: flex; gap: 7px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.success { background: var(--success); box-shadow: 0 0 0 4px #e5f5ef; }
.dot.danger { background: var(--danger); box-shadow: 0 0 0 4px #fbe8ea; }
.success-text { color: var(--success); }.warning-text { color: var(--warning); }.error-text { color: var(--danger); }
.bot-row-list { display: grid; }
.bot-row { display: grid; grid-template-columns: minmax(160px, 1.2fr) minmax(120px, 1fr) 80px 120px; gap: 16px; align-items: center; padding: 14px 0; border-top: 1px solid var(--line); }
.bot-row:first-child { border-top: 0; }
.bot-row div { display: flex; flex-direction: column; gap: 2px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #edf2f5; border-radius: 6px; padding: 3px 6px; word-break: break-word; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { color: var(--muted); text-align: left; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
.result-cell { max-width: 380px; }
.badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; background: #edf1f4; color: var(--muted); font-size: 12px; font-weight: 720; white-space: nowrap; }
.status-replied { background: #e4f5ed; color: #11734e; }
.status-sent_unconfirmed { background: #e6f2fb; color: #14638f; }
.status-failed, .status-auth_required { background: #fbe7e9; color: #a82f39; }
.status-retrying, .status-sending, .status-queued { background: #fff1d9; color: #91550c; }
.status-skipped { background: #edf0f2; color: #65717c; }
.card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.bot-card { padding: 22px; }
.bot-card-head { display: flex; justify-content: space-between; gap: 15px; }
.bot-card-head h2 { margin-bottom: 2px; }
.details-list { display: grid; gap: 0; margin: 20px 0; }
.details-list > div { display: grid; grid-template-columns: 140px 1fr; gap: 16px; border-top: 1px solid var(--line); padding: 11px 0; }
.details-list dt { color: var(--muted); font-size: 13px; }.details-list dd { margin: 0; }
.compact { margin: 8px 0 20px; }
.delete-details { position: relative; color: var(--danger); font-size: 13px; }
.delete-details summary { cursor: pointer; padding: 8px; }
.delete-details form { position: absolute; z-index: 3; right: 0; width: 230px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); color: var(--text); }
.full-span { grid-column: 1 / -1; }
.empty-state { border: 1px dashed #c7d1d8; background: var(--surface-soft); color: var(--muted); border-radius: 14px; padding: 28px; text-align: center; }
.form-card, .auth-card { padding: clamp(24px, 5vw, 42px); }
.wide-auth { max-width: 920px; margin-left: -80px; margin-right: -80px; }
.setup-grid { display: grid; grid-template-columns: 260px 1fr; gap: 36px; align-items: start; margin-top: 24px; }
.qr-panel { text-align: center; }
.qr-panel img { display: block; width: 220px; height: 220px; margin: 0 auto 14px; background: white; border-radius: 12px; }
.secret-code { display: block; margin-top: 10px; }
.stack-form { display: grid; gap: 16px; margin-top: 22px; }
.field { display: grid; gap: 7px; }
.field label { font-size: 14px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #cbd5dc; background: var(--surface); color: var(--text); border-radius: 10px; padding: 11px 12px; font: inherit; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(22,138,205,.14); }
input[type="checkbox"] { width: 18px; height: 18px; }
.checkbox { display: flex !important; align-items: center; gap: 9px; }
.help { color: var(--muted); font-size: 12px; line-height: 1.45; }
.error, .form-error { color: var(--danger); font-size: 13px; }
.form-error ul, .errorlist { margin: 0; padding-left: 18px; }
.has-error input { border-color: var(--danger); }
.recovery-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 22px 0; }
.recovery-grid code { padding: 9px; text-align: center; }
.filter-bar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.filter-bar label { min-width: 150px; display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.settings-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 16px; }
.settings-grid .panel { margin-top: 0; }
@media (prefers-color-scheme: dark) {
  :root { --bg: #10161c; --surface: #172029; --surface-soft: #141c24; --text: #edf4f8; --muted: #9babb7; --line: #293743; --shadow: 0 14px 40px rgba(0,0,0,.22); }
  .topbar { background: rgba(23,32,41,.92); }
  nav a:hover, nav a[aria-current="page"] { background: #20313d; }
  code { background: #24323d; }
  .button.secondary { background: #17384b; border-color: #28536a; color: #9edcff; }
  .button.danger-outline { background: #382126; border-color: #69343c; }
  .message.success { background: #173229; }.message.error,.callout.warning { background: #34291b; }.message.info { background: #18303d; }
  input,select,textarea { border-color: #3b4a55; }
}
@media (max-width: 860px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .card-grid, .settings-grid { grid-template-columns: 1fr; }
  .bot-row { grid-template-columns: 1fr 100px; }
  .bot-row code, .bot-row > span:last-child { display: none; }
  .wide-auth { margin: 0; }
}
@media (max-width: 640px) {
  .topbar { height: auto; padding: 12px 16px; gap: 10px; flex-wrap: wrap; }
  .brand { flex: 1; }
  nav { order: 3; width: 100%; overflow-x: auto; }
  nav a { flex: 1; text-align: center; padding: 8px; }
  .page { padding: 28px 16px 70px; }
  .split-heading { align-items: stretch; flex-direction: column; }
  .heading-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .heading-actions form, .heading-actions button { width: 100%; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 130px; }
  .setup-grid { grid-template-columns: 1fr; }
  .callout { align-items: stretch; flex-direction: column; }
  .details-list > div { grid-template-columns: 110px 1fr; }
  .recovery-grid { grid-template-columns: 1fr; }
}
