:root {
  --bg: #07090e;
  --bg-glow-1: rgba(91, 108, 255, .10);
  --bg-glow-2: rgba(167, 90, 255, .07);
  --surface: rgba(255, 255, 255, .035);
  --surface-2: rgba(255, 255, 255, .06);
  --line: rgba(255, 255, 255, .08);
  --line-strong: rgba(255, 255, 255, .14);
  --text: #eef1f7;
  --muted: #9aa6ba;
  --accent: #6e7bff;
  --accent-2: #9aa4ff;
  --grad: linear-gradient(135deg, #6e7bff 0%, #a06bff 100%);
  --ok: #41c98a; --warn: #e6b04c; --bad: #ef6a62;
  --radius: 16px;
  --shadow: 0 8px 32px rgba(0, 0, 0, .35);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  background-image:
    radial-gradient(800px 500px at 15% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(700px 450px at 95% 110%, var(--bg-glow-2), transparent 60%);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
.mono { font-family: ui-monospace, "SF Mono", monospace; word-break: break-all; font-size: 12px; }

::selection { background: rgba(110, 123, 255, .35); }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .12); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background-color: rgba(255, 255, 255, .22); }
::-webkit-scrollbar-track { background: transparent; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ── Login ─────────────────────────────────────────────── */
.login { display: grid; place-items: center; height: 100vh; padding: 20px; }
.login-card {
  text-align: center; padding: 56px 64px; max-width: 420px;
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.02));
  border: 1px solid var(--line); border-radius: 24px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.06);
  backdrop-filter: blur(20px);
  animation: fadeUp .5s ease both;
}
.login-card .logo { font-size: 34px; margin-bottom: 4px; }
.login-card p { margin: 10px 0 24px; }
.login-card .btn { display: block; margin: 0 auto 12px; }
.login-card a.small { display: inline-block; margin-top: 10px; color: var(--muted); }

