/* OraxGPT — OpenAI-style Chat UI */
:root {
  --bg: #212121;
  --bg-elevated: #2f2f2f;
  --bg-hover: #383838;
  --bg-input: #303030;
  --border: #424242;
  --text: #ececec;
  --text-muted: #9b9b9b;
  --accent: #10a37f;
  --sidebar-w: 260px;
  --topbar-h: 52px;
  --composer-max: 768px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'Cascadia Code', ui-monospace, monospace;
  --radius: 12px;
  --danger: #ef4444;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6; }

.app { display: flex; height: 100vh; height: 100dvh; }
.hidden { display: none !important; }

.sidebar {
  width: var(--sidebar-w);
  background: #171717;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 50;
}

.sidebar-top { padding: .75rem; display: flex; gap: .5rem; align-items: center; }

.btn-new-chat {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .65rem 1rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: .875rem;
  cursor: pointer;
}
.btn-new-chat:hover { background: var(--bg-hover); }

.sidebar-search { padding: 0 .75rem .5rem; }
.sidebar-search input {
  width: 100%;
  padding: .55rem .75rem;
  background: var(--bg-elevated);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: .85rem;
}

.chat-list { flex: 1; overflow-y: auto; padding: .25rem .5rem; }

.chat-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem .75rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: .875rem;
  color: var(--text-muted);
  border: none;
  background: none;
  width: 100%;
  text-align: right;
  font-family: inherit;
}
.chat-item:hover { background: var(--bg-hover); color: var(--text); }
.chat-item.active { background: var(--bg-elevated); color: var(--text); }
.chat-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .del { opacity: 0; padding: .2rem .4rem; font-size: .75rem; }
.chat-item:hover .del { opacity: 1; }

.sidebar-bottom { padding: .75rem; border-top: 1px solid var(--border); }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem .75rem;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: .875rem;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  width: 100%;
  text-align: right;
}
.sidebar-link:hover { background: var(--bg-hover); color: var(--text); }
.mobile-close { display: none; }

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

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: .4rem .5rem;
  border-radius: 6px;
  font-size: 1rem;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }
#sidebar-open { display: none; }

.model-picker { position: relative; flex: 1; display: flex; justify-content: center; }
.model-btn {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .75rem;
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
}
.model-btn:hover { background: var(--bg-hover); }

.model-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 50%;
  transform: translateX(50%);
  min-width: 300px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  z-index: 200;
  padding: .5rem;
}
.model-empty { padding: .75rem 1rem; color: var(--text-muted); font-size: .8rem; text-align: center; }

.model-group-label {
  font-size: .7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: .5rem .75rem .25rem;
}

