/* ============================================================
   KeepRunning.ai — Components
   Requires kr-tokens.css. All colors via var(); theme-agnostic.
   ============================================================ */

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-body);
  font-size: 13.5px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-lg);
  border: 1px solid transparent; cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
  white-space: nowrap; line-height: 1;
}
.btn svg { width: 15px; height: 15px; flex: none; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

.btn--primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-glow); }
.btn--primary:active { transform: translateY(0); }

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

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

.btn--run { background: var(--run); color: var(--run-fg); border-color: var(--run); }
.btn--run:hover { transform: translateY(-1px); filter: brightness(1.05); }

.btn--danger { background: transparent; color: var(--danger); border-color: var(--danger-soft); }
.btn--danger:hover { background: var(--danger-soft); }

.btn--sm { padding: 6px 11px; font-size: 12.5px; }
.btn--icon { padding: 8px; }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12.5px; font-weight: 500; color: var(--text-muted); }
.input, .select {
  font-family: var(--font-body); font-size: 13.5px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius-md); padding: 9px 12px; width: 100%;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.input::placeholder { color: var(--text-faint); }
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input--mono { font-family: var(--font-mono); }

/* native select → branded dropdown (custom chevron, no OS chrome) */
.select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  cursor: pointer; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238A8F99' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='4 6 8 10 12 6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
.select:hover { border-color: var(--text-faint); }
.select option { background: var(--surface); color: var(--text); }

/* ---------- Toggle / switch ---------- */
.switch { position: relative; width: 38px; height: 22px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch .track { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; transition: background var(--dur-base); }
.switch .thumb { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform var(--dur-base) var(--ease-out); box-shadow: 0 1px 2px rgba(0,0,0,0.3); }
.switch input:checked + .track { background: var(--run); }
.switch input:checked + .track + .thumb { transform: translateX(16px); }

/* ---------- Badges ---------- */
.badge {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 500;
  letter-spacing: 0.04em; padding: 3px 8px; border-radius: var(--radius-full);
  display: inline-flex; align-items: center; gap: 5px; line-height: 1;
  border: 1px solid transparent;
}
.badge--run    { color: var(--run);    background: var(--run-soft);    border-color: var(--run-soft); }
.badge--warn   { color: var(--warn);   background: var(--warn-soft);   border-color: var(--warn-soft); }
.badge--danger { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-soft); }
.badge--accent { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-soft); }
.badge--neutral{ color: var(--text-muted); background: var(--surface-2); border-color: var(--border); }

/* Plan badge (Starter / Growth / Scale / Enterprise) */
.plan-badge {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  padding: 4px 9px; border-radius: var(--radius-md);
  color: var(--accent); background: var(--accent-soft);
  border: 1px solid var(--accent-soft); display: inline-flex; line-height: 1;
}

/* Channel/feature pills — KeepRunning's small signature chip */
.pill {
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.12em;
  padding: 6px 12px; border-radius: var(--radius-full);
  border: 1px solid var(--border-strong); color: var(--text-muted);
  background: transparent; display: inline-flex; align-items: center; gap: 7px; line-height: 1;
  white-space: nowrap;
}
.pill svg { width: 13px; height: 13px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-2xl); box-shadow: var(--shadow-soft);
  padding: var(--space-5);
  transition: transform var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out), border-color var(--dur-base);
}
.card--hover:hover { transform: translateY(-2px); box-shadow: var(--shadow-pop); }

/* Stat card */
.stat-card { display: flex; flex-direction: column; gap: 10px; }
.stat-card .label { font-size: 12.5px; color: var(--text-muted); display: flex; align-items: center; gap: 7px; }
.stat-card .value { font-family: var(--font-display); font-weight: 700; font-size: 30px; letter-spacing: -0.03em; font-feature-settings: 'tnum'; color: var(--text); line-height: 1; }
.stat-card .delta { font-family: var(--font-mono); font-size: 11.5px; color: var(--run); }
.stat-card .icon { width: 30px; height: 30px; border-radius: var(--radius-md); display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.stat-card .icon svg { width: 16px; height: 16px; }

/* Session / agent card */
.session-card { display: flex; flex-direction: column; gap: 12px; }
.session-card .top { display: flex; align-items: center; justify-content: space-between; }
.session-card .name { font-family: var(--font-display); font-weight: 600; font-size: 15px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.session-card .meta { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-faint); display: flex; gap: 14px; }

/* ---------- Limit / usage bar ---------- */
.usage { display: flex; flex-direction: column; gap: 7px; }
.usage .row { display: flex; justify-content: space-between; font-size: 12px; }
.usage .row .k { color: var(--text-muted); }
.usage .row .v { font-family: var(--font-mono); color: var(--text); white-space: nowrap; }
.usage .bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.usage .bar > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.usage .bar.is-run > span { background: var(--run); }
.usage .bar.is-warn > span { background: var(--warn); }

/* ---------- Sidebar nav ---------- */
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 11px; border-radius: var(--radius-md);
  font-size: 13.5px; font-weight: 500; color: var(--text-muted);
  cursor: pointer; transition: background var(--dur-fast), color var(--dur-fast);
}
.nav-item svg { width: 16px; height: 16px; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- Segmented control ---------- */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 3px; gap: 2px; }
.seg button {
  font-family: var(--font-body); font-size: 12.5px; font-weight: 500;
  padding: 6px 13px; border-radius: var(--radius-md); border: none;
  background: transparent; color: var(--text-muted); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: all var(--dur-fast);
}
.seg button svg { width: 14px; height: 14px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-soft); }

