:root {
  --bg: #f7f8fa; --panel: #ffffff; --line: #e3e6eb; --text: #1d2330; --muted: #6b7280;
  --accent: #0e6e8c; --accent-weak: #e6f2f6; --user: #eef1f5;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
button { font: inherit; cursor: pointer; }
button.primary { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 8px 16px; }
button.primary:disabled { opacity: .5; cursor: default; }
button.link { background: none; border: 0; color: var(--accent); padding: 4px 0; }
input, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }

/* login */
#login { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-card { width: min(420px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 28px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card label { display: block; margin: 16px 0 6px; font-size: 14px; }
.login-card button.primary { margin-top: 12px; width: 100%; }
.msg { color: #b42318; min-height: 1.2em; }
.notice { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; margin-top: 16px; }

/* layout */
#app { display: flex; height: 100vh; }
#sidebar { width: 270px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px; }
.brand { font-weight: 600; margin-bottom: 12px; }
.new-chat { display: block; width: 100%; text-align: left; background: var(--accent-weak); border: 1px solid #cfe3ea; border-radius: 6px; padding: 8px 10px; margin-bottom: 6px; color: var(--accent); }
.side-title { margin: 16px 0 6px; font-size: 13px; color: var(--muted); }
#conv-list { flex: 1; overflow-y: auto; }
.conv { display: flex; align-items: center; gap: 6px; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.conv:hover, .conv.active { background: var(--user); }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.conv-meta { font-size: 11px; color: var(--muted); }
.conv-del { background: none; border: 0; color: var(--muted); visibility: hidden; }
.conv:hover .conv-del { visibility: visible; }
.side-foot { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; align-items: flex-start; }

main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
main > header { padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); font-weight: 600; display: flex; justify-content: space-between; }
#messages { flex: 1; overflow-y: auto; padding: 20px; }
.intro { color: var(--muted); max-width: 760px; }
.msg-user, .msg-assistant { max-width: 960px; margin: 0 0 16px; padding: 12px 16px; border-radius: 10px; }
.msg-user { background: var(--user); margin-left: auto; max-width: 760px; }
.msg-assistant { background: var(--panel); border: 1px solid var(--line); }
.plain { white-space: pre-wrap; }
.files { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.msg-assistant table { border-collapse: collapse; margin: 8px 0; font-size: 14px; display: block; overflow-x: auto; }
.msg-assistant th, .msg-assistant td { border: 1px solid var(--line); padding: 5px 8px; vertical-align: top; text-align: left; }
.msg-assistant th { background: var(--bg); }
#progress { padding: 8px 20px; font-size: 13px; color: var(--muted); background: var(--accent-weak); }
.step { font-family: ui-monospace, Consolas, monospace; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#composer { border-top: 1px solid var(--line); background: var(--panel); padding: 12px 20px; }
.composer-row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.attach { color: var(--accent); cursor: pointer; font-size: 14px; }
.chip { display: inline-block; background: var(--user); border-radius: 12px; padding: 2px 10px; margin: 0 6px 6px 0; }
.chip a { cursor: pointer; color: var(--muted); }

/* admin */
#admin { overflow-y: auto; }
.admin-body { padding: 20px; max-width: 1100px; }
.admin-body h2 { font-size: 17px; margin-top: 28px; }
.row { display: flex; gap: 8px; margin-bottom: 10px; }
.row input { flex: 1; }
.admin-body table { border-collapse: collapse; width: 100%; font-size: 14px; background: var(--panel); }
.admin-body th, .admin-body td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; white-space: pre-line; }
.clickable { cursor: pointer; }
.clickable:hover { background: var(--user); }
#admin-conv-view { margin-top: 16px; }

@media (max-width: 760px) {
  #sidebar { width: 210px; }
  .row { flex-direction: column; }
}
.row { flex-wrap: wrap; }
.row select { flex: 1; min-width: 220px; }
.checks { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.checks label { display: inline-flex; gap: 4px; align-items: center; white-space: nowrap; }
td.pre { white-space: pre-line; }
#model { max-width: 60%; }