.model-option {
  display: block;
  width: 100%;
  padding: .6rem .75rem;
  text-align: right;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: .875rem;
  cursor: pointer;
}
.model-option-name {
  display: block;
  font-family: ui-monospace, 'Cascadia Code', monospace;
  font-size: .82rem;
  direction: ltr;
  text-align: left;
}
.model-option:hover { background: var(--bg-hover); }
.model-option.selected { background: rgba(16,163,127,.15); color: var(--accent); }
.model-option.selected .model-option-name { color: var(--accent); }
.model-option-meta { display: block; margin-top: .25rem; font-size: .72rem; }
.load-badge.on { color: #4ade80; }
.load-badge.off { color: var(--text-muted); }
.default-tag { color: var(--accent); font-size: .68rem; margin-right: .35rem; }
.model-option small { display: block; color: var(--text-muted); font-size: .75rem; }

.status-badge {
  font-size: .7rem;
  padding: .2rem .55rem;
  border-radius: 999px;
  background: rgba(16,163,127,.15);
  color: var(--accent);
}
.status-badge.off { background: rgba(239,68,68,.15); color: var(--danger); }

.btn-turbo {
  padding: .35rem .75rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  transition: .15s;
}
.btn-turbo.active {
  background: rgba(245,158,11,.15);
  border-color: rgba(245,158,11,.4);
  color: #fcd34d;
}
.btn-turbo:hover { border-color: #fcd34d; }

.messages-wrap { flex: 1; overflow-y: auto; }
.messages { max-width: var(--composer-max); margin: 0 auto; padding: 1.5rem 1rem 2rem; }

.welcome { text-align: center; padding: 4rem 1rem 2rem; }
.welcome-logo { font-size: 2.5rem; margin-bottom: 1rem; }
.welcome h1 { font-size: 1.75rem; font-weight: 600; margin-bottom: .5rem; }
.welcome p { color: var(--text-muted); margin-bottom: 2rem; }

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem;
  max-width: 600px;
  margin: 0 auto;
}

.prompt-card {
  padding: 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: right;
  font-family: inherit;
  color: var(--text);
}
.prompt-card:hover { background: var(--bg-hover); border-color: var(--text-muted); }
.prompt-card .icon { font-size: 1.25rem; margin-bottom: .35rem; }
.prompt-card .title { font-size: .875rem; font-weight: 600; }
.prompt-card .desc { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }

.turn { display: flex; gap: 1rem; padding: 1.25rem 0; border-bottom: 1px solid rgba(255,255,255,.04); }
.avatar {
  width: 32px; height: 32px; border-radius: 4px;
  display: grid; place-items: center; font-size: .85rem; flex-shrink: 0;
}
.turn.user .avatar { background: #5436da; }
.turn.assistant .avatar { background: var(--accent); }
.turn-body { flex: 1; min-width: 0; }

.turn-header {
  display: flex; align-items: center; gap: .5rem;
  margin-bottom: .35rem; font-size: .8rem; font-weight: 600; color: var(--text-muted);
}
.turn-actions { display: flex; gap: .25rem; opacity: 0; }
.turn:hover .turn-actions { opacity: 1; }
.turn-actions button {
  background: var(--bg-elevated); border: none; color: var(--text-muted);
  padding: .25rem .5rem; border-radius: 4px; font-size: .7rem; cursor: pointer; font-family: inherit;
}

.turn-content { font-size: .95rem; line-height: 1.7; word-break: break-word; }
.turn-content pre {
  background: #0d0d0d; border-radius: 8px; padding: 1rem;
  overflow-x: auto; margin: .75rem 0; direction: ltr; text-align: left;
}
.turn-content code { font-family: var(--mono); font-size: .85em; }
.turn-content :not(pre) > code { background: rgba(255,255,255,.08); padding: .15rem .35rem; border-radius: 4px; }

.code-header {
  display: flex; justify-content: space-between; align-items: center;
  background: #1a1a1a; padding: .4rem .75rem; border-radius: 8px 8px 0 0;
  font-size: .75rem; color: var(--text-muted); direction: ltr;
}
.copy-code { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: .75rem; }

.turn-meta { font-size: .7rem; color: var(--text-muted); margin-top: .5rem; }
.turn.error .turn-content { color: #fca5a5; }
.typing-cursor::after { content: '▋'; animation: blink 1s step-end infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.composer { padding: .75rem 1rem 1.25rem; flex-shrink: 0; }
.composer-inner { max-width: var(--composer-max); margin: 0 auto; }
.composer-box {
  display: flex; align-items: flex-end; gap: .5rem;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 1.25rem; padding: .5rem .5rem .5rem 1rem;
}
.composer-box:focus-within { border-color: var(--text-muted); }
.composer-box textarea {
  flex: 1; background: none; border: none; color: var(--text);
  font-family: inherit; font-size: .95rem; resize: none; max-height: 200px; min-height: 24px; padding: .4rem 0;
}
.composer-box textarea:focus { outline: none; }

.btn-send, .btn-stop {
  width: 36px; height: 36px; border-radius: 10px; border: none;
  cursor: pointer; display: grid; place-items: center;
}
.btn-send { background: var(--text); color: var(--bg); }
.btn-send:disabled { opacity: .35; cursor: not-allowed; }
.btn-stop { background: var(--danger); color: #fff; }
.composer-hint { text-align: center; font-size: .7rem; color: var(--text-muted); margin-top: .6rem; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; }
.settings-panel {
  position: fixed; top: 0; left: 0; width: min(400px, 100vw); height: 100%;
  background: var(--bg-elevated); border-right: 1px solid var(--border);
  z-index: 201; display: flex; flex-direction: column;
}
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.settings-body { flex: 1; overflow-y: auto; padding: 1rem 1.25rem; }
.settings-body section { margin-bottom: 1.5rem; }
.settings-body h3 { font-size: .75rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: .75rem; }

.field { display: block; margin-bottom: .85rem; }
.field > span { display: block; font-size: .8rem; color: var(--text-muted); margin-bottom: .35rem; }
.field input, .field textarea {
  width: 100%; padding: .6rem .75rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-family: inherit; font-size: .875rem;
}
.input-actions { display: flex; align-items: stretch; gap: .35rem; }
.input-actions input {
  flex: 1; min-width: 0; width: auto;
  font-family: ui-monospace, 'Cascadia Code', monospace; font-size: .8rem; direction: ltr; text-align: left;
}
.input-action-btn {
  flex-shrink: 0; padding: .5rem .7rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text-muted);
  cursor: pointer; font-family: inherit; font-size: .75rem; white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s;
}
.input-action-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--text-muted); }
.input-action-btn.ok { color: var(--accent); border-color: var(--accent); }
.range-field input[type="range"] { width: 100%; accent-color: var(--accent); }
.checkbox-field { display: flex; align-items: center; gap: .65rem; cursor: pointer; }
.btn-danger {
  width: 100%; padding: .65rem; background: rgba(239,68,68,.15);
  border: 1px solid rgba(239,68,68,.3); color: #fca5a5; border-radius: 8px; cursor: pointer; font-family: inherit;
}

@media (max-width: 768px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: translateX(0); }
  .mobile-close, #sidebar-open { display: block; }
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
