:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-subtle: #f9fafb;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --ink: #101828;
  --ink-2: #344054;
  --muted: #667085;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;
  --teal: #0f766e;
  --green: #059669;
  --green-soft: #ecfdf5;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 4px 12px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.48;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.muted { color: var(--muted); font-size: 13px; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  background: #f2f4f7;
  padding: 2px 5px;
  border-radius: 4px;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

/* Shell */
.app-shell {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.logo-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 17px;
  flex-shrink: 0;
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: none;
  background: transparent;
  color: var(--ink-2);
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.14s ease, color 0.14s ease;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--muted); }
.nav-item:hover { background: var(--surface-subtle); color: var(--ink); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item.active svg { color: var(--primary); }
.nav-badge {
  margin-left: auto;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 99px;
}

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.clock-box {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
}
.clock-time { font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; }
.clock-status { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Main */
.main {
  padding: 24px 28px 40px;
  max-width: 1420px;
  width: 100%;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
h2 { margin: 0 0 12px 0; font-size: 15px; font-weight: 600; }
h3 { margin: 0 0 8px 0; font-size: 14px; font-weight: 600; }
.page-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Banners */
.banner {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}
.banner-warn {
  background: var(--amber-soft);
  border: 1px solid #fcd34d;
  color: #92400e;
}
.blockers {
  background: var(--red-soft);
  border: 1px solid #fecaca;
  color: #991b1b;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
}
.blockers ul { margin: 4px 0 0 18px; padding: 0; }

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card-head h2 { margin: 0; }

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.control-card { display: flex; flex-direction: column; justify-content: space-between; gap: 12px; }
.control-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.control-title { font-weight: 600; font-size: 14px; }
.control-desc { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.control-meta {
  font-size: 12px;
  color: var(--ink-2);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.kpi-card { padding: 16px 18px; }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.kpi-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 6px 0 4px;
  font-variant-numeric: tabular-nums;
}
.kpi-blue { color: var(--primary); }
.kpi-green { color: var(--green); }
.kpi-foot { font-size: 12px; color: var(--muted); }

.two-col-wide { display: grid; grid-template-columns: 1.65fr 1fr; gap: 16px; }
.two-col-equal { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.uploads-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.upload-card { display: flex; flex-direction: column; gap: 10px; }
.upload-card .btn { margin-top: auto; align-self: flex-start; }

/* Chart */
.legend { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.dot-teal { background: var(--teal); }
.dot-blue { background: var(--primary); }
.dot-amber { background: #d97706; }
.chart-box { width: 100%; min-height: 220px; }
.chart-box svg { width: 100%; height: 220px; display: block; }

/* Checklist */
.checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.checklist li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  font-size: 13px;
}
.check-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.check-ok { background: var(--green); }
.check-warn { background: #d97706; }
.check-err { background: var(--red); }

/* Switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #d0d5dd; border-radius: 99px; transition: background 0.16s;
}
.slider:before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform 0.16s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider:before { transform: translateX(18px); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, opacity 0.14s;
  text-decoration: none;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-subtle); }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-subtle); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--surface);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}
.form-error {
  color: var(--red);
  background: var(--red-soft);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  margin-bottom: 12px;
}
.inline-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-filters input { width: 240px; }
.inline-filters select { width: auto; }

/* Tables */
.table-wrap { overflow-x: auto; }
.max-h-240 { max-height: 240px; overflow-y: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-subtle); }
.num-input { width: 68px !important; padding: 5px 7px !important; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: var(--green-soft); color: #047857; }
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-gray { background: #f2f4f7; color: var(--ink-2); }

/* Inbox 3-pane */
.inbox-layout {
  display: grid;
  grid-template-columns: 230px 320px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
.inbox-filters { display: flex; flex-direction: column; gap: 12px; }
.filter-group label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-subtle); border: 1px solid var(--border); border-radius: 7px; padding: 2px; gap: 2px; }
.seg { border: none; background: transparent; padding: 6px 4px; border-radius: 5px; font: inherit; font-size: 12px; font-weight: 500; cursor: pointer; color: var(--ink-2); }
.seg.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm); }

.inbox-list { padding: 8px; max-height: calc(100vh - 170px); overflow-y: auto; }
.thread-item {
  padding: 11px 12px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 4px;
  transition: background 0.12s;
}
.thread-item:hover { background: var(--surface-subtle); }
.thread-item.active { background: var(--primary-soft); border-color: #bfdbfe; }
.thread-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.thread-email { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-date { font-size: 11.5px; color: var(--muted); flex-shrink: 0; }
.thread-subj { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-snip { font-size: 12px; color: var(--muted); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.thread-tags { display: flex; gap: 6px; align-items: center; margin-top: 6px; flex-wrap: wrap; }

.inbox-thread { min-height: 520px; display: flex; flex-direction: column; gap: 14px; }
.thread-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.thread-meta-line { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.thread-messages { display: flex; flex-direction: column; gap: 10px; max-height: 360px; overflow-y: auto; padding-right: 4px; }
.msg-bubble {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 11px 13px;
  background: var(--surface-subtle);
}
.msg-bubble.in { background: #ffffff; border-left: 3px solid var(--primary); }
.msg-bubble.in.stop { border-left-color: var(--red); background: #fffafa; }
.msg-bubble.out { background: #f8fafc; border-left: 3px solid #94a3b8; }
.msg-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.msg-body { white-space: pre-wrap; font-size: 13.5px; color: var(--ink); word-break: break-word; }

.reply-composer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.reply-composer textarea { min-height: 92px; resize: vertical; }

/* Templates & Logs */
.tpl-pre {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 13.5px;
  margin: 10px 0 0;
}
.log-pre {
  background: #101828;
  color: #e4e7ec;
  border-radius: 8px;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  max-height: 320px;
  overflow: auto;
  margin: 0;
}
.bot-status-box {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}
.empty-state { padding: 36px 16px; text-align: center; color: var(--muted); font-size: 13.5px; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: var(--ink);
  color: #fff;
  padding: 11px 16px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 999;
  max-width: 420px;
}
.toast.err { background: #991b1b; }

@media (max-width: 1120px) {
  .controls-grid, .uploads-grid, .two-col-wide, .two-col-equal { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .inbox-layout { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .main { padding: 16px; }
}
