:root {
  --bg: #0f1115; --panel: #171a21; --line: #262b36; --text: #e6e8ee;
  --muted: #8b93a7; --accent: #7c9cff; --user: #243056; --err: #ff7b7b;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f5f6f8; --panel: #fff; --line: #e1e4ea; --text: #1b1e25;
          --muted: #636b7d; --accent: #3c5ce0; --user: #e3e9ff; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
       font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
       height: 100vh; display: flex; flex-direction: column; }
header { display: flex; justify-content: space-between; align-items: center;
         padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.brand small { color: var(--muted); font-weight: 400; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #3ecf8e; }
nav { display: flex; gap: 4px; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 8px;
         padding: 8px 14px; background: var(--accent); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
button.ghost, .tab { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.tab.active { color: var(--text); border-color: var(--accent); }
main { flex: 1; min-height: 0; max-width: 900px; width: 100%; margin: 0 auto; padding: 0 16px; }
.panel { display: none; height: 100%; flex-direction: column; }
.panel.active { display: flex; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 0; }
select, input, textarea { font: inherit; color: var(--text); background: var(--panel);
         border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
textarea { resize: vertical; width: 100%; }
input:disabled { opacity: .45; }
.check { color: var(--muted); font-size: 13px; display: flex; gap: 6px; align-items: center; }
.hidden { display: none !important; }
#log { flex: 1; overflow-y: auto; padding: 8px 0; display: flex; flex-direction: column; gap: 12px; }
.msg { padding: 10px 14px; border-radius: 12px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--user); }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.error { color: var(--err); }
.empty { color: var(--muted); text-align: center; margin: auto; }
#chatForm { display: flex; gap: 8px; padding: 12px 0 16px; }
.imgform { display: flex; flex-direction: column; gap: 10px; padding: 16px 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.grid label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.source { display: flex; gap: 12px; align-items: stretch; flex-wrap: wrap; }
.drop { flex: 1; min-width: 200px; min-height: 90px; border: 1px dashed var(--line);
        border-radius: 10px; display: flex; align-items: center; justify-content: center;
        gap: 10px; padding: 8px; cursor: pointer; color: var(--muted); font-size: 13px; }
.drop.over { border-color: var(--accent); }
.drop img { max-height: 140px; max-width: 100%; border-radius: 6px; }
.srcControls { display: flex; flex-direction: column; gap: 6px; min-width: 200px;
               font-size: 13px; color: var(--muted); }
.srcControls label { display: flex; flex-direction: column; gap: 4px; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.login { display: flex; align-items: center; justify-content: center; }
.login form { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 320px;
              background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.login .brand { justify-content: center; margin-bottom: 4px; }
/* The whole Image tab scrolls like a page, so results are never squeezed into
   whatever strip is left under the form. */
#image.panel, #video.panel { overflow-y: auto; }
.grid select { width: 100%; }
.progress .bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.progress .bar div { height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.progress .hint { margin-top: 6px; }
#videos { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
          gap: 12px; padding-bottom: 16px; }
#videos figure { margin: 0; background: var(--panel); border: 1px solid var(--line);
                 border-radius: 10px; overflow: hidden; }
#videos video { width: 100%; display: block; background: #000; }
#videos figcaption { font-size: 12px; color: var(--muted); padding: 6px 8px;
                     display: flex; justify-content: space-between; gap: 6px; }
#videos a { color: var(--accent); }
.imgform { flex-shrink: 0; }
#gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
           gap: 12px; padding-bottom: 16px; }
#gallery figure { margin: 0; background: var(--panel); border: 1px solid var(--line);
                  border-radius: 10px; overflow: hidden; }
#gallery img { width: 100%; display: block; }
#gallery figcaption { font-size: 12px; color: var(--muted); padding: 6px 8px;
                      display: flex; justify-content: space-between; gap: 6px; }
#gallery a { color: var(--accent); }
