:root {
  --bg: #ffffff;
  --side: #f9f9f8;
  --hover: #efefed;
  --line: #ebebea;
  --line-strong: #dcdcda;
  --ink: #1d1d1b;
  --ink-2: #4a4a47;
  --muted: #8a8a86;
  --accent: #2f5bea;
  --accent-soft: #edf2ff;
  --green: #1f8a4c; --green-soft: #e8f6ee;
  --amber: #b26a00; --amber-soft: #fdf3e2;
  --red: #c4362c; --red-soft: #fcecea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink); font-size: 14px; line-height: 1.5;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: #fff; padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #000; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px; background: #fff; outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 12px; }
label.field > .input, label.field > select, label.field > textarea { margin-top: 5px; font-weight: 400; font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 500px at 50% -10%, #f1f4ff 0%, #fff 60%); }
.login-card { width: 380px; text-align: center; padding: 40px 32px; border: 1px solid var(--line); border-radius: 16px; background: #fff; box-shadow: var(--shadow); }
.login-card h1 { font-size: 24px; margin: 16px 0 6px; letter-spacing: -.02em; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.login-card .gbtn { display: flex; justify-content: center; min-height: 44px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 20px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.logo { width: 44px; height: 44px; border-radius: 12px; background: var(--ink); display: inline-grid; place-items: center; }
.logo svg { width: 26px; }
.logo.sm { width: 26px; height: 26px; border-radius: 7px; }
.logo.sm svg { width: 16px; }
.lock-note { margin-top: 22px; font-size: 12px; color: var(--muted); display: flex; gap: 6px; justify-content: center; align-items: center; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 14px 14px 8px; display: flex; align-items: center; gap: 9px; font-weight: 600; }
.side-head .org { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-section { padding: 4px 8px; }
.side-label { font-size: 11px; font-weight: 600; color: var(--muted); padding: 12px 8px 4px; text-transform: uppercase; letter-spacing: .04em; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--ink-2); font-weight: 500; user-select: none; }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--hover); color: var(--ink); }
.nav-item svg { width: 16px; height: 16px; flex: none; opacity: .8; }
.nav-item .badge { margin-left: auto; }
.new-chat { width: 100%; justify-content: center; margin: 6px 0 4px; }
.history { flex: 1; overflow-y: auto; padding: 0 8px 8px; min-height: 0; }
.history .nav-item { font-weight: 400; font-size: 13px; }
.history .nav-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.history .nav-item .x { visibility: hidden; color: var(--muted); padding: 0 2px; }
.history .nav-item:hover .x { visibility: visible; }
.side-foot { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #dfe5ff; color: var(--accent); display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.who { min-width: 0; flex: 1; line-height: 1.25; }
.who b { display: block; font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { overflow-y: auto; min-width: 0; position: relative; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: var(--hover); color: var(--ink-2); white-space: nowrap; }
.badge.founder { background: #f3e8ff; color: #7a3fc4; }
.badge.admin { background: #1d1d1b; color: #fff; }
.badge.manager { background: var(--accent-soft); color: var(--accent); }
.badge.member { background: var(--hover); }
.badge.ready, .badge.high { background: var(--green-soft); color: var(--green); }
.badge.processing, .badge.medium { background: var(--amber-soft); color: var(--amber); }
.badge.failed, .badge.low, .badge.none { background: var(--red-soft); color: var(--red); }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 6px; background: #f1f1ef; color: var(--ink-2); margin: 0 4px 4px 0; }

/* ---------- page ---------- */
.page { max-width: 1080px; margin: 0 auto; padding: 36px 40px 60px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 24px; }
.page-head h1 { font-size: 26px; letter-spacing: -.02em; margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.card { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 18px; }
.card h3 { margin: 0 0 12px; font-size: 14px; }
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; height: 100vh; }
.chat-top { display: flex; align-items: center; gap: 10px; padding: 10px 20px; border-bottom: 1px solid transparent; }
.chat-top select { width: auto; padding: 5px 8px; border-color: transparent; background: transparent; font-weight: 500; cursor: pointer; }
.chat-top select:hover { background: var(--hover); }
.thread { flex: 1; overflow-y: auto; }
.thread-inner { max-width: 760px; margin: 0 auto; padding: 20px 24px 40px; }
.hero { text-align: center; padding: 12vh 0 30px; }
.hero h2 { font-size: 28px; letter-spacing: -.02em; margin: 18px 0 6px; }
.hero p { color: var(--muted); margin: 0; }
.suggest { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 32px; text-align: left; }
.suggest button { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 12px 14px; cursor: pointer; color: var(--ink-2); text-align: left; }
.suggest button:hover { background: var(--side); }
.msg { margin: 22px 0; display: flex; gap: 12px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: #f3f3f1; padding: 10px 14px; border-radius: 16px; max-width: 80%; white-space: pre-wrap; }
.msg.ai .icon { flex: none; margin-top: 2px; }
.msg.ai .body { flex: 1; min-width: 0; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md h1, .md h2, .md h3 { font-size: 15px; margin: 14px 0 6px; }
.md code { background: #f3f3f1; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.md em { color: var(--muted); }
.md table { border-collapse: collapse; margin: 8px 0 12px; font-size: 13px; }
.md td, .md th { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.cite { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; font-size: 11px; font-weight: 600; border-radius: 5px; background: var(--accent-soft); color: var(--accent); cursor: pointer; vertical-align: 2px; margin: 0 1px; }
.meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.sources { margin-top: 10px; display: grid; gap: 6px; }
.source { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; background: #fff; }
.source.flash { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.source-head { display: flex; align-items: center; gap: 8px; }
.source-head b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source .ex { color: var(--ink-2); margin-top: 4px; font-size: 12.5px; border-left: 2px solid var(--line-strong); padding-left: 8px; }
.source .ex mark { background: #fff4c2; padding: 0 1px; }
.composer-wrap { padding: 0 24px 18px; }
.composer { max-width: 760px; margin: 0 auto; border: 1px solid var(--line-strong); border-radius: 16px; padding: 10px 10px 10px 16px; display: flex; gap: 8px; align-items: flex-end; box-shadow: var(--shadow); background: #fff; }
.composer textarea { flex: 1; border: 0; outline: none; resize: none; max-height: 200px; padding: 6px 0; background: transparent; }
.send { width: 34px; height: 34px; border-radius: 10px; border: 0; background: var(--ink); color: #fff; cursor: pointer; display: grid; place-items: center; }
.send:disabled { background: var(--line-strong); cursor: default; }
.disclaimer { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 8px; }
.typing span { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); margin-right: 4px; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s } .typing span:nth-child(3) { animation-delay: .4s }
@keyframes blink { 0%, 80%, 100% { opacity: .2 } 40% { opacity: 1 } }
.conf { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.conf-bar { width: 46px; height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.conf-bar i { display: block; height: 100%; }

/* ---------- library ---------- */
.pills { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.pill { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.pill.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.pill .n { opacity: .6; margin-left: 4px; }
.doc-list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.doc-row { display: grid; grid-template-columns: 34px 1fr 130px 110px 90px; gap: 12px; align-items: center; padding: 11px 14px; border-top: 1px solid var(--line); cursor: pointer; background: #fff; }
.doc-row:first-child { border-top: 0; }
.doc-row:hover { background: var(--side); }
.doc-row .t b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-row .t span { font-size: 12px; color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ftype { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; font-size: 10px; font-weight: 700; color: #fff; text-transform: uppercase; }
.drawer-bg { position: fixed; inset: 0; background: rgba(20,20,20,.25); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 520px; max-width: 100%; background: #fff; z-index: 41; box-shadow: -10px 0 30px rgba(0,0,0,.08); overflow-y: auto; padding: 24px 26px; }
.drawer h2 { margin: 8px 0 4px; font-size: 20px; letter-spacing: -.01em; }
.drawer section { margin-top: 22px; }
.drawer section h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.decisions li { margin-bottom: 6px; }
.modal { position: fixed; z-index: 41; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 460px; max-width: 94vw; max-height: 86vh; overflow-y: auto; background: #fff; border-radius: 14px; padding: 22px; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 14px; }
.checks { display: grid; gap: 6px; max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.checks label { display: flex; gap: 8px; align-items: center; font-size: 13px; }

/* ---------- upload ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab { padding: 8px 14px; cursor: pointer; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); }
.drop { border: 1.5px dashed var(--line-strong); border-radius: 12px; padding: 38px 20px; text-align: center; color: var(--muted); cursor: pointer; background: var(--side); transition: .15s; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.drop b { color: var(--ink); display: block; font-size: 15px; margin: 8px 0 4px; }
.filelist { margin-top: 12px; display: grid; gap: 6px; }
.filelist div { display: flex; justify-content: space-between; font-size: 13px; padding: 6px 10px; background: var(--side); border-radius: 6px; }
.upload-grid { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }

/* ---------- dashboard ---------- */
.kpi { padding: 16px 18px; }
.kpi .v { font-size: 26px; font-weight: 600; letter-spacing: -.02em; margin-top: 2px; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chart svg { width: 100%; display: block; }
.hbar { display: grid; grid-template-columns: 110px 1fr 36px; gap: 10px; align-items: center; font-size: 13px; margin: 7px 0; }
.hbar .track { height: 8px; background: #f1f1ef; border-radius: 4px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.hbar .n { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th { text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl select { padding: 4px 6px; width: auto; }

/* ---------- workspaces ---------- */
.ws-card { cursor: default; }
.ws-card .ic { font-size: 22px; }
.ws-card h4 { margin: 8px 0 2px; font-size: 15px; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60; }
#toast div { background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 10px; margin-top: 6px; box-shadow: var(--shadow); font-size: 13px; }
#toast div.err { background: var(--red); }

.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line-strong); border-radius: 20px; cursor: pointer; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--ink); }
.switch input:checked + span::before { transform: translateX(16px); }
.setting { display: flex; gap: 16px; align-items: center; padding: 14px 0; border-top: 1px solid var(--line); }
.setting:first-of-type { border-top: 0; }
.setting .d { flex: 1; }
.setting .d b { display: block; font-weight: 500; }
.setting .d span { font-size: 13px; color: var(--muted); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .g4 { grid-template-columns: 1fr 1fr; } .g2, .g3, .upload-grid { grid-template-columns: 1fr; }
  .doc-row { grid-template-columns: 34px 1fr 90px; } .doc-row > :nth-child(4), .doc-row > :nth-child(5) { display: none; }
  .page { padding: 24px 18px; }
}
.mobile-menu { display: none; position: fixed; top: 10px; right: 10px; z-index: 30; padding: 6px 8px; }
@media (max-width: 860px) {
  .mobile-menu { display: inline-flex; }
  .side.open { display: flex; position: fixed; inset: 0 30% 0 0; z-index: 50; box-shadow: var(--shadow); }
}
.doc-row .t { min-width: 0; }
.zoho-btn { width: 300px; height: 44px; justify-content: center; gap: 10px; border-radius: 999px; font-weight: 500; color: var(--ink); margin: 0 auto; display: flex; }
