:root {
  --brand: #0b8f6a;
  --brand-dark: #076b50;
  --brand-soft: #e6f6f0;
  --ink: #14202b;
  --ink-soft: #5b6b7a;
  --line: #e3e9ef;
  --bg: #f5f8fa;
  --card: #ffffff;
  --side: #0f1d2c;
  --side-ink: #b9c7d4;
  --warn: #b7791f;
  --warn-soft: #fdf5e6;
  --danger: #c53030;
  --danger-soft: #fdecec;
  --info: #2b6cb0;
  --info-soft: #ebf4ff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 32, 43, .06), 0 4px 14px rgba(20, 32, 43, .05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e7eef5;
    --ink-soft: #94a3b2;
    --line: #243241;
    --bg: #0c1620;
    --card: #132130;
    --brand-soft: #113a2f;
    --warn-soft: #3a2c10;
    --danger-soft: #3d1717;
    --info-soft: #14284a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
p { margin: 0 0 1em; }
img, svg { max-width: 100%; }

.container { width: min(1120px, 100% - 32px); margin: 0 auto; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 999px; border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 15px; cursor: pointer;
  background: var(--brand); color: #fff; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--card); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #9b2424; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; font-size: 14px; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 96px; resize: vertical; }
.field { margin-bottom: 16px; }
.hint { font-size: 12px; color: var(--ink-soft); margin-top: 6px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------- cards & badges ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--line); color: var(--ink-soft);
}
.badge-ok { background: var(--brand-soft); color: var(--brand-dark); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }

.alert { padding: 12px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 16px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-ok { background: var(--brand-soft); color: var(--brand-dark); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); font-weight: 600; }
tr:last-child td { border-bottom: none; }

/* ---------- auth pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(420px, 100%); }
.auth-tabs { display: flex; background: var(--bg); border-radius: 999px; padding: 4px; margin-bottom: 24px; }
.auth-tabs button {
  flex: 1; border: 0; background: none; padding: 8px; border-radius: 999px; font: inherit;
  font-weight: 600; color: var(--ink-soft); cursor: pointer;
}
.auth-tabs button.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(8, 16, 24, .55); display: grid; place-items: center;
  padding: 16px; z-index: 50;
}
.modal { width: min(540px, 100%); max-height: 90vh; overflow: auto; }
.modal h2 { font-size: 20px; }

.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: var(--card);
  padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; z-index: 60;
  max-width: calc(100% - 40px);
}
.toast.error { background: var(--danger); color: #fff; }

.empty { text-align: center; padding: 40px 16px; color: var(--ink-soft); }
.empty h3 { color: var(--ink); }

/* ---------- dashboard shell ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--side); color: var(--side-ink); padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand-link { color: #fff; font-weight: 800; font-size: 20px; padding: 4px 10px 20px; display: flex; align-items: center; gap: 10px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--side-ink); font-weight: 500; font-size: 14px;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar nav a.active { background: rgba(11, 143, 106, .25); color: #fff; }
.sidebar .spacer { flex: 1; }
.sidebar .account { font-size: 13px; padding: 12px; border-top: 1px solid rgba(255, 255, 255, .08); margin-top: 12px; }
.sidebar .account button { margin-top: 8px; }
.main { padding: 28px clamp(16px, 3vw, 36px); min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { font-size: 26px; margin: 0 0 4px; }
.page-head p { margin: 0; color: var(--ink-soft); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat .label { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.stat .value { font-size: 28px; font-weight: 800; margin-top: 4px; }

.bars { display: flex; align-items: flex-end; gap: 12px; height: 180px; padding-top: 12px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; font-size: 12px; color: var(--ink-soft); }
.bar div { width: 100%; background: var(--brand); border-radius: 8px 8px 4px 4px; min-height: 4px; }

.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border-bottom: none; }
.check { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; background: var(--line); color: var(--ink-soft); }
.check.done { background: var(--brand); color: #fff; }

.inbox { display: grid; grid-template-columns: 320px 1fr; gap: 16px; height: calc(100vh - 150px); min-height: 480px; }
.convo-list { overflow: auto; padding: 0; }
.convo { display: block; padding: 12px 14px; border-bottom: 1px solid var(--line); color: var(--ink); }
.convo:hover, .convo.active { background: var(--brand-soft); }
.convo .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 14px; }
.convo .preview { font-size: 13px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.thread-head { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.thread-body { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.bubble { max-width: 70%; padding: 10px 14px; border-radius: 14px; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; background: var(--card); border: 1px solid var(--line); }
.bubble.out { align-self: flex-end; background: #d9fdd3; border-color: #c6eec0; color: #111; }
.bubble.failed { border-color: var(--danger); }
.bubble .meta { font-size: 11px; color: #667; margin-top: 4px; text-align: right; }
.bubble.in .meta { color: var(--ink-soft); }
.composer { border-top: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.composer .row { flex-wrap: nowrap; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; }
  .sidebar .brand-link { padding: 0 8px; }
  .sidebar nav { display: flex; overflow-x: auto; gap: 4px; flex: 1; }
  .sidebar nav a { white-space: nowrap; padding: 8px 10px; }
  .sidebar .spacer, .sidebar .account { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .convo-list { max-height: 260px; }
  .thread-body { min-height: 360px; }
  .bubble { max-width: 88%; }
}
