:root {
  --ink: #181918;
  --ink-soft: #3e413f;
  --muted: #6d716e;
  --line: #d9dad6;
  --line-dark: #b8bbb7;
  --paper: #f3f3ef;
  --surface: #ffffff;
  --surface-alt: #e9e9e3;
  --red: #d92e25;
  --red-dark: #ab211b;
  --green: #24734b;
  --amber: #9b6815;
  --blue: #285f91;
  --sidebar: 224px;
  --topbar: 64px;
  --radius: 8px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Avenir Next", Avenir, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}
a { color: inherit; text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(217, 46, 37, .25);
  outline-offset: 2px;
}

.shell { min-height: 100vh; padding-top: var(--topbar); }
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  height: var(--topbar);
  display: flex;
  align-items: center;
  border-bottom: 1px solid #292b29;
  background: #151615;
  color: white;
}
.brand {
  width: var(--sidebar);
  height: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 18px;
  color: white;
  text-decoration: none;
  border-right: 1px solid #303230;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  background: var(--red);
  color: white;
  font-weight: 900;
  letter-spacing: -.06em;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; letter-spacing: .01em; }
.brand small { color: #9ea29f; font-size: 11px; margin-top: 1px; }
.topbar-state { margin-left: auto; display: flex; align-items: center; gap: 18px; padding: 0 20px; }
.run-state { display: flex; align-items: center; gap: 8px; color: #babdba; font-size: 12px; }
.run-state i { width: 7px; height: 7px; border-radius: 50%; background: #6d716e; }
.run-state.is-on i { background: #4fc282; box-shadow: 0 0 0 4px rgba(79, 194, 130, .13); }
.quiet-button { border: 0; background: transparent; color: #d5d7d5; padding: 7px 0; }
.quiet-button:hover { color: white; }
.nav-toggle { display: none; }

.sidebar {
  position: fixed;
  z-index: 20;
  inset: var(--topbar) auto 0 0;
  width: var(--sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #e8e8e2;
}
.sidebar nav { padding: 18px 12px; display: grid; gap: 3px; }
.sidebar nav a {
  display: block;
  padding: 9px 11px;
  border-left: 3px solid transparent;
  color: #464946;
  text-decoration: none;
  font-weight: 560;
}
.sidebar nav a:hover { color: var(--ink); background: rgba(255,255,255,.55); }
.sidebar nav a.active { border-left-color: var(--red); background: white; color: var(--ink); }
.sidebar-foot { margin-top: auto; padding: 18px 20px; border-top: 1px solid var(--line); }
.sidebar-foot strong, .sidebar-foot span { display: block; }
.sidebar-foot strong { font-size: 12px; }
.sidebar-foot span { margin-top: 3px; color: var(--muted); font-size: 11px; }

.main { margin-left: var(--sidebar); padding: 28px 34px 60px; max-width: 1500px; }
.page-head { min-height: 62px; display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 25px; line-height: 1.15; letter-spacing: -.025em; }
.page-head p { margin: 6px 0 0; color: var(--muted); }
.head-actions, .form-actions, .inbox-actions { display: flex; align-items: center; gap: 10px; }
.head-actions form { margin: 0; }
.back-link { display: inline-block; margin-bottom: 8px; color: var(--muted); font-size: 12px; }

.primary-button, .secondary-button, .danger-button, .text-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 8px 14px;
  font-weight: 650;
  line-height: 1;
  text-decoration: none;
}
.primary-button { border: 1px solid var(--red); background: var(--red); color: white; }
.primary-button:hover { border-color: var(--red-dark); background: var(--red-dark); }
.secondary-button { border: 1px solid var(--line-dark); background: var(--surface); color: var(--ink); }
.secondary-button:hover { border-color: #8f938f; background: #fafaf8; }
.danger-button { border: 1px solid #c84a43; background: white; color: #a01e18; }
.danger-button:hover { background: #fff3f2; }
.text-button { border: 0; background: transparent; color: var(--muted); }
.text-link { color: var(--muted); }
.danger-text { color: var(--red-dark); }
.full { width: 100%; }

.panel {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 1px rgba(24,25,24,.03);
}
section.panel, aside.panel { padding: 18px 20px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 15px; }
.panel h2, .panel-head h2 { margin: 0; font-size: 16px; line-height: 1.25; letter-spacing: -.01em; }
.panel h3 { margin: 0; font-size: 14px; }
.panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.panel-head > a { color: var(--muted); font-size: 12px; }

.flash-stack { margin-bottom: 18px; display: grid; gap: 8px; }
.flash { border: 1px solid var(--line); border-left-width: 4px; border-radius: 5px; background: white; padding: 10px 13px; }
.flash.success { border-left-color: var(--green); }
.flash.warning { border-left-color: var(--amber); }
.flash.error { border-left-color: var(--red); background: #fff8f7; }

.status-strip {
  display: grid;
  grid-template-columns: 66px 1fr auto;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 1px solid;
  border-left-width: 5px;
  border-radius: 5px;
  background: white;
}
.status-strip strong { font-size: 13px; letter-spacing: .04em; }
.status-strip span { color: var(--ink-soft); }
.status-strip a { color: var(--muted); font-size: 12px; }
.status-ok { border-color: #a8cbb7; border-left-color: var(--green); }
.status-watch { border-color: #d7c196; border-left-color: var(--amber); }
.status-stop { border-color: #e2aba7; border-left-color: var(--red); }

.metric-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.metric-row > div { min-width: 0; padding: 15px 17px; border-right: 1px solid var(--line); }
.metric-row > div:last-child { border-right: 0; }
.metric-row span, .metric-row small, .metric-row strong { display: block; }
.metric-row span { color: var(--muted); font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .045em; }
.metric-row strong { margin-top: 3px; font-size: 24px; letter-spacing: -.035em; }
.metric-row small { margin-top: 1px; color: var(--muted); font-size: 11px; }

.content-grid { display: grid; gap: 18px; }
.dashboard-grid { grid-template-columns: minmax(0, 2.25fr) minmax(260px, .75fr); }
.queue-panel, .stage-panel { min-height: 250px; }
.count-box { min-width: 28px; height: 28px; display: grid; place-items: center; background: var(--ink); color: white; font-weight: 700; }
.reply-list { margin: 0 -20px -18px; border-top: 1px solid var(--line); }
.reply-row { display: grid; grid-template-columns: 90px 1fr auto; gap: 14px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.reply-row:last-child { border-bottom: 0; }
.reply-type { align-self: start; padding: 4px 6px; border-left: 3px solid var(--blue); background: #eef4f8; color: #244e72; font-size: 10px; font-weight: 750; text-transform: uppercase; letter-spacing: .04em; }
.type-interested { border-color: var(--green); background: #eef7f1; color: #1e6541; }
.type-wrong_person, .type-not_now { border-color: var(--amber); background: #fbf6eb; color: #78500f; }
.reply-main a { font-weight: 700; }
.reply-main span { display: block; color: var(--muted); font-size: 11px; }
.reply-main p { margin: 7px 0 0; color: var(--ink-soft); font-size: 13px; white-space: pre-wrap; }
.reply-row time { color: var(--muted); font-size: 11px; }
.stage-list { margin: 0 -20px -18px; border-top: 1px solid var(--line); }
.stage-list a { display: flex; justify-content: space-between; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--line); text-decoration: none; }
.stage-list a:last-child { border-bottom: 0; }
.stage-list a:hover { background: #fafaf8; }
.stage-list span { color: var(--ink-soft); }

.table-wrap { width: 100%; overflow-x: auto; }
.table-panel { padding: 0; overflow: hidden; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { padding: 9px 11px; border-bottom: 1px solid var(--line-dark); color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .045em; text-transform: uppercase; }
td { padding: 11px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
.contact-table tbody tr:hover { background: #fafaf8; }
.row-link { font-weight: 700; }
.subline { display: block; max-width: 320px; margin-top: 2px; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
.muted { color: var(--muted); }
.mono, code, pre { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.empty-cell { padding: 36px; color: var(--muted); text-align: center; }
.state-label, .stage-tag {
  display: inline-block;
  border-radius: 4px;
  padding: 3px 6px;
  background: #eceeeb;
  color: #4f534f;
  font-size: 10px;
  font-weight: 750;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: .035em;
}
.state-label.ok { background: #e8f3ec; color: #1f6842; }
.state-label.warn { background: #fbf2df; color: #79500c; }
.state-label.stop { background: #fae8e6; color: #972019; }
.state-label.neutral { background: #eceeeb; color: #575b57; }
.stage-tag.large { padding: 6px 9px; font-size: 11px; }
.stage-interested, .stage-won { background: #e5f3ea; color: #1c6840; }
.stage-needs_review, .stage-wrong_person { background: #fff0dc; color: #86530c; }
.stage-order_form, .stage-sample_sent, .stage-conversation { background: #e8f0f7; color: #255d87; }
.stage-closed { background: #ececeb; color: #656865; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 13px; border-top: 1px solid var(--line); }
.pagination span { color: var(--muted); }

.filter-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.filter-bar .search-field { flex: 1; }
.filter-bar input, .filter-bar select { height: 38px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

label { display: block; color: var(--ink-soft); font-size: 12px; font-weight: 650; }
label > span { color: var(--muted); font-weight: 450; }
input, select, textarea {
  width: 100%;
  margin-top: 5px;
  border: 1px solid var(--line-dark);
  border-radius: 5px;
  background: white;
  color: var(--ink);
  padding: 9px 10px;
}
input:hover, select:hover, textarea:hover { border-color: #969a96; }
textarea { resize: vertical; line-height: 1.5; }
input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--red); }
input[type="file"] { padding: 8px; background: #fafaf8; }
.stack-form { display: grid; gap: 15px; }
.compact-form { gap: 11px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-actions span { color: var(--muted); font-size: 11px; }
.check-row { display: flex; align-items: flex-start; gap: 9px; }
.check-row input { margin-top: 2px; }
.check-row strong, .check-row small { display: block; }
.check-row small { margin-top: 2px; color: var(--muted); font-weight: 450; }
.field-help, label small { display: block; margin: 5px 0 0; color: var(--muted); font-size: 11px; font-weight: 450; }

.narrow-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(250px, .8fr); gap: 18px; max-width: 920px; }
.help-panel p { color: var(--muted); }
.result-panel { max-width: 920px; }
.result-panel pre { padding: 14px; background: #f2f3ef; border: 1px solid var(--line); white-space: pre-wrap; }

.contact-head { align-items: center; }
.contact-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; }
.composer textarea { min-height: 210px; }
.contact-side .panel { padding: 16px; }
.detail-list dl { margin: 13px 0 0; }
.detail-list dl > div { display: grid; grid-template-columns: 92px 1fr; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.detail-list dt { color: var(--muted); font-size: 11px; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }
.danger-zone { padding: 0 !important; }
.danger-zone summary { padding: 14px 16px; color: var(--red-dark); font-weight: 650; cursor: pointer; }
.danger-zone form { padding: 0 16px 16px; }
.timeline { display: grid; gap: 0; }
.timeline-item { position: relative; display: grid; grid-template-columns: 18px 1fr; gap: 9px; }
.timeline-item::before { content: ""; position: absolute; left: 5px; top: 16px; bottom: -1px; width: 1px; background: var(--line-dark); }
.timeline-item:last-child::before { display: none; }
.timeline-mark { position: relative; z-index: 1; width: 11px; height: 11px; margin-top: 13px; border: 3px solid white; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 1px var(--line-dark); }
.timeline-item.inbound .timeline-mark { background: var(--green); }
.timeline-card { margin-bottom: 15px; border: 1px solid var(--line); border-radius: 6px; background: #fafaf8; overflow: hidden; }
.timeline-card header { display: flex; justify-content: space-between; gap: 12px; padding: 9px 11px; border-bottom: 1px solid var(--line); }
.timeline-card header strong { font-size: 11px; text-transform: capitalize; }
.timeline-card time { color: var(--muted); font-size: 10px; }
.timeline-card h3 { padding: 10px 12px 0; }
.timeline-card pre { max-height: 410px; overflow: auto; margin: 0; padding: 10px 12px 13px; color: var(--ink-soft); font-family: inherit; font-size: 12px; white-space: pre-wrap; }

.sequence-map { max-width: 880px; margin-bottom: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: white; overflow: hidden; }
.sequence-step { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 14px; min-height: 72px; padding: 12px 16px; border-bottom: 1px solid var(--line); text-decoration: none; }
.sequence-step:last-child { border-bottom: 0; }
.sequence-step:hover { background: #fafaf8; }
.sequence-step > span { display: grid; place-items: center; width: 32px; height: 32px; background: var(--ink); color: white; font-weight: 800; }
.sequence-step strong { font-size: 12px; }
.sequence-step p { margin: 3px 0 0; color: var(--muted); }
.sequence-step em { color: var(--muted); font-size: 11px; font-style: normal; }
.copy-rules { max-width: 880px; }
.copy-rules ul { margin-bottom: 0; color: var(--muted); }
.editor-layout { display: grid; grid-template-columns: minmax(520px, 1fr) minmax(320px, .8fr); gap: 18px; align-items: start; }
.editor-panel textarea[name="body"] { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.preview-panel { position: sticky; top: calc(var(--topbar) + 18px); }
.preview-label { margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 750; text-transform: uppercase; letter-spacing: .05em; }
.email-preview { border: 1px solid var(--line-dark); border-radius: 7px; background: white; box-shadow: 0 8px 24px rgba(24,25,24,.08); overflow: hidden; }
.email-preview header { padding: 12px 15px; border-bottom: 1px solid var(--line); }
.email-preview header span, .email-preview header strong { display: block; }
.email-preview header span { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.email-preview header strong { margin-top: 3px; }
.email-preview pre { max-height: 650px; overflow: auto; margin: 0; padding: 18px; font-family: inherit; font-size: 12px; line-height: 1.55; white-space: pre-wrap; }

.inbox-list { max-width: 980px; }
.inbox-card { padding: 0 !important; }
.inbox-card summary, .add-inbox summary { display: flex; align-items: center; gap: 12px; padding: 14px 17px; cursor: pointer; list-style: none; }
.inbox-card summary::-webkit-details-marker, .add-inbox summary::-webkit-details-marker { display: none; }
.inbox-card summary > div { flex: 1; }
.inbox-card summary strong, .inbox-card summary small { display: block; }
.inbox-card summary small { margin-top: 2px; color: var(--muted); }
.inbox-dot { width: 9px; height: 9px; border-radius: 50%; background: #999; }
.inbox-dot.on { background: var(--green); }
.inbox-form { padding: 18px; border-top: 1px solid var(--line); background: #fafaf8; }
.inbox-actions { justify-content: space-between; padding: 12px 18px; border-top: 1px solid var(--line); }
.add-inbox { max-width: 980px; padding: 0 !important; }
.add-inbox summary { font-weight: 700; }

.settings-form { max-width: 980px; }
.settings-form .panel { padding: 18px 20px; }
.settings-form .panel > h2 { margin-bottom: 15px; }
.settings-form .panel > label, .settings-form .panel > .form-row { margin-bottom: 13px; }
.day-checks { display: flex; gap: 7px; margin-bottom: 14px; }
.day-checks label input { position: absolute; opacity: 0; pointer-events: none; }
.day-checks span { display: block; min-width: 46px; padding: 8px 10px; border: 1px solid var(--line-dark); border-radius: 5px; background: white; color: var(--ink-soft); text-align: center; }
.day-checks input:checked + span { border-color: var(--ink); background: var(--ink); color: white; }
.sticky-save { position: sticky; bottom: 14px; z-index: 5; display: flex; justify-content: flex-end; padding: 10px; border: 1px solid var(--line); background: rgba(243,243,239,.92); backdrop-filter: blur(5px); }
.validation-box { max-width: 980px; margin-bottom: 18px; padding: 15px 18px; border: 1px solid var(--line-dark); border-left: 5px solid var(--amber); background: white; }
.validation-box h2 { margin: 0 0 8px; font-size: 15px; }
.validation-box p { margin: 4px 0; }
.validation-error { color: var(--red-dark); }
.validation-warning { color: #76510f; }
.manual-controls { max-width: 980px; margin-top: 30px; }
.password-panel { max-width: 980px; margin-top: 18px; }
.password-panel h2 { margin-bottom: 15px; }
.manual-grid { display: grid; grid-template-columns: 1fr 1.4fr; gap: 18px; margin-top: 14px; }
.manual-grid > div { padding: 14px; border: 1px solid var(--line); background: #fafaf8; }
.manual-grid p { color: var(--muted); }
.inline-form { display: flex; align-items: end; gap: 8px; }
.inline-form label { max-width: 120px; }

.tabs { display: flex; gap: 2px; margin-bottom: 10px; border-bottom: 1px solid var(--line-dark); }
.tabs button { border: 0; border-bottom: 3px solid transparent; background: transparent; padding: 9px 13px; color: var(--muted); }
.tabs button.active { border-bottom-color: var(--red); color: var(--ink); font-weight: 700; }
.tab-panel { display: none; padding: 0 !important; overflow: hidden; }
.tab-panel.active { display: block; }

.empty-state { min-height: 140px; display: grid; place-content: center; gap: 4px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--ink-soft); }
.empty-state.compact { min-height: 80px; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #171817; }
.login-page::before { content: ""; position: fixed; inset: 0 auto 0 0; width: 7px; background: var(--red); }
.login-panel { width: min(400px, 100%); padding: 31px; border-top: 5px solid var(--red); border-radius: 5px; background: white; box-shadow: 0 28px 80px rgba(0,0,0,.3); }
.login-brand { display: flex; align-items: center; gap: 9px; margin-bottom: 34px; font-weight: 750; }
.login-brand span { display: grid; place-items: center; width: 30px; height: 30px; background: var(--red); color: white; font-weight: 900; }
.login-panel h1 { margin: 0; font-size: 25px; }
.login-panel > p { margin: 7px 0 22px; color: var(--muted); }
.login-panel form { display: grid; gap: 15px; }

@media (max-width: 1050px) {
  .metric-row { grid-template-columns: repeat(3, 1fr); }
  .metric-row > div:nth-child(3) { border-right: 0; }
  .metric-row > div:nth-child(n+4) { border-top: 1px solid var(--line); }
  .dashboard-grid, .contact-layout, .editor-layout { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
  .contact-side { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; align-items: start; }
  .contact-side .panel { margin-bottom: 0; }
}

@media (max-width: 760px) {
  :root { --topbar: 58px; }
  .topbar { padding: 0 12px; }
  .brand { width: auto; border-right: 0; padding: 0 10px; }
  .brand small { display: none; }
  .nav-toggle { display: block; border: 1px solid #454845; border-radius: 4px; background: transparent; color: white; padding: 6px 8px; }
  .topbar-state .run-state { display: none; }
  .sidebar { transform: translateX(-100%); transition: transform .18s ease; box-shadow: 8px 0 24px rgba(0,0,0,.16); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding: 20px 15px 48px; }
  .page-head { min-height: auto; flex-direction: column; }
  .head-actions { width: 100%; flex-wrap: wrap; }
  .metric-row { grid-template-columns: repeat(2, 1fr); }
  .metric-row > div { border-top: 1px solid var(--line); border-right: 1px solid var(--line) !important; }
  .metric-row > div:nth-child(odd) { border-right: 1px solid var(--line) !important; }
  .metric-row > div:nth-child(even) { border-right: 0 !important; }
  .status-strip { grid-template-columns: 54px 1fr; }
  .status-strip a { grid-column: 2; }
  .reply-row { grid-template-columns: 1fr; }
  .reply-type { width: max-content; }
  .reply-row time { position: absolute; right: 20px; }
  .filter-bar { align-items: stretch; flex-direction: column; }
  .form-row, .form-row.three, .narrow-layout, .manual-grid { grid-template-columns: 1fr; }
  .contact-side { grid-template-columns: 1fr; }
  .editor-layout { display: block; }
  .editor-panel { min-width: 0; }
  .sequence-step { grid-template-columns: 34px 1fr; }
  .sequence-step em { display: none; }
  .day-checks { flex-wrap: wrap; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .inline-form label { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
