/* ════════════════════════════════════════════════
   bases design system
   Warm Functional Precision
   ════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,400;0,9..144,500;0,9..144,600;1,9..144,300;1,9..144,400&family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&family=Outfit:wght@600;700&display=swap');

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

/* ── Tokens ───────────────────────────────────── */
:root {
  /* Surface */
  --bg:               #f7f4ee;
  --surface:          #fdfcf8;
  --surface-raised:   #ffffff;

  /* Text */
  --text:             #1a1814;
  --text-muted:       #7c7469;
  --text-faint:       #bab5aa;

  /* Borders */
  --border:           #dbd6cc;
  --border-strong:    #c4bfb3;

  /* Brand — forest green */
  --accent:           #2a5f4f;
  --accent-deep:      #1d4538;
  --accent-mid:       #3d7a66;
  --accent-bg:        #edf5f1;

  /* Amber — stopped / warning */
  --amber:            #b35800;
  --amber-mid:        #c86800;
  --amber-bg:         #fdf3e0;

  /* Red — error / destructive */
  --red:              #c12b2b;
  --red-mid:          #9e2020;
  --red-bg:           #fdf1f1;

  /* Green — running / success */
  --green:            #276947;
  --green-mid:        #1e5038;
  --green-bg:         #eef7f2;

  /* Blue — info */
  --blue:             #1e5799;
  --blue-bg:          #eef2fa;

  /* Typography */
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body:    'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono:    'DM Mono', 'Fira Code', 'Fira Mono', ui-monospace, monospace;
  --font-brand:   'Outfit', system-ui, sans-serif;

  /* Type scale — base is 17px (106.25% on html) */
  --text-xs:   0.75rem;    /*  ~13px */
  --text-sm:   0.875rem;   /*  ~15px */
  --text-base: 1rem;       /*  ~17px */
  --text-lg:   1.125rem;   /*  ~19px */
  --text-xl:   1.375rem;   /*  ~23px */
  --text-2xl:  1.75rem;    /*  ~30px */
  --text-3xl:  2.25rem;    /*  ~38px */
  --text-4xl:  3rem;       /*  ~51px */
  --text-5xl:  4rem;       /*  ~68px */

  /* Spacing */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;
  --sp-16: 4rem;

  /* Layout */
  --max-width:        56rem;
  --max-width-narrow: 42rem;
}

/* ── Base ─────────────────────────────────────── */
html {
  font-size: 106.25%; /* 17px base — scales the entire rem system */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.65;
  min-height: 100dvh;
}

/* ── Layout ───────────────────────────────────── */
.container {
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--sp-8);
}

.container--narrow {
  max-width: var(--max-width-narrow);
}

/* ── Typography ───────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-body);
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
  letter-spacing: -0.015em;
}

h1 { font-size: var(--text-3xl); letter-spacing: -0.025em; }
h2 { font-size: var(--text-2xl); letter-spacing: -0.02em; }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }

p + p { margin-top: 0.75em; }

a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

/* Display / Fraunces */
.display {
  font-family: var(--font-display);
  font-optical-sizing: auto;
}

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

/* Text utilities */
.text-muted  { color: var(--text-muted); }
.text-faint  { color: var(--text-faint); }
.text-accent { color: var(--accent); }
.text-sm     { font-size: var(--text-sm); }
.text-xs     { font-size: var(--text-xs); }

/* Label / Eyebrow */
.label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── Header / Nav ─────────────────────────────── */
.site-header {
  border-bottom: 1px solid var(--border);
  padding-block: var(--sp-4);
  background: var(--surface-raised);
}

.site-header .container {
  display: flex;
  align-items: center;
  gap: var(--sp-8);
}

