*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  --gold: #c9a96e;
  --gold-light: #d4b87a;
  --dark: #0a0a0a;
  --dark-2: #111;
  --dark-3: #171717;
  --line: rgba(255,255,255,0.08);
  --text: rgba(255,255,255,0.92);
  --text-dim: rgba(255,255,255,0.55);
  --text-faint: rgba(255,255,255,0.38);
}

html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--dark);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.6;
}

button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: var(--gold); }

/* ── sign in ─────────────────────────────────────────────── */

.signin {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.signin-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.signin-card img.logo { height: 42px; margin-bottom: 36px; }
.signin-card h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.6px;
  margin-bottom: 8px;
}
.signin-card h1 span { color: var(--gold); }
.signin-card p.lead { color: var(--text-dim); margin-bottom: 32px; font-size: 14px; }
.field { text-align: left; margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 11px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 8px;
  font-weight: 600;
}
.field input {
  width: 100%;
  background: var(--dark-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 16px;
  outline: none;
  transition: border-color .2s ease;
}
.field input:focus { border-color: var(--gold); }
.btn-gold {
  width: 100%;
  background: var(--gold);
  color: #0a0a0a;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-size: 13px;
  padding: 14px;
  border-radius: 90px;
  transition: background .2s ease;
}
.btn-gold:hover { background: var(--gold-light); }
.btn-gold:disabled { opacity: .55; cursor: default; }
.form-error {
  color: #e8795f;
  font-size: 13px;
  margin-top: 14px;
  min-height: 19px;
}

/* ── layout ──────────────────────────────────────────────── */

.app { display: flex; height: 100dvh; overflow: hidden; }

.sidebar {
  width: 272px;
  flex-shrink: 0;
  background: var(--dark-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.sidebar-head {
  padding: 18px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.sidebar-head img { height: 26px; }
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  transition: background .2s ease, color .2s ease;
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.07); color: var(--text); }

.new-chat {
  margin: 0 16px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  transition: border-color .2s ease, background .2s ease;
}
.new-chat:hover { border-color: var(--gold); background: rgba(201,169,110,.08); }

.history { flex: 1; overflow-y: auto; padding: 0 10px 10px; }
.history h2 {
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 10px 6px;
  font-weight: 600;
}
.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--text-dim);
  transition: background .15s ease, color .15s ease;
}
.chat-item:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.chat-item.active { background: rgba(201,169,110,.12); color: var(--text); }
.chat-item .label {
  flex: 1;
  text-align: left;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item .del { opacity: 0; color: var(--text-faint); padding: 2px; }
.chat-item:hover .del, .chat-item.active .del { opacity: 1; }
.chat-item .del:hover { color: #e8795f; }

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--gold);
  color: #0a0a0a;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.who { flex: 1; min-width: 0; }
.who .name { font-size: 13px; font-weight: 600; }
.who .role { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 1px; }

/* ── main ────────────────────────────────────────────────── */

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 56px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  flex-shrink: 0;
}
.topbar .title { font-size: 14px; font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .model {
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 1px;
  text-transform: uppercase;
}
#menuBtn { display: none; }

.thread { flex: 1; overflow-y: auto; padding: 28px 0 10px; }
.thread-inner { max-width: 780px; margin: 0 auto; padding: 0 20px; }

.welcome { text-align: center; padding: 60px 0 40px; }
.welcome img { height: 48px; margin-bottom: 26px; opacity: .95; }
.welcome h1 { font-size: 30px; font-weight: 700; letter-spacing: -1px; margin-bottom: 10px; }
.welcome h1 span { color: var(--gold); }
.welcome p { color: var(--text-dim); max-width: 440px; margin: 0 auto; }
.starters {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 34px;
  text-align: left;
}
.starter {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  color: var(--text-dim);
  font-size: 14px;
  transition: border-color .2s ease, color .2s ease, background .2s ease;
}
.starter:hover { border-color: var(--gold); color: var(--text); background: rgba(201,169,110,.06); }
.starter strong { display: block; color: var(--text); font-weight: 600; margin-bottom: 4px; font-size: 14px; }

.msg { display: flex; gap: 14px; margin-bottom: 28px; }
.msg .bubble-avatar {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}
.msg.user .bubble-avatar { background: rgba(255,255,255,0.1); color: var(--text); }
.msg.assistant .bubble-avatar { background: var(--gold); color: #0a0a0a; padding: 5px; }
.msg.assistant .bubble-avatar img { width: 100%; }
.msg .body { flex: 1; min-width: 0; padding-top: 3px; }
.msg .name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.msg .content { overflow-wrap: anywhere; }
.msg .content p { margin-bottom: 12px; }
.msg .content p:last-child { margin-bottom: 0; }
.msg .content ul, .msg .content ol { margin: 0 0 12px 22px; }
.msg .content li { margin-bottom: 5px; }
.msg .content h1, .msg .content h2, .msg .content h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 18px 0 10px;
}
.msg .content code {
  background: rgba(255,255,255,0.08);
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 13px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
}
.msg .content pre {
  background: var(--dark-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  margin-bottom: 12px;
}
.msg .content pre code { background: none; padding: 0; font-size: 13px; line-height: 1.6; }
.msg .content blockquote {
  border-left: 2px solid var(--gold);
  padding-left: 14px;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.msg .content table { border-collapse: collapse; margin-bottom: 12px; width: 100%; }
.msg .content th, .msg .content td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; font-size: 14px; }
.msg .images { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.msg .images a { display: block; }
.msg .images img {
  max-width: 320px;
  max-height: 320px;
  border-radius: 10px;
  border: 1px solid var(--line);
  display: block;
}
.msg .caption { font-size: 12px; color: var(--text-faint); margin-top: 8px; }
.cursor-dot {
  display: inline-block;
  width: 7px;
  height: 15px;
  background: var(--gold);
  vertical-align: text-bottom;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── composer ────────────────────────────────────────────── */

.composer-wrap { border-top: 1px solid var(--line); padding: 16px 20px 20px; flex-shrink: 0; }
.composer { max-width: 780px; margin: 0 auto; }
.mode-row { display: flex; gap: 8px; margin-bottom: 10px; }
.mode {
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--text-faint);
  border: 1px solid var(--line);
  border-radius: 90px;
  padding: 6px 15px;
  transition: all .2s ease;
}
.mode.on { color: #0a0a0a; background: var(--gold); border-color: var(--gold); }
.box {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--dark-2);
  padding: 10px 10px 10px 16px;
  transition: border-color .2s ease;
}
.box:focus-within { border-color: var(--gold); }
.attachments { display: flex; gap: 8px; flex-wrap: wrap; padding: 4px 0 10px; }
.attachment { position: relative; }
.attachment img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.attachment button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #000;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  line-height: 1;
}
.input-row { display: flex; align-items: flex-end; gap: 8px; }
.input-row textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  max-height: 200px;
  padding: 8px 0;
  line-height: 1.6;
}
.input-row textarea::placeholder { color: var(--text-faint); }
.send {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--gold);
  color: #0a0a0a;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: opacity .2s ease;
}
.send:disabled { opacity: .35; cursor: default; }
.hint { font-size: 11px; color: var(--text-faint); text-align: center; margin-top: 10px; }
.err-bar {
  max-width: 780px;
  margin: 0 auto 10px;
  background: rgba(232,121,95,.12);
  border: 1px solid rgba(232,121,95,.35);
  color: #f0a08c;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
}

