:root {
  --bg: #0d0f14; --panel: #151922; --panel2: #1b2030; --line: #262c3b; --text: #e8ebf2; --muted: #8a93a8;
  --accent: #d4a84b; --accent2: #f0c867; --err: #ff6b6b; --ok: #4cd18a;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .err { color: var(--err); min-height: 1em; margin: 6px 0; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.logo { color: var(--accent); }

.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav button { text-align: left; background: none; border: 0; padding: 9px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; }
.side nav button:hover { background: var(--panel2); color: var(--text); }
.side nav button.active { background: var(--panel2); color: var(--accent2); }
.me { margin-top: auto; display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--line); padding-top: 14px; }

.main { padding: 28px 32px; min-width: 0; }
h1 { margin: 0 0 18px; font-size: 22px; } h3 { margin: 18px 0 8px; font-size: 15px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 18px; }
label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; color: var(--muted); font-size: 12px; min-width: 0; }
label input, label select, label textarea { width: 100%; min-width: 0; }
label.check input { width: auto; }
label.check { flex-direction: row; align-items: center; gap: 8px; text-transform: none; color: var(--text); font-size: 13px; }
input, select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; outline: none; text-transform: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row label { margin-bottom: 0; }

.btn { color: var(--text); border: 1px solid var(--line); background: var(--panel2); padding: 9px 16px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #17130a; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent2); }
.btn:disabled { opacity: .5; cursor: wait; }
.btn.ghost { background: transparent; } .btn.small { padding: 5px 10px; font-size: 12px; } .btn.danger:hover { border-color: var(--err); color: var(--err); }

.gen-grid { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 20px; align-items: start; }
.gen-grid .panel { min-width: 0; }
.gen-grid .panel { position: sticky; top: 20px; }
.opts { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 10px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.thumb { position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; background: var(--bg); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 10px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .x { position: absolute; top: 2px; right: 2px; border: 0; background: #000a; color: #fff; border-radius: 50%; width: 18px; height: 18px; line-height: 16px; cursor: pointer; padding: 0; }

.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.card .media { min-height: 140px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: var(--bg); padding: 0; }
.card .media img, .card .media video { width: 100%; display: block; }
.card .media audio { width: 92%; margin: 18px 0; }
.card .media .textout { margin: 12px; align-self: stretch; }
.card .media .err { padding: 14px; }
.card .meta { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.prompt { cursor: pointer; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.textout { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; max-height: 360px; overflow: auto; margin: 10px 0; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.chat { display: flex; flex-direction: column; gap: 12px; height: calc(100vh - 110px); }
.chat-log { flex: 1; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; flex-direction: column; gap: 4px; max-width: 80%; }
.msg.user { align-self: flex-end; } .msg.assistant { align-self: flex-start; }
.bubble { white-space: pre-wrap; padding: 10px 14px; border-radius: 12px; background: var(--panel2); }
.msg.user .bubble { background: #3a2f14; }
.chat-in { display: flex; gap: 8px; } .chat-in textarea { flex: 1; }

.chip { border: 1px solid var(--line); background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 99px; cursor: pointer; }
.chip.active { border-color: var(--accent); color: var(--accent2); }
.filters { margin-bottom: 10px; }

.keybox { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.keybox code { background: var(--bg); border: 1px solid var(--line); padding: 8px 10px; border-radius: 8px; word-break: break-all; }
pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 14px; overflow: auto; font-size: 12px; }
.ops-list .op { padding: 4px 0; border-bottom: 1px solid var(--line); }
.tbl { width: 100%; border-collapse: collapse; margin-top: 10px; }
.tbl th, .tbl td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--muted); font-weight: 500; font-size: 12px; }
.small-in { width: 80px; padding: 5px 8px; }
.keyrow { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #17130a; padding: 9px 18px; border-radius: 8px; font-weight: 600; z-index: 99; }

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 30px; width: 340px; display: flex; flex-direction: column; }
.login-card .btn { margin-top: 6px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .gen-grid { grid-template-columns: 1fr; } .gen-grid .panel { position: static; }
  .main { padding: 18px 16px; }
}
