:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #dbe3ef;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft: #eaf2ff;
  --success: #16803c;
  --success-soft: #eaf8ef;
  --warning: #a15c00;
  --warning-soft: #fff7df;
  --danger: #b42318;
  --danger-soft: #fff0ef;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.07);
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(37, 99, 235, 0.08), transparent 32%),
    var(--bg);
}

button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.34);
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 18px 16px calc(28px + var(--safe-bottom));
}

.onboarding-shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 28px 16px calc(32px + var(--safe-bottom));
}

.onboarding-header { margin-bottom: 18px; }
.onboarding-header h1 { margin-bottom: 9px; }
.onboarding-header > p:last-child {
  margin-bottom: 0;
  color: var(--text-muted);
  line-height: 1.5;
}

.onboarding-card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.onboarding-card .settings-summary { margin-top: 0; }
.onboarding-submit { width: 100%; margin-top: 16px; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(23px, 6vw, 32px); line-height: 1.08; }
h2 { margin-bottom: 5px; font-size: 21px; }
h3 { margin-bottom: 6px; font-size: 18px; }

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--primary);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 25px;
  line-height: 1;
}

.icon-button:disabled { cursor: wait; opacity: 0.55; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(12px);
}

.tab {
  min-height: 42px;
  border: 0;
  border-radius: 11px;
  color: var(--text-muted);
  background: transparent;
  font-weight: 750;
  cursor: pointer;
}

.tab.is-active {
  color: var(--primary);
  background: var(--surface);
  box-shadow: 0 3px 12px rgba(15, 23, 42, 0.08);
}
.tab:disabled { cursor: default; opacity: 0.58; }

.upgrade-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  margin-bottom: 18px;
  padding: 7px 8px 7px 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--text-muted);
  background: var(--surface-muted);
  font-size: 13px;
  font-weight: 750;
  white-space: pre-line;
}

.upgrade-strip .button { flex: 0 0 auto; }
.upgrade-copy { display: grid; gap: 3px; min-width: 0; }
.upgrade-copy small { color: var(--text-muted); font-size: 11px; font-weight: 650; }
.upgrade-copy small.maintenance-warning { color: var(--warning); }
.upgrade-copy small.maintenance-error { color: var(--danger); }

.panel { display: none; }
.panel.is-active { display: block; }

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.section-heading p { margin-bottom: 0; color: var(--text-muted); font-size: 14px; }
.section-heading-with-action { align-items: center; }

.card-list { display: grid; gap: 14px; }
.project-group { display: grid; gap: 14px; }
.project-group + .project-group { margin-top: 22px; }
.project-group h3 { margin: 0; font-size: 15px; color: var(--text-muted); }
.archive-disclosure {
  min-width: 0;
  padding-top: 20px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
}
.archive-disclosure-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-muted);
}
.archive-disclosure-copy { min-width: 0; }
.archive-disclosure-copy h3 { margin: 0; color: var(--text); font-size: 17px; overflow-wrap: anywhere; }
.archive-disclosure-count { margin: 5px 0 0; color: var(--text-muted); font-size: 13px; overflow-wrap: anywhere; }
.archive-disclosure-button { flex: 0 0 auto; min-width: 108px; }
.archive-disclosure-content { display: grid; gap: 14px; margin-top: 14px; }
.archive-disclosure-content[hidden] { display: none; }