/* ── admin ───────────────────────────────────────────────── */

.page { max-width: 820px; margin: 0 auto; padding: 48px 24px 80px; }
.page header { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.page header img { height: 30px; }
.page h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.6px; }
.page .sub { color: var(--text-dim); margin-bottom: 34px; font-size: 14px; }
.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--dark-2);
  padding: 24px;
  margin-bottom: 24px;
}
.panel h2 { font-size: 16px; font-weight: 600; margin-bottom: 18px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row .field { flex: 1; min-width: 160px; margin-bottom: 0; }
.row .field select {
  width: 100%;
  background: var(--dark-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 16px;
  outline: none;
}
.row .btn-gold { width: auto; padding: 14px 28px; }
table.users { width: 100%; border-collapse: collapse; }
table.users th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--text-faint);
  padding-bottom: 10px;
  font-weight: 600;
}
table.users td { padding: 12px 0; border-top: 1px solid var(--line); font-size: 14px; }
table.users td.actions { text-align: right; }
.link-btn { color: var(--text-dim); font-size: 13px; margin-left: 14px; }
.link-btn:hover { color: var(--gold); }
.link-btn.danger:hover { color: #e8795f; }
.tag {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--gold);
  border: 1px solid rgba(201,169,110,.4);
  border-radius: 90px;
  padding: 2px 10px;
}
.notice { font-size: 13px; margin-top: 14px; min-height: 19px; }
.notice.ok { color: var(--gold); }
.notice.bad { color: #e8795f; }

/* ── responsive ──────────────────────────────────────────── */

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .scrim {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 40;
    display: none;
  }
  .scrim.show { display: block; }
  #menuBtn { display: grid; }
  .starters { grid-template-columns: 1fr; }
  .msg .images img { max-width: 100%; }
}
