/* AI Chat — premium minimalism */
:root {
  --bg: #fbfbfa; --panel: #ffffff; --side: #f4f4f2; --text: #111110; --muted: #8a8a86; --faint: #b9b9b4;
  --border: #ebebe8; --border-2: #dcdcd8; --accent: #111110; --accent-2: #3a3a38; --on-accent: #ffffff;
  --user: #f1f1ef; --code: #f5f5f3; --hover: rgba(17,17,16,.045); --active: rgba(17,17,16,.07);
  --danger: #d0402f; --warn: #c9962b; --link: #2b5bd7;
  --shadow-sm: 0 1px 2px rgba(17,17,16,.04);
  --shadow: 0 1px 2px rgba(17,17,16,.04), 0 8px 28px -6px rgba(17,17,16,.08);
  --shadow-lg: 0 2px 4px rgba(17,17,16,.04), 0 18px 48px -12px rgba(17,17,16,.14);
  --r: 14px; --ease: cubic-bezier(.2,.8,.2,1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e0f; --panel: #161617; --side: #121213; --text: #ededeb; --muted: #8b8b89; --faint: #5a5a58;
    --border: #232325; --border-2: #303033; --accent: #ededeb; --accent-2: #ffffff; --on-accent: #0e0e0f;
    --user: #1e1e20; --code: #1a1a1c; --hover: rgba(255,255,255,.045); --active: rgba(255,255,255,.075);
    --danger: #ef6b5b; --warn: #e0b04a; --link: #8fb0ff;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -8px rgba(0,0,0,.5);
    --shadow-lg: 0 2px 4px rgba(0,0,0,.3), 0 20px 50px -12px rgba(0,0,0,.6);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.65 "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Roboto, system-ui, sans-serif;
  letter-spacing: -.006em; overscroll-behavior: none; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
button { font: inherit; color: inherit; cursor: pointer; transition: background-color .18s var(--ease), color .18s var(--ease), border-color .18s var(--ease), opacity .18s var(--ease), transform .18s var(--ease); }
button:active:not(:disabled) { transform: scale(.97); }
input, textarea { font: inherit; color: inherit; font-size: 16px; }
::selection { background: var(--text); color: var(--bg); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--faint); }
::-webkit-scrollbar-track { background: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
textarea:focus, textarea:focus-visible, .login input:focus-visible { outline: none; }

/* login */
.login { display: grid; place-items: center; height: 100dvh; padding: 20px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--side), transparent 70%), var(--bg); }
.login form { background: var(--panel); border: 1px solid var(--border); border-radius: 22px; padding: 36px 32px 32px; width: 100%; max-width: 380px; display: grid; gap: 14px; box-shadow: var(--shadow-lg); animation: rise .5s var(--ease); }
.login .mark { width: 40px; height: 40px; border-radius: 12px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; margin-bottom: 6px; }
.login h1 { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -.025em; }
.login p { margin: -6px 0 8px; color: var(--muted); font-size: 14px; }
.login input { padding: 13px 15px; border-radius: 12px; border: 1px solid var(--border-2); background: var(--bg); outline: none; transition: border-color .18s, box-shadow .18s; }
.login input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--hover); }
.login button { padding: 13px; border: 0; border-radius: 12px; background: var(--accent); color: var(--on-accent); font-weight: 550; letter-spacing: -.01em; }
.login button:hover { opacity: .88; }
.login .err { color: var(--danger); font-size: 13px; min-height: 1em; margin: -4px 0; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* layout */
.app { display: flex; height: 100dvh; }
aside { width: 272px; flex-shrink: 0; background: var(--side); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
aside .top { padding: 14px 12px 8px; display: flex; gap: 8px; }
.new-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel); font-weight: 550; font-size: 14px; letter-spacing: -.01em; box-shadow: var(--shadow-sm); }
.new-btn:hover { border-color: var(--border-2); box-shadow: var(--shadow); }
.dev-btn { margin: 0 12px 4px; display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 10px; padding: 9px 12px; border-radius: 12px; border: 1px dashed var(--border-2); background: none; text-align: left; color: var(--muted); }
.dev-btn svg { grid-row: span 2; }
.dev-btn span { font-size: 13.5px; font-weight: 550; color: var(--text); line-height: 1.2; }
.dev-btn small { font-size: 11px; line-height: 1.2; }
.dev-btn:hover { border-style: solid; background: var(--panel); color: var(--text); }
.app.dev .dev-btn { border-style: solid; background: var(--panel); box-shadow: var(--shadow-sm); }
.chat-item .dev-ic { flex-shrink: 0; color: var(--faint); }
.chat-item.active .dev-ic { color: var(--text); }
.dev-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; border: 1px solid var(--border-2); font-size: 12px; font-weight: 550; color: var(--text); margin-bottom: 14px; }
.app.dev .box { border-style: dashed; border-color: var(--border-2); }
.msg.system.deploy { display: block; text-align: center; }
.msg.system.deploy::before, .msg.system.deploy::after { display: none; }
.msg.system.deploy .sys { display: inline-block; white-space: pre-wrap; text-align: left; max-width: 100%; padding: 7px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--muted); font-size: 12.5px; letter-spacing: 0; box-shadow: var(--shadow-sm); }
.chats { flex: 1; overflow-y: auto; padding: 8px 8px 12px; }
.chats::before { content: "Suhbatlar"; display: block; padding: 6px 10px 6px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.chat-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin: 1px 0; border-radius: 10px; cursor: pointer; font-size: 14px; color: var(--muted); transition: background-color .15s, color .15s; }
.chat-item:hover { background: var(--hover); color: var(--text); }
.chat-item.active { background: var(--active); color: var(--text); font-weight: 500; }
.chat-item .t { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text); flex-shrink: 0; animation: pulse 1s infinite alternate; }
.chat-item .act { opacity: 0; border: 0; background: none; padding: 2px 5px; color: var(--muted); border-radius: 6px; font-size: 12px; }
.chat-item:hover .act { opacity: 1; }
.chat-item .act:hover { color: var(--text); background: var(--active); }
aside .foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; color: var(--faint); font-size: 12px; letter-spacing: .01em; }
aside .foot button { border: 0; background: none; color: var(--muted); padding: 4px 8px; border-radius: 8px; font-size: 12px; }
aside .foot button:hover { color: var(--text); background: var(--hover); }

