/* ============================================
   Sonoran Spark Console — Design System
   (tokens shared with sonoranspark-site)
   ============================================ */

:root {
  /* Colors */
  --color-bg: #0a0a0f;
  --color-bg-alt: #111118;
  --color-bg-card: #16161f;
  --color-bg-card-hover: #1c1c28;
  --color-surface: #1e1e2a;
  --color-border: rgba(255, 255, 255, 0.06);
  --color-border-hover: rgba(255, 255, 255, 0.12);

  --color-text: #e4e4e7;
  --color-text-muted: #a1a1aa;
  --color-text-dim: #71717a;

  --color-amber-50: #fffbeb;
  --color-amber-200: #fde68a;
  --color-amber-300: #fcd34d;
  --color-amber-400: #fbbf24;
  --color-amber-500: #f59e0b;
  --color-orange-500: #f97316;
  --color-orange-600: #ea580c;

  --color-green: #22c55e;
  --color-red: #ef4444;
  --color-blue: #3b82f6;

  --gradient-spark: linear-gradient(135deg, #fbbf24, #f59e0b, #f97316);
  --gradient-spark-hover: linear-gradient(135deg, #fcd34d, #fbbf24, #f59e0b);
  --gradient-text: linear-gradient(135deg, #fde68a, #f59e0b);

  /* Typography */
  --font-heading: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, monospace;

  --sidebar-width: 240px;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
ul { list-style: none; }

.table__note { color: var(--color-text-dim); font-size: 0.8rem; }

.text--accent {
  background: var(--gradient-text);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ============================================
   Shell layout (sidebar + main)
   ============================================ */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-bg-alt);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar__logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.25rem 1.25rem 1rem;
}

.sidebar__logo-icon { width: 34px; height: 34px; border-radius: 8px; }

.sidebar__logo-text { display: flex; flex-direction: column; line-height: 1.1; }

.sidebar__logo-sonoran {
  font-family: var(--font-heading);
  font-weight: 500;
  font-size: 0.8rem;
  color: #d4d4d8;
  letter-spacing: 0.02em;
}

.sidebar__logo-spark {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.05rem;
  background: var(--gradient-text);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar__tag {
  margin: 0 1.25rem 1.25rem;
  font-family: var(--font-heading);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-text-dim);
  border: 1px solid var(--color-border);
  border-radius: 99px;
  padding: 0.15rem 0.6rem;
  align-self: flex-start;
}

.sidebar__nav { flex: 1; padding: 0 0.75rem; display: flex; flex-direction: column; gap: 0.15rem; }

.sidebar__section {
  font-family: var(--font-heading);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-dim);
  padding: 1.1rem 0.6rem 0.35rem;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  font-size: 0.88rem;
  color: var(--color-text-muted);
  transition: background 0.15s var(--ease-out), color 0.15s var(--ease-out);
}

.sidebar__link:hover { background: var(--color-bg-card-hover); color: var(--color-text); }

.sidebar__link--active {
  background: var(--color-bg-card-hover);
  color: var(--color-amber-400);
}

.sidebar__link svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar__footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.sidebar__user { min-width: 0; }
.sidebar__user-name { font-size: 0.85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__user-role { font-size: 0.72rem; color: var(--color-text-dim); }

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

.main__inner { padding: 2rem clamp(1.25rem, 3vw, 2.5rem); max-width: 1200px; width: 100%; }

/* ============================================
   Page headers
   ============================================ */

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.75rem; flex-wrap: wrap; }

.page-header__title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.page-header__subtitle { color: var(--color-text-muted); font-size: 0.9rem; margin-top: 0.15rem; }

.page-header__actions { display: flex; gap: 0.6rem; align-items: center; }

.breadcrumbs { display: flex; gap: 0.4rem; font-size: 0.8rem; color: var(--color-text-dim); margin-bottom: 0.5rem; }
.breadcrumbs a:hover { color: var(--color-amber-400); }

/* ============================================
   Buttons
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 1.1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s var(--ease-out);
  white-space: nowrap;
}

.btn--primary { background: var(--gradient-spark); color: #0a0a0f; }
.btn--primary:hover { background: var(--gradient-spark-hover); transform: translateY(-1px); }

.btn--ghost { background: transparent; color: var(--color-text-muted); border-color: var(--color-border-hover); }
.btn--ghost:hover { color: var(--color-text); border-color: rgba(255, 255, 255, 0.25); }

.btn--danger { background: transparent; color: var(--color-red); border-color: rgba(239, 68, 68, 0.35); }
.btn--danger:hover { background: rgba(239, 68, 68, 0.1); }

.btn--sm { font-size: 0.78rem; padding: 0.35rem 0.8rem; }
.btn--block { width: 100%; justify-content: center; }

/* Inline SVG icons follow the text size and color of their parent. */
.icon { display: inline-block; width: 1em; height: 1em; flex-shrink: 0; }

/* A row of buttons outside a form (form footers use .form__actions). */
.actions { display: flex; align-items: center; gap: 0.6rem; margin-top: 1rem; }

/* ============================================
   Cards, stats, tables
   ============================================ */

.card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 1.25rem;
}

.card + .card { margin-top: 1rem; }

.card__title {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.9rem;
}

.card__title .icon { vertical-align: -0.15em; margin-right: 0.45rem; color: var(--color-amber-500); }
.card__title-note { color: var(--color-text-dim); font-weight: 400; font-size: 0.75rem; }

.card__text { font-size: 0.85rem; color: var(--color-text-muted); margin-bottom: 0.8rem; }
.card__footnote { font-size: 0.78rem; color: var(--color-text-dim); margin-top: 0.6rem; }

/* Destructive actions live in a red-bordered card. */
.card--danger { border-color: rgba(239, 68, 68, 0.25); }
.card--danger .card__title { color: var(--color-red); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.75rem; }

.stat {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
}

.stat__label {
  font-family: var(--font-heading);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-dim);
}

