:root {
  --bg: #0b0e14;
  --bg-2: #11151f;
  --panel: #161b27;
  --panel-2: #1c2333;
  --border: #232b3d;
  --text: #e6e9f0;
  --muted: #8b95ab;
  --primary: #6366f1;
  --primary-2: #818cf8;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --cyan: #06b6d4;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
a { color: var(--primary-2); text-decoration: none; }
h1,h2,h3 { margin: 0; font-weight: 650; }
small { color: var(--muted); }
input, textarea, select {
  width: 100%; padding: 10px 12px; background: var(--bg-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; font: inherit; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 90px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }

.btn {
  cursor: pointer; border: 1px solid var(--border); background: var(--panel-2);
  color: var(--text); padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 550;
  transition: .15s; display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: #3a2530; color: #fda4af; }
.btn.danger:hover { border-color: var(--red); }
.btn.sm { padding: 6px 10px; font-size: 12px; }

/* ---------- Auth ---------- */
.auth { position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 70% -10%, #1b2440 0%, var(--bg) 55%); }
.auth-card { width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; }
.brand .logo { font-size: 22px; }
/* Lockup: mark + name in the sans, descriptor in the mono. currentColor lets
   the one mark serve the dark hub and the daylight public site alike. */
.brand .mark { width: 28px; height: 28px; flex: none; color: currentColor; }
.brand .wm { display: flex; flex-direction: column; line-height: 1; }
.brand .wm b { font-weight: 800; letter-spacing: -0.025em; font-size: 16px; }
.brand .wm i {
  font-family: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  font-style: normal; font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--muted); margin-top: 3px;
}
.auth-sub { color: var(--muted); margin: 8px 0 18px; }
.tabs { display: flex; gap: 6px; background: var(--bg-2); padding: 4px; border-radius: 10px; margin-bottom: 16px; }
.tab { flex: 1; padding: 8px; border: 0; background: transparent; color: var(--muted); border-radius: 8px; cursor: pointer; font: inherit; }
.tab.active { background: var(--panel-2); color: var(--text); }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.hint { color: var(--muted); font-size: 12px; text-align: center; margin: 4px 0 0; }
.auth-error { color: #fda4af; min-height: 18px; text-align: center; margin: 10px 0 0; font-size: 13px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; height: 100vh; }
.sidebar { background: var(--bg-2); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 12px; }
.sidebar .brand { padding: 4px 8px 18px; font-size: 16px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a { color: var(--muted); padding: 10px 12px; border-radius: 10px; display: flex; align-items: center; gap: 10px; font-weight: 550; }
.nav a .ic { width: 18px; text-align: center; }
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a.active { background: var(--panel-2); color: var(--text); }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.me { display: flex; align-items: center; gap: 10px; }
.me-info { line-height: 1.2; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; background: var(--primary); flex-shrink: 0; }

.main { display: flex; flex-direction: column; overflow: hidden; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; border-bottom: 1px solid var(--border); }
.page-actions { display: flex; gap: 8px; }
.view { padding: 24px; overflow: auto; flex: 1; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.cards { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card.click { cursor: pointer; transition: .15s; }
.card.click:hover { border-color: var(--primary); transform: translateY(-2px); }
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat .num { font-size: 30px; font-weight: 750; }
.stat .lbl { color: var(--muted); font-size: 13px; }

.section-title { display: flex; align-items: center; justify-content: space-between; margin: 24px 0 12px; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--panel-2); }
/* On phones, let wide tables scroll sideways instead of overflowing the page. */
@media (max-width: 600px) {
  .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  .table th, .table td { padding: 9px 11px; }
}

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; border: 1px solid var(--border); }
.badge.code { font-family: ui-monospace, monospace; background: var(--bg-2); }
.p-low { color: #93c5fd; border-color: #1e3a5f; }
.p-medium { color: #fcd34d; border-color: #4a3a16; }
.p-high { color: #fdba74; border-color: #4a3216; }
.p-urgent { color: #fca5a5; border-color: #4a2020; }
.s-open { color: #93c5fd; }
.s-in_progress { color: #fcd34d; }
.s-waiting { color: #c4b5fd; }
.s-resolved { color: #86efac; }
.s-closed { color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.on { background: var(--green); }

.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.spread { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pill { background: var(--bg-2); border: 1px solid var(--border); padding: 4px 10px; border-radius: 8px; font-size: 12px; }

/* ---------- Detail layout ---------- */
.detail { display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; }
.kv .k { color: var(--muted); }
.doc { background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 16px; white-space: pre-wrap; line-height: 1.55; }
.doc h1,.doc h2,.doc h3 { margin: 14px 0 6px; }
.doc code { background: #0d1117; padding: 1px 5px; border-radius: 5px; font-family: ui-monospace, monospace; }
.doc ul,.doc ol { margin: 6px 0; padding-left: 22px; }

/* ---------- Chat ---------- */
.chat { display: grid; grid-template-columns: 220px 1fr 200px; gap: 0; height: calc(100vh - 70px); border-top: 1px solid var(--border); margin: -24px; }
.chat-rail { border-right: 1px solid var(--border); padding: 14px; overflow: auto; }
.chan { padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.chan:hover { background: var(--panel); color: var(--text); }
.chan.active { background: var(--panel-2); color: var(--text); }
.chat-main { display: flex; flex-direction: column; overflow: hidden; }
.chat-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.messages { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; }
.msg .bubble { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.msg .who { font-size: 12px; margin-bottom: 2px; }
.msg .who b { color: var(--text); } .msg .who small { margin-left: 6px; }
.msg.system .bubble { background: transparent; border: 0; color: var(--muted); font-style: italic; }
.composer { border-top: 1px solid var(--border); padding: 12px 16px; display: flex; gap: 10px; }
.composer input { flex: 1; }
.presence { border-left: 1px solid var(--border); padding: 14px; overflow: auto; }
.presence h4 { color: var(--muted); font-size: 12px; text-transform: uppercase; margin: 0 0 10px; }
.pres-user { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.typing { color: var(--muted); font-size: 12px; padding: 0 18px 6px; height: 16px; }

/* ---------- Screen share ---------- */
.rtc-bar { display: flex; gap: 8px; align-items: center; }
.rtc-stage { position: fixed; right: 16px; bottom: 16px; width: 360px; background: #000; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); z-index: 50; }
.rtc-stage video { width: 100%; display: block; background: #000; }
.rtc-stage .rtc-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; background: var(--panel); font-size: 12px; }

/* ---------- Remote terminal ---------- */
.term-stage { position: fixed; right: 16px; bottom: 16px; width: 420px; max-width: calc(100vw - 32px); background: #0b0f14; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); z-index: 50; display: flex; flex-direction: column; }
.term-stage .rtc-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; background: var(--panel); font-size: 12px; }
.term-log { flex: 1; min-height: 160px; max-height: 320px; overflow-y: auto; font-family: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace; font-size: 12px; line-height: 1.5; color: #d1d5db; padding: 8px 10px; white-space: pre-wrap; }
.term-log .err { color: #fda4af; }
.term-input-row { display: flex; gap: 6px; padding: 6px 8px; border-top: 1px solid var(--border); }
.term-input-row input { flex: 1; padding: 6px 8px; font-size: 12px; }

/* ---------- AI ---------- */
.ai-wrap { display: flex; flex-direction: column; height: calc(100vh - 110px); }
.ai-msgs { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 14px; padding: 4px; }
.ai-msg { max-width: 80%; padding: 12px 14px; border-radius: 12px; line-height: 1.55; white-space: pre-wrap; }
.ai-msg.user { align-self: flex-end; background: var(--primary); color: #fff; }
.ai-msg.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); }
.ai-msg.bot code { background: #0d1117; padding: 1px 5px; border-radius: 5px; }

/* ---------- Modal ---------- */
/* Flex + margin:auto centers the modal when it fits and lets the backdrop
   scroll (vertically) when it doesn't — instead of grid clipping it off-screen. */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; justify-content: center; align-items: flex-start; overflow-y: auto; z-index: 100; padding: 24px; }
.modal { width: min(640px, calc(100vw - 24px)); margin: auto; max-height: calc(100vh - 48px); overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 22px; box-shadow: var(--shadow); }
.modal.wide { width: min(820px, calc(100vw - 24px)); }
.modal-body { overflow-wrap: anywhere; }
@media (max-width: 600px) {
  .modal-bg { padding: 10px; }
  .modal, .modal.wide { width: 100%; padding: 16px; border-radius: 12px; max-height: calc(100vh - 20px); }
  .modal .row { flex-wrap: wrap; }
}
.modal h2 { margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Toast ---------- */
.toast-root { position: fixed; right: 18px; top: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--panel-2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); animation: slide .2s; }
.toast.ok { border-color: #1f3a2a; } .toast.err { border-color: #3a2020; }
@keyframes slide { from { transform: translateX(20px); opacity: 0; } }

.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.loading { color: var(--muted); padding: 30px; text-align: center; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 64px 1fr; }
  .sidebar .brand span:last-child, .nav a span:last-child, .me-info { display: none; }
  .detail, .spread { grid-template-columns: 1fr; }
  .chat { grid-template-columns: 1fr; }
  .chat-rail, .presence { display: none; }
}