main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
header { display: none; align-items: center; gap: 8px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px); position: sticky; top: 0; z-index: 5; }
header .title { font-weight: 550; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: 0; background: none; padding: 7px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--text); }

.messages { flex: 1; overflow-y: auto; padding: 40px 20px 12px; scroll-behavior: smooth; }
.inner { max-width: 740px; margin: 0 auto; }
.empty { height: 100%; display: grid; place-items: center; text-align: center; color: var(--muted); font-size: 14px; animation: rise .6s var(--ease); }
.empty h2 { color: var(--text); font-weight: 600; font-size: 30px; letter-spacing: -.035em; line-height: 1.2; margin: 0 0 10px; }
.empty > div { max-width: 360px; }

.msg { margin: 0 0 30px; animation: msgIn .35s var(--ease); }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble { background: var(--user); padding: 10px 16px; border-radius: 20px; max-width: 80%; white-space: pre-wrap; word-wrap: break-word; }
.msg.assistant .bubble { word-wrap: break-word; }
.bubble > :first-child { margin-top: 0; } .bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 .85em; }
.bubble h1, .bubble h2, .bubble h3 { letter-spacing: -.02em; line-height: 1.3; margin: 1.4em 0 .5em; font-weight: 600; }
.bubble h1 { font-size: 1.45em; } .bubble h2 { font-size: 1.25em; } .bubble h3 { font-size: 1.08em; }
.bubble ul, .bubble ol { padding-left: 1.3em; } .bubble li { margin: .25em 0; } .bubble li::marker { color: var(--faint); }
.bubble hr { border: 0; height: 1px; background: var(--border); margin: 1.6em 0; }
.bubble img { max-width: 100%; border-radius: 12px; cursor: zoom-in; }
.bubble pre { background: var(--code); border: 1px solid var(--border); padding: 14px 16px; border-radius: 12px; overflow-x: auto; font-size: 13px; line-height: 1.55; position: relative; }
.bubble code { font-family: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: .88em; }
.bubble :not(pre) > code { background: var(--code); border: 1px solid var(--border); padding: 1px 5px; border-radius: 6px; }
.bubble table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.bubble th, .bubble td { border-bottom: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.bubble th { font-weight: 600; border-bottom-color: var(--border-2); }
.bubble a { color: var(--link); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--link) 30%, transparent); }
.bubble a:hover { border-bottom-color: var(--link); }
.bubble blockquote { margin: 0 0 .85em; padding: 2px 0 2px 14px; border-left: 2px solid var(--border-2); color: var(--muted); }
.copy { position: absolute; top: 8px; right: 8px; font-size: 11px; padding: 3px 9px; border-radius: 7px; border: 1px solid var(--border); background: var(--panel); color: var(--muted); opacity: 0; }
.bubble pre:hover .copy { opacity: 1; }
.copy:hover { color: var(--text); }
@media (hover: none) { .copy { opacity: .8; } }

