/**
 * KaiNet shared theme — use with <html data-theme="light|dark">.
 * Set data-theme early (inline script) to avoid flash; toggle updates localStorage key kainet-theme.
 *
 * Load order: put <link rel="stylesheet" href="/static/kainet-theme.css" /> in <head>
 * before page-local <style>. Optional: inline script before CSS to set data-theme from localStorage.
 */

@import url("https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap");

html[data-theme="light"] {
  --ink: #161c26;
  --ink-soft: #3d4a5c;
  --paper: #f9f9ff;
  --card: #ffffff;
  --line: rgba(22, 28, 38, 0.08);
  --accent: #006b55;
  --accent-hover: #005445;
  --accent-soft: rgba(0, 107, 85, 0.08);
  --teal: #2bb391;
  --amber: #d97706;
  --radius: 16px;
  --shadow: 0 12px 40px rgba(22, 28, 38, 0.06);
  --font-sans: "Outfit", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Outfit", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  --bg0: #f9f9ff;
  --bg1: #ffffff;
  --bg2: #f0f3ff;
  --surface: rgba(22, 28, 38, 0.04);
  --surface2: #ffffff;
  --surface3: #e3e8f7;
  --border: rgba(22, 28, 38, 0.1);
  --border-hover: rgba(0, 107, 85, 0.22);
  --text: #161c26;
  --text-secondary: #3d4a5c;
  --muted: #64748b;
  --accent-medium: rgba(0, 107, 85, 0.18);
  --accent-glow: rgba(43, 179, 145, 0.06);
  --teal-soft: rgba(43, 179, 145, 0.12);
  --danger: #e11d48;
  --success: #059669;
  --error: #dc2626;
  --radius-sm: 12px;
  --radius-xs: 6px;
  --font-body: var(--font-sans);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --hero-glow-1: rgba(0, 107, 85, 0.10);
  --hero-glow-2: rgba(43, 179, 145, 0.07);
  --hero-glow-3: rgba(0, 107, 85, 0.05);
  --grain-opacity: 0.06;
  --primary-btn-fg: #ffffff;
  --primary-btn-shadow: rgba(0, 107, 85, 0.25);
  --gradient-btn: linear-gradient(135deg, var(--accent), var(--teal));
  --gradient-btn-hover: linear-gradient(135deg, var(--accent-hover), #24a07f);
  --gradient-teal-bar: linear-gradient(90deg, var(--accent), var(--teal));

  /* Status */
  --status-up: #059669;
  --status-down: #dc2626;
  --status-warn: #d97706;
  --status-skip: #64748b;
  --status-accent: #006b55;

  /* Chat / tools */
  --page-bg-gradient: linear-gradient(180deg, #f9f9ff 0%, #f0f3ff 45%, #f9f9ff 100%);
  --chat-glass-bg: rgba(255, 255, 255, 0.92);
  --chat-glass-border: rgba(22, 28, 38, 0.08);
  --chat-surface-subtle: #f0f3ff;
  --chat-surface-muted: #e3e8f7;
  --chat-content-bg: #ffffff;
  --chat-progress-track: #dde2f1;
  --chat-scrollbar-track: #eef1f5;
  --chat-scrollbar-thumb: #bccac3;
  --chat-scrollbar-thumb-hover: #94a3b8;
  --chat-code-bg: #1e293b;
  --chat-code-fg: #e2e8f0;
  --chat-log-bg: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  --chat-log-fg: #e2e8f0;
  --chat-secondary-btn-bg: #f0f3ff;
  --chat-secondary-btn-hover: #e3e8f7;
  --accent-muted: rgba(0, 107, 85, 0.12);
  --accent-focus-ring: rgba(43, 179, 145, 0.35);
  --accent-shadow-soft: rgba(0, 107, 85, 0.28);
  --text-primary: var(--ink);
  --text-muted: #64748b;
  --border-chat: rgba(22, 28, 38, 0.12);
  --shadow-sm: 0 1px 2px rgba(22, 28, 38, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(22, 28, 38, 0.07), 0 2px 4px -2px rgba(22, 28, 38, 0.05);
  --shadow-lg: 0 20px 25px -5px rgba(22, 28, 38, 0.08), 0 8px 10px -6px rgba(22, 28, 38, 0.04);
  --shadow-xl: 0 25px 50px -12px rgba(22, 28, 38, 0.12);
  --success-chat: #059669;
  --error-chat: #dc2626;
  --chat-stage-success-bg: #ecfdf5;
  --chat-stage-error-bg: #fef2f2;
  --chat-table-header-bg: var(--chat-surface-subtle);
  --chat-fade-mask: linear-gradient(to bottom, transparent, var(--chat-surface-subtle));
  --chat-agent-inner-bg: #f9fafb;
  --chat-container-gradient: linear-gradient(165deg, #ffffff 0%, #f0f3ff 100%);
  --chat-progress-end: #2bb391;
  --card-hover-shadow: 0 8px 32px rgba(22, 28, 38, 0.1);
  --modal-scrim: rgba(22, 28, 38, 0.45);
  --ring-focus: 0 0 0 3px var(--accent-focus-ring);
  --hairline: rgba(22, 28, 38, 0.08);
  --hairline-strong: rgba(22, 28, 38, 0.12);
  --shadow-card: 0 12px 40px rgba(22, 28, 38, 0.07);
  --shadow-card-hover: 0 20px 50px rgba(22, 28, 38, 0.11);
  --row-hover: rgba(22, 28, 38, 0.05);
  --stripe-accent: var(--accent);
}

html[data-theme="dark"] {
  --ink: #ededef;
  --ink-soft: #a1a1aa;
  --paper: #0c1018;
  --card: rgba(255, 255, 255, 0.05);
  --line: rgba(255, 255, 255, 0.08);
  --accent: #2bb391;
  --accent-hover: #34d399;
  --accent-soft: rgba(43, 179, 145, 0.12);
  --teal: #5eead4;
  --amber: #fbbf24;
  --radius: 16px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  --font-sans: "Outfit", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Outfit", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  --bg0: #0c1018;
  --bg1: #111722;
  --bg2: #18202e;
  --surface: rgba(255, 255, 255, 0.04);
  --surface2: rgba(255, 255, 255, 0.06);
  --surface3: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(43, 179, 145, 0.3);
  --text: #ededef;
  --text-secondary: #a1a1aa;
  --muted: #71717a;
  --accent-medium: rgba(43, 179, 145, 0.22);
  --accent-glow: rgba(43, 179, 145, 0.08);
  --teal-soft: rgba(94, 234, 212, 0.1);
  --danger: #fb7185;
  --success: #34d399;
  --error: #f87171;
  --radius-sm: 12px;
  --radius-xs: 6px;
  --font-body: var(--font-sans);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --hero-glow-1: rgba(43, 179, 145, 0.08);
  --hero-glow-2: rgba(0, 107, 85, 0.06);
  --hero-glow-3: rgba(43, 179, 145, 0.04);
  --grain-opacity: 0.25;
  --primary-btn-fg: #ffffff;
  --primary-btn-shadow: rgba(43, 179, 145, 0.3);
  --gradient-btn: linear-gradient(135deg, var(--accent), var(--teal));
  --gradient-btn-hover: linear-gradient(135deg, var(--accent-hover), #0d9488);
  --gradient-teal-bar: linear-gradient(90deg, var(--accent), var(--teal));

  --status-up: #34d399;
  --status-down: #f87171;
  --status-warn: #fbbf24;
  --status-skip: #64748b;
  --status-accent: #2bb391;

  --page-bg-gradient:
    radial-gradient(ellipse 900px 600px at 15% -5%, rgba(0, 107, 85, 0.1), transparent 60%),
    radial-gradient(ellipse 700px 500px at 85% 10%, rgba(43, 179, 145, 0.06), transparent 50%),
    var(--bg0);
  --chat-glass-bg: rgba(18, 24, 36, 0.92);
  --chat-glass-border: rgba(255, 255, 255, 0.1);
  --chat-surface-subtle: rgba(255, 255, 255, 0.04);
  --chat-surface-muted: rgba(255, 255, 255, 0.07);
  --chat-content-bg: #141820;
  --chat-progress-track: rgba(255, 255, 255, 0.1);
  --chat-scrollbar-track: rgba(255, 255, 255, 0.04);
  --chat-scrollbar-thumb: rgba(255, 255, 255, 0.15);
  --chat-scrollbar-thumb-hover: rgba(255, 255, 255, 0.25);
  --chat-code-bg: #0f1419;
  --chat-code-fg: #cbd5e1;
  --chat-log-bg: linear-gradient(180deg, #050508 0%, #12121a 100%);
  --chat-log-fg: #cbd5e1;
  --chat-secondary-btn-bg: rgba(255, 255, 255, 0.06);
  --chat-secondary-btn-hover: rgba(255, 255, 255, 0.1);
  --accent-muted: rgba(43, 179, 145, 0.15);
  --accent-focus-ring: rgba(43, 179, 145, 0.25);
  --accent-shadow-soft: rgba(43, 179, 145, 0.35);
  --text-primary: var(--ink);
  --text-muted: #71717a;
  --border-chat: rgba(255, 255, 255, 0.1);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.25);
  --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.45);
  --success-chat: #34d399;
  --error-chat: #f87171;
  --chat-stage-success-bg: rgba(52, 211, 153, 0.12);
  --chat-stage-error-bg: rgba(248, 113, 113, 0.12);
  --chat-table-header-bg: rgba(255, 255, 255, 0.05);
  --chat-fade-mask: linear-gradient(to bottom, transparent, var(--bg2));
  --chat-agent-inner-bg: rgba(255, 255, 255, 0.03);
  --chat-container-gradient: linear-gradient(165deg, #12121a 0%, #0c0c10 100%);
  --chat-progress-end: #5eead4;
  --card-hover-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --modal-scrim: rgba(0, 0, 0, 0.62);
  --ring-focus: 0 0 0 3px var(--accent-focus-ring);
  --hairline: rgba(255, 255, 255, 0.1);
  --hairline-strong: rgba(255, 255, 255, 0.14);
  --shadow-card: 0 12px 40px rgba(0, 0, 0, 0.35);
  --shadow-card-hover: 0 20px 50px rgba(0, 0, 0, 0.45);
  --row-hover: rgba(255, 255, 255, 0.06);
  --stripe-accent: var(--accent);
}

/* Default to light tokens when data-theme is missing (first paint) */
html:not([data-theme]) {
  color-scheme: light only;
}

/* Theme toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--surface2);
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  transition:
    background 0.28s var(--ease-out),
    color 0.28s var(--ease-out),
    transform 0.2s var(--ease-out);
}

.theme-toggle:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.theme-toggle:active {
  transform: scale(0.97);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: var(--ring-focus);
}

/* -------------------------------------------------------------------------- */
/* KaiNet layout primitives (.kn-*) — use with html[data-theme] + this file */
/* -------------------------------------------------------------------------- */

html[data-theme="light"] body.kn-surface,
html[data-theme="dark"] body.kn-surface {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--page-bg-gradient);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

html[data-theme="light"] body,
html[data-theme="dark"] body {
  font-family: var(--font-body);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.kn-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* Double-bezel card */
.kn-card-shell {
  padding: 0.375rem;
  border-radius: calc(var(--radius) + 0.25rem);
  background: var(--surface);
  box-shadow: inset 0 1px 0 var(--hairline-strong);
  border: 1px solid var(--hairline);
}

.kn-card-inner {
  border-radius: var(--radius);
  background: var(--card);
  box-shadow:
    var(--shadow-sm),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  border: 1px solid var(--border);
}

html[data-theme="dark"] .kn-card-inner {
  box-shadow:
    var(--shadow-sm),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* Primary / secondary buttons */
.kn-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.875rem;
  line-height: 1.25;
  border-radius: 9999px;
  padding: 0.625rem 1.25rem;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition:
    background 0.35s var(--ease-out),
    color 0.35s var(--ease-out),
    box-shadow 0.35s var(--ease-out),
    transform 0.2s var(--ease-out),
    opacity 0.2s var(--ease-out);
}

.kn-btn:focus-visible {
  outline: none;
  box-shadow: var(--ring-focus);
}

.kn-btn:active {
  transform: scale(0.98) translateY(1px);
}

.kn-btn--primary {
  background: var(--accent);
  color: var(--primary-btn-fg);
  box-shadow: 0 4px 14px var(--primary-btn-shadow);
}

.kn-btn--primary:hover {
  background: var(--accent-hover);
}

.kn-btn--secondary {
  background: var(--surface2);
  color: var(--ink);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

html[data-theme="dark"] .kn-btn--secondary {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.kn-btn--secondary:hover {
  border-color: var(--border-hover);
  background: var(--surface3);
}

/* Link styled as quiet control */
.kn-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.25s var(--ease-out);
}

.kn-link:hover {
  color: var(--accent-hover);
}

/* Reveal on scroll (editorial pages): add .kn-reveal; toggled .kn-reveal--inview via IO */
.kn-reveal {
  opacity: 0;
  transform: translateY(1rem);
  transition:
    opacity 0.75s var(--ease-out),
    transform 0.75s var(--ease-out);
}

.kn-reveal.kn-reveal--inview {
  opacity: 1;
  transform: translateY(0);
}

/* Scoped :focus-visible ring for pages using the .kn-surface shell.
   Kept inside .kn-surface to avoid altering existing pages that style their
   own focus rings. */
.kn-surface :focus-visible {
  outline: none;
  box-shadow: var(--ring-focus);
  border-radius: var(--radius-xs);
}
.kn-surface button:focus-visible,
.kn-surface a:focus-visible,
.kn-surface [role="button"]:focus-visible,
.kn-surface input:focus-visible,
.kn-surface select:focus-visible,
.kn-surface textarea:focus-visible {
  outline: none;
  box-shadow: var(--ring-focus);
}
