:root {
  --bg: #0a0e16;
  --panel: #121826;
  --panel2: #0f1420;
  --accent: #38e1ff;
  --accent2: #b388ff;
  --text: #e6edf6;
  --muted: #8aa0b8;
  --border: #1f2a3a;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .6rem 1rem;
  background: linear-gradient(90deg, #0d1422, #111a2c);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.logo { font-weight: 700; font-size: 1.1rem; }
.tabs { display: flex; gap: .4rem; flex-wrap: wrap; }
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: .45rem .8rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: .9rem;
}
.tab.active { color: var(--text); background: var(--panel); border-color: var(--border); }
.tab:hover { color: var(--text); }

.layout { display: flex; gap: 1rem; padding: 1rem; align-items: flex-start; }
.content { flex: 1; min-width: 0; }
.panel { display: none; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; }
.panel.active { display: block; }

.bar { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; margin-bottom: .8rem; }
label { font-size: .8rem; color: var(--muted); display: flex; flex-direction: column; gap: .25rem; }
select, input, textarea {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .45rem .6rem;
  font-size: .9rem;
  font-family: inherit;
}
select { min-width: 200px; }

.btn {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  color: #06121c;
  border: none;
  border-radius: 8px;
  padding: .55rem 1.1rem;
  font-weight: 700;
  cursor: pointer;
  font-size: .9rem;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.prompt { width: 100%; min-height: 90px; margin-bottom: .6rem; resize: vertical; }
.chat-log { background: var(--panel2); border: 1px solid var(--border); border-radius: 10px; padding: .8rem; height: 52vh; overflow-y: auto; margin-bottom: .6rem; }
.msg { margin-bottom: .8rem; padding: .6rem .8rem; border-radius: 10px; white-space: pre-wrap; line-height: 1.45; }
.msg.user { background: #15263b; border: 1px solid #1d3550; }
.msg.assistant { background: #1a1730; border: 1px solid #2a2350; }
.composer { display: flex; gap: .6rem; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 54px; resize: vertical; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .8rem; margin-top: .8rem; }
.media-grid img, .media-grid video { width: 100%; border-radius: 10px; border: 1px solid var(--border); background: #000; }
.media-grid a { color: var(--accent); word-break: break-all; }
.media-card { background: var(--panel2); border: 1px solid var(--border); border-radius: 10px; padding: .6rem; }

.history { width: 220px; flex-shrink: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: .8rem; max-height: 80vh; overflow-y: auto; }
.history h4 { margin: 0 0 .6rem; font-size: .9rem; color: var(--muted); }
.hist-item { font-size: .8rem; border-bottom: 1px solid var(--border); padding: .4rem 0; cursor: pointer; }
.hist-item:hover { color: var(--accent); }
.hist-type { display: inline-block; font-size: .65rem; padding: .1rem .4rem; border-radius: 6px; background: #1d2a3f; color: var(--accent); margin-right: .3rem; }

.hint { color: var(--muted); font-size: .82rem; line-height: 1.5; }
code { background: #0c1320; padding: .1rem .35rem; border-radius: 5px; color: var(--accent); font-size: .8rem; }
.status { font-size: .85rem; min-height: 1.2rem; }
.toast {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: #1c2333; border: 1px solid var(--border); color: var(--text);
  padding: .6rem 1rem; border-radius: 10px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(4,8,14,.82);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 1.6rem; width: min(440px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal h2 { margin: 0 0 .6rem; font-size: 1.15rem; }
.modal label { margin-top: .8rem; }

.ref-row { display: flex; align-items: center; gap: .6rem; margin: .4rem 0; flex-wrap: wrap; }
.file-btn { background: var(--panel2); border: 1px dashed var(--border); color: var(--muted); padding: .4rem .7rem; border-radius: 8px; cursor: pointer; font-size: .82rem; }
.file-btn:hover { color: var(--text); border-color: var(--accent); }
.ref-thumb { max-width: 90px; max-height: 70px; border-radius: 8px; border: 1px solid var(--border); margin-top: .3rem; }
.ref-name { font-size: .78rem; color: var(--muted); }
.ref-clear { background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: 6px; cursor: pointer; padding: .2rem .5rem; }
.ref-clear:hover { color: #ff6b6b; border-color: #ff6b6b; }

@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .history { width: 100%; max-height: 240px; }
}
