:root {
  --bg: #f6f4ef; --surface: #ffffff; --text: #1e1d1a; --muted: #6d6a63; --line: #e4e0d6;
  --accent: #2f6fed; --accent-2: #e8effd; --accent-text: #fff;
  --warn-bg: #fff3d1; --warn-text: #7a5200; --ok-bg: #e2f3e6; --ok-text: #1f6b35; --bad-bg: #fde3df; --bad-text: #8a1f14;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412; --surface: #1e1e1b; --text: #ecebe6; --muted: #a3a199; --line: #34332e;
    --accent: #6d9bff; --accent-2: #1b2a4a; --accent-text: #0b1a3a;
    --warn-bg: #3d2f08; --warn-text: #ffd97a; --ok-bg: #0f3320; --ok-text: #9be3b0; --bad-bg: #40130f; --bad-text: #ffb3ab;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font: inherit; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
  padding: 36px 28px; text-align: center; box-shadow: var(--shadow);
}
.login .logo { margin-bottom: 14px; }
.login h1 { font-size: 26px; margin: 0 0 8px; letter-spacing: -.02em; }
.login .lead { color: var(--muted); margin: 0 0 24px; }
.gsi { display: flex; justify-content: center; min-height: 44px; margin-bottom: 14px; }
.muted { color: var(--muted); } .small { font-size: 13px; }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top-inner { max-width: 1000px; margin: 0 auto; padding: 10px 14px; display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 999px; padding: 3px; margin-left: auto; }
.tab { border: 0; background: transparent; color: var(--muted); padding: 7px 14px; border-radius: 999px; cursor: pointer; font-weight: 600; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.account { display: flex; align-items: center; gap: 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; }
.user { font-size: 13px; color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) {
  .brand span { display: none; }
  .user { display: none; }
}

main { max-width: 1000px; margin: 0 auto; padding: 14px 14px 90px; }

/* ---------- controls ---------- */
.search input {
  width: 100%; font: inherit; font-size: 17px; padding: 13px 16px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text); outline: none; box-shadow: var(--shadow);
}
.search input:focus { border-color: var(--accent); }
.filters { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
@media (min-width: 720px) { .filters { grid-template-columns: repeat(4, 1fr); } }
select, input, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; width: 100%;
}
.summary { color: var(--muted); font-size: 13px; margin: 14px 2px 8px; }
.banner { margin: 12px 0 4px; padding: 10px 14px; border-radius: 12px; background: var(--warn-bg); color: var(--warn-text); font-size: 14px; cursor: pointer; }

/* ---------- list ---------- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
@media (min-width: 720px) { .list { grid-template-columns: 1fr 1fr; } }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; box-shadow: var(--shadow); transition: transform .08s ease;
}
.card:active { transform: scale(.985); }
.card .t { font-weight: 600; grid-column: 1; }
.card .d { color: var(--muted); font-size: 13px; grid-column: 2; grid-row: 1; white-space: nowrap; }
.card .s { color: var(--muted); font-size: 13px; grid-column: 1 / -1; }
.card .s b { color: var(--text); font-weight: 500; }
.tag { display: inline-block; font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); margin: 4px 4px 0 0; }
.tag.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.tag.ok { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.tag.bad { background: var(--bad-bg); color: var(--bad-text); border-color: transparent; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; cursor: pointer;
  font-weight: 600; padding: 10px 16px; border-radius: 11px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
}
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn.ghost { background: transparent; color: var(--accent); border-color: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.wide { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: .6; cursor: default; }
.icon { font: inherit; font-size: 20px; background: none; border: 0; color: var(--text); cursor: pointer; padding: 4px 8px; }
.empty, .foot { color: var(--muted); text-align: center; font-size: 13px; margin-top: 22px; }
.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--accent-text); font-size: 28px; box-shadow: var(--shadow); cursor: pointer; z-index: 4;
}

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; gap: 12px; min-height: 50vh; padding-bottom: 10px; }
.msg { display: flex; flex-direction: column; max-width: 85%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; }
.bubble { padding: 11px 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); white-space: pre-wrap; box-shadow: var(--shadow); }
.msg.user .bubble { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.bubble.thinking { color: var(--muted); font-style: italic; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; text-align: left; }
.chip.doc { background: var(--accent-2); border-color: transparent; color: var(--text); }
.askbar { position: sticky; bottom: 0; display: flex; gap: 8px; padding: 10px 0 calc(6px + env(safe-area-inset-bottom)); background: var(--bg); }
.askbar input { flex: 1; font-size: 16px; padding: 12px 14px; border-radius: 999px; }
.askbar .btn { border-radius: 999px; }

/* ---------- detail ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 9; }
.sheet { position: fixed; inset: 0; z-index: 10; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch; }
@media (min-width: 900px) { .sheet { left: auto; width: 600px; box-shadow: -8px 0 30px rgba(0,0,0,.2); } }
.sheet-head { position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 6px; padding: 8px 10px; z-index: 1; }
.sheet-head h2 { font-size: 16px; margin: 0; line-height: 1.3; }
.sheet-body { padding: 12px 14px 40px; }
.badges { margin-bottom: 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 12px 0; font-size: 14px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-word; }
.preview { margin-top: 12px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); min-height: 120px; }
.preview iframe { width: 100%; height: 62vh; border: 0; display: block; }
.preview-loading { padding: 40px; text-align: center; color: var(--muted); }
.edit { margin-top: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.edit h3 { margin: 0 0 10px; font-size: 15px; }
.edit label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.edit label > input, .edit label > select, .edit label > textarea { margin-top: 4px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; box-shadow: var(--shadow);
}
