/* affinova.ai Portal — indigo & white theme */
:root {
  --indigo-950:#1e1b4b; --indigo-900:#312e81; --indigo-800:#3730a3; --indigo-700:#4338ca;
  --indigo-600:#4f46e5; --indigo-500:#6366f1; --indigo-100:#e0e7ff; --indigo-50:#eef2ff;
  --bg:#f6f7fb; --card:#ffffff; --text:#1f2937; --muted:#6b7280; --border:#e5e7eb;
  --ok:#059669; --ok-bg:#d1fae5; --bad:#dc2626; --bad-bg:#fee2e2; --warn:#d97706; --warn-bg:#fef3c7;
  --shadow:0 1px 3px rgba(17,24,39,.06), 0 8px 24px rgba(17,24,39,.05);
  --radius:16px;
}
* { box-sizing:border-box; margin:0; }
html, body { height:100%; }
body {
  font:14px/1.55 "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  background:var(--bg); color:var(--text);
  -webkit-font-smoothing:antialiased;
}
h1 { font-size:20px; font-weight:800; letter-spacing:-.02em; }
h2 { font-size:12px; text-transform:uppercase; letter-spacing:.08em; color:var(--indigo-600); margin-bottom:12px; font-weight:700; }
h3 { font-size:14px; font-weight:700; margin-bottom:6px; }
.sub { color:var(--muted); font-size:12.5px; }

/* ===== Layout: sidebar + content ===== */
#shell { display:flex; min-height:100vh; }
#sidebar {
  width:264px; flex-shrink:0; position:sticky; top:0; height:100vh; overflow-y:auto;
  background:#0e1129;
  color:#fff; display:flex; flex-direction:column; padding:22px 16px 16px;
}
#logo { display:flex; align-items:center; gap:12px; padding:2px 8px 18px; border-bottom:1px solid rgba(255,255,255,.08); margin-bottom:14px; }
#logo .mark {
  width:42px; height:42px; display:grid; place-items:center;
  border-radius:12px; box-shadow:0 4px 14px rgba(99,102,241,.35);
}
#logo .mark svg { display:block; }
#logo .name { font-size:18px; font-weight:800; letter-spacing:-.02em; }
#logo .tag { font-size:10.5px; color:#8f97c9; letter-spacing:.28em; text-transform:uppercase; font-weight:600; }

#tabs { display:flex; flex-direction:column; gap:2px; flex:1; }
.nav-section {
  font-size:10.5px; font-weight:700; letter-spacing:.28em; text-transform:uppercase;
  color:#5b638f; padding:16px 10px 8px;
}
#tabs button {
  display:flex; align-items:center; gap:13px; width:100%; text-align:left;
  background:transparent; color:#aab1d6; border:0; padding:10px 12px;
  border-radius:14px; cursor:pointer; font:inherit;
  transition:background .15s, color .15s;
}
#tabs button .ico { flex-shrink:0; width:22px; height:22px; color:#7c85b8; }
#tabs button .ico svg { width:22px; height:22px; display:block; }
#tabs button .txt { display:flex; flex-direction:column; line-height:1.25; }
#tabs button .txt .t { font-weight:700; font-size:14.5px; color:#c8cdea; }
#tabs button .txt .d { font-size:11.5px; color:#6d759f; font-weight:500; }
#tabs button:hover { background:rgba(255,255,255,.05); }
#tabs button:hover .txt .t { color:#fff; }
#tabs button.active { background:rgba(99,102,241,.16); box-shadow:inset 0 0 0 1px rgba(129,140,248,.25); position:relative; }
#tabs button.active .ico { color:#818cf8; }
#tabs button.active .txt .t { color:#fff; }
#tabs button.active::after {
  content:''; width:7px; height:7px; border-radius:50%; background:#6366f1;
  margin-left:auto; box-shadow:0 0 8px #6366f1;
}

#sidefoot { margin-top:14px; }
#sidefoot .session {
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  border:1px solid rgba(255,255,255,.12); border-radius:14px; padding:12px 14px;
}
#sidefoot .session .lbl { font-size:12px; color:#8f97c9; }
#sidefoot .session .who { font-weight:700; color:#fff; font-size:14px; }
#sidefoot .session .pill { background:rgba(99,102,241,.25); color:#c7d2fe; }
#sidefoot .exit {
  background:transparent; box-shadow:none; padding:6px; border-radius:10px; color:#8f97c9;
}
#sidefoot .exit:hover { background:rgba(255,255,255,.08); color:#fff; }
#sidefoot .exit svg { width:20px; height:20px; display:block; }