.stat__value { font-family: var(--font-heading); font-size: 1.7rem; font-weight: 700; margin-top: 0.2rem; }
.stat__value--accent {
  background: var(--gradient-text);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.stat__hint { font-size: 0.75rem; color: var(--color-text-dim); margin-top: 0.1rem; }

.table-wrap { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }

.table th {
  text-align: left;
  font-family: var(--font-heading);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-dim);
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--color-border);
}

.table td { padding: 0.75rem 0.9rem; border-bottom: 1px solid var(--color-border); vertical-align: middle; }

.table tr:last-child td { border-bottom: none; }

.table tbody tr { transition: background 0.15s; }
.table tbody tr:hover { background: var(--color-bg-card-hover); }

.table a.table__link { color: var(--color-amber-300); font-weight: 500; }
.table a.table__link:hover { text-decoration: underline; }

/* ============================================
   Badges & status
   ============================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-heading);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.18rem 0.6rem;
  border-radius: 99px;
  border: 1px solid;
}

.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.badge--green { color: var(--color-green); border-color: rgba(34, 197, 94, 0.35); background: rgba(34, 197, 94, 0.08); }
.badge--amber { color: var(--color-amber-400); border-color: rgba(251, 191, 36, 0.35); background: rgba(251, 191, 36, 0.08); }
.badge--red { color: var(--color-red); border-color: rgba(239, 68, 68, 0.35); background: rgba(239, 68, 68, 0.08); }
.badge--blue { color: var(--color-blue); border-color: rgba(59, 130, 246, 0.35); background: rgba(59, 130, 246, 0.08); }
.badge--gray { color: var(--color-text-dim); border-color: var(--color-border-hover); background: rgba(255, 255, 255, 0.03); }

.badge--pulse::before { animation: pulse 1.5s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ============================================
   Forms
   ============================================ */

.form { display: flex; flex-direction: column; gap: 1.25rem; }

.field { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; }

.field label {
  font-family: var(--font-heading);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-muted);
  transition: color 0.15s;
}

/* The label ignites while its control has focus. */
.field:focus-within label { color: var(--color-amber-400); }
.field--invalid label { color: #fca5a5; }

.field input:where([type="text"], [type="email"], [type="password"], [type="url"], [type="number"]),
.field select,
.field textarea {
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border-hover);
  border-radius: 8px;
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 0.92rem;
  line-height: 1.4;
  padding: 0.6rem 0.85rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field :where(input, select, textarea):hover { border-color: rgba(255, 255, 255, 0.2); }

.field :where(input, select, textarea):focus {
  outline: none;
  border-color: var(--color-amber-500);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
}

.field :where(input, select, textarea)::placeholder { color: var(--color-text-dim); opacity: 1; }

/* Machine-facing values — commands, URLs, env vars — read in the mono face. */
.field .mono { font-family: var(--font-mono); font-size: 0.86rem; }

.field textarea { resize: vertical; min-height: 4.5rem; line-height: 1.5; }

.field select {
  appearance: none;
  -webkit-appearance: none;
  color-scheme: dark;
  cursor: pointer;
  padding-right: 2.4rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 14px;
}

.field select:focus {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23fbbf24' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

.field--invalid :where(input, select, textarea) { border-color: rgba(239, 68, 68, 0.6); }
.field--invalid :where(input, select, textarea):focus {
  border-color: var(--color-red);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18);
}

.field__hint { font-size: 0.78rem; line-height: 1.45; color: var(--color-text-dim); }
.field__error { font-size: 0.8rem; line-height: 1.45; color: #fca5a5; }

/* Checkbox: control leads its label on one row; error/hint wrap beneath. */
.field--check { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 0.6rem; }

.field--check input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  accent-color: var(--color-amber-500);
  cursor: pointer;
}

.field--check label {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
}

.field--check:focus-within label { color: var(--color-text); }
.field--check .field__hint, .field--check .field__error { flex-basis: 100%; }

.form__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 700px) { .form__grid { grid-template-columns: 1fr; } }

.form__actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--color-border);
}

.form .errors { margin-bottom: 0; }

/* ============================================
   Flash + errors
   ============================================ */

