:root {
  --bg: #F2F4F8;
  --surface: #FFFFFF;
  --surface2: #E8ECF1;
  --surface3: #D8DEE6;
  --border: #D0D7E0;
  --border2: #C0C8D4;
  --text: #1D2433;
  --muted: #5A6578;
  --muted2: #8B95A5;
  --cyan: #0891B2;
  --purple: #7C3AED;
  --green: #16A34A;
  --amber: #CA8A04;
  --red: #DC2626;
  --gradient: linear-gradient(135deg, #0891B2 0%, #7C3AED 100%);
  --radius: 10px;
  --rail-w: 56px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; line-height: 1.5; height: 100%; font-size: 14px; }

/* ── Login ── */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 40px 36px; width: 360px; text-align: center; }
.login-logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 24px; }
.logo-pill { background: var(--gradient); border-radius: 10px; padding: 6px 14px; font-weight: 800; font-size: 1.1rem; color: #fff; letter-spacing: -0.3px; }
.login-card h1 { font-size: 1.1rem; font-weight: 600; margin-bottom: 6px; }
.login-card p { color: var(--muted); font-size: 0.85rem; margin-bottom: 28px; }
.login-error { color: var(--red); font-size: 0.8rem; margin-top: 12px; }

/* ── Layout ── */
.shell { display: flex; height: 100vh; overflow: hidden; }

/* ── Rail ── */
.rail { width: var(--rail-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding: 12px 0; flex-shrink: 0; }
.rail-logo { width: 34px; height: 34px; background: var(--gradient); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 0.75rem; color: #fff; margin-bottom: 20px; cursor: pointer; }
.rail-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.rail-btn { width: 40px; height: 40px; border-radius: 8px; display: flex; align-items: center; justify-content: center; background: none; border: none; cursor: pointer; color: var(--muted); transition: all 0.15s; position: relative; }
.rail-btn:hover { background: var(--surface2); color: var(--text); }
.rail-btn.active { background: rgba(8,145,178,0.10); color: var(--cyan); }
.rail-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rail-tooltip { position: absolute; left: 52px; background: var(--surface3); border: 1px solid var(--border2); border-radius: 6px; padding: 4px 10px; font-size: 0.75rem; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity 0.1s; z-index: 999; }
.rail-btn:hover .rail-tooltip { opacity: 1; }
.rail-badge { position: absolute; top: 4px; right: 4px; background: var(--red); color: #fff; border-radius: 99px; font-size: 0.6rem; font-weight: 700; min-width: 14px; height: 14px; display: flex; align-items: center; justify-content: center; padding: 0 3px; }
.rail-bottom { margin-top: auto; }

/* ── Main ── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar { height: 52px; border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 24px; gap: 12px; flex-shrink: 0; background: var(--surface); }
.topbar-title { font-size: 0.9rem; font-weight: 600; }
.topbar-sub { color: var(--muted); font-size: 0.8rem; }
.topbar-sep { color: var(--border2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.admin-pill { background: rgba(124,58,237,0.10); color: var(--purple); border-radius: 6px; padding: 3px 10px; font-size: 0.72rem; font-weight: 600; }

/* ── Content ── */
.content { flex: 1; overflow-y: auto; padding: 24px; }
.content-split { display: flex; gap: 20px; height: 100%; overflow: hidden; }
.list-pane { flex: 0 0 460px; overflow-y: auto; display: flex; flex-direction: column; gap: 0; }
.detail-pane { flex: 1; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }

/* ── Stat cards ── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 28px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.stat-label { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.8px; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1; }
.stat-value.cyan { color: var(--cyan); }
.stat-value.purple { color: var(--purple); }
.stat-value.green { color: var(--green); }
.stat-value.amber { color: var(--amber); }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-head h2 { font-size: 0.85rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; }

/* ── Table ── */
.tbl-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th { padding: 10px 14px; text-align: left; font-size: 0.72rem; font-weight: 600; color: var(--muted); letter-spacing: 0.6px; text-transform: uppercase; border-bottom: 1px solid var(--border); background: var(--surface2); }
tbody tr { border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody tr.selected { background: rgba(8,145,178,0.06); }
tbody td { padding: 11px 14px; font-size: 0.83rem; }
.td-muted { color: var(--muted); font-size: 0.78rem; }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 5px; font-size: 0.72rem; font-weight: 600; }
.badge-green  { background: rgba(22,163,74,0.10); color: var(--green); }
.badge-amber  { background: rgba(202,138,4,0.10); color: var(--amber); }
.badge-red    { background: rgba(220,38,38,0.10); color: var(--red); }
.badge-cyan   { background: rgba(8,145,178,0.10); color: var(--cyan); }
.card-mini { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.badge-purple { background: rgba(124,58,237,0.10); color: var(--purple); }
.badge-gray   { background: var(--surface3); color: var(--muted); }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 7px; font-size: 0.82rem; font-weight: 500; border: none; cursor: pointer; transition: all 0.15s; text-decoration: none; }
.btn-primary { background: var(--gradient); color: #fff; }
.btn-primary:hover { opacity: 0.88; }
.btn-ghost  { background: var(--surface2); color: var(--text); border: 1px solid var(--border2); }
.btn-ghost:hover { background: var(--surface3); }
.btn-cyan   { background: rgba(8,145,178,0.10); color: var(--cyan); border: 1px solid rgba(8,145,178,0.18); }
.btn-cyan:hover { background: rgba(8,145,178,0.18); }
.btn-purple { background: rgba(124,58,237,0.10); color: var(--purple); border: 1px solid rgba(124,58,237,0.18); }
.btn-purple:hover { background: rgba(124,58,237,0.18); }
.btn-red    { background: rgba(220,38,38,0.10); color: var(--red); border: 1px solid rgba(220,38,38,0.18); }
.btn-red:hover { background: rgba(220,38,38,0.20); }
.btn-sm { padding: 4px 10px; font-size: 0.76rem; }
.btn-icon { padding: 6px; }
.btn-amber { background: rgba(202,138,4,0.10); color: var(--amber); border: 1px solid rgba(202,138,4,0.18); }
.btn-amber:hover { background: rgba(202,138,4,0.20); }

/* ── Detail pane ── */
.detail-header { padding: 20px 24px 0; border-bottom: 1px solid var(--border); }
.detail-name { font-size: 1.1rem; font-weight: 700; margin-bottom: 4px; }
.detail-meta { font-size: 0.78rem; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.detail-actions { display: flex; gap: 8px; padding-bottom: 16px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; padding-top: 4px; }
.tab { padding: 8px 14px; font-size: 0.82rem; font-weight: 500; color: var(--muted); border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.15s; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--cyan); border-bottom-color: var(--cyan); }
.detail-body { padding: 20px 24px; }
.detail-empty { text-align: center; padding: 48px 24px; color: var(--muted); font-size: 0.85rem; }

/* ── Forms & inputs ── */
input, select, textarea {
  background: var(--surface2); border: 1px solid var(--border2); border-radius: 7px;
  color: var(--text); font-size: 0.85rem; padding: 8px 12px; width: 100%;
  font-family: inherit; outline: none; transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--cyan); }
textarea { resize: vertical; min-height: 80px; }
.form-row { margin-bottom: 14px; }
.form-label { font-size: 0.78rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; display: block; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 8px; margin-top: 18px; justify-content: flex-end; }

/* ── Modal ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); z-index: 500; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--surface); border: 1px solid var(--border2); border-radius: 12px; padding: 28px; width: 440px; max-width: 95vw; }
.modal h2 { font-size: 1rem; font-weight: 700; margin-bottom: 20px; }

/* ── Sublist ── */
.sub-list { display: flex; flex-direction: column; gap: 8px; }
.sub-item { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.sub-item-main { flex: 1; }
.sub-item-name { font-size: 0.85rem; font-weight: 500; }
.sub-item-meta { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.sub-item-actions { display: flex; gap: 6px; }

/* ── Config viewer ── */
.config-block { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin-bottom: 12px; }
.config-block-label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin-bottom: 6px; }
.config-block-value { font-size: 0.83rem; color: var(--text); white-space: pre-wrap; word-break: break-word; }

/* ── Message thread ── */
.msg-list { display: flex; flex-direction: column; gap: 8px; }
.msg-bubble { padding: 10px 14px; border-radius: 10px; max-width: 75%; font-size: 0.83rem; line-height: 1.5; }
.msg-bubble.inbound { background: var(--surface2); border: 1px solid var(--border); align-self: flex-start; }
.msg-bubble.outbound { background: rgba(8,145,178,0.10); border: 1px solid rgba(8,145,178,0.18); align-self: flex-end; }
.msg-meta { font-size: 0.7rem; color: var(--muted); margin-top: 3px; }

/* ── Toast ── */
#toast-root { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface3); border: 1px solid var(--border2); border-radius: 8px; padding: 10px 16px; font-size: 0.83rem; animation: slide-in 0.2s ease; max-width: 320px; }
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.warning { border-left: 3px solid var(--amber); }
@keyframes slide-in { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── SSO button ── */
.sso-btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 11px 16px; background: var(--surface2); border: 1px solid var(--border2); border-radius: 8px; color: var(--text); font-size: 0.875rem; font-weight: 500; text-decoration: none; cursor: pointer; transition: background 0.15s; }
.sso-btn:hover { background: var(--surface3); }

/* ── Content area ── */
.content-area { padding: 24px; }

/* ── Misc ── */
.empty-state { text-align: center; padding: 40px 24px; color: var(--muted); }
.empty-state svg { width: 40px; height: 40px; stroke: var(--muted2); margin-bottom: 12px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 0.78rem; }
.mt-16 { margin-top: 16px; }
.flex-gap { display: flex; gap: 8px; flex-wrap: wrap; }
.no-results { padding: 32px; text-align: center; color: var(--muted); font-size: 0.85rem; }
.search-bar { position: relative; margin-bottom: 14px; }
.search-bar input { padding-left: 34px; }
.search-bar svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; stroke: var(--muted); pointer-events: none; }