.tools { display: flex; flex-direction: column; gap: 2px; margin: 0 0 10px; font-size: 12.5px; color: var(--muted); }
.tools details summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border: 1px solid var(--border); border-radius: 999px; width: fit-content; transition: border-color .15s, color .15s; }
.tools details summary::-webkit-details-marker { display: none; }
.tools details summary:hover { color: var(--text); border-color: var(--border-2); }
.tools details summary::before { content: ""; width: 5px; height: 5px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform .2s var(--ease); }
.tools details[open] summary::before { transform: rotate(45deg); }
.tools details > div { padding: 2px 0 2px 14px; border-left: 1px solid var(--border); margin-left: 10px; font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools details[open] > div:first-of-type { margin-top: 8px; }
.tools .live { animation: fade 1.2s infinite alternate; }
.typing { display: inline-flex; gap: 5px; padding: 8px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text); animation: bounce 1.1s infinite var(--ease); opacity: .25; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { opacity: .25; transform: none; } 30% { opacity: .9; transform: translateY(-3px); } }
@keyframes pulse { from { opacity: .25; } to { opacity: 1; } }
@keyframes fade { from { opacity: .45; } to { opacity: 1; } }

.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.msg.user .files { justify-content: flex-end; }
.file { display: flex; align-items: center; gap: 8px; padding: 9px 13px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); font-size: 13px; text-decoration: none; color: inherit; max-width: 280px; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s; }
.file:hover { border-color: var(--border-2); box-shadow: var(--shadow); }
.file .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.file .s { color: var(--muted); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.thumb { display: block; border-radius: 14px; overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.thumb img { display: block; max-width: 260px; max-height: 260px; object-fit: cover; cursor: zoom-in; transition: transform .4s var(--ease); }
.thumb:hover img { transform: scale(1.02); }
.files audio, .files video { max-width: 100%; border-radius: 12px; }
.meta { font-size: 11.5px; color: var(--faint); margin-top: 8px; font-variant-numeric: tabular-nums; letter-spacing: .01em; }

/* composer */
.composer { padding: 6px 20px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 22px); position: relative; }
.box { max-width: 740px; margin: 0 auto; background: var(--panel); border: 1px solid var(--border); border-radius: 22px; padding: 8px 8px 8px 6px; box-shadow: var(--shadow); transition: border-color .2s var(--ease), box-shadow .2s var(--ease); }
.box:focus-within { border-color: var(--border-2); box-shadow: var(--shadow-lg); }
.box.drag { border-style: dashed; border-color: var(--text); }
.suggest { max-width: 740px; margin: 0 auto 10px; display: flex; align-items: center; gap: 12px; padding: 6px 6px 6px 6px; background: var(--panel); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); cursor: pointer; animation: sgIn .3s var(--ease); transition: box-shadow .2s, border-color .2s; }
.suggest:hover { border-color: var(--border-2); box-shadow: var(--shadow-lg); }
.suggest[hidden] { display: none; }
.suggest img { width: 48px; height: 48px; object-fit: cover; border-radius: 12px; flex-shrink: 0; border: 1px solid var(--border); }
.suggest .t { flex: 1; font-size: 13.5px; font-weight: 550; line-height: 1.35; letter-spacing: -.01em; }
.suggest .t small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; letter-spacing: 0; }
.suggest .x { border: 0; background: none; color: var(--faint); font-size: 13px; width: 32px; height: 32px; border-radius: 10px; }
.suggest .x:hover { background: var(--hover); color: var(--text); }
@keyframes sgIn { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.pending { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 4px 8px 6px; }
.pending:empty { display: none; }
.chip { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 4px; border: 1px solid var(--border); border-radius: 12px; font-size: 12px; max-width: 210px; background: var(--bg); animation: sgIn .25s var(--ease); }
.chip .pv { position: relative; width: 40px; height: 40px; flex-shrink: 0; display: grid; place-items: center; border-radius: 9px; overflow: hidden; background: var(--code); }
.chip .pv img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chip .pv .doc { font-size: 18px; }
.chip .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.chip .x { border: 0; background: none; color: var(--faint); padding: 2px 4px; border-radius: 6px; }
.chip .x:hover { color: var(--text); background: var(--hover); }
.chip.up .n { color: var(--muted); }
/* yuklanish: rasm ustida aylanuvchi doira + foiz */
.chip .load { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.5); }
.chip .ring { position: absolute; width: 32px; height: 32px; animation: spin .9s linear infinite; }
.chip .ring circle { fill: none; stroke-width: 3; }
.chip .ring .bg { stroke: rgba(255,255,255,.22); }
.chip .ring .fg { stroke: #fff; stroke-linecap: round; stroke-dasharray: 8 100; transition: stroke-dasharray .2s; }
.chip .pct { position: relative; color: #fff; font-size: 9px; font-weight: 600; font-variant-numeric: tabular-nums; }
.send .spin { width: 15px; height: 15px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--on-accent) 35%, transparent); border-top-color: var(--on-accent); animation: spin .8s linear infinite; }
.send.waiting:disabled { opacity: .85; cursor: progress; }
@keyframes spin { to { transform: rotate(360deg); } }
.row { display: flex; align-items: flex-end; gap: 2px; }
.row .icon-btn { width: 38px; height: 38px; border-radius: 12px; }
textarea { flex: 1; resize: none; border: 0; outline: none; background: none; padding: 8px 6px; max-height: 220px; line-height: 1.5; }
textarea::placeholder { color: var(--faint); }
.send { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; flex-shrink: 0; box-shadow: var(--shadow-sm); }
.send:hover:not(:disabled) { background: var(--accent-2); }
.send:disabled { background: var(--border); color: var(--faint); box-shadow: none; cursor: default; }
.send.stop { background: var(--accent); color: var(--on-accent); }
.hint { max-width: 740px; margin: 8px auto 0; font-size: 11.5px; color: var(--faint); display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 24px; padding: 0 8px; letter-spacing: .01em; }
.hint .keys { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctx { display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0; margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }
.ctx[hidden] { display: none; }
.ctx-bar { width: 64px; height: 3px; border-radius: 3px; background: var(--border); overflow: hidden; }
.ctx-bar i { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--muted); transition: width .5s var(--ease), background-color .3s; }
.ctx.mid .ctx-bar i { background: var(--warn); }
.ctx.high .ctx-bar i { background: var(--danger); }
.ctx.high #ctxPct { color: var(--danger); font-weight: 600; }
.ctx-btn { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); color: var(--muted); font-size: 11.5px; }
.ctx-btn:hover:not(:disabled) { color: var(--text); border-color: var(--border-2); }
.ctx-btn:disabled { opacity: .45; cursor: default; }
.msg.system { display: flex; align-items: center; gap: 14px; color: var(--faint); font-size: 11.5px; letter-spacing: .02em; }
.msg.system::before, .msg.system::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.msg.system .sys { white-space: nowrap; }

