:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --ink: #15171c;
  --muted: #6b7280;
  --line: #e4e6eb;
  --side: #111318;
  --side-ink: #c9ccd3;
  --accent: #0f766e;
  --accent-soft: #e6f4f2;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #a15c07;
  --warn-soft: #fff6e5;
  --ok: #157f3d;
  --ok-soft: #e8f6ec;
  --radius: 8px;
  font-size: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 13px; margin: 16px 0 8px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
small, .muted { color: var(--muted); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
code { background: #f1f2f4; padding: 1px 5px; border-radius: 4px; word-break: break-all; }

.layout { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { color: #fff; font-weight: 700; font-size: 15px; padding: 0 10px 14px; letter-spacing: -0.01em; }
.brand small { display: block; color: #8b909b; font-weight: 400; font-size: 12px; margin-top: 2px; }
.side nav a { display: flex; justify-content: space-between; align-items: center; color: var(--side-ink); padding: 7px 10px; border-radius: 6px; margin: 1px 0; }
.side nav a:hover { background: #1d2028; text-decoration: none; color: #fff; }
.side nav a.on { background: #23262f; color: #fff; }
.side .group { color: #6f7480; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 14px 10px 4px; }
.count { background: #2e323c; color: #fff; font-size: 11px; padding: 0 6px; border-radius: 4px; min-width: 18px; text-align: center; }
.count.hot { background: var(--danger); }
.main { padding: 0 28px 48px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.topbar form { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.topbar select { min-width: 220px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.card.tight { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi b { display: block; font-size: 24px; font-weight: 650; letter-spacing: -0.02em; }
.kpi span { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 9px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbfc; }

label { display: block; font-weight: 600; font-size: 12px; margin: 10px 0 4px; color: #374151; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; font-size: 13px; color: var(--ink); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=url], input[type=tel], input[type=file], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #d3d6dc; border-radius: 6px; background: #fff; font: inherit; color: inherit;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #99d5cf; border-color: var(--accent); }
.inline input, .inline select { width: auto; }
.help { color: var(--muted); font-size: 12px; margin-top: 4px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 6px; border: 1px solid #cfd3da; background: #fff; color: var(--ink); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f6f7f9; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #0c5f59; }
.btn.danger { color: var(--danger); border-color: #efc4bf; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0; }
form.inline-form { display: inline; margin: 0; }

.badge { display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: 11.5px; font-weight: 600; background: #eef0f3; color: #3f4652; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--danger-soft); color: var(--danger); }
.badge.acc { background: var(--accent-soft); color: var(--accent); }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.flash.ok { background: var(--ok-soft); border-color: #bfe3cb; color: #0f5c2c; }
.flash.err { background: var(--danger-soft); border-color: #f2c1bb; color: #8c1c13; }
.flash.warn { background: var(--warn-soft); border-color: #f1d9a8; color: #7a4507; }
.note-box { background: #fafbfc; border: 1px dashed #d3d6dc; border-radius: 6px; padding: 10px 12px; font-size: 13px; }

/* Инбокс */
.inbox { display: grid; grid-template-columns: 320px 1fr; gap: 18px; align-items: start; }
.convlist a { display: block; padding: 11px 14px; border-bottom: 1px solid var(--line); color: var(--ink); }
.convlist a:hover { background: #fafbfc; text-decoration: none; }
.convlist a.on { background: var(--accent-soft); }
.convlist .who { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.convlist .prev { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { display: flex; flex-direction: column; gap: 8px; max-height: 62vh; overflow-y: auto; padding: 4px 2px 8px; }
.msg { max-width: 76%; padding: 9px 12px; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 5px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.msg.in { align-self: flex-start; background: #eef0f3; border-bottom-left-radius: 3px; }
.msg.out { align-self: flex-end; background: var(--accent-soft); border-bottom-right-radius: 3px; }
.msg.out.ai { background: #e9f1fb; }
.msg.voice { align-self: stretch; max-width: 100%; background: #fff; border: 1px solid var(--line); }
.msg.note { align-self: stretch; max-width: 100%; background: #fffbea; border: 1px solid #f3e3a6; }
.msg.failed { outline: 1px solid #efc4bf; }
.composer { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px; }
.counter { font-size: 12px; color: var(--muted); }

.steps .step { border: 1px solid var(--line); border-radius: 6px; padding: 12px; margin: 10px 0; background: #fcfcfd; }
.checklist li { margin: 4px 0; }
details > summary { cursor: pointer; color: var(--accent); font-weight: 550; }
.login { max-width: 360px; margin: 12vh auto; }

/* Automation workspace: compact navigation, independent controls, clear states. */
[hidden] { display: none !important; }
.main { max-width: 1600px; width: 100%; }
.brand { font-size: 18px; padding-top: 4px; }
.brand::before { content: ""; display: inline-grid; place-items: center; width: 28px; height: 28px; margin-right: 8px; border-radius: 7px; background: url('/static/dent-mark.svg') center / cover no-repeat; vertical-align: middle; }
.brand small { padding: 5px 0 0 36px; }
.side nav a { padding: 9px 12px; margin: 3px 0; }
.side nav a.on { background: #203832; color: #beebdd; box-shadow: inset 3px 0 #65b7a7; }
.page-heading { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 18px; margin: 4px 0 22px; }
.page-heading h1 { font-size: 27px; margin: 5px 0 6px; letter-spacing: -.03em; }
.page-heading p { margin: 0; max-width: 680px; }
.eyebrow { font-size: 10px; letter-spacing: .11em; font-weight: 650; color: var(--muted); text-transform: uppercase; }
.automation-summary { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; margin: 0 0 20px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.feature-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 28px; }
.feature-card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px; display: flex; flex-direction: column; }
.feature-card:hover { border-color: #9daea8; }
.feature-card-link::after { content: ""; position: absolute; inset: 0; border-radius: 10px; }
.feature-card:focus-within { border-color: var(--accent); }
.feature-footer a { position: relative; z-index: 1; }
.feature-category { font-size: 10px; letter-spacing: .07em; text-transform: uppercase; font-weight: 650; color: var(--muted); }
.feature-card h2 { font-size: 17px; margin: 20px 0 7px; }
.feature-card h2 a { color: var(--ink); }
.feature-card p { color: var(--muted); margin: 0 0 18px; font-size: 13px; line-height: 1.65; flex: 1; }
.feature-mode { border-top: 1px solid var(--line); padding-top: 13px; font-size: 12px; display: flex; flex-direction: column; gap: 4px; }
.feature-mode span { color: var(--muted); }
.feature-mode strong { font-weight: 550; }
.feature-footer { margin-top: 18px; font-size: 11px; }
.sending-card { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; }
.sending-card p { max-width: 380px; font-size: 13px; }
.back-link { display: inline-block; font-size: 12px; margin-bottom: 15px; }
.feature-tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 1px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.feature-tabs a { flex-shrink: 0; color: var(--muted); padding: 10px 12px; font-size: 12px; border-bottom: 2px solid transparent; }
.feature-tabs a.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 650; }
.automation-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(240px, 1fr); gap: 22px; align-items: start; }
.automation-form { padding: 24px; }
.mode-fieldset { padding: 0; border: 0; margin: 0; min-width: 0; }
.mode-fieldset legend { font-size: 15px; font-weight: 650; margin-bottom: 15px; }
.mode-option { display: flex; align-items: start; gap: 12px; border: 1px solid var(--line); border-radius: 7px; padding: 13px 15px; margin: 0 0 9px; font-size: 13px; cursor: pointer; }
.mode-option:has(input:checked) { border-color: var(--accent); background: #f1f9f7; }
.mode-option input { margin: 3px 0 0; accent-color: var(--accent); flex-shrink: 0; }
.mode-option strong { display: block; font-weight: 600; }
.mode-option small { display: block; font-weight: 400; line-height: 1.6; margin-top: 3px; }
.form-section { border-top: 1px solid var(--line); margin-top: 22px; padding-top: 20px; }
.form-section .help { line-height: 1.7; margin: 12px 0; }
.form-section a { font-size: 12px; }
.form-actions { border-top: 1px solid var(--line); margin-top: 24px; padding-top: 18px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.resource-row { display: flex; align-items: start; justify-content: space-between; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.resource-row .badge { white-space: normal; text-align: right; }
.automation-aside a { display: inline-block; margin: 9px 0 4px; font-size: 12px; }
.automation-aside .help { line-height: 1.7; }
.table-scroll { overflow-x: auto; }
.table-scroll td { overflow-wrap: anywhere; }
.empty-state { padding: 28px 12px; text-align: center; color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (max-width: 1200px) { .feature-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .side nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .side .group { display: none; }
  .main { padding: 0 14px 40px; }
  .g2, .g3, .g4, .inbox { grid-template-columns: 1fr; }
  .msg { max-width: 92%; }
  .feature-grid, .automation-layout, .sending-card { grid-template-columns: 1fr; }
  .page-heading h1 { font-size: 23px; }
  .topbar select { min-width: 0; max-width: 190px; }
  .automation-form { padding: 18px; }
  .topbar { flex-wrap: wrap; }
}