#content { flex:1; min-width:0; display:flex; flex-direction:column; }
#topbar {
  display:flex; align-items:center; gap:14px; padding:18px 28px;
  background:transparent;
}
#pagetitle { font-size:22px; font-weight:800; letter-spacing:-.02em; }
main { padding:0 28px 40px; }

/* ===== Cards & grid ===== */
.grid { display:grid; grid-template-columns:repeat(auto-fit, minmax(360px, 1fr)); gap:18px; }
.card {
  background:var(--card); border:1px solid var(--border); border-radius:var(--radius);
  padding:20px; overflow-x:auto; box-shadow:var(--shadow);
}
.row { display:flex; gap:10px; align-items:center; flex-wrap:wrap; margin:8px 0; }
.spread { justify-content:space-between; }

/* ===== Tables ===== */
table { width:100%; border-collapse:collapse; font-size:13px; }
th, td { text-align:left; padding:9px 10px; border-bottom:1px solid var(--border); white-space:nowrap; }
th { color:var(--muted); font-weight:600; font-size:11.5px; text-transform:uppercase; letter-spacing:.05em; }
tr:last-child td { border-bottom:0; }
tbody tr:hover, table tr:hover td { background:#fafaff; }

/* ===== Forms ===== */
input, select, textarea {
  padding:9px 12px; border-radius:10px; border:1px solid var(--border);
  background:#fff; color:var(--text); font:inherit; outline:none;
  transition:border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color:var(--indigo-500); box-shadow:0 0 0 3px var(--indigo-100);
}
textarea { width:100%; min-height:80px; resize:vertical; }
input[type="checkbox"] { width:16px; height:16px; accent-color:var(--indigo-600); }
input[type="time"] { padding:6px 8px; }
label { font-size:11.5px; color:var(--muted); display:block; margin-bottom:4px; font-weight:600; text-transform:uppercase; letter-spacing:.04em; }
.field { display:flex; flex-direction:column; }

/* ===== Buttons ===== */
button {
  padding:9px 16px; border:0; border-radius:10px; cursor:pointer;
  background:var(--indigo-600); color:#fff; font:inherit; font-weight:700; font-size:13px;
  box-shadow:0 1px 2px rgba(79,70,229,.35); transition:background .15s, transform .05s;
}
button:hover { background:var(--indigo-700); }
button:active { transform:translateY(1px); }
button.ghost { background:var(--indigo-50); color:var(--indigo-700); box-shadow:none; }
button.ghost:hover { background:var(--indigo-100); }
button.small { padding:5px 10px; font-size:12px; border-radius:8px; }
button.danger { background:var(--bad-bg); color:var(--bad); box-shadow:none; }
button.danger:hover { background:#fecaca; }
button:disabled { opacity:.45; cursor:default; }

/* ===== KPIs & pills ===== */
.big { font-size:30px; font-weight:800; color:var(--indigo-700); letter-spacing:-.03em; }
.kpis { display:flex; gap:34px; }
.ok { color:var(--ok); } .bad { color:var(--bad); } .warn { color:var(--warn); }
.pill {
  display:inline-block; padding:2px 10px; border-radius:99px; font-size:11px; font-weight:700;
  background:var(--indigo-50); color:var(--indigo-700);
}
.pill.on { background:var(--ok-bg); color:var(--ok); }
.pill.off { background:var(--bad-bg); color:var(--bad); }

/* ===== Inventory & routing widgets ===== */
.merchant { border:1px solid var(--border); border-radius:14px; padding:16px; margin-bottom:14px; background:#fbfbfe; }
.cascade-item {
  display:flex; align-items:center; gap:10px; background:#fff; border:1px solid var(--border);
  border-radius:12px; padding:9px 12px; margin:6px 0; box-shadow:0 1px 2px rgba(17,24,39,.04);
}
.cascade-item .name { flex:1; font-weight:600; }
.cascade-item .sub { min-width:14px; }

/* ===== Login ===== */
#login {
  min-height:100vh; display:flex; align-items:center; justify-content:center;
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(129,140,248,.35), transparent 60%),
    radial-gradient(700px 450px at -10% 100%, rgba(99,102,241,.28), transparent 55%),
    linear-gradient(160deg, var(--indigo-900), var(--indigo-950));
  padding:16px;
}
#login .panel {
  width:380px; background:#fff; border-radius:20px; padding:34px 30px;
  box-shadow:0 24px 60px rgba(15,23,42,.45); text-align:center;
}
#login .mark {
  width:52px; height:52px; margin:0 auto 14px; border-radius:15px; display:grid; place-items:center;
  box-shadow:0 8px 20px rgba(99,102,241,.4);
}
#login .mark svg { display:block; }
#login h1 { margin-bottom:4px; }
#login .sub { margin-bottom:20px; }
#login input { width:100%; margin:6px 0 14px; text-align:center; }
#login button { width:100%; padding:11px; }

