:root {
  --bg: #faf9f7;
  --panel: #ffffff;
  --line: #e8e5e0;
  --text: #2c2a27;
  --muted: #8a857d;
  --accent: #d97757;
  --accent-soft: #fbeee8;
  --radius: 12px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- login ---------- */
.login-wrap { height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  width: 340px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 32px 28px; box-shadow: 0 8px 30px rgba(0,0,0,.05);
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; margin-bottom: 20px; }
.asterisk {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--accent); font-size: 20px; font-weight: 700;
}
.login-card input {
  width: 100%; margin-bottom: 12px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 10px;
  padding: 8px 14px; color: var(--text);
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--text); color: #fff; border-color: var(--text); width: 100%; padding: 10px; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.error { color: #b3402a; font-size: .9em; min-height: 1.2em; margin: 4px 0 8px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 280px 1fr; height: 100vh; }
.shell.with-files { grid-template-columns: 280px 1fr 340px; }

.sidebar {
  background: #f4f2ef; border-right: 1px solid var(--line);
  padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
}
.sidebar .logo { margin-bottom: 12px; }
.side-btn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; border: 0; background: transparent; border-radius: 8px;
  text-align: left; color: var(--text);
}
.side-btn:hover, .side-btn.active { background: #e9e6e1; }
.side-label { font-size: .72em; letter-spacing: .08em; color: var(--muted); margin: 14px 0 4px 8px; text-transform: uppercase; }
.count { margin-left: auto; color: var(--muted); font-size: .85em; }
.search {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); margin: 6px 0;
}

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; height: 100vh; min-width: 0; background: var(--panel); }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 10px 18px;
  border-bottom: 1px solid var(--line); font-size: .92em;
}
.crumb { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb .dot { color: #3aa76d; margin-left: 6px; }
.usage { color: var(--muted); white-space: nowrap; }
.tabs { margin-left: auto; display: flex; gap: 4px; }
.tab { border: 0; background: transparent; padding: 6px 10px; border-radius: 8px; color: var(--muted); }
.tab:hover { background: var(--bg); color: var(--text); }
.tab.active { background: #efece8; color: var(--text); }

.chat-scroll { flex: 1; overflow-y: auto; padding: 24px 0; }
.chat-inner { max-width: 760px; margin: 0 auto; padding: 0 20px; }

.hero { text-align: center; margin-top: 12vh; }
.hero .asterisk { width: 64px; height: 64px; font-size: 34px; margin-bottom: 14px; }
.hero h1 { margin: 0 0 6px; font-size: 1.7em; }
.hero .sub { color: var(--muted); margin-bottom: 10px; }
.model-pill {
  display: inline-flex; gap: 6px; align-items: center; background: var(--bg);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: .88em;
}

.msg { margin-bottom: 18px; line-height: 1.55; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: #f1eeea; border-radius: 14px; padding: 10px 14px; max-width: 85%;
  white-space: pre-wrap;
}
.msg.assistant .bubble { white-space: pre-wrap; }
.msg .tool {
  display: inline-block; background: var(--accent-soft); color: #a2542f;
  border-radius: 8px; padding: 2px 10px; font-size: .82em; margin: 4px 0;
  font-weight: 600; letter-spacing: .04em;
}
.msg code, .file-view pre { background: #f4f2ef; border-radius: 6px; padding: 1px 5px; }

.composer-wrap { padding: 14px 20px 8px; }
.composer {
  max-width: 760px; margin: 0 auto; background: var(--bg);
  border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px; position: relative;
}
.composer textarea {
  width: 100%; border: 0; background: transparent; resize: none; outline: none;
  min-height: 44px; max-height: 200px; padding: 4px 6px;
}
.composer-row { display: flex; align-items: center; gap: 8px; }
.composer select {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 4px 10px; font-size: .85em;
}
.send {
  margin-left: auto; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: var(--text); color: #fff; font-size: 16px;
}
.send:disabled { opacity: .4; cursor: default; }
.hint { text-align: center; color: var(--muted); font-size: .78em; padding: 6px 0 12px; }

/* slash palette */
.palette {
  position: absolute; bottom: calc(100% + 8px); left: 0; right: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.08); overflow: hidden; z-index: 5;
}
.palette .item { display: flex; gap: 12px; padding: 9px 14px; cursor: pointer; }
.palette .item:hover, .palette .item.sel { background: var(--bg); }
.palette .cmd { font-family: ui-monospace, monospace; color: var(--text); min-width: 110px; }
.palette .desc { color: var(--muted); }

/* ---------- files panel ---------- */
.files {
  border-left: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; min-width: 0;
}
.files-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--line); font-size: .85em; color: var(--muted);
}
.files-head .grow { flex: 1; }
.files-body { flex: 1; overflow: auto; padding: 8px; font-size: .9em; }
.tree-item { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.tree-item:hover { background: var(--bg); }
.tree-kids { margin-left: 16px; }
.ficon { width: 16px; text-align: center; color: var(--muted); }
.dir > .tree-item .ficon { color: #d9a057; }

.file-view { position: fixed; inset: 0; background: rgba(30,28,25,.35); display: flex; z-index: 20; }
.file-card {
  margin: auto; width: min(900px, 94vw); height: min(86vh, 900px);
  background: var(--panel); border-radius: 14px; display: flex; flex-direction: column; overflow: hidden;
}
.file-card header {
  display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line);
  font-size: .9em;
}
.file-card header .path { font-family: ui-monospace, monospace; color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; }
.file-card .body { flex: 1; overflow: auto; }
.file-card iframe, .file-card img { width: 100%; height: 100%; border: 0; object-fit: contain; }
.file-card textarea {
  width: 100%; height: 100%; border: 0; outline: none; resize: none;
  padding: 14px; font-family: ui-monospace, monospace; font-size: .9em;
}

/* ---------- admin ---------- */
.admin { max-width: 860px; margin: 0 auto; padding: 24px 20px; overflow-y: auto; }
.admin h1 { display: flex; align-items: center; }
.admin h1 .btn { margin-left: auto; font-weight: 400; }
.admin-tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.admin-tabs button {
  border: 0; background: none; padding: 8px 2px; color: var(--muted);
  border-bottom: 2px solid transparent;
}
.admin-tabs button.active { color: var(--text); border-color: var(--text); }
.card {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row input, .row select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
}
.badge { font-size: .78em; padding: 2px 8px; border-radius: 999px; background: #e9e6e1; color: var(--muted); }
.badge.admin { background: #e2f3e8; color: #2c7a4b; }
.badge.off { background: #f7e3de; color: #b3402a; }
.chip {
  display: inline-flex; gap: 6px; align-items: center; background: #eef7f0; color: #2c7a4b;
  border-radius: 999px; padding: 2px 10px; font-size: .82em; margin: 2px 4px 0 0;
}
.chip button { border: 0; background: none; color: inherit; padding: 0; }
.mini-label { font-size: .72em; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; display: block; margin-bottom: 4px; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

@media (max-width: 900px) {
  .shell, .shell.with-files { grid-template-columns: 1fr; }
  .sidebar, .files { display: none; }
}

/* ---------- panel additions ---------- */
.empty { color: var(--muted); padding: 18px 10px; line-height: 1.5; }
.empty code { background: #f4f2ef; border-radius: 4px; padding: 1px 5px; }

.art-card {
  display: flex; gap: 10px; align-items: center; padding: 10px;
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px;
  cursor: pointer; background: var(--panel);
}
.art-card:hover { border-color: var(--muted); }
.art-icon { font-size: 22px; }
.art-meta { min-width: 0; }
.art-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.think-item {
  display: flex; gap: 8px; align-items: baseline; padding: 8px 6px;
  border-bottom: 1px dashed var(--line); font-size: .9em;
}
.think-item .tool {
  background: var(--accent-soft); color: #a2542f; border-radius: 8px;
  padding: 2px 8px; font-size: .8em; font-weight: 600;
}
.think-line { padding: 6px; }

/* ---------- markdown body ---------- */
.md-body { line-height: 1.6; }
.md-body h1, .md-body h2, .md-body h3 { margin: .8em 0 .4em; line-height: 1.25; }
.md-body p { margin: .5em 0; }
.md-body pre {
  background: #f4f2ef; border-radius: 8px; padding: 10px 12px; overflow-x: auto;
  font-size: .88em;
}
.md-body table { border-collapse: collapse; margin: .6em 0; }
.md-body th, .md-body td { border: 1px solid var(--line); padding: 5px 10px; }
.md-body th { background: #2e3a4d; color: #fff; }
.md-body tr:nth-child(even) td { background: #f7f5f2; }
.md-body blockquote { border-left: 3px solid var(--accent); margin: .6em 0; padding: 2px 12px; color: var(--muted); }
.md-page { max-width: 720px; margin: 0 auto; padding: 24px; }

/* ---------- office viewers ---------- */
.office-view { padding: 16px; overflow: auto; height: 100%; }
.sheet-tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.sheet-tab.active { background: var(--text); color: #fff; border-color: var(--text); }
.xl-table table { border-collapse: collapse; font-size: .88em; }
.xl-table td, .xl-table th { border: 1px solid var(--line); padding: 4px 8px; white-space: nowrap; }
.xl-table tr:first-child td { background: #2e3a4d; color: #fff; font-weight: 600; }
.fv-full { height: 100%; }
.fv-full textarea {
  width: 100%; height: 100%; border: 0; outline: none; resize: none;
  padding: 14px; font-family: ui-monospace, monospace; font-size: .9em;
}

/* ---------- artifact card in chat ---------- */
.chat-art {
  display: flex; gap: 12px; align-items: center; max-width: 480px;
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px;
  background: var(--bg); cursor: pointer;
}
.chat-art:hover { border-color: var(--accent); }
.chat-art .art-open { margin-left: auto; color: var(--accent); font-size: .85em; white-space: nowrap; }
