:root {
  --cu-gold: #cfb87c;
  --cu-gold-dark: #b9a25e;
  --black: #000000;
  --dark-gray: #565a5c;
  --light-gray: #a2a4a3;
  --surface: #ffffff;
  --surface-alt: #f6f4ef;
  --user-bubble: #efe9d8;
  --assistant-bubble: #ffffff;
  --border: #e2ddd0;
  --danger: #8a1f11;
}

* { box-sizing: border-box; }

/* Ensure the `hidden` attribute always wins over class display rules
   (e.g. .dropdown-menu sets display:flex, which would otherwise show it). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--black);
  background: var(--surface-alt);
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

/* Notice banner */
.notice {
  background: #2b2b2b;
  color: #f4efe2;
  font-size: 0.82rem;
  line-height: 1.4;
  padding: 0.55rem 1rem;
  border-bottom: 3px solid var(--cu-gold);
}
.notice strong { color: var(--cu-gold); }
.notice a { color: var(--cu-gold); }

/* Top bar */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 1rem;
  background: var(--black);
  color: #fff;
  border-bottom: 2px solid var(--cu-gold);
  flex-wrap: wrap;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
#model {
  background: #1c1c1c; color: #fff; border: 1px solid var(--dark-gray);
  border-radius: 6px; padding: 0.35rem 0.5rem; font-size: 0.9rem; max-width: 320px;
}
.pricing-link { color: var(--cu-gold); font-size: 0.78rem; text-decoration: none; }
.pricing-link:hover { text-decoration: underline; }
.rates { color: var(--light-gray); font-size: 0.72rem; }
.quota { color: var(--cu-gold); font-size: 0.8rem; }
.usage { color: var(--light-gray); font-size: 0.72rem; }

.icon-btn {
  background: transparent; border: 1px solid var(--dark-gray); color: #fff;
  border-radius: 6px; cursor: pointer; padding: 0.3rem 0.5rem; font-size: 0.95rem;
}
.icon-btn:hover { border-color: var(--cu-gold); }

/* Transcript */
#transcript {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}
.msg { margin: 0 0 1rem; display: flex; flex-direction: column; }
.msg .role { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--dark-gray); margin-bottom: 0.25rem; }
.bubble {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.5;
  background: var(--assistant-bubble);
}
.msg.user .bubble { background: var(--user-bubble); }
.msg.user { align-items: flex-end; }
.msg.user .bubble { border-top-right-radius: 2px; }
.msg.assistant .bubble { border-top-left-radius: 2px; }
.msg .meta { font-size: 0.7rem; color: var(--dark-gray); margin-top: 0.3rem; }
.msg .attach { font-size: 0.72rem; color: var(--dark-gray); margin-top: 0.3rem; }
.msg.error .bubble { border-color: var(--danger); color: var(--danger); background: #fbeeec; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0 0.25rem; }
.chip {
  background: var(--user-bubble); border: 1px solid var(--border); border-radius: 999px;
  padding: 0.15rem 0.6rem; font-size: 0.75rem; display: inline-flex; align-items: center; gap: 0.35rem;
}
.chip button { border: none; background: none; cursor: pointer; font-size: 0.85rem; line-height: 1; color: var(--dark-gray); }

/* Composer */
#composer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 0.6rem 1rem 0.8rem;
}
.composer-row { display: flex; align-items: flex-end; gap: 0.5rem; max-width: 900px; margin: 0.4rem auto 0; }
#input {
  flex: 1; resize: none; font: inherit; padding: 0.6rem 0.7rem;
  border: 1px solid var(--border); border-radius: 8px;
  /* Floor of ~2.5 lines so the resting box is roomier; autogrow (app.js) still
     expands it from scrollHeight up to the max as the user types. */
  min-height: 3.5rem; max-height: 40vh;
}
#input:focus, #model:focus { outline: 2px solid var(--cu-gold); }
#sendBtn {
  background: var(--cu-gold); color: #1c1c1c; font-weight: 600; border: none;
  border-radius: 8px; padding: 0.6rem 1.1rem; cursor: pointer;
}
#sendBtn:hover { background: var(--cu-gold-dark); }
#sendBtn:disabled { opacity: 0.5; cursor: default; }