.flash {
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font-size: 0.88rem;
  margin-bottom: 1.25rem;
  border: 1px solid;
}

.flash--notice { color: var(--color-amber-200); border-color: rgba(251, 191, 36, 0.3); background: rgba(251, 191, 36, 0.07); }
.flash--alert { color: #fca5a5; border-color: rgba(239, 68, 68, 0.3); background: rgba(239, 68, 68, 0.07); }

.errors {
  border: 1px solid rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.07);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.85rem;
  color: #fca5a5;
}

.errors ul { margin-top: 0.3rem; padding-left: 1rem; list-style: disc; }

/* ============================================
   Auth (login) screen
   ============================================ */

.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background:
    radial-gradient(ellipse 60% 50% at 50% -10%, rgba(245, 158, 11, 0.12), transparent),
    var(--color-bg);
}

.auth__card {
  width: 100%;
  max-width: 400px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: 2.25rem;
}

.auth__logo { display: flex; align-items: center; gap: 0.7rem; justify-content: center; margin-bottom: 0.75rem; }
.auth__logo-icon { width: 44px; height: 44px; border-radius: 10px; }

.auth__title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
}

.auth__subtitle { text-align: center; color: var(--color-text-muted); font-size: 0.85rem; margin: 0.3rem 0 1.75rem; }

.auth .form { gap: 1rem; }
.auth .form .btn--block { margin-top: 0.35rem; }

.auth__footer { text-align: center; margin-top: 1.5rem; font-size: 0.8rem; color: var(--color-text-dim); }
.auth__footer a { color: var(--color-amber-400); }

/* ============================================
   App detail: tabs, log viewer, misc
   ============================================ */

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 1.5rem;
  overflow-x: auto;
}

.tabs__link {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-muted);
  padding: 0.55rem 0.9rem;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tabs__link:hover { color: var(--color-text); }
.tabs__link--active { color: var(--color-amber-400); border-bottom-color: var(--color-amber-500); }

.log-viewer {
  background: #0d0d13;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.7;
  color: #b8b8c4;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 480px;
  overflow-y: auto;
}

.mono { font-family: var(--font-mono); font-size: 0.82rem; }

.copy-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border-hover);
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  overflow-x: auto;
  white-space: nowrap;
}

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 0.45rem 1rem; font-size: 0.88rem; }
.kv dt { color: var(--color-text-dim); }
.kv dd { min-width: 0; overflow-wrap: anywhere; }

.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-dim);
  font-size: 0.9rem;
}

.empty__icon { font-size: 1.75rem; margin-bottom: 0.6rem; color: var(--color-text-dim); opacity: 0.7; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.section-gap { margin-top: 1.75rem; }

.divider { border: none; border-top: 1px solid var(--color-border); margin: 1.25rem 0; }

.health-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.health-dot--healthy { background: var(--color-green); box-shadow: 0 0 8px rgba(34, 197, 94, 0.6); }
.health-dot--degraded { background: var(--color-amber-500); box-shadow: 0 0 8px rgba(245, 158, 11, 0.6); }
.health-dot--down { background: var(--color-red); box-shadow: 0 0 8px rgba(239, 68, 68, 0.6); }
.health-dot--unknown { background: var(--color-text-dim); }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar__nav { flex-direction: row; flex-wrap: wrap; padding: 0.5rem; }
  .sidebar__section { display: none; }
  .sidebar__footer { border-top: none; margin-left: auto; }
}

/* ============================================
   Copy fields, help center, auth flash
   ============================================ */

.card--form { max-width: 720px; }

.copy-field__text { flex: 1; overflow-x: auto; white-space: nowrap; }
.copy-field .btn { flex-shrink: 0; }

.auth__flash {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  min-width: 320px;
}
.auth__flash .flash { margin-bottom: 0.5rem; }

.help-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
  padding: 0.9rem 1.25rem;
}
.help-toc a {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-muted);
}
.help-toc a:hover { color: var(--color-amber-400); }

.help-steps { padding-left: 1.25rem; display: flex; flex-direction: column; gap: 0.7rem; font-size: 0.92rem; }
.help-steps li::marker { color: var(--color-amber-500); font-weight: 700; }

.help-text { font-size: 0.88rem; color: var(--color-text-muted); }
.help-text + .help-text { margin-top: 0.7rem; }
.help-text strong { color: var(--color-text); }
.help-text .health-dot { margin-right: 0.35rem; }

.help-faq dt {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.92rem;
  margin-top: 1rem;
}
.help-faq dt:first-child { margin-top: 0; }
.help-faq dd { font-size: 0.88rem; color: var(--color-text-muted); margin-top: 0.25rem; }

/* ============================================
   Environments
   ============================================ */

.env-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; }
.env-card__head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.9rem; }
.env-card__head .card__title { margin-bottom: 0; }
.env-card .kv dd > div + div { margin-top: 0.3rem; }

.synced { font-size: 0.75rem; color: var(--color-text-dim); }
.synced--stale { color: var(--color-amber-400); }

/* ============================================
   Reduced motion
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .btn--primary:hover { transform: none; }
}
