:root {
  --bg: #f6f7fb; --surface: #ffffff; --text: #1d2433; --muted: #667085; --border: #e2e6ef;
  --accent: #3b5bdb; --accent-text: #ffffff; --accent-soft: #e8edff;
  --mark: #3b5bdb; --mark-text: #ffffff; --action: #f1f5f9;
  --paid: #b54708; --paid-bg: #fef0c7; --free: #067647; --free-bg: #dcfae6;
  --error: #b42318; --shadow: 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141b; --surface: #1a1f2b; --text: #e6e9f0; --muted: #98a2b3; --border: #2c3344;
    --accent: #6d8bff; --accent-text: #0b1020; --accent-soft: #222c4a;
    --mark: #4c6ef5; --mark-text: #ffffff; --action: #222838;
    --paid: #fdb022; --paid-bg: #3a2a0a; --free: #47cd89; --free-bg: #0f2e1f;
    --error: #f97066; --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex; flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 8px;
  padding: 8px 14px; cursor: pointer; white-space: nowrap;
}
button:disabled { opacity: .5; cursor: progress; }
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
textarea { resize: vertical; width: 100%; }
a { color: var(--accent); }

.header {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; white-space: nowrap; }
.logo { width: 28px; height: 28px; }
.right { display: flex; align-items: center; gap: 10px; }
#logout { padding: 5px 10px; font-size: 13px; }
#logout .short { display: none; }
.counter { color: var(--muted); font-size: 13px; text-align: right; white-space: nowrap; }
.badge { font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 99px; background: var(--paid-bg); color: var(--paid); }
.hidden { display: none !important; }

.tabs {
  display: flex; gap: 4px; padding: 6px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.tabs button { background: transparent; color: var(--muted); border-radius: 6px; padding: 6px 12px; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { flex: 1; min-height: 0; display: flex; }
.panel { display: none; flex: 1; flex-direction: column; gap: 12px; padding: 16px; overflow-y: auto;
  max-width: 980px; margin: 0 auto; width: 100%; }
.panel.active { display: flex; }
#chat { padding-bottom: 0; overflow: hidden; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 10px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.row > input, .row > select { flex: 1 1 160px; }
.row.end { justify-content: flex-end; }
.free, .paid { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; }
.free { background: var(--free-bg); color: var(--free); }
.paid { background: var(--paid-bg); color: var(--paid); }
button .paid { margin-left: 4px; }
.muted { color: var(--muted); font-size: 13px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
  display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.item .title { font-weight: 600; }
.item .meta { color: var(--muted); font-size: 13px; }
.item .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.item .actions button { padding: 5px 10px; font-size: 13px; }
.status { font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.empty { color: var(--muted); text-align: center; padding: 24px; }

/* Chat */
.thread { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px 12px; }
.welcome { margin: auto; max-width: 620px; text-align: center; }
.welcome h2 { margin-bottom: 4px; }
.suggestions { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.suggestion { background: var(--surface); color: var(--text); border: 1px solid var(--border); width: 100%;
  white-space: normal; text-align: left; }
.bubble { max-width: 80%; padding: 9px 13px; border-radius: 14px; overflow-wrap: anywhere; }
.bubble.mark { align-self: flex-end; background: var(--mark); color: var(--mark-text); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.bubble.ai { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.action { align-self: center; background: var(--action); color: var(--muted); font-size: 13px; border-radius: 8px; max-width: 95%; }
.bubble.action a { margin-left: 6px; }
.bubble.waiting { align-self: flex-start; color: var(--muted); font-style: italic; background: transparent; }
.pending { background: var(--paid-bg); color: var(--text); border-radius: 12px; padding: 12px 14px;
  display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 8px; }
.composer { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px; margin-bottom: 14px; }
.composer textarea { border: 0; padding: 4px; resize: none; outline: none; background: transparent; }
.composer-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* Documents and dialogs */
.overlay { position: fixed; inset: 0; background: rgba(10, 14, 22, .55); display: flex; align-items: center;
  justify-content: center; padding: 16px; z-index: 10; }
.document { background: var(--surface); border-radius: 14px; width: min(900px, 100%); max-height: 100%;
  display: flex; flex-direction: column; overflow: hidden; }
.document-header { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 16px; border-bottom: 1px solid var(--border); font-weight: 600; overflow-wrap: anywhere; }
.document-body { padding: 4px 20px 20px; overflow-y: auto; }
.dialog { background: var(--surface); border-radius: 14px; padding: 18px 20px; width: min(460px, 100%); }
.dialog h3 { margin-top: 0; }
.notification { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text);
  color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: calc(100% - 32px); z-index: 20; white-space: pre-wrap; }
.notification.error { background: var(--error); color: #fff; }
.scroll-table { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.bar { height: 8px; background: var(--action); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.bar > div { height: 100%; background: var(--accent); }

/* Markdown */
.md h1, .md h2, .md h3 { margin: 18px 0 6px; line-height: 1.3; }
.md h1 { font-size: 20px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15px; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md code { background: var(--action); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.md table { margin: 8px 0; }
.md td, .md th { white-space: normal; }
.md hr { border: 0; border-top: 1px solid var(--border); }
.bubble.ai > :first-child { margin-top: 0; } .bubble.ai > :last-child { margin-bottom: 0; }

@media (max-width: 640px) {
  .panel { padding: 10px; }
  .bubble { max-width: 92%; }
  .counter { font-size: 12px; }
  .counter .long { display: none; }
  #logout { font-size: 12px; padding: 4px 8px; }
  #logout .long { display: none; }
  #logout .short { display: inline; }
  .right { gap: 6px; }
  .brand { font-size: 15px; gap: 8px; }
}

/* Login (online) */
.login-page { justify-content: center; align-items: center; padding: 16px; }
.login-page main { flex: 0 0 auto; }
.login { width: min(400px, 100%); display: flex; flex-direction: column; gap: 12px; }
.login .brand { justify-content: center; }
.login input { width: 100%; font-size: 17px; }
.login #code { letter-spacing: .3em; text-align: center; }
.login button { width: 100%; }
#login-message:empty { display: none; }
@media (max-width: 420px) {
  .header { padding: 10px 12px; }
  .header .name { display: none; }
}