.brand {
  font-family: var(--font-brand);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.brand:hover { color: var(--accent-deep); }

.brand-mark {
  display: block;
  width: 6px;
  height: 6px;
  background: currentColor;
  flex-shrink: 0;
}

.site-nav {
  display: flex;
  gap: var(--sp-5);
  list-style: none;
  align-items: center;
}

.site-nav a {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.12s;
}

.site-nav a:hover  { color: var(--text); }
.site-nav a.active { color: var(--text); font-weight: 500; }

.site-header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

/* ── Main ─────────────────────────────────────── */
.site-main {
  padding-block: var(--sp-10);
}

/* ── Page Header ──────────────────────────────── */
.page-header {
  margin-bottom: var(--sp-8);
  padding-bottom: var(--sp-6);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--sp-2);
}

/* ── Card ─────────────────────────────────────── */
.card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  padding: var(--sp-8);
}

.card--sm  { padding: var(--sp-5) var(--sp-6); }
.card--lg  { padding: var(--sp-10) var(--sp-12); }
.card--flat { background: var(--surface); }

/* ── Divider ──────────────────────────────────── */
hr, .divider {
  border: none;
  border-top: 1px solid var(--border);
}

/* ── Badge / Status ───────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.2em 0.6em;
  border: 1px solid;
  white-space: nowrap;
}

.badge-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge--running {
  color: var(--green);
  background: var(--green-bg);
  border-color: color-mix(in srgb, var(--green) 25%, transparent);
}

.badge--stopped {
  color: var(--amber);
  background: var(--amber-bg);
  border-color: color-mix(in srgb, var(--amber) 25%, transparent);
}

.badge--starting {
  color: var(--accent);
  background: var(--accent-bg);
  border-color: color-mix(in srgb, var(--accent) 25%, transparent);
}

.badge--error {
  color: var(--red);
  background: var(--red-bg);
  border-color: color-mix(in srgb, var(--red) 25%, transparent);
}

.badge--stopped .badge-dot  { animation: pulse 2.6s ease-in-out infinite; }
.badge--starting .badge-dot { animation: pulse 1.2s ease-in-out infinite; }

/* ── Button ───────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s, opacity 0.12s;
  -webkit-user-select: none;
  user-select: none;
}

.btn--primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn--primary:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  color: white;
}

.btn--secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn--secondary:hover {
  background: var(--bg);
  border-color: var(--text-faint);
}

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

.btn--danger {
  background: transparent;
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 35%, transparent);
}
.btn--danger:hover {
  background: var(--red-bg);
  border-color: var(--red);
}

.btn--sm {
  font-size: var(--text-xs);
  padding: 0.3rem 0.65rem;
}

.btn--lg {
  font-size: var(--text-base);
  padding: 0.65rem 1.4rem;
}

.btn:disabled,
.btn.htmx-request {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Form ─────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-bottom: var(--sp-5);
}

.form-label,
label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: block;
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-faint);
  margin-top: var(--sp-1);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
select,
textarea {
  display: block;
  width: 100%;
  max-width: 32rem;
  padding: 0.4rem 0.65rem;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  appearance: none;
  transition: border-color 0.12s, box-shadow 0.12s;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

input.is-error,
input:invalid:not(:placeholder-shown) {
  border-color: var(--red);
}

/* ── Table ────────────────────────────────────── */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

thead th {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 400;
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}

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

tbody tr:hover td {
  background: color-mix(in srgb, var(--bg) 60%, transparent);
}

.cell-name {
  font-weight: 500;
  font-size: var(--text-sm);
}

.cell-mono {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.cell-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ── Code ─────────────────────────────────────── */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--border);
  color: var(--text);
  padding: 0.1em 0.35em;
}

pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  padding: var(--sp-5);
  overflow-x: auto;
  line-height: 1.75;
}

pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

/* ── Notice / Alert ───────────────────────────── */
.notice {
  padding: var(--sp-4) var(--sp-5);
  border-left: 2px solid currentColor;
  font-size: var(--text-sm);
  line-height: 1.6;
}

