/* Shared design system for skyn.tools surfaces.
 * Tokens, baseline typography, app-header chrome, controls, skeletons.
 * Page-specific layouts live inline in each HTML file. */

:root {
  --brand-navy: #0a2540;
  --brand-navy-deep: #061a30;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #dbeafe;
  --brand-tint: #eff6ff;
  --accent: #0ea5e9;
  --logo-cyan: #14ade4;
  --logo-navy: #065c8a;

  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-alt: #fafbfc;
  --border: #e6e8eb;
  --border-strong: #d1d5db;

  --text: #0f172a;
  --text-muted: #5a6776;
  --text-faint: #99a1ad;

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

  --shadow-xs: 0 1px 1px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-pop: 0 12px 32px rgba(15, 18, 22, 0.16), 0 2px 6px rgba(15, 18, 22, 0.08);

  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --page-max: 1280px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, kbd { font-family: var(--mono); }

h1, h2, h3 { color: var(--text); margin-top: 0; }
h1 {
  font-size: 1.5rem; font-weight: 600;
  letter-spacing: -0.015em;
}
h2 {
  font-size: 0.8rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-muted);
  margin: 1.75rem 0 0.75rem;
}
h3 { font-size: 0.95rem; font-weight: 600; }

p { margin: 0 0 0.6rem; }

/* ===================================================================
 * App header (brand band)
 * =================================================================*/
.app-header {
  background: linear-gradient(180deg, var(--brand-navy) 0%, var(--brand-navy-deep) 100%);
  color: white;
  padding: 1rem 2rem;
  border-bottom: 3px solid var(--brand);
}
.app-header-inner {
  max-width: var(--page-max); margin: 0 auto;
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; flex-wrap: wrap;
}
.app-header h1 { color: white; }

.wordmark {
  display: inline-flex; align-items: center; gap: 0.6rem;
  color: white; font-weight: 700; letter-spacing: 0.02em;
  text-decoration: none;
}
.wordmark:hover { text-decoration: none; opacity: 0.9; }
.wordmark .logo { display: block; width: auto; height: 26px; }
.wordmark .name { font-size: 15px; }

.header-links {
  display: flex; align-items: center; gap: 0.25rem; flex-wrap: wrap;
  font-size: 13px;
}
.header-links a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  transition: color 100ms var(--ease), background 100ms var(--ease);
}
.header-links a:hover {
  color: white;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.10);
}
.header-links a .icon { opacity: 0.7; }
.header-links a:hover .icon { opacity: 1; }

/* User menu: username dropdown trigger.
 * Sits in the dark header band alongside text links (Demo, Docs).
 * Styled as a link, not a button: no border, no resting background.
 * Hover/open get a subtle pill background so the trigger reads as
 * "opens a menu" without competing with the adjacent text links. */
.user-menu { position: relative; }
.user-menu-trigger {
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  border: none;
  font: inherit; font-size: 13px;
  height: auto;
  padding: 0.3rem 0.55rem;
  margin-right: -0.55rem;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.35rem;
  transition: background 100ms var(--ease), color 100ms var(--ease);
}
.user-menu-trigger:hover {
  background: rgba(255, 255, 255, 0.10);
  color: white;
}
.user-menu-trigger[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.14);
  color: white;
}
.user-menu-trigger code {
  font-family: var(--sans); font-size: 13px;
  color: inherit;
  background: transparent;
  padding: 0;
}
.user-menu-trigger .icon svg { transition: transform 150ms var(--ease); }
.user-menu-trigger[aria-expanded="true"] .icon svg { transform: rotate(180deg); }
.user-menu-panel {
  position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 180px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-pop);
  padding: 0.35rem;
  z-index: 50;
}
.user-menu-panel[hidden] { display: none; }
.user-menu-item {
  display: block; width: 100%; text-align: left;
  background: transparent; border: none;
  font: inherit; font-size: 13px;
  color: var(--text);
  padding: 0.45rem 0.7rem;
  border-radius: 5px;
  cursor: pointer;
  height: auto;
}
.user-menu-item:hover { background: var(--brand-tint); }
.user-menu-item.danger { color: var(--err); }
.user-menu-item.danger:hover { background: var(--err-bg); }

/* ===================================================================
 * Page container
 * =================================================================*/
.page { max-width: var(--page-max); margin: 0 auto; padding: 1.5rem 2rem 3rem; }
.page-narrow { max-width: 760px; margin: 0 auto; padding: 1.5rem 2rem 3rem; }

/* ===================================================================
 * Section header (replaces fieldset+legend pattern)
 * =================================================================*/
.section { margin-bottom: 1.75rem; }
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.9rem;
  gap: 0.75rem; flex-wrap: wrap;
}
.section-header h2 {
  margin: 0; padding: 0; border: none;
  font-size: 0.78rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted);
  display: inline-flex; align-items: baseline; gap: 0.5rem;
}
.section-header h2 .count {
  font-weight: 500; color: var(--text-faint);
  font-size: 0.78rem; letter-spacing: 0;
}
.section-actions { display: flex; gap: 0.4rem; align-items: center; }

