/*
 * Core stylesheet for the crmgorilla/core package.
 * All color, typography, and radius decisions flow through the :root tokens below;
 * an instance theme.css (loaded after this file) can re-declare any token to rebrand
 * without touching component rules. Spacing follows an 8px scale. No brand strings,
 * no external URLs, no inline styles anywhere (CSP: default-src 'self').
 */

:root {
  --cg-bg: #f5f6f8;
  --cg-surface: #ffffff;
  --cg-text: #16181d;
  --cg-muted: #5b6270;
  --cg-accent: #1f6f43;
  --cg-accent-text: #ffffff;
  --cg-danger: #b3261e;
  /* Danger surface tokens — derived defaults matching the historical rgb(179 38 30)
     alert look. Re-token --cg-danger together with these to restyle the alert wholesale
     (e.g. a dark theme). */
  --cg-danger-bg: rgb(179 38 30 / .07);
  --cg-danger-border: rgb(179 38 30 / .3);
  /* Neutral borders/dividers — every hairline flows through one of these so a theme
     can re-token chrome without touching component rules. */
  --cg-border: #d5d8de;        /* default input / control border */
  --cg-border-strong: #b8bdc7; /* hover / emphasized border */
  --cg-border-soft: #e3e5ea;   /* topbar underline */
  --cg-divider: #eef0f3;       /* list-row dividers */
  --cg-radius: 10px;
  --cg-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--cg-bg);
  color: var(--cg-text);
  font-family: var(--cg-font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.cg-main {
  display: block;
  min-height: 100vh;
}

:focus-visible {
  outline: 2px solid var(--cg-accent);
  outline-offset: 1px;
}

.cg-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Auth pages ---------- */

.cg-auth {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
}

.cg-wordmark {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--cg-text);
  text-align: center;
}

/* ---------- Card ---------- */

.cg-card {
  width: 100%;
  max-width: 400px;
  background: var(--cg-surface);
  border-radius: var(--cg-radius);
  padding: 32px;
  box-shadow: 0 1px 3px rgb(0 0 0 / .08), 0 8px 24px rgb(0 0 0 / .06);
}

.cg-card--wide {
  max-width: none;
}

.cg-card-title {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
}

.cg-hint {
  margin: 0 0 24px;
  font-size: 14px;
  color: var(--cg-muted);
}

/* ---------- Forms ---------- */

.cg-field {
  margin-bottom: 16px;
}

.cg-label,
.cg-label-static {
  display: block;
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--cg-text);
}

.cg-input {
  display: block;
  width: 100%;
  height: 44px;
  padding: 0 12px;
  font-family: var(--cg-font);
  font-size: 16px;
  color: var(--cg-text);
  background: var(--cg-surface);
  border: 1px solid var(--cg-border);
  border-radius: calc(var(--cg-radius) - 2px);
  transition: border-color 120ms ease;
}

.cg-input:hover {
  border-color: var(--cg-border-strong);
}

.cg-input:focus-visible {
  outline: 2px solid var(--cg-accent);
  outline-offset: 1px;
  border-color: var(--cg-accent);
}

.cg-input--error {
  border-color: var(--cg-danger);
}

.cg-input--error:focus-visible {
  outline-color: var(--cg-danger);
}

.cg-input--code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 18px;
  letter-spacing: 0.3em;
  text-align: center;
}

.cg-field-error {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--cg-danger);
}

.cg-alert {
  margin: 0 0 16px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--cg-danger);
  background: var(--cg-danger-bg);
  border: 1px solid var(--cg-danger-border);
  border-radius: calc(var(--cg-radius) - 2px);
}

/* ---------- Buttons ---------- */

.cg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--cg-font);
  font-size: 15px;
  font-weight: 600;
  border-radius: calc(var(--cg-radius) - 2px);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.cg-btn:focus-visible {
  outline: 2px solid var(--cg-accent);
  outline-offset: 2px;
}

.cg-btn--primary {
  width: 100%;
  height: 44px;
  margin-top: 8px;
  color: var(--cg-accent-text);
  background: var(--cg-accent);
}