.notice--error   { color: var(--red);   background: var(--red-bg);   border-color: var(--red); }
.notice--warning { color: var(--amber); background: var(--amber-bg); border-color: var(--amber); }
.notice--success { color: var(--green); background: var(--green-bg); border-color: var(--green); }
.notice--info    { color: var(--blue);  background: var(--blue-bg);  border-color: var(--blue); }

/* ── Empty State ──────────────────────────────── */
.empty-state {
  padding: var(--sp-16) var(--sp-8);
  text-align: center;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.empty-state-title {
  font-size: var(--text-lg);
  font-weight: 500;
  color: var(--text);
  margin-bottom: var(--sp-2);
}

.empty-state-body {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--sp-6);
  max-width: 28rem;
  margin-inline: auto;
}

/* ── Key-value pairs ──────────────────────────── */
.kv-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--sp-2) var(--sp-6);
  font-size: var(--text-sm);
}

.kv-key {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  align-self: baseline;
  padding-top: 0.1em;
}

.kv-value {
  color: var(--text);
}

/* ── Animations ───────────────────────────────── */
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Dark mode tokens ─────────────────────────── */
[data-theme="dark"] {
  --bg:               #141210;
  --surface:          #1a1815;
  --surface-raised:   #201e1a;

  --text:             #ede8de;
  --text-muted:       #857e75;
  --text-faint:       #4a4640;

  --border:           #2c2924;
  --border-strong:    #3a3630;

  --accent:           #4a9f82;
  --accent-deep:      #3d8a6e;
  --accent-mid:       #57b090;
  --accent-bg:        #152520;

  --amber:            #e07800;
  --amber-mid:        #c56a00;
  --amber-bg:         #261a08;

  --red:              #d95050;
  --red-mid:          #c03838;
  --red-bg:           #281010;

  --green:            #48a068;
  --green-mid:        #3c8c58;
  --green-bg:         #0d2418;

  --blue:             #5a8fcc;
  --blue-bg:          #0c1e30;
}

/* ── Theme transition ─────────────────────────── */
/* Applied briefly around a theme switch to animate colors */
html.theme-transitioning,
html.theme-transitioning * {
  transition:
    background-color 0.22s ease,
    color 0.22s ease,
    border-color 0.22s ease,
    box-shadow 0.22s ease !important;
}

/* ── Theme toggle button ──────────────────────── */
.btn-theme {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  padding: 0.3rem 0.65rem;
  cursor: pointer;
  line-height: 1;
  transition: color 0.12s, border-color 0.12s;
  flex-shrink: 0;
}

.btn-theme:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* Icon visibility driven by data-theme — no JS needed */
.btn-theme .icon-sun  { display: none; }
.btn-theme .icon-moon { display: block; }
.btn-theme .theme-label-dark  { display: inline; }
.btn-theme .theme-label-light { display: none; }

[data-theme="dark"] .btn-theme .icon-sun  { display: block; }
[data-theme="dark"] .btn-theme .icon-moon { display: none; }
[data-theme="dark"] .btn-theme .theme-label-dark  { display: none; }
[data-theme="dark"] .btn-theme .theme-label-light { display: inline; }

/* ── Utilities ────────────────────────────────── */
.flex          { display: flex; }
.inline-flex   { display: inline-flex; }
.items-center  { align-items: center; }
.items-start   { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.gap-2         { gap: var(--sp-2); }
.gap-3         { gap: var(--sp-3); }
.gap-4         { gap: var(--sp-4); }
.gap-6         { gap: var(--sp-6); }
.mt-2          { margin-top: var(--sp-2); }
.mt-4          { margin-top: var(--sp-4); }
.mt-6          { margin-top: var(--sp-6); }
.mt-8          { margin-top: var(--sp-8); }
.mb-2          { margin-bottom: var(--sp-2); }
.mb-4          { margin-bottom: var(--sp-4); }
.mb-6          { margin-bottom: var(--sp-6); }
.mb-8          { margin-bottom: var(--sp-8); }
.ml-auto       { margin-left: auto; }
.w-full        { width: 100%; }
.truncate      { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}
