:root {
  --bg: #f7f6f3;
  --panel: #efede8;
  --surface: #ffffff;
  --text: #1d1c1a;
  --muted: #74716b;
  --line: #e2dfd8;
  --line-strong: #cfcbc2;
  --accent: #1d1c1a;
  --accent-text: #f7f6f3;
  --pro: #3d63e6;
  --danger: #a33a2c;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191917; --panel: #1f1f1d; --surface: #262624; --text: #ecebe7; --muted: #9b988f;
    --line: #2f2e2b; --line-strong: #44423e; --accent: #ecebe7; --accent-text: #191917; --pro: #7d9bff; --danger: #e07b6c;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.6 var(--sans); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.wordmark { display: inline-flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 26px; letter-spacing: -0.01em; }
.wordmark img { width: 1.1em; height: 1.1em; }
.small-mark { font-size: 21px; gap: 8px; }
.empty-logo { width: 44px; height: 44px; display: block; margin-bottom: 18px; }
.msg .meta { display: flex; align-items: center; gap: 7px; }
.msg .meta img { width: 16px; height: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); font-weight: 500; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { opacity: .9; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--text); }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 0; background: none; color: var(--muted); }
.icon-btn:hover { background: var(--panel); color: var(--text); }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-box { width: 100%; max-width: 360px; }
.login-box .wordmark { margin-bottom: 48px; }
.login h1 { font-family: var(--serif); font-weight: 400; font-size: 30px; line-height: 1.2; margin: 0 0 8px; }
.login p { margin: 0 0 24px; }
.login label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.login input[type=email] {
  width: 100%; height: 44px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; margin-bottom: 14px;
}
.login input:focus, textarea:focus { outline: 2px solid var(--text); outline-offset: -1px; }
.login .btn { width: 100%; height: 44px; }
.form-error { color: var(--danger); font-size: 14px; min-height: 22px; margin: 12px 0 0 !important; }
.dev-note { font-size: 13px; padding: 10px 12px; border-left: 2px solid var(--pro); background: var(--panel); }
.code-inputs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 16px; }
.code-inputs input {
  height: 54px; text-align: center; font: 500 22px var(--mono); border: 1px solid var(--line-strong);
  border-radius: 8px; background: var(--surface); color: var(--text); min-width: 0;
}

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 264px 1fr; height: 100%; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 14px; }
.new-chat { margin: 0 12px 12px; justify-content: flex-start; background: transparent; }
.new-chat:hover { background: var(--surface); }
.history { flex: 1; overflow-y: auto; padding: 4px 8px; }
.history .group { font-size: 12px; color: var(--muted); padding: 14px 10px 6px; }
.conv { display: flex; align-items: center; border-radius: 7px; }
.conv a {
  flex: 1; min-width: 0; padding: 7px 10px; color: var(--text); text-decoration: none; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv:hover, .conv.active { background: var(--surface); }
.conv .del { visibility: hidden; width: 28px; height: 28px; }
.conv:hover .del { visibility: visible; }
.conv .del svg { width: 15px; height: 15px; }

.account { border-top: 1px solid var(--line); padding: 16px 18px 18px; font-size: 13px; }
.usage-row { display: flex; justify-content: space-between; color: var(--muted); margin-bottom: 6px; }
.bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--text); transition: width .4s; }
.bar.high div { background: var(--danger); }
.usage-reset { color: var(--muted); font-size: 12px; margin-top: 6px; min-height: 18px; }
.who { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; }
.who-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-tag { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; padding: 2px 7px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--muted); }
.plan-tag.pro { color: var(--pro); border-color: var(--pro); }
.account-actions { display: flex; gap: 16px; margin-top: 10px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; }
.model-switch { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--panel); border: 1px solid var(--line); }
.model-switch button {
  border: 0; background: none; padding: 5px 14px; border-radius: 6px; font-size: 14px; color: var(--muted);
}
.model-switch button[aria-checked=true] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.model-switch button span { display: block; font-size: 11px; line-height: 1.2; }
.demo-badge { font-size: 12px; color: var(--pro); border: 1px solid var(--pro); padding: 1px 8px; border-radius: 4px; }