.logo {
  font-size: 21px; font-weight: 800; letter-spacing: -.02em;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ── Shell ─────────────────────────────────────────────── */
.shell { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: 232px; flex: none; display: flex; flex-direction: column; gap: 3px;
  padding: 22px 14px; border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, .02); backdrop-filter: blur(20px);
}
.sidebar .logo { padding: 0 12px 2px; }
.tenant-name { padding: 0 12px 18px; font-size: 12px; color: var(--muted); letter-spacing: .02em; }
.nav {
  display: flex; align-items: center; gap: 4px;
  padding: 9px 12px; border-radius: 10px; cursor: pointer;
  color: var(--muted); text-decoration: none; user-select: none;
  font-weight: 500; font-size: 14px;
  transition: color .15s, background .15s;
}
.nav:hover { background: var(--surface-2); color: var(--text); }
.nav.active { background: linear-gradient(135deg, rgba(110,123,255,.16), rgba(160,107,255,.10)); color: var(--accent-2); }
.badge {
  background: var(--grad); color: #fff; border-radius: 999px;
  padding: 1px 7px; font-size: 11px; font-weight: 700; margin-left: 4px;
  box-shadow: 0 2px 8px rgba(110, 123, 255, .45);
}
.spacer { flex: 1; }
.userline { padding: 6px 12px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar form { padding: 0 8px 4px; }

/* ── Main / views ──────────────────────────────────────── */
.main { flex: 1; overflow-y: auto; padding: 28px 32px; }
.view { max-width: 880px; margin: 0 auto; animation: fadeUp .35s ease both; }
.view-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.view-head h2 { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: -.02em; }

.card {
  background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,.02));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 16px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.card h3 { margin: 0 0 8px; font-size: 15px; font-weight: 650; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.input, select, textarea {
  background: rgba(0, 0, 0, .25); color: var(--text);
  border: 1px solid var(--line); border-radius: 11px;
  padding: 10px 13px; font: inherit; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(110, 123, 255, .18);
}
.btn {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 11px;
  padding: 9px 16px; font: inherit; font-weight: 550; cursor: pointer;
  text-decoration: none; display: inline-block;
  transition: transform .12s, box-shadow .15s, border-color .15s, background .15s;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn:active { transform: none; }
.btn.primary {
  background: var(--grad); border: none; color: #fff;
  box-shadow: 0 4px 18px rgba(110, 123, 255, .35);
}
.btn.primary:hover { box-shadow: 0 6px 24px rgba(110, 123, 255, .5); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.small { padding: 5px 12px; font-size: 12.5px; border-radius: 9px; }
.btn.ok { background: linear-gradient(135deg, #34b87c, #4ad295); border: none; color: #04130b; font-weight: 650; box-shadow: 0 4px 16px rgba(65, 201, 138, .3); }
.btn.bad { background: transparent; border-color: rgba(239, 106, 98, .5); color: var(--bad); }
.btn.bad:hover { border-color: var(--bad); background: rgba(239, 106, 98, .08); }

.pill {
  font-size: 12px; font-weight: 600; padding: 4px 12px; border-radius: 999px;
  border: 1px solid var(--line-strong); color: var(--muted);
}
.pill.ok { color: var(--ok); border-color: rgba(65, 201, 138, .4); background: rgba(65, 201, 138, .08); }
.pill.bad { color: var(--bad); border-color: rgba(239, 106, 98, .4); background: rgba(239, 106, 98, .08); }

/* ── Chat ──────────────────────────────────────────────── */
#view-chat { display: flex; flex-direction: column; height: calc(100vh - 56px); height: calc(100dvh - 56px); }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 2px 18px; }
.msg {
  max-width: 74%; padding: 12px 16px; border-radius: 18px;
  white-space: pre-wrap; word-wrap: break-word;
  animation: fadeUp .3s ease both;
}
.msg.user {
  align-self: flex-end; color: #fff;
  background: var(--grad); border-bottom-right-radius: 6px;
  box-shadow: 0 4px 16px rgba(110, 123, 255, .25);
}
.msg.assistant {
  align-self: flex-start; white-space: normal;
  background: var(--surface-2); border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.msg.notice {
  align-self: center; background: transparent; max-width: 88%;
  color: var(--muted); font-size: 13px; text-align: center;
}
.chat-input { display: flex; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.chat-input textarea {
  flex: 1; resize: none; max-height: 140px; border-radius: 14px;
  background: rgba(255, 255, 255, .04);
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 2px 8px; }
.chips-bar { display: flex; justify-content: flex-start; padding-top: 8px; }
.chips-bar .chip { font-size: 12px; padding: 4px 12px; color: var(--muted); }
.chip {
  background: var(--surface); border: 1px solid var(--line-strong); color: var(--text);
  border-radius: 999px; padding: 8px 15px; font-size: 13px; font-weight: 500; cursor: pointer;
  transition: border-color .15s, color .15s, transform .12s, box-shadow .15s;
}
.chip:hover {
  border-color: var(--accent); color: var(--accent-2);
  transform: translateY(-1px); box-shadow: 0 4px 14px rgba(110, 123, 255, .18);
}

/* ── Approvals ─────────────────────────────────────────── */
.approval {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,.02));
  border: 1px solid var(--line); border-left: 3px solid var(--warn);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px;
  animation: fadeUp .3s ease both;
}
.approval .grow { flex: 1; min-width: 0; }
.approval .summary { font-weight: 600; margin-bottom: 2px; }
.approval.done { opacity: .55; border-left-color: var(--line-strong); }

/* ── Activity ──────────────────────────────────────────── */
.event { display: flex; gap: 12px; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: 13px; align-items: baseline; }
.event:last-child { border-bottom: 0; }
.event .ts { color: var(--muted); flex: none; width: 152px; font-variant-numeric: tabular-nums; font-size: 12px; }
.event .type { flex: none; width: 164px; color: var(--accent-2); font-weight: 550; font-family: ui-monospace, monospace; font-size: 12px; }

/* ── Memory ────────────────────────────────────────────── */
#memory-q { width: 100%; margin-bottom: 4px; }
.memcard {
  background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,.02));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin: 12px 0; animation: fadeUp .3s ease both;
}
.memcard .meta { font-size: 11.5px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .06em; }
.memcard strong { font-size: 15px; }
.memcard .prose { margin-top: 6px; color: #c9d2e0; }

/* ── Prose / rendered markdown ─────────────────────────── */
.prose { white-space: pre-wrap; }
.msg h4, .prose h4 {
  margin: 10px 0 5px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; color: var(--accent-2);
}
.msg h4:first-child, .prose h4:first-child { margin-top: 2px; }
.msg .li, .prose .li { padding-left: 6px; margin: 3px 0; }
.msg .sp, .prose .sp { height: 8px; }

/* ── Settings / admin bits ─────────────────────────────── */
.auto-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.auto-row:last-child { border-bottom: 0; }
.auto-row .grow { flex: 1; min-width: 0; }
.risk { font-size: 10.5px; font-weight: 700; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.risk.outward { color: var(--warn); border-color: rgba(230, 176, 76, .45); background: rgba(230, 176, 76, .08); }
.risk.financial { color: var(--bad); border-color: rgba(239, 106, 98, .45); background: rgba(239, 106, 98, .08); }
.small-num { width: 88px; padding: 6px 9px; font-size: 12.5px; }
input[type="checkbox"] { accent-color: var(--accent); width: 17px; height: 17px; cursor: pointer; }

/* ── Mobile ────────────────────────────────────────────── */
@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex-direction: row; align-items: center; gap: 2px;
    overflow-x: auto; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line);
    scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar .logo { padding: 0 8px 0 2px; font-size: 18px; }
  .nav { flex: none; font-size: 13px; padding: 7px 10px; }
  .tenant-name, .userline, .sidebar form, .sidebar .spacer { display: none; }
  .main { padding: 16px 14px; }
  .msg { max-width: 88%; }
  #view-chat { height: calc(100dvh - 110px); }
  .login-card { padding: 40px 28px; }
  .event .ts { width: 118px; }
  .event .type { width: 120px; }
}