.lightbox { position: fixed; inset: 0; background: rgba(8,8,9,.88); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); display: grid; place-items: center; z-index: 50; cursor: zoom-out; padding: 20px; animation: lbIn .25s var(--ease); }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; box-shadow: 0 30px 80px rgba(0,0,0,.5); animation: rise .35s var(--ease); }
@keyframes lbIn { from { opacity: 0; } }
.backdrop { display: none; }
.toast { position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(92vw, 420px); padding: 10px 16px; border-radius: 14px; background: var(--accent); color: var(--on-accent); font-size: 13px; line-height: 1.4; text-align: center; box-shadow: var(--shadow-lg); z-index: 60; animation: toastIn .3s var(--ease); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (max-width: 760px) {
  aside { position: fixed; inset: 0 auto 0 0; z-index: 20; transform: translateX(-100%); transition: transform .32s var(--ease), box-shadow .32s; width: 84%; max-width: 310px; padding-top: env(safe-area-inset-top); border-right: 0; }
  .app.open aside { transform: none; box-shadow: var(--shadow-lg); }
  .app.open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.28); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); z-index: 15; animation: lbIn .25s var(--ease); }
  header { display: flex; }
  .messages { padding: 20px 16px 8px; }
  .composer { padding: 4px 10px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .box { border-radius: 24px; }
  .chat-item { padding: 10px 12px; font-size: 15px; }
  .chat-item .act { opacity: 1; }
  .msg { margin-bottom: 24px; }
  .msg.user .bubble { max-width: 88%; }
  .empty h2 { font-size: 26px; }
  .hint .keys { display: none; }
  .hint { margin-top: 4px; min-height: 0; }
  .msg.system .sys { white-space: normal; text-align: center; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