.cg-btn--primary:hover {
  background: var(--cg-accent); /* fallback: color-mix() unsupported -> keep a solid bg */
  background: color-mix(in srgb, var(--cg-accent), #000000 12%);
}

.cg-btn--primary:active {
  background: var(--cg-accent); /* fallback: color-mix() unsupported -> keep a solid bg */
  background: color-mix(in srgb, var(--cg-accent), #000000 20%);
}

.cg-btn--ghost {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  color: var(--cg-text);
  background: transparent;
  border-color: var(--cg-border);
}

.cg-btn--ghost:hover {
  background: var(--cg-bg);
  border-color: var(--cg-border-strong);
}

/* ---------- 2FA setup ---------- */

.cg-secret {
  margin: 0 0 16px;
  padding: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  letter-spacing: 0.12em;
  text-align: center;
  word-break: break-all;
  color: var(--cg-text);
  background: var(--cg-bg);
  border: 1px solid var(--cg-border);
  border-radius: calc(var(--cg-radius) - 2px);
  user-select: all;
  -webkit-user-select: all;
}

.cg-details {
  margin: 0 0 24px;
  font-size: 13px;
  color: var(--cg-muted);
}

.cg-details summary {
  cursor: pointer;
  font-weight: 500;
  border-radius: 4px;
}

.cg-details summary:hover {
  color: var(--cg-text);
}

.cg-uri {
  margin: 8px 0 0;
  padding: 8px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
  background: var(--cg-bg);
  border-radius: calc(var(--cg-radius) - 4px);
  user-select: all;
  -webkit-user-select: all;
}

/* ---------- Dashboard ---------- */

.cg-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 56px;
  padding: 0 24px;
  background: var(--cg-surface);
  border-bottom: 1px solid var(--cg-border-soft);
}

.cg-topbar-brand {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.cg-topbar-user {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.cg-topbar-email {
  font-size: 14px;
  color: var(--cg-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cg-logout-form {
  margin: 0;
}

.cg-content {
  max-width: 720px;
  margin: 32px auto;
  padding: 0 24px;
}

.cg-checks {
  list-style: none;
  margin: 0;
  padding: 0;
}

.cg-check {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--cg-divider);
}

.cg-check:last-child {
  border-bottom: none;
}

.cg-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* Non-color cue (WCAG 1.4.1): "ok" is a solid filled disc, "fail" is a hollow
   ring — the shape differs, not just the hue. A visible "Not ready" text label
   (below) reinforces the fail state for anyone who can't perceive either. */
.cg-dot--ok {
  background: var(--cg-accent);
}

.cg-dot--fail {
  background: transparent;
  border: 2px solid var(--cg-danger);
}

.cg-check-label {
  font-size: 15px;
}

.cg-check-status {
  margin-left: auto;
  flex: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--cg-danger);
}

/* ---------- AI gateway keys ---------- */

/* A wider content column than the 720px dashboard default — the key table needs room. */
.cg-content--wide {
  max-width: 960px;
}

/* Stack the page's cards with even vertical rhythm. */
.cg-content--wide > .cg-card + .cg-card {
  margin-top: 24px;
}

.cg-card-subtitle {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.cg-hint--flush {
  margin-bottom: 0;
}

/* Success / status notice — the additive counterpart to .cg-alert, tokenised off the
   accent so a theme restyles it alongside the palette. */
.cg-notice {
  margin: 0 0 16px;
  padding: 12px 16px;
  font-size: 14px;
  border-radius: calc(var(--cg-radius) - 2px);
  border: 1px solid transparent;
}

.cg-notice--ok {
  color: var(--cg-accent);
  background: var(--cg-bg); /* fallback: color-mix() unsupported -> keep a solid tint */
  background: color-mix(in srgb, var(--cg-accent) 8%, transparent);
  border-color: var(--cg-border); /* fallback */
  border-color: color-mix(in srgb, var(--cg-accent) 28%, transparent);
}

/* One-time token reveal — deliberately prominent so the operator notices they must
   copy it now. */
.cg-reveal {
  margin: 8px 0 0;
  padding: 16px;
  background: var(--cg-bg); /* fallback: color-mix() unsupported -> keep a solid surface */
  background: color-mix(in srgb, var(--cg-accent) 6%, var(--cg-surface));
  border: 1px solid var(--cg-border); /* fallback */
  border-color: color-mix(in srgb, var(--cg-accent) 28%, transparent);
  border-radius: calc(var(--cg-radius) - 2px);
}

.cg-reveal-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--cg-muted);
  text-transform: uppercase;
}

.cg-reveal-token {
  margin: 0 0 8px;
  padding: 12px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  word-break: break-all;
  color: var(--cg-text);
  background: var(--cg-surface);
  border: 1px solid var(--cg-border);
  border-radius: calc(var(--cg-radius) - 4px);
  user-select: all;
  -webkit-user-select: all;
}

.cg-reveal-note {
  margin: 0;
  font-size: 13px;
  color: var(--cg-muted);
}

/* Mint form — constrained width; fields read as a compact panel, not a full-page form. */
.cg-keyform {
  max-width: 460px;
}

.cg-select {
  display: block;
  width: 100%;
  height: 44px;
  padding: 0 12px;
  font-family: var(--cg-font);
  font-size: 16px;
  color: var(--cg-text);
  background: var(--cg-surface);
  border: 1px solid var(--cg-border);
  border-radius: calc(var(--cg-radius) - 2px);
  transition: border-color 120ms ease;
}

.cg-select:hover {
  border-color: var(--cg-border-strong);
}

.cg-select:focus-visible {
  outline: 2px solid var(--cg-accent);
  outline-offset: 1px;
  border-color: var(--cg-accent);
}

/* An inline (auto-width) variant of the primary button for in-panel forms — the base
   .cg-btn--primary is full-width, which is wrong for a short "Create key" action. */
.cg-btn--inline {
  width: auto;
  padding: 0 20px;
}

.cg-btn--danger {
  color: var(--cg-danger);
  border-color: var(--cg-border);
}

.cg-btn--danger:hover {
  color: var(--cg-danger);
  background: var(--cg-danger-bg);
  border-color: var(--cg-danger-border);
}

.cg-inline-form {
  margin: 0;
}

/* Key table — horizontal scroll wrapper keeps the layout from overflowing on narrow
   viewports; the table itself is a clean, borderless-row list. */
.cg-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.cg-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.cg-table th,
.cg-table td {
  padding: 12px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--cg-divider);
  white-space: nowrap;
}

.cg-table th {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--cg-muted);
  text-transform: uppercase;
}