.composer-tools { display: flex; gap: 0.5rem; max-width: 900px; margin: 0.5rem auto 0; }
button.secondary {
  background: var(--surface-alt); border: 1px solid var(--border); color: var(--black);
  border-radius: 6px; padding: 0.35rem 0.7rem; cursor: pointer; font-size: 0.8rem;
}
button.secondary:hover { border-color: var(--cu-gold); }

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; bottom: 110%; left: 0; background: #fff; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,0.12); display: flex; flex-direction: column; min-width: 200px; z-index: 10;
}
.dropdown-menu button { background: none; border: none; text-align: left; padding: 0.55rem 0.8rem; cursor: pointer; font-size: 0.82rem; }
.dropdown-menu button:hover { background: var(--surface-alt); }

/* Preprompt panel */
.panel {
  max-width: 900px; margin: 0.5rem auto; width: calc(100% - 2rem);
  background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 0.8rem;
}
.panel textarea { width: 100%; font: inherit; padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; resize: vertical; }
.panel-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.panel-actions button { background: var(--cu-gold); border: none; border-radius: 6px; padding: 0.35rem 0.8rem; cursor: pointer; }
.panel-actions button.secondary { background: var(--surface-alt); border: 1px solid var(--border); }
.panel-note { color: var(--dark-gray); font-size: 0.82rem; line-height: 1.4; margin: 0.3rem 0 0.7rem; }
.keys-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.35rem 0; }
.keys-row span:first-child { font-weight: 600; min-width: 9rem; }
.keys-state { color: var(--dark-gray); font-size: 0.8rem; flex: 1; }
.keys-row input { flex: 1; font: inherit; padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; }
.keys-row button { background: var(--cu-gold); border: none; border-radius: 6px; padding: 0.35rem 0.8rem; cursor: pointer; }
.keys-row button.secondary { background: var(--surface-alt); border: 1px solid var(--border); }

/* Gateway API keys (§7.5): setup hints + the one-time secret */
.api-setup { font-size: 0.82rem; margin-bottom: 0.6rem; }
.api-tool { margin: 0.2rem 0 0.7rem; }
.api-tool-name { font-weight: 700; margin-bottom: 0.2rem; }
.api-step { color: var(--dark-gray); margin: 0.25rem 0 0.15rem; }
.api-cmd-box { position: relative; margin: 0.1rem 0; }
.api-cmd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78rem;
  background: var(--surface-alt); border: 1px solid var(--border); border-radius: 6px;
  padding: 0.4rem 3.6rem 0.4rem 0.6rem; margin: 0; overflow-x: auto; white-space: pre;
  line-height: 1.5;
}
.api-copy {
  position: absolute; top: 0.3rem; right: 0.3rem;
  font-size: 0.72rem; padding: 0.15rem 0.5rem; border-radius: 5px; cursor: pointer;
  background: var(--surface-alt); border: 1px solid var(--border);
}
.api-key-secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8rem;
  background: var(--surface-alt); padding: 0.05rem 0.35rem; border-radius: 4px; word-break: break-all;
}
#apiKeyNew { border: 1px solid var(--cu-gold); border-radius: 6px; padding: 0.5rem 0.7rem; margin-top: 0.6rem; }
.api-key-secret { display: inline-block; margin: 0.2rem 0.5rem 0.2rem 0; padding: 0.25rem 0.5rem; }

/* Signed-in identity + logout (topbar, hosted mode) */
.who {
  color: var(--dark-gray); font-size: 0.78rem; font-weight: 600;
  max-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Login page */
.login-body { align-items: center; justify-content: center; }
.login-card {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  border-top: 4px solid var(--cu-gold);
  box-shadow: 0 6px 24px rgba(0,0,0,0.10);
  padding: 2rem; width: calc(100% - 2rem); max-width: 380px;
}
.login-card h1 { margin: 0 0 0.3rem; font-size: 1.4rem; }
.login-sub { margin: 0 0 1.2rem; color: var(--dark-gray); font-size: 0.85rem; line-height: 1.4; }
#loginForm { display: flex; flex-direction: column; gap: 0.7rem; }
#loginForm input {
  font: inherit; padding: 0.6rem 0.7rem; border: 1px solid var(--border);
  border-radius: 8px; width: 100%;
}
#loginForm input:focus { outline: none; border-color: var(--cu-gold); }
#loginBtn {
  background: var(--cu-gold); color: #1c1c1c; font-weight: 600; border: none;
  border-radius: 8px; padding: 0.6rem 1.1rem; cursor: pointer;
}
#loginBtn:hover { background: var(--cu-gold-dark); }
#loginBtn:disabled { opacity: 0.5; cursor: default; }
.login-error { color: var(--danger); font-size: 0.82rem; margin: 0.9rem 0 0; }

.empty-hint { color: var(--dark-gray); text-align: center; margin-top: 15vh; font-size: 0.95rem; }
