:root {
  color-scheme: dark;
  --codex-bg: #071018;
  --codex-bg-2: #0d1622;
  --codex-card: rgba(13, 22, 34, 0.92);
  --codex-card-2: rgba(10, 16, 24, 0.78);
  --codex-line: rgba(103, 132, 186, 0.25);
  --codex-line-strong: rgba(34, 211, 238, 0.36);
  --codex-text: #e5efff;
  --codex-muted: #8ea3c3;
  --codex-brand: #3794ff;
  --codex-brand-2: #22d3ee;
  --codex-green: #34d399;
  --codex-yellow: #fbbf24;
  --codex-red: #f87171;
  --codex-shadow: 0 18px 60px rgba(0, 0, 0, 0.36);
  --codex-shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(180deg, rgba(14, 165, 233, 0.08), transparent 220px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 3px),
    var(--codex-bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--codex-text);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--codex-line);
  border-radius: 8px;
  padding: 0 13px;
  cursor: pointer;
  color: var(--codex-text);
  background: rgba(255, 255, 255, 0.05);
  transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}

button:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(148, 163, 184, 0.4);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.1;
}

h2 {
  font-size: 15px;
}

h3 {
  font-size: 13px;
}

code,
pre,
textarea {
  font-family: "Fira Code", Consolas, "SFMono-Regular", monospace;
}

.cliproxy-page {
  width: min(1240px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  display: grid;
  gap: 12px;
  padding: 16px;
}

.codex-card {
  min-width: 0;
  border: 1px solid var(--codex-line);
  border-radius: 8px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(20, 33, 50, 0.92), var(--codex-card));
  box-shadow: var(--codex-shadow-soft);
}

.cliproxy-hero {
  overflow: hidden;
  border-color: rgba(34, 211, 238, 0.28);
  background:
    linear-gradient(90deg, rgba(34, 211, 238, 0.1), transparent 40%),
    linear-gradient(180deg, rgba(15, 23, 42, 0.95), rgba(7, 16, 24, 0.95));
}

.hero-grid,
.codex-card-head,
.cliproxy-inline-actions,
.cliproxy-hero-actions,
.cliproxy-connect-actions,
.cliproxy-row-actions,
.cliproxy-quota-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: flex-start;
}

.hero-grid > div {
  min-width: 0;
}

.cliproxy-kicker {
  margin-bottom: 8px;
  color: var(--codex-muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.muted,
.row small,
.cliproxy-table td small,
.cliproxy-metric small,
.cliproxy-metric span,
.cliproxy-oauth-card span,
.cliproxy-provider-strip button span,
.cliproxy-quota-provider small,
.cliproxy-quota-card small {
  color: var(--codex-muted);
  font-size: 12px;
}

.muted {
  max-width: calc(100vw - 48px);
  overflow-wrap: anywhere;
}

.cliproxy-connect-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin-top: 14px;
}

.codex-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.codex-field span {
  color: var(--codex-muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.input,
.textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid rgba(103, 132, 186, 0.28);
  border-radius: 8px;
  color: var(--codex-text);
  background: rgba(5, 8, 12, 0.72);
  outline: none;
  padding: 0 11px;
}

.textarea {
  min-height: 120px;
  padding: 10px;
  line-height: 1.55;
  resize: vertical;
}

.mini-textarea {
  min-height: 74px;
}

.compact-select {
  width: min(260px, 100%);
}

.input:focus,
.textarea:focus {
  border-color: var(--codex-line-strong);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12);
}

.primary-button {
  border-color: rgba(34, 211, 238, 0.42);
  background: linear-gradient(180deg, rgba(55, 148, 255, 0.36), rgba(29, 78, 216, 0.26));
  color: #eff6ff;
  font-weight: 800;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.045);
  color: var(--codex-text);
}

.danger {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.34);
}

.notice {
  border: 1px solid rgba(251, 191, 36, 0.28);
  border-radius: 8px;
  padding: 10px 12px;
  color: #fde68a;
  background: rgba(251, 191, 36, 0.09);
  font-size: 13px;
}

.notice.is-ok {
  color: #bbf7d0;
  border-color: rgba(52, 211, 153, 0.3);
  background: rgba(52, 211, 153, 0.11);
}

.notice.is-error {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.34);
  background: rgba(248, 113, 113, 0.1);
}

.cliproxy-metrics,
.cliproxy-info-grid,
.cliproxy-quota-overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.cliproxy-metric {
  display: grid;
  gap: 4px;
  min-width: 0;
  border: 1px solid var(--codex-line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(10, 16, 24, 0.74);
  box-shadow: var(--codex-shadow-soft);
}

.cliproxy-metric strong {
  font-size: 20px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.cliproxy-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px;
}

.cliproxy-tabs button,
.cliproxy-provider-strip button,
.cliproxy-oauth-card {
  border: 1px solid var(--codex-line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--codex-text);
}

.cliproxy-tabs button {
  flex: 0 0 auto;
  min-height: 38px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
}

.cliproxy-tabs button.is-active,
.cliproxy-provider-strip button.is-active,
.cliproxy-oauth-card.is-active {
  background: rgba(55, 148, 255, 0.15);
  border-color: var(--codex-line-strong);
}

.cliproxy-tab-panel {
  display: grid;
  gap: 12px;
}

.cliproxy-two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.cliproxy-settings-grid,
.cliproxy-form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.cliproxy-form-grid {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
}

.cliproxy-toggle {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid rgba(103, 132, 186, 0.25);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--codex-text);
  font-size: 12px;
  font-weight: 800;
}

