/* ============================================================================
   Deploy Agent — visual system
   Three token layers: primitives -> semantic -> components.
   Components reference only semantic tokens. Light values live on bare :root;
   dark is redefined three ways so both the OS setting and the manual toggle win.
   ========================================================================== */

:root {
  /* --- primitives ------------------------------------------------------- */
  --slate-50:  #f8fafc;  --slate-100: #f1f5f9;  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;  --slate-400: #94a3b8;  --slate-500: #64748b;
  --slate-600: #475569;  --slate-700: #334155;  --slate-800: #1e293b;
  --slate-900: #0f172a;  --slate-950: #0b0f16;

  --indigo-500: #6366f1; --indigo-600: #4f46e5;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius-sm: 6px;  --radius: 8px;  --radius-lg: 12px;  --radius-pill: 999px;
  --shadow-card: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-pop:  0 10px 30px -12px rgba(15, 23, 42, .28);
  --dur-fast: 150ms; --dur: 220ms; --ease: cubic-bezier(.4, 0, .2, 1);

  /* --- semantic (LIGHT) ---------------------------------------------------- */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: var(--slate-50);
  --border: var(--slate-200);
  --border-strong: var(--slate-300);
  --text: var(--slate-800);
  --text-muted: var(--slate-500);
  --text-faint: var(--slate-400);
  --accent: var(--indigo-600);
  --accent-text: #ffffff;
  --focus-ring: var(--indigo-500);

  --ok-fg: #15803d;   --ok-bg: #dcfce7;
  --warn-fg: #a16207; --warn-bg: #fef9c3;
  --err-fg: #b91c1c;  --err-bg: #fee2e2;

  --wash-a: #eef2ff;  --wash-b: #ecfeff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--slate-950);
    --surface: #111827;
    --surface-2: var(--slate-900);
    --border: var(--slate-800);
    --border-strong: var(--slate-700);
    --text: var(--slate-300);
    --text-muted: var(--slate-400);
    --text-faint: var(--slate-500);
    --accent: var(--indigo-500);
    --accent-text: #ffffff;
    --focus-ring: var(--indigo-500);

    --ok-fg: #4ade80;   --ok-bg: rgba(34, 197, 94, .16);
    --warn-fg: #fbbf24; --warn-bg: rgba(251, 191, 36, .16);
    --err-fg: #f87171;  --err-bg: rgba(248, 113, 113, .16);

    --wash-a: #1e1b4b;  --wash-b: #0f172a;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-pop:  0 20px 50px -12px rgba(0, 0, 0, .55);
  }
}