.card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card-body { padding: 17px; }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.status-stack { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.card-title { margin-bottom: 3px; font-size: 19px; word-break: break-word; }
.card-subtitle { margin: 0; color: var(--text-muted); font-size: 13px; word-break: break-all; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-success { color: var(--success); background: var(--success-soft); }
.status-warning { color: var(--warning); background: var(--warning-soft); }
.status-danger { color: var(--danger); background: var(--danger-soft); }
.status-neutral { color: var(--text-muted); background: #eef2f7; }

.info-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.info-item {
  min-width: 0;
  padding: 11px 12px;
  border-radius: 12px;
  background: var(--surface-muted);
}
.info-item-full { grid-column: 1 / -1; }
.info-label { display: block; margin-bottom: 4px; color: var(--text-muted); font-size: 12px; }
.info-value { display: block; font-size: 14px; font-weight: 750; word-break: break-word; }

.quota-block { margin-top: 17px; padding-top: 16px; border-top: 1px solid var(--border); }
.quota-section + .quota-section { margin-top: 18px; }
.quota-section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.quota-section-heading h4 { margin: 0; font-size: 15px; }
.freshness {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 5px 8px;
  border-radius: 999px;
  color: var(--text-muted);
  background: #eef2f7;
  font-size: 11px;
  font-weight: 800;
  text-align: right;
}
.freshness-fresh { color: var(--success); background: var(--success-soft); }
.freshness-pending, .freshness-stale { color: var(--warning); background: var(--warning-soft); }
.freshness-unavailable { color: var(--danger); background: var(--danger-soft); }
.quota-freshness-copy { margin: 0 0 12px; color: var(--text-muted); font-size: 12px; line-height: 1.4; }
.quota-pending {
  padding: 14px;
  border-radius: 12px;
  color: var(--warning);
  background: var(--warning-soft);
  font-size: 13px;
  font-weight: 750;
}
.quota-row + .quota-row { margin-top: 14px; }
.quota-topline { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 7px; font-size: 13px; }
.quota-name { color: var(--text-muted); }
.quota-value { font-weight: 800; }
.progress-track { height: 8px; overflow: hidden; border-radius: 999px; background: #e8edf5; }
.progress-bar { height: 100%; border-radius: inherit; background: var(--primary); transition: width 220ms ease; }
.quota-reset { margin: 6px 0 0; color: var(--text-muted); font-size: 12px; }
.quota-reset-details { display: grid; gap: 3px; margin-top: 8px; color: var(--text-muted); font-size: 12px; }
.quota-reset-details time { color: var(--text); font-weight: 750; }
.quota-reset-past { color: var(--danger); }
.quota-reached { margin: 6px 0 0; color: var(--danger); font-size: 12px; font-weight: 750; }
.quota-explanation { margin-top: 10px; }
.quota-scope { margin: 0 0 6px; color: var(--text-muted); font-size: 12px; line-height: 1.4; }
.quota-bucket-label { margin: 0 0 12px; color: var(--text); font-size: 12px; font-weight: 750; }
.archive-guidance { margin: 8px 0 0; color: var(--warning); font-size: 12px; }
.quota-button { width: 100%; border: 0; color: inherit; background: transparent; text-align: left; cursor: pointer; }
.quota-button:disabled { cursor: default; opacity: 1; }
.quota-compact { display: block; }
.quota-row-empty .quota-reset { margin-top: 0; }

.reset-credit-intro { margin: 0 0 12px; color: var(--text-muted); font-size: 12px; line-height: 1.45; }
.reset-credit-list { display: grid; gap: 10px; }
.reset-credit-row {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-muted);
}
.reset-credit-row-warning { border-color: #e7b85a; background: var(--warning-soft); }
.reset-credit-row-danger { border-color: #efb4ae; background: var(--danger-soft); }
.reset-credit-title { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.reset-credit-expiry { display: grid; gap: 3px; margin: 7px 0 10px; font-size: 12px; }
.reset-credit-expiry time { font-weight: 750; }
.reset-credit-state { color: var(--text-muted); }
.reset-credit-state-warning { color: var(--warning); font-weight: 750; }
.reset-credit-state-danger { color: var(--danger); font-weight: 750; }
.reset-credit-partial { margin: 12px 0 0; color: var(--text-muted); font-size: 12px; }
.reset-credit-row .button { width: 100%; }
.reset-credit-partial + .button,
.reset-credit-list + .button { width: 100%; margin-top: 12px; }

.card-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 9px;
  padding: 13px 17px 17px;
}

.button {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 800;
  text-align: center;
  cursor: pointer;
}
.button-primary { color: #fff; border-color: var(--primary); background: var(--primary); }
.button-primary:hover { background: var(--primary-strong); }
.button-secondary { color: var(--primary); border-color: #bdd2f9; background: var(--primary-soft); }
.button-compact { min-height: 38px; padding: 8px 12px; font-size: 13px; }
.button-link { display: flex; align-items: center; justify-content: center; text-decoration: none; }
.button:disabled { color: #8b98aa; border-color: #d7dee8; background: #eef2f6; cursor: not-allowed; }

@media (max-width: 380px) {
  .quota-section-heading { display: grid; }
  .freshness { width: fit-content; text-align: left; }
  .quota-topline { display: grid; gap: 4px; }
  .archive-disclosure-header { align-items: stretch; flex-direction: column; }
  .archive-disclosure-button { width: 100%; }
}

.notice { padding: 12px 14px; margin-bottom: 14px; border-radius: 12px; color: var(--text); background: var(--warning-soft); font-size: 14px; }
.notice-success { color: var(--success); background: var(--success-soft); }
.notice-error { color: var(--danger); background: var(--danger-soft); }
.notice-critical { color: var(--danger); background: var(--danger-soft); border: 1px solid var(--danger); }
.auth-recovery { padding: 18px; margin-bottom: 18px; }
.auth-recovery h2 { margin-bottom: 8px; }
.auth-recovery p { margin-bottom: 14px; color: var(--text); line-height: 1.5; }
.is-hidden { display: none !important; }

.empty-state { padding: 30px 18px; border: 1px dashed var(--border); border-radius: var(--radius); text-align: center; background: rgba(255,255,255,0.55); }
.empty-state p { margin-bottom: 0; color: var(--text-muted); }
.empty-icon { display: grid; place-items: center; width: 48px; height: 48px; margin: 0 auto 12px; border-radius: 15px; color: var(--primary); background: var(--primary-soft); font-weight: 900; }

.skeleton { overflow: hidden; position: relative; min-height: 170px; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,0.82), transparent); animation: shimmer 1.2s infinite; }
.skeleton-line { height: 14px; margin: 15px 17px 0; border-radius: 8px; background: #e9eef5; }
.skeleton-line.short { width: 42%; }
.skeleton-line.medium { width: 67%; }
@keyframes shimmer { to { transform: translateX(100%); } }

.dialog-backdrop {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 18px 14px calc(18px + var(--safe-bottom));
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(4px);
}

.dialog-card {
  width: min(100%, 520px);
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 25px 80px rgba(15,23,42,0.28);
}
.dialog-copy { color: var(--text-muted); line-height: 1.45; overflow-wrap: anywhere; }
.dialog-actions { display: grid; gap: 9px; margin-top: 18px; }

.field { display: block; margin-top: 15px; }
.field > span { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 800; }
.field input, .field select { width: 100%; min-height: 46px; padding: 0 13px; border: 1px solid var(--border); border-radius: 12px; color: var(--text); background: var(--surface); outline: none; }
.field input:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.field input:disabled, .field select:disabled { color: var(--text-muted); background: var(--surface-muted); cursor: wait; }
.field small { display: block; margin-top: 6px; color: var(--text-muted); overflow-wrap: anywhere; }

.auth-code-card { padding: 16px; margin: 18px 0 12px; border: 1px solid var(--border); border-radius: 15px; text-align: center; background: var(--surface-muted); }
.auth-code-card span { display: block; color: var(--text-muted); font-size: 12px; }
.auth-code-card strong { display: block; margin: 8px 0 12px; font-size: 28px; letter-spacing: 0.12em; }

.progress-row { display: flex; align-items: center; gap: 10px; margin-top: 16px; color: var(--text-muted); font-size: 14px; }
.spinner { width: 18px; height: 18px; border: 2px solid #d4deec; border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.launch-settings {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-muted);
}
.launch-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.launch-settings h4 {
  margin: 0;
  font-size: 14px;
}
.settings-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}
.settings-column-title {
  display: block;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}
.settings-list {
  display: grid;
  gap: 7px;
  margin: 0;
}
.settings-list div { min-width: 0; }
.settings-list dt {
  color: var(--text-muted);
  font-size: 12px;
}
.settings-list dd {
  margin: 2px 0 0;
  font-size: 13px;
  font-weight: 750;
  overflow-wrap: anywhere;
}
.settings-compact-line {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  overflow-wrap: anywhere;
}
.settings-summary {
  display: grid;
  gap: 9px;
  margin: 14px 0 4px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-muted);
}
.settings-summary-row,
.confirmation-summary div {
  display: grid;
  grid-template-columns: minmax(88px, 0.35fr) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}
.settings-summary-row span,
.confirmation-summary span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}
.settings-summary-row strong,
.confirmation-summary strong {
  min-width: 0;
  font-size: 13px;
  overflow-wrap: anywhere;
}
.refresh-models-button {
  width: 100%;
  margin-top: 12px;
}
.confirmation-summary {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-muted);
}

@media (max-width: 420px) {
  .app-shell { padding-inline: 12px; }
  .onboarding-shell { padding: 20px 12px calc(24px + var(--safe-bottom)); }
  .onboarding-card { padding: 16px; }
  .app-header { align-items: flex-start; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .card-header { flex-direction: column; }
  .status-stack { align-items: flex-start; }
  .status-pill { white-space: normal; }
  .info-grid { grid-template-columns: 1fr; }
  .info-item-full { grid-column: auto; }
  .card-actions { grid-template-columns: 1fr; }
  .settings-columns { grid-template-columns: 1fr; }
  .settings-summary-row,
  .confirmation-summary div { grid-template-columns: 1fr; gap: 3px; }
  .dialog-card { padding: 16px; border-radius: 18px; }
  .dialog-actions { grid-template-columns: 1fr; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #111b2d;
    --surface-muted: #162236;
    --text: #edf4ff;
    --text-muted: #98a8bd;
    --border: #263650;
    --primary: #69a2ff;
    --primary-strong: #4d8df6;
    --primary-soft: #162d50;
    --success: #64d889;
    --success-soft: #163724;
    --warning: #ffc768;
    --warning-soft: #3b2b13;
    --danger: #ff8b83;
    --danger-soft: #431e1c;
    --shadow: 0 12px 34px rgba(0, 0, 0, 0.22);
  }
  .tabs { background: rgba(17,27,45,0.78); }
  .archive-disclosure-header { background: #162236; }
  .progress-track { background: #27354b; }
  .freshness { background: #223149; }
  .button:disabled { color: #75849a; border-color: #304058; background: #1a273a; }
  .skeleton-line { background: #223149; }
  .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent); }
}

.confirmation-copy { margin-top: 16px; color: var(--text); line-height: 1.5; }
.confirmation-copy p:last-child { margin-bottom: 0; }