.cliproxy-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--codex-brand-2);
}

.cliproxy-provider-strip,
.cliproxy-oauth-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.platform-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.platform-card {
  display: grid;
  gap: 9px;
  min-width: 0;
  border: 1px solid rgba(103, 132, 186, 0.24);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.035);
}

.platform-card strong,
.platform-card span,
.platform-card small,
.platform-card p {
  display: block;
  overflow-wrap: anywhere;
}

.platform-card span,
.platform-card small,
.platform-card p {
  color: var(--codex-muted);
  font-size: 12px;
  line-height: 1.45;
}

.cliproxy-oauth-grid {
  grid-template-columns: repeat(3, minmax(150px, 1fr));
}

.cliproxy-provider-strip button,
.cliproxy-oauth-card {
  display: grid;
  gap: 4px;
  align-content: start;
  min-height: 76px;
  text-align: left;
  border-radius: 8px;
  padding: 11px;
}

.cliproxy-warning {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: #fde68a;
  border: 1px solid rgba(251, 191, 36, 0.24);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(251, 191, 36, 0.08);
  font-size: 12px;
}

.cliproxy-oauth-flow {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  border: 1px solid rgba(103, 132, 186, 0.22);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.cliproxy-table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid rgba(103, 132, 186, 0.2);
  border-radius: 8px;
  margin-top: 12px;
}

.cliproxy-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

.cliproxy-table th,
.cliproxy-table td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(103, 132, 186, 0.16);
  text-align: left;
  vertical-align: top;
  font-size: 12px;
}

.cliproxy-table th {
  color: var(--codex-muted);
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.cliproxy-table td strong,
.cliproxy-table td small {
  display: block;
  overflow-wrap: anywhere;
}

.cliproxy-table code {
  color: #fcd34d;
  overflow-wrap: anywhere;
}

.cliproxy-pill {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 800;
  border: 1px solid transparent;
  white-space: nowrap;
}

.cliproxy-pill.is-ok {
  color: #bbf7d0;
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.32);
}

.cliproxy-pill.is-warn {
  color: #fde68a;
  background: rgba(251, 191, 36, 0.11);
  border-color: rgba(251, 191, 36, 0.32);
}

.cliproxy-pill.is-error {
  color: #fecaca;
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.32);
}

.cliproxy-quota-provider,
.cliproxy-quota-card,
.row {
  display: grid;
  gap: 7px;
  min-width: 0;
  border: 1px solid rgba(103, 132, 186, 0.2);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.035);
}

.rows {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.row strong,
.row small {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.cliproxy-quota-bar {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(148, 163, 184, 0.15);
}

.cliproxy-quota-bar-fill {
  display: block;
  height: 100%;
  min-width: 2px;
  border-radius: inherit;
  background: var(--codex-green);
}

.cliproxy-quota-bar-fill.is-warn {
  background: var(--codex-yellow);
}

.cliproxy-quota-bar-fill.is-danger {
  background: var(--codex-red);
}

.cliproxy-log-view {
  min-height: 260px;
  max-height: 58vh;
  margin: 12px 0 0;
  border: 1px solid rgba(103, 132, 186, 0.18);
  border-radius: 8px;
  background: rgba(5, 8, 12, 0.65);
  color: #dbeafe;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow: auto;
  padding: 12px;
}

.chat-card {
  min-height: min(720px, calc(100dvh - 190px));
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto auto;
  gap: 10px;
}

.chat-transcript {
  min-height: 260px;
  max-height: calc(100dvh - 390px);
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  border: 1px solid rgba(103, 132, 186, 0.18);
  border-radius: 8px;
  padding: 12px;
  background: rgba(5, 8, 12, 0.45);
}

.chat-empty {
  display: grid;
  gap: 5px;
  color: var(--codex-muted);
  font-size: 13px;
}

.chat-message {
  max-width: min(760px, 92%);
  display: grid;
  gap: 6px;
  border: 1px solid rgba(103, 132, 186, 0.2);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.chat-message.is-user {
  justify-self: end;
  border-color: rgba(34, 211, 238, 0.32);
  background: rgba(14, 116, 144, 0.16);
}

.chat-message.is-assistant,
.chat-message.is-agent {
  justify-self: start;
}

.chat-message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--codex-muted);
  font-size: 11px;
}

.chat-message-body {
  color: var(--codex-text);
  font-size: 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.chat-agent-row {
  display: grid;
}

[hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  .hero-grid,
  .cliproxy-connect-grid,
  .cliproxy-settings-grid,
  .cliproxy-form-grid,
  .cliproxy-two-col,
  .cliproxy-metrics,
  .cliproxy-info-grid,
  .cliproxy-quota-overview,
  .cliproxy-provider-strip,
  .cliproxy-oauth-grid,
  .platform-grid,
  .chat-composer {
    grid-template-columns: 1fr;
  }

  .cliproxy-connect-actions,
  .cliproxy-hero-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 620px) {
  .cliproxy-page {
    padding: 10px;
  }

  .codex-card {
    padding: 12px;
  }

  .hero-grid,
  .codex-card-head,
  .cliproxy-inline-actions {
    align-items: stretch;
    flex-direction: column;
  }

  button {
    width: 100%;
  }
}