:root[data-theme="dark"] {
  --bg: var(--slate-950);
  --surface: #111827;
  --surface-2: var(--slate-900);
  --border: var(--slate-800);
  --border-strong: var(--slate-700);
  --text: var(--slate-300);
  --text-muted: var(--slate-400);
  --text-faint: var(--slate-500);
  --accent: var(--indigo-500);
  --accent-text: #ffffff;
  --focus-ring: var(--indigo-500);

  --ok-fg: #4ade80;   --ok-bg: rgba(34, 197, 94, .16);
  --warn-fg: #fbbf24; --warn-bg: rgba(251, 191, 36, .16);
  --err-fg: #f87171;  --err-bg: rgba(248, 113, 113, .16);

  --wash-a: #1e1b4b;  --wash-b: #0f172a;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-pop:  0 20px 50px -12px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

code, pre { font-family: var(--font-mono); font-size: 13px; }

a { color: var(--accent); }

/* --- top bar ----------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex; align-items: center; gap: 9px;
  font-weight: 650; text-decoration: none; color: var(--text);
}
.brand::before {
  content: "D";
  display: grid; place-items: center;
  width: 24px; height: 24px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--indigo-500), var(--indigo-600));
  color: #fff; font-size: 13px; font-weight: 700;
}
.topbar nav { display: flex; align-items: center; gap: 18px; }
.topbar nav a {
  color: var(--text-muted); text-decoration: none;
  border-bottom: 1px solid transparent; padding-bottom: 2px;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.topbar nav a:hover { color: var(--text); border-color: var(--border-strong); }

.theme-toggle {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; padding: 0;
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14px; line-height: 1;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.theme-toggle:hover { color: var(--text); border-color: var(--border-strong); }

main { max-width: 960px; margin: 0 auto; padding: 28px 24px 64px; }

h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 24px 0 8px; }
p { margin: 6px 0; }

.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; color: var(--text); text-decoration: none; }
.strong:hover { text-decoration: underline; }
.right { text-align: right; }
.row-between { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.inline { display: inline; }

/* --- cards ------------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin: 16px 0;
  box-shadow: var(--shadow-card);
}
.card--narrow { max-width: 380px; margin: 48px auto; }
.empty { text-align: center; padding: 48px 20px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
fieldset {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin: 0; display: flex; flex-direction: column; gap: 14px;
}
legend {
  padding: 0 6px; font-weight: 600; font-size: 13px;
  text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted);
}
label { display: flex; flex-direction: column; gap: 5px; font-size: 14px; font-weight: 500; }
label small { font-weight: 400; color: var(--text-faint); }
label.row { flex-direction: row; align-items: center; gap: 8px; }
label.row input[type="checkbox"] { width: 16px; height: 16px; }

input, select, textarea {
  padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
select[multiple] { padding: 4px; }
textarea { resize: vertical; font-family: var(--font-mono); }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--focus-ring); outline-offset: -1px; border-color: var(--focus-ring);
}

/* --- select widget (progressive enhancement of a native <select>/<input>) --- */
.sw { position: relative; }
.sw__native {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.sw__trigger {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 8px 10px; font: inherit; font-weight: 400; text-align: left;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
.sw__trigger:hover { filter: none; }
.sw__trigger[aria-expanded="true"] { border-color: var(--focus-ring); }
.sw__trigger:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.sw__value { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw__placeholder { flex: 1; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw__chips { flex: 1; display: flex; flex-wrap: wrap; gap: 4px; }
.sw__chip {
  padding: 1px 7px; font-size: 12px; border-radius: var(--radius-pill);
  background: var(--surface-2); border: 1px solid var(--border);
}
.sw__caret { color: var(--text-faint); font-size: 11px; }

.sw__panel {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px);
  padding: 6px; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop);
}
.sw__search {
  width: 100%; margin-bottom: 6px; padding: 6px 8px; font: inherit; font-size: 14px;
}
.sw__list { margin: 0; padding: 0; list-style: none; max-height: 240px; overflow-y: auto; }
.sw__group {
  padding: 8px 8px 4px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint);
}
.sw__opt {
  padding: 7px 9px; border-radius: var(--radius-sm); font-size: 14px;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sw__opt:hover, .sw__opt--active { background: var(--surface-2); }
.sw__opt[aria-selected="true"] { background: var(--accent); color: var(--accent-text); }
.sw__opt--create { color: var(--accent); font-style: italic; }
.sw__opt--create[aria-selected], .sw__opt--create:hover { color: var(--accent-text); }

/* --- buttons --------------------------------------------------------- */
button, .button {
  display: inline-block; padding: 8px 14px; font: inherit; font-weight: 500;
  color: var(--accent-text); background: var(--accent); border: 1px solid transparent;
  border-radius: var(--radius-sm); cursor: pointer; text-decoration: none;
  transition: filter var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
button:hover, .button:hover { filter: brightness(1.08); }
button:focus-visible, .button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.button--quiet { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.button--quiet:hover { filter: none; background: var(--surface-2); }
.button--danger { background: var(--err-fg); color: #fff; }
button.link { background: none; border: none; color: var(--text-muted); padding: 0; cursor: pointer; }
button.link:hover { color: var(--text); filter: none; }

/* --- tables --------------------------------------------------------- */
.table {
  width: 100%; border-collapse: collapse; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr { transition: background var(--dur-fast) var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table tr:last-child td { border-bottom: none; }
.table td form, .table td .button { margin-left: 6px; }
.table td code { color: var(--text-muted); }

/* --- badges --------------------------------------------------------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 600; background: var(--border); color: var(--text);
}
.badge--success { background: var(--ok-bg); color: var(--ok-fg); }
.badge--running, .badge--queued { background: var(--warn-bg); color: var(--warn-fg); animation: badge-pulse 1.6s var(--ease) infinite; }
.badge--failed, .badge--rejected, .badge--rolled-back-unhealthy { background: var(--err-bg); color: var(--err-fg); }
.badge--rolled-back { background: var(--warn-bg); color: var(--warn-fg); }

@keyframes badge-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

/* --- alerts -------------------------------------------------------- */
.alert {
  padding: 12px 16px; border-radius: var(--radius); margin: 0 0 16px;
  border-left: 3px solid transparent;
}
.alert--ok { background: var(--ok-bg); color: var(--ok-fg); border-left-color: var(--ok-fg); }
.alert--warn { background: var(--warn-bg); color: var(--warn-fg); border-left-color: var(--warn-fg); }
.alert--error { background: var(--err-bg); color: var(--err-fg); border-left-color: var(--err-fg); }
.alert ul { margin: 6px 0 0; padding-left: 20px; }

/* --- log pane (always dark, both themes) -------------------------- */
.log {
  background: #0a0c10; color: #d7dbe2; padding: 16px; border-radius: var(--radius);
  overflow-x: auto; max-height: 60vh; overflow-y: auto; white-space: pre; line-height: 1.5;
  border: 1px solid #1b1f27;
}

.copyable {
  background: var(--bg); border: 1px solid var(--border); padding: 10px 12px;
  border-radius: var(--radius-sm); overflow-x: auto; cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease);
}
.copyable:hover { border-color: var(--accent); }
.device-code { font-size: 28px; text-align: center; letter-spacing: 0.2em; }

.danger { border-color: var(--err-fg); }
.danger h2 { color: var(--err-fg); margin-top: 0; }

/* --- responsive --------------------------------------------------- */
@media (max-width: 640px) {
  main { padding: 20px 14px 48px; }
  .row-between { flex-direction: column; }
  .table thead { display: none; }
  .table td { display: block; border-bottom: none; padding: 4px 14px; }
  .table tr { display: block; border-bottom: 1px solid var(--border); padding: 10px 0; }
}

/* --- motion ------------------------------------------------------- */
main { animation: page-in var(--dur) var(--ease) both; }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.log[data-status="running"] {
  border-left: 2px solid var(--accent);
  animation: badge-pulse 1.4s var(--ease) infinite;
}

/* --- edge pages: sign-in, connect, empty state ------------------ */
@keyframes wash { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }

.edge, .edge-canvas {
  background:
    linear-gradient(120deg, var(--wash-a), var(--bg) 40%, var(--wash-b) 70%, var(--wash-a));
  background-size: 300% 300%;
  animation: wash 16s var(--ease) infinite;
}
.edge-canvas {
  position: relative; overflow: hidden;
  border-radius: var(--radius-lg); border: 1px solid var(--border);
}
.edge .card--narrow, .edge-canvas .card { position: relative; z-index: 1; box-shadow: var(--shadow-pop); }

.edge::before, .edge::after {
  content: ""; position: fixed; border-radius: 50%;
  filter: blur(46px); opacity: .5; pointer-events: none; z-index: 0;
}
.edge::before { width: 260px; height: 260px; background: var(--wash-a); top: -60px; left: -40px; animation: blob-a 15s var(--ease) infinite; }
.edge::after  { width: 300px; height: 300px; background: var(--wash-b); bottom: -80px; right: -60px; animation: blob-b 18s var(--ease) infinite; }
@keyframes blob-a { 50% { transform: translate(36px, 26px); } }
@keyframes blob-b { 50% { transform: translate(-30px, -22px); } }

.edge .topbar { background: transparent; border-bottom-color: transparent; }
.edge main { position: relative; z-index: 1; }

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