/* ===== Toast ===== */
#toast {
  position:fixed; bottom:24px; right:24px; background:#fff; color:var(--text);
  border:1px solid var(--border); border-left:4px solid var(--ok);
  border-radius:12px; padding:12px 18px; display:none; z-index:99;
  box-shadow:0 12px 30px rgba(17,24,39,.15); font-weight:600;
}
#toast.show { display:block; }

/* ===== Date filter bar ===== */
.filterbar {
  display:flex; align-items:center; gap:8px; flex-wrap:wrap;
  background:var(--card); border:1px solid var(--border); border-radius:14px;
  padding:10px 14px; margin-bottom:18px; box-shadow:var(--shadow);
}
.filterbar .presets { display:flex; gap:4px; background:var(--indigo-50); border-radius:10px; padding:3px; }
.filterbar .presets button {
  background:transparent; color:var(--indigo-700); box-shadow:none; padding:6px 12px; border-radius:8px; font-size:12.5px;
}
.filterbar .presets button.active { background:var(--indigo-600); color:#fff; }
.filterbar .sep { width:1px; height:22px; background:var(--border); margin:0 4px; }
.filterbar input[type="date"] { padding:6px 10px; font-size:12.5px; }
.filterbar .grow { flex:1; }

/* ===== Conversations / chat thread ===== */
.conv-row { cursor:pointer; }
.thread-overlay {
  position:fixed; inset:0; background:rgba(15,23,42,.45); z-index:50;
  display:flex; justify-content:flex-end;
}
.thread-panel {
  width:min(480px, 100%); height:100%; background:#fff; display:flex; flex-direction:column;
  box-shadow:-16px 0 40px rgba(15,23,42,.25);
}
.thread-head {
  padding:16px 20px; border-bottom:1px solid var(--border);
  display:flex; align-items:center; gap:12px;
}
.thread-head .avatar {
  width:38px; height:38px; border-radius:50%; background:var(--indigo-100); color:var(--indigo-700);
  display:grid; place-items:center; font-weight:800;
}
.thread-body { flex:1; overflow-y:auto; padding:18px; background:#f3f4f9; display:flex; flex-direction:column; gap:8px; }
.bubble { max-width:78%; padding:9px 13px; border-radius:14px; font-size:13.5px; white-space:pre-wrap; word-break:break-word; }
.bubble.in { align-self:flex-start; background:#fff; border:1px solid var(--border); border-bottom-left-radius:4px; }
.bubble.out { align-self:flex-end; background:var(--indigo-600); color:#fff; border-bottom-right-radius:4px; }
.bubble .when { display:block; font-size:10px; opacity:.65; margin-top:4px; }
.bubble .agent-tag { display:block; font-size:10.5px; font-weight:700; opacity:.85; margin-bottom:3px; }
.thread-compose {
  display:flex; gap:8px; padding:12px 16px; border-top:1px solid var(--border); background:#fff;
}
.thread-compose input { flex:1; }

/* ===== Responsive ===== */
@media (max-width: 860px) {
  #shell { flex-direction:column; }
  #sidebar { width:100%; height:auto; position:static; padding:10px 14px; }
  #logo { margin-bottom:6px; padding-bottom:10px; }
  #tabs { flex-direction:row; overflow-x:auto; }
  .nav-section { display:none; }
  #tabs button { white-space:nowrap; padding:8px 10px; }
  #tabs button .txt .d { display:none; }
  #tabs button.active::after { display:none; }
  #sidefoot { display:none; }
  main, #topbar { padding-left:16px; padding-right:16px; }
}