.cg-table tbody tr:last-child td {
  border-bottom: none;
}

.cg-row--revoked td {
  color: var(--cg-muted);
}

.cg-cell--action {
  text-align: right;
}

.cg-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  color: var(--cg-text);
}

/* Pills — small status/scope labels. Neutral base; scope/state variants tint from the
   token palette so a theme rebrands them for free. */
.cg-pill {
  display: inline-block;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  border-radius: 999px;
  border: 1px solid var(--cg-border);
  color: var(--cg-muted);
  background: var(--cg-bg);
}

.cg-pill--operator,
.cg-pill--active {
  color: var(--cg-accent);
  background: var(--cg-bg); /* fallback: color-mix() unsupported -> keep a solid tint */
  background: color-mix(in srgb, var(--cg-accent) 8%, transparent);
  border-color: var(--cg-border); /* fallback */
  border-color: color-mix(in srgb, var(--cg-accent) 26%, transparent);
}

.cg-pill--analyst {
  color: var(--cg-muted);
  background: var(--cg-bg);
  border-color: var(--cg-border);
}

.cg-pill--revoked {
  color: var(--cg-danger);
  background: var(--cg-danger-bg);
  border-color: var(--cg-danger-border);
}

/* ---------- Small screens ---------- */

@media (max-width: 480px) {
  .cg-card {
    padding: 24px;
  }

  .cg-auth {
    padding: 24px 16px;
  }

  .cg-topbar {
    padding: 0 16px;
  }

  .cg-content {
    margin: 16px auto;
    padding: 0 16px;
  }

  /* Collapse the key table into stacked rows: each cell becomes a labelled line
     (label from the data-label attribute), so the data stays readable without a
     horizontal scroll on phones. */
  .cg-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  .cg-table,
  .cg-table tbody,
  .cg-table tr,
  .cg-table td {
    display: block;
    width: 100%;
  }

  .cg-table tr {
    padding: 12px 0;
    border-bottom: 1px solid var(--cg-divider);
  }

  .cg-table tbody tr:last-child {
    border-bottom: none;
  }

  .cg-table td {
    padding: 4px 0;
    border-bottom: none;
    white-space: normal;
  }

  .cg-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--cg-muted);
    text-transform: uppercase;
  }

  .cg-table td.cg-cell--action {
    text-align: left;
  }

  .cg-table td.cg-cell--action::before {
    content: none;
  }
}