/* ===================================================================
 * Buttons (Linear-style)
 * =================================================================*/
button, .btn {
  font: inherit; font-size: 13px; font-weight: 500;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  height: 32px; padding: 0 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  white-space: nowrap; vertical-align: middle;
  letter-spacing: -0.005em;
  transition:
    background 100ms var(--ease),
    border-color 100ms var(--ease),
    color 100ms var(--ease),
    box-shadow 100ms var(--ease);
  -webkit-appearance: none; appearance: none;
  user-select: none;
}
button:hover, .btn:hover {
  background: var(--surface-alt);
  border-color: var(--text-faint);
}
button:active, .btn:active { background: var(--bg); }
button:focus-visible, .btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--brand-soft);
  border-color: var(--brand);
}
button:disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Icons inside buttons / menu items. Lucide-style line icons. */
.icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.icon svg {
  width: 14px;
  height: 14px;
  display: block;
}
button.small .icon svg, .btn.small .icon svg { width: 12px; height: 12px; }
button.large .icon svg, .btn.large .icon svg { width: 16px; height: 16px; }
.user-menu-item .icon { margin-right: 0.45rem; opacity: 0.75; }
.user-menu-item:hover .icon { opacity: 1; }

button.primary, .btn.primary {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}
button.primary:hover, .btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
button.primary:active, .btn.primary:active { background: var(--brand-dark); }
button.primary:focus-visible, .btn.primary:focus-visible {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--brand-soft);
}

button.danger, .btn.danger {
  background: var(--surface);
  color: var(--err);
  border-color: var(--border-strong);
}
button.danger:hover, .btn.danger:hover {
  background: var(--err-bg);
  border-color: var(--err);
  color: var(--err);
}
button.danger:active, .btn.danger:active { background: var(--err-bg); }
button.danger.primary, .btn.danger.primary {
  background: var(--err); color: white; border-color: var(--err);
}
button.danger.primary:hover, .btn.danger.primary:hover {
  background: #991b1b; border-color: #991b1b;
}

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

button.small, .btn.small { height: 26px; padding: 0 0.6rem; font-size: 12px; }
button.large, .btn.large { height: 38px; padding: 0 1.15rem; font-size: 14px; }

/* Inline loading state: spinner replaces text in place */
button.loading, .btn.loading {
  color: transparent !important;
  pointer-events: none;
  position: relative;
}
button.loading::after, .btn.loading::after {
  content: ""; position: absolute;
  width: 14px; height: 14px;
  top: calc(50% - 7px); left: calc(50% - 7px);
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: skyn-spin 0.6s linear infinite;
  color: var(--text-muted);
}
button.primary.loading::after, .btn.primary.loading::after { color: white; }
@keyframes skyn-spin { to { transform: rotate(360deg); } }

/* ===================================================================
 * Form controls
 * =================================================================*/
input[type=text], input[type=password], input[type=email], input[type=number], input[type=search],
textarea, select {
  font: inherit;
  height: 32px;
  padding: 0 0.7rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 6px;
  transition: border-color 100ms var(--ease), box-shadow 100ms var(--ease);
}
textarea { height: auto; padding: 0.55rem 0.7rem; font-family: var(--mono); font-size: 12.5px; min-height: 140px; line-height: 1.5; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
label {
  color: var(--text-muted); font-size: 13px;
}

/* ===================================================================
 * Tables
 * =================================================================*/
table {
  width: 100%; border-collapse: collapse; font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; box-shadow: var(--shadow-xs);
}
th, td { text-align: left; padding: 0.6rem 0.85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  background: var(--surface-alt); color: var(--text-muted);
  font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.55rem 0.85rem;
  position: sticky; top: 0; z-index: 1;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 80ms var(--ease); }
tbody tr:hover { background: var(--brand-tint); }
tbody tr.row-link { cursor: pointer; }
tbody tr.row-link:hover td:first-child code { color: var(--brand-dark); }
td code { font-size: 12px; color: var(--text); font-variant-numeric: tabular-nums; }
td.actions {
  white-space: nowrap;
  text-align: right;
}
td.actions > * { margin-left: 0.35rem; vertical-align: middle; }
td.actions > *:first-child { margin-left: 0; }
th.actions { text-align: right; }
td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; }

/* Toolbar above tables */
.toolbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.5rem; gap: 0.5rem; flex-wrap: wrap;
}
.toolbar .left, .toolbar .right { display: flex; gap: 0.5rem; align-items: center; }

/* ===================================================================
 * Skeleton placeholders (loading state)
 * =================================================================*/
.skeleton {
  display: inline-block;
  background: linear-gradient(
    90deg,
    rgba(15, 23, 42, 0.06) 0%,
    rgba(15, 23, 42, 0.10) 50%,
    rgba(15, 23, 42, 0.06) 100%
  );
  background-size: 200% 100%;
  border-radius: 4px;
  animation: skyn-shimmer 1.4s ease-in-out infinite;
  color: transparent !important;
  user-select: none;
  pointer-events: none;
  vertical-align: middle;
}
@keyframes skyn-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skel-text       { width: 8rem;  height: 0.85em; }
.skel-text.short { width: 4rem; }
.skel-text.long  { width: 12rem; }
.skel-text.xlong { width: 18rem; }
.skel-num        { width: 3rem; height: 1em; }
.skel-block      { width: 100%; height: 1.4rem; display: block; }
.skel-block.tall { height: 4rem; }
.skel-pill       { width: 4rem; height: 1.1em; border-radius: 999px; }