/* ---------- thread ---------- */
.thread { flex: 1; overflow-y: auto; padding: 8px 20px 24px; }
.empty { max-width: 720px; margin: 18vh auto 0; }
.empty h2 { font-family: var(--serif); font-weight: 400; font-size: 38px; line-height: 1.15; margin: 0 0 10px; letter-spacing: -0.01em; }
.messages { max-width: 720px; margin: 0 auto; }
.msg { margin: 26px 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  max-width: 85%; background: var(--panel); border: 1px solid var(--line); padding: 10px 15px; border-radius: 14px 14px 4px 14px;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.assistant .body { word-wrap: break-word; }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }
.body p { margin: 0 0 14px; }
.body h1, .body h2, .body h3, .body h4 { font-family: var(--serif); font-weight: 500; line-height: 1.3; margin: 24px 0 10px; }
.body h1 { font-size: 24px; } .body h2 { font-size: 21px; } .body h3 { font-size: 18px; } .body h4 { font-size: 16px; }
.body ul, .body ol { padding-left: 22px; margin: 0 0 14px; }
.body li { margin: 4px 0; }
.body a { color: inherit; text-underline-offset: 3px; }
.body blockquote { margin: 0 0 14px; padding-left: 14px; border-left: 2px solid var(--line-strong); color: var(--muted); }
.body code { font: 13.5px var(--mono); background: var(--panel); padding: 1px 5px; border-radius: 4px; }
.body pre { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; overflow-x: auto; margin: 0 0 14px; }
.body pre code { background: none; padding: 0; font-size: 13px; line-height: 1.55; }
.body pre .lang { position: absolute; top: 6px; right: 10px; font: 11px var(--sans); color: var(--muted); }
.body table { border-collapse: collapse; margin: 0 0 14px; font-size: 14px; display: block; overflow-x: auto; }
.body th, .body td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.body hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.gen-image img { display: block; width: 100%; max-width: 512px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); }
.gen-image .actions { margin-top: 8px; font-size: 13px; }
.thinking { color: var(--muted); font-size: 14px; display: inline-flex; gap: 4px; align-items: center; }
.thinking i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: pulse 1.2s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .15s; } .thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.err { color: var(--danger); font-size: 14px; }
.limit-card { border: 1px solid var(--line-strong); border-radius: 10px; padding: 14px 16px; font-size: 14px; }
.limit-card .btn { margin-top: 10px; height: 34px; }

/* ---------- composer ---------- */
.composer { padding: 0 20px 14px; }
.composer-box { max-width: 720px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 14px; padding: 12px 12px 10px 16px; }
.composer-box:focus-within { border-color: var(--muted); }
.composer textarea {
  width: 100%; border: 0; resize: none; background: none; color: var(--text); font: inherit; line-height: 1.5;
  max-height: 220px; padding: 2px 0; outline: none !important;
}
.composer-row { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px; border-radius: 8px;
  border: 1px solid var(--line); background: none; font-size: 13px; color: var(--muted);
}
.chip svg { width: 16px; height: 16px; }
.chip:hover { color: var(--text); }
.chip[aria-pressed=true] { color: var(--text); border-color: var(--text); }
.cost { margin-left: auto; font-size: 12px; color: var(--muted); }
.send { width: 34px; height: 34px; border-radius: 8px; border: 0; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; }
.send:disabled { opacity: .35; cursor: default; }
.fineprint { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 0 0; }

/* ---------- plans ---------- */
.plans { border: 1px solid var(--line-strong); border-radius: 14px; padding: 24px; width: min(680px, calc(100% - 32px)); background: var(--bg); color: var(--text); }
.plans::backdrop { background: rgba(20, 20, 18, .4); }
.plans-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.plans h2 { font-family: var(--serif); font-weight: 400; font-size: 26px; margin: 0; }
.plan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.plan { border: 1px solid var(--line-strong); border-radius: 10px; padding: 20px; display: flex; flex-direction: column; background: var(--surface); }
.plan.pro { border-color: var(--pro); }
.plan h3 { margin: 0; font-size: 15px; letter-spacing: .04em; text-transform: uppercase; }
.plan.pro h3 { color: var(--pro); }
.price { font-family: var(--serif); font-size: 30px; margin: 6px 0 14px; }
.price span { font-size: 15px; color: var(--muted); font-family: var(--sans); }
.plan ul { margin: 0 0 20px; padding-left: 18px; font-size: 14px; flex: 1; }
.plan li { margin: 6px 0; }
.plan .btn[disabled] { background: none; color: var(--muted); border-color: var(--line); }
.plans-note { margin: 16px 0 0; }

/* ---------- mobile ---------- */
.only-mobile { display: none; }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(20, 20, 18, .35); }
  .only-mobile { display: inline-grid; }
  .plan-grid { grid-template-columns: 1fr; }
  .plans { padding: 18px; max-height: calc(100dvh - 32px); overflow-y: auto; }
  .empty { margin-top: 12vh; }
  .empty h2 { font-size: 30px; }
  .thread, .composer, .topbar { padding-left: 14px; padding-right: 14px; }
  .topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .composer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .fineprint { display: none; }
  .composer textarea, .login input { font-size: 16px; } /* fara zoom automat pe iPhone */
  .msg.user .bubble { max-width: 92%; }
  .conv .del { visibility: visible; }
  .sidebar { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
}
.app { height: 100dvh; }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
