:root {
  --bg: #efe7dc;
  --ink: #1c1915;
  --muted: #6f675d;
  --card: #fffaf3;
  --line: #e2d5c6;
  --side: #17211c;
  --side-ink: #f3f6f1;
  --green: #0d6b43;
  --green-ink: #f3fff7;
  --lime: #d7f56a;
  --danger: #8f2d2d;
  --warn: #8a5a12;
  --shadow: 0 18px 50px rgba(48, 36, 18, 0.08);
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    radial-gradient(900px 420px at 10% -10%, #f7e7c2 0%, transparent 60%),
    radial-gradient(700px 400px at 100% 100%, #d9efe3 0%, transparent 55%),
    var(--bg);
}
.gate-card {
  width: min(440px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.gate-card h1 { font-size: 32px; line-height: 1.05; margin: 8px 0 12px; letter-spacing: -0.04em; }
.lede { color: var(--muted); margin: 0 0 22px; }
.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  color: var(--green);
  font-weight: 700;
}
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #9cba8d; box-shadow: 0 0 0 3px rgba(13, 107, 67, 0.12); }
.btn {
  border: 0;
  background: var(--green);
  color: var(--green-ink);
  border-radius: 999px;
  padding: 11px 18px;
  font-weight: 650;
}
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn:disabled { opacity: 0.55; cursor: default; }
.form-error { color: var(--danger); min-height: 1.2em; margin: 10px 0 0; }

.shell { min-height: 100%; display: grid; grid-template-columns: 232px 1fr; }
.side {
  background: var(--side);
  color: var(--side-ink);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 0 8px; }
.brand strong { display: block; }
.brand small { color: #b7c4bb; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--lime); color: #17211c; font-weight: 800;
}
.nav { display: grid; gap: 4px; }
.nav button, .side-out {
  text-align: left;
  border: 0;
  background: transparent;
  color: #d5e0d8;
  border-radius: 12px;
  padding: 10px 12px;
}
.nav button.active, .nav button:hover { background: rgba(255,255,255,0.06); color: white; }
.side-out { margin-top: auto; color: #b7c4bb; }
.badge {
  display: inline-grid; place-items: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 99px; background: var(--lime); color: #17211c;
  font-style: normal; font-size: 11px; margin-left: 6px;
}

main { min-width: 0; }
.screen { padding: 28px 32px 48px; }
.screen-fill { height: 100vh; padding: 0; }
.top { display: flex; justify-content: space-between; gap: 16px; align-items: end; margin-bottom: 18px; }
.top h2 { margin: 4px 0 0; font-size: 32px; letter-spacing: -0.04em; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.card, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 18px;
}
.card span { color: var(--muted); font-size: 13px; }
.card strong { display: block; margin-top: 8px; font-size: 28px; letter-spacing: -0.04em; }
.card em { font-style: normal; color: var(--muted); font-size: 13px; }
.setup { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.setup button {
  text-align: left;
  border: 1px dashed #c9b8a2;
  background: transparent;
  border-radius: 16px;
  padding: 14px;
}
.setup b { display: block; margin-bottom: 4px; }
.setup span { color: var(--muted); font-size: 13px; }
.steps { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }
.steps li { margin: 6px 0; }
.hint { color: var(--muted); font-size: 13px; }
.row-actions, .toolbar, .pager, .composer-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar { margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 16px; background: var(--card); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.pager { margin-top: 12px; }

.chat { height: 100vh; display: grid; grid-template-columns: 320px 1fr; }
.chat-list { border-right: 1px solid var(--line); display: flex; flex-direction: column; background: #f7f1e8; min-height: 0; }
.chat-list-head { padding: 18px 16px 10px; }
.chat-list-head h2 { margin: 0 0 10px; }
.chat-items { overflow: auto; }
.chat-item, .camp-item {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 12px 14px;
}
.chat-item.on, .camp-item.on { background: #fff; }
.chat-item b, .camp-item b { display: block; }
.chat-item small, .camp-item small { color: var(--muted); }
.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #f3ecdf; }
.thread-empty { margin: auto; color: var(--muted); }
.thread-head, .composer { padding: 14px 16px; background: var(--card); }
.thread-head { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); align-items: center; }
.thread-head span, .thread-head strong { display: block; }
#thread { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.messages { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: min(560px, 80%); padding: 10px 12px; border-radius: 16px; background: white; border: 1px solid var(--line); }
.bubble.out { margin-left: auto; background: #e7f6ee; border-color: #cfe6d8; }
.bubble p { margin: 0; white-space: pre-wrap; word-break: break-word; }
.bubble small { color: var(--muted); }
.composer { border-top: 1px solid var(--line); }
.seg { display: flex; gap: 6px; margin-bottom: 8px; }
.seg button { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 12px; }
.seg button.on { background: var(--side); color: white; border-color: var(--side); }
.slots { display: grid; gap: 8px; margin-top: 8px; }
.pill { border-radius: 999px; padding: 4px 10px; font-size: 12px; background: #eee6da; }
.pill.ok { background: #e5f6ec; color: var(--green); }
.pill.bad { background: #fde8e4; color: var(--danger); }
.pill.wait { background: #fff1d6; color: var(--warn); }

.split { display: grid; grid-template-columns: 300px 1fr; gap: 14px; align-items: start; }
.stack { display: grid; gap: 10px; }
.settings-grid { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 14px; align-items: start; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form h3, .panel h3 { margin-top: 0; }
.funnel { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 12px 0; }
.funnel div { background: #f6f1e8; border-radius: 12px; padding: 10px; }
.funnel b { display: block; font-size: 20px; }
.fail-list { margin: 0; padding-left: 18px; color: var(--danger); }

.modal { position: fixed; inset: 0; background: rgba(28, 25, 21, 0.35); display: grid; place-items: center; padding: 16px; }
.modal-card { width: min(560px, 100%); background: var(--card); border-radius: 20px; padding: 20px; box-shadow: var(--shadow); }
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--side); color: white; padding: 10px 14px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: relative; height: auto; }
  .nav { grid-template-columns: repeat(3, 1fr); }
  .cards, .setup, .split, .settings-grid, .funnel { grid-template-columns: 1fr 1fr; }
  .chat { grid-template-columns: 1fr; height: auto; }
  .screen-fill { height: auto; }
  .chat-list { max-height: 280px; }
  .messages { min-height: 360px; }
}