/* Fade-in for content swapped in from skeleton */
.fade-in {
  animation: skyn-fade-in 200ms var(--ease);
}
@keyframes skyn-fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===================================================================
 * Empty states (proper card, not italic text)
 * =================================================================*/
.empty-state {
  padding: 2.25rem 1.5rem;
  text-align: center;
  background: var(--surface-alt);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
}
.empty-state-icon {
  width: 36px; height: 36px;
  margin: 0 auto 0.6rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-tint); color: var(--brand);
  border-radius: 50%;
  font-size: 16px; font-weight: 600;
}
.empty-state-title {
  margin: 0 0 0.3rem;
  font-size: 0.95rem; font-weight: 600; color: var(--text);
}
.empty-state-body {
  color: var(--text-muted); margin: 0 0 1rem;
  font-size: 13px;
}
.empty-state-body:last-child { margin-bottom: 0; }

/* Inline empty placeholder (small, in a table cell or section) */
.empty {
  color: var(--text-faint);
  font-size: 13px;
  padding: 0.5rem 0;
}

.hint { color: var(--text-muted); font-size: 12.5px; }

.toast.err {
  border: 1px solid var(--err); color: var(--err);
  padding: 0.6rem 0.9rem; border-radius: 6px; margin-bottom: 1rem;
  background: var(--err-bg);
}

/* ===================================================================
 * Status badges (for prediction levels, statuses, etc.)
 * =================================================================*/
.badge {
  display: inline-flex; align-items: center;
  font-size: 11px; font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--surface-alt); color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.err { background: var(--err-bg); color: var(--err); border-color: transparent; }
.badge.info { background: var(--brand-soft); color: var(--brand-dark); border-color: transparent; }

/* ===================================================================
 * Auth-card layout (login + bootstrap-style screens)
 * =================================================================*/
.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
}
.auth-card {
  max-width: 420px; width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1.75rem 1.75rem 1.5rem;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
}
.auth-card .wordmark {
  color: var(--brand-navy);
  margin-bottom: 1.25rem;
  pointer-events: none;
}
.auth-card .wordmark .logo { height: 36px; }
.auth-card .wordmark .name {
  color: var(--brand-navy);
  font-size: 1.25rem;
}
.auth-card h1 { font-size: 1.15rem; margin: 0 0 1rem; color: var(--text); }
.auth-card label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
  font-weight: 600;
}
.auth-card input { width: 100%; margin-bottom: 0.85rem; }
.auth-card input:last-of-type { margin-bottom: 0; }
.auth-card form button.primary { width: 100%; margin-top: 0.85rem; }
.auth-card > button.primary { width: 100%; }
.auth-card .hint { margin-top: 0.85rem; }
.auth-card .toast.err { margin-bottom: 0.85rem; }

/* ===================================================================
 * Stat tiles (dashboard summaries)
 * =================================================================*/
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem; margin-bottom: 1.5rem;
}
.stat {
  padding: 1rem 1.15rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow-xs);
  position: relative; overflow: hidden;
  transition: border-color 120ms var(--ease), box-shadow 120ms var(--ease);
}
.stat::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--brand);
}
.stat:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.stat-label {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 0.4rem; font-weight: 600;
}
.stat-val {
  font-size: 1.55rem; color: var(--text); font-weight: 600;
  letter-spacing: -0.015em; font-variant-numeric: tabular-nums;
  min-height: 1.55rem;
}

/* ===================================================================
 * Modal
 * =================================================================*/
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 18, 22, 0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  animation: skyn-overlay-in 140ms var(--ease);
  backdrop-filter: blur(2px);
}
@keyframes skyn-overlay-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  max-width: 520px; width: 100%;
  box-shadow: var(--shadow-pop);
  max-height: 90vh; overflow-y: auto;
  animation: skyn-modal-in 180ms var(--ease);
}
@keyframes skyn-modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal h3 { color: var(--text); margin: 0 0 0.75rem; font-size: 1.05rem; font-weight: 600; }
.modal .body { color: var(--text); }
.modal .body p { margin: 0.4rem 0; }
.modal .body .warn { color: var(--err); font-weight: 600; }
.modal .body code {
  display: block; word-break: break-all; user-select: all;
  background: var(--surface-alt); border: 1px solid var(--border); border-radius: 6px;
  padding: 0.55rem 0.75rem; margin: 0.5rem 0;
  font-size: 12px; color: var(--text);
}
.modal .field { margin: 0.6rem 0; }
.modal .field label {
  display: block; font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 0.25rem; font-weight: 600;
}
.modal .field input { width: 100%; min-width: 0; }
.modal .field-error { color: var(--err); font-size: 12px; margin-top: 0.3rem; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 0.85rem;
}