/* ---------- kbd ---------- */
.kbd {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-bottom-width: 2px; border-radius: var(--radius-sm); padding: 2px 6px; line-height: 1;
}

/* ============================================================
   The signature surface — VS Code-style editor
   ============================================================ */
.kr-editor {
  border-radius: var(--radius-xl); overflow: hidden;
  border: 1px solid var(--border); background: var(--bg);
  font-family: var(--font-mono); box-shadow: var(--shadow-pop);
}
.kr-editor .titlebar { height: 38px; display: flex; align-items: center; gap: 12px; padding: 0 14px; background: var(--bg-deep); border-bottom: 1px solid var(--border); }
.kr-editor .lights { display: flex; gap: 7px; }
.kr-editor .lights i { width: 11px; height: 11px; border-radius: 50%; display: block; }
.kr-editor .etab { display: inline-flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--text); background: var(--bg); padding: 7px 13px; border-radius: 6px 6px 0 0; border: 1px solid var(--border); border-bottom: none; position: relative; top: 1px; }
.kr-editor .etab .fdot { width: 7px; height: 7px; border-radius: 2px; background: var(--accent); }
.kr-editor .run-pill { margin-left: auto; display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.06em; color: var(--run); background: var(--run-soft); padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.kr-editor .run-pill .d { width: 6px; height: 6px; border-radius: 50%; background: var(--run); animation: kr-pulse 2.4s var(--ease-out) infinite; }

.kr-editor .body-row { display: flex; min-height: 230px; }
.kr-editor .esidebar { width: 188px; flex: none; background: var(--bg-deep); border-right: 1px solid var(--border); padding: 13px 9px; }
.kr-editor .side-label { font-size: 9.5px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-faint); padding: 0 9px 9px; }
.kr-editor .tree { display: flex; align-items: center; gap: 8px; padding: 5px 9px; border-radius: 6px; font-size: 12px; color: var(--text-muted); }
.kr-editor .tree.nest { padding-left: 24px; }
.kr-editor .tree.active { background: var(--accent-soft); color: var(--text); }
.kr-editor .tree svg { width: 14px; height: 14px; flex: none; }
.kr-editor .tree .ac { color: var(--accent); }

.kr-editor .epane { flex: 1; padding: 15px 18px; background: var(--bg); overflow: hidden; }
.kr-editor .code { font-size: 12.5px; line-height: 1.85; white-space: pre; }
.kr-editor .code .ln { display: block; }
.kr-editor .gutter { color: var(--text-faint); opacity: 0.7; display: inline-block; width: 20px; user-select: none; }
.tk-com{color:var(--s-com);font-style:italic;} .tk-kw{color:var(--s-kw);} .tk-fn{color:var(--s-fn);}
.tk-str{color:var(--s-str);} .tk-num{color:var(--s-num);} .tk-var{color:var(--s-var);}
.tk-pl{color:var(--text);} .tk-pun{color:var(--text-muted);}

.kr-editor .terminal { background: var(--terminal-bg); border-top: 1px solid var(--border); padding: 12px 18px 14px; font-size: 12px; line-height: 1.75; color: var(--term-text); }
.kr-editor .terminal .tprompt { color: var(--accent); }
.kr-editor .terminal .tok { color: var(--run); }
.kr-editor .terminal .tdim { color: var(--term-muted); }
.kr-editor .terminal .runline { display: flex; align-items: center; gap: 8px; }
.kr-editor .terminal .runline .d { width: 6px; height: 6px; border-radius: 50%; background: var(--run); }

/* ============================================================
   Textures — background-image / SVG based so they render on any
   surface and in any renderer. Theme-aware via tokens.
   Stack on top of an element's own background-color.
   ============================================================ */

/* 1. Dot grid — technical, quiet. Add a radial mask wrapper if you want edge-fade. */
.tex-dots {
  background-image: radial-gradient(var(--border-strong) 1.1px, transparent 1.3px);
  background-size: 22px 22px;
}

/* 2. Line grid */
.tex-grid {
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 28px 28px;
}

/* 3. Aurora — soft green glow blobs for heroes / dividers */
.tex-aurora {
  background-image:
    radial-gradient(42% 60% at 20% 28%, var(--accent-soft), transparent 70%),
    radial-gradient(46% 55% at 84% 78%, var(--accent-soft), transparent 72%);
}

/* 4. Grain — matte fractal-noise finish (opacity baked into the SVG) */
.tex-grain {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
}

/* 5. Pulse field — the brand heartbeat tiled. Apply to a dedicated overlay
      layer (it paints the whole box green through the mask). */
.tex-pulse {
  background: var(--accent);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='118' height='52' fill='none'%3E%3Cpath d='M0 26 L70 26 L78 16 L86 26 L94 7 L101 45 L108 26 L118 26' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") repeat-x center / 118px 52px;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='118' height='52' fill='none'%3E%3Cpath d='M0 26 L70 26 L78 16 L86 26 L94 7 L101 45 L108 26 L118 26' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") repeat-x center / 118px 52px;
  opacity: 0.12;
}

/* Page-level film grain (fixed overlay, whole viewport) */
.kr-grain {
  position: fixed; inset: 0; z-index: 9999; pointer-events: none;
  mix-blend-mode: overlay; opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
[data-theme="dark"] .kr-grain { opacity: 0.06; }
