/* =====================================================================
   Web Utility Suite — Shared Design System (base.css)
   Premium SaaS aesthetic · Glassmorphism · Dark/Light · Fully responsive
   Used by every app in the suite. Do not fork; extend in each app's app.css.
   ===================================================================== */

:root {
  color-scheme: dark;

  /* ---- Brand ---- */
  --brand-400: #818cf8;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --accent-500: #8b5cf6;
  --accent-pink: #d946ef;
  --accent-cyan: #22d3ee;
  --gradient-brand: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
  --gradient-brand-soft: linear-gradient(135deg, rgba(99,102,241,.16), rgba(139,92,246,.16));

  /* ---- Surfaces (dark, default) ---- */
  --bg: #08090d;
  --bg-grad-1: rgba(99,102,241,.14);
  --bg-grad-2: rgba(139,92,246,.11);
  --bg-grad-3: rgba(34,211,238,.07);
  --surface: rgba(255,255,255,.035);
  --surface-2: rgba(255,255,255,.06);
  --surface-3: rgba(255,255,255,.09);
  --surface-solid: #111219;
  --elevated: rgba(20,21,30,.74);
  --glass: rgba(16,17,26,.55);
  --border: rgba(255,255,255,.08);
  --border-strong: rgba(255,255,255,.15);

  /* ---- Text ---- */
  --text: #f4f5fa;
  --text-secondary: #b4b7c6;
  --text-muted: #71758a;
  --text-inverse: #08090d;

  /* ---- Semantic ---- */
  --success: #22c55e;
  --success-soft: rgba(34,197,94,.15);
  --warning: #f59e0b;
  --warning-soft: rgba(245,158,11,.15);
  --danger: #ef4444;
  --danger-soft: rgba(239,68,68,.15);
  --info: #38bdf8;
  --info-soft: rgba(56,189,248,.15);

  /* ---- Typography ---- */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;

  /* ---- Spacing (4px base) ---- */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px;
  --space-12: 48px;--space-16: 64px;--space-20: 80px;

  /* ---- Radius ---- */
  --radius-sm: 8px; --radius-md: 12px; --radius-lg: 16px;
  --radius-xl: 22px; --radius-2xl: 28px; --radius-full: 999px;

  /* ---- Shadows ---- */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.32);
  --shadow-md: 0 8px 26px -10px rgba(0,0,0,.55);
  --shadow-lg: 0 24px 64px -18px rgba(0,0,0,.62);
  --shadow-glow: 0 0 0 1px rgba(99,102,241,.35), 0 10px 32px -8px rgba(99,102,241,.45);

  /* ---- Motion ---- */
  --ease: cubic-bezier(.16,1,.3,1);
  --ease-out: cubic-bezier(.22,1,.36,1);
  --dur-1: .15s; --dur-2: .25s; --dur-3: .4s;

  --container: 1120px;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6fb;
  --bg-grad-1: rgba(99,102,241,.12);
  --bg-grad-2: rgba(139,92,246,.10);
  --bg-grad-3: rgba(34,211,238,.06);
  --surface: rgba(255,255,255,.72);
  --surface-2: rgba(255,255,255,.92);
  --surface-3: rgba(15,18,40,.05);
  --surface-solid: #ffffff;
  --elevated: rgba(255,255,255,.86);
  --glass: rgba(255,255,255,.62);
  --border: rgba(15,18,40,.09);
  --border-strong: rgba(15,18,40,.16);
  --text: #0c0e1a;
  --text-secondary: #474b60;
  --text-muted: #7d8197;
  --text-inverse: #ffffff;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
  --shadow-md: 0 10px 30px -12px rgba(16,24,40,.18);
  --shadow-lg: 0 24px 60px -18px rgba(16,24,40,.22);
}

/* ===================== Reset & base ===================== */
*,*::before,*::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Ambient animated background */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -2; pointer-events: none;
  background:
    radial-gradient(60vw 60vw at 10% -10%, var(--bg-grad-1), transparent 60%),
    radial-gradient(52vw 52vw at 105% 0%, var(--bg-grad-2), transparent 55%),
    radial-gradient(48vw 48vw at 50% 120%, var(--bg-grad-3), transparent 60%);
  animation: bgFloat 20s var(--ease) infinite alternate;
}
body::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: .45;
  background-image: radial-gradient(rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 24px 24px;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 22%, #000 78%, transparent);
          mask-image: linear-gradient(to bottom, transparent, #000 22%, #000 78%, transparent);
}
[data-theme="light"] body::after { opacity: .5; background-image: radial-gradient(rgba(15,18,40,.05) 1px, transparent 1px); }
@keyframes bgFloat { from { transform: translate3d(0,0,0); } to { transform: translate3d(0,-2.2%,0); } }

h1,h2,h3,h4 { margin: 0 0 .4em; font-weight: 700; letter-spacing: -.02em; line-height: 1.16; }
h1 { font-size: clamp(1.8rem, 1.2rem + 2.4vw, 2.9rem); }
p { margin: 0 0 1em; }
a { color: var(--brand-400); text-decoration: none; transition: color var(--dur-1); }
a:hover { color: var(--brand-500); text-decoration: underline; }
::selection { background: rgba(99,102,241,.35); color: #fff; }
hr { border: none; border-top: 1px solid var(--border); margin: var(--space-6) 0; }
small { color: var(--text-muted); }

.container { width: 100%; max-width: var(--container); margin-inline: auto; padding-inline: var(--space-6); }

/* ===================== Surfaces ===================== */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
          backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.panel {
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
          backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
}

/* ===================== Top bar ===================== */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-4) 0; margin-bottom: var(--space-6);
}
.brand { display: flex; align-items: center; gap: var(--space-3); font-weight: 700; letter-spacing: -.02em; font-size: 1.05rem; }
.brand .logo {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--gradient-brand); box-shadow: var(--shadow-glow); color: #fff; flex: none;
}
.brand .logo svg { width: 22px; height: 22px; }
.brand .sub { font-weight: 500; color: var(--text-muted); font-size: .8rem; }
.topbar .spacer { flex: 1; }

/* ===================== Buttons ===================== */
.btn {
  --_bg: var(--surface-2);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  font: 600 14px/1 var(--font-sans); color: var(--text); background: var(--_bg);
  border: 1px solid var(--border); padding: 10px 16px; border-radius: var(--radius-md);
  cursor: pointer; user-select: none; white-space: nowrap;
  transition: transform var(--dur-1) var(--ease), background var(--dur-1), border-color var(--dur-1), box-shadow var(--dur-2), opacity var(--dur-1);
}
.btn:hover { transform: translateY(-1px); border-color: var(--border-strong); background: var(--surface-3); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(99,102,241,.45); }
.btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--gradient-brand); border-color: transparent; color: #fff; box-shadow: var(--shadow-glow); }
.btn--primary:hover { background: var(--gradient-brand); box-shadow: 0 12px 36px -10px rgba(99,102,241,.6); }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--surface-2); }
.btn--danger { color: #fff; background: var(--danger); border-color: transparent; }
.btn--icon { padding: 0; width: 40px; height: 40px; flex: none; }
.btn--sm { padding: 7px 12px; font-size: 13px; }
.btn--block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ===================== Form controls ===================== */
input[type=text],input[type=number],input[type=url],input[type=email],input[type=tel],
input[type=password],input[type=search],input[type=date],textarea,select {
  width: 100%; font: 500 14px/1.5 var(--font-sans); color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 11px 14px; transition: border-color var(--dur-1), box-shadow var(--dur-1), background var(--dur-1);
}
textarea { resize: vertical; line-height: 1.6; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(99,102,241,.18); background: var(--surface-2);
}
::placeholder { color: var(--text-muted); }
label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.field { display: flex; flex-direction: column; gap: var(--space-2); }
select {
  -webkit-appearance: none; appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2371758a' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px;
}

/* Range slider */
input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px;
  border-radius: 999px; background: var(--surface-3); outline: none; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--gradient-brand); cursor: pointer; border: 3px solid var(--bg); box-shadow: var(--shadow-glow);
  transition: transform var(--dur-1);
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.12); }
input[type=range]::-moz-range-thumb {
  width: 18px; height: 18px; border: 3px solid var(--bg); border-radius: 50%;
  background: var(--accent-500); cursor: pointer;
}
input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(99,102,241,.4); }

/* Switch */
.switch { position: relative; display: inline-flex; width: 46px; height: 26px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; background: var(--surface-3); border: 1px solid var(--border); border-radius: 999px; transition: background var(--dur-2), border-color var(--dur-2); }
.switch .thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--text-secondary); transition: transform var(--dur-2) var(--ease), background var(--dur-2); }
.switch input:checked ~ .track { background: var(--gradient-brand); border-color: transparent; }
.switch input:checked ~ .thumb { transform: translateX(20px); background: #fff; }
.switch input:focus-visible ~ .track { box-shadow: 0 0 0 3px rgba(99,102,241,.4); }

/* Checkbox row */
.check { display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; user-select: none; }

/* Segmented control / tabs */
.segmented { display: inline-flex; padding: 4px; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.segmented button { border: none; background: transparent; color: var(--text-secondary); font: 600 13px/1 var(--font-sans); padding: 8px 14px; border-radius: 9px; cursor: pointer; transition: color var(--dur-1), background var(--dur-1); white-space: nowrap; }
.segmented button:hover { color: var(--text); }
.segmented button[aria-selected="true"], .segmented button.is-active { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow-sm); }

/* Badge / chip */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-secondary); }
.badge--success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge--warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge--danger  { background: var(--danger-soft);  color: var(--danger);  border-color: transparent; }
.badge--info    { background: var(--info-soft);    color: var(--info);    border-color: transparent; }

/* Toast */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 10px; align-items: center; pointer-events: none; width: max-content; max-width: 92vw; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--radius-md); background: var(--elevated); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500; color: var(--text); animation: toastIn .35s var(--ease); }
.toast.--out { animation: toastOut .3s var(--ease) forwards; }
.toast .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex: none; box-shadow: 0 0 12px var(--success); }
.toast.--error .dot { background: var(--danger); box-shadow: 0 0 12px var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(12px) scale(.96); } }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 900; background: rgba(4,5,9,.6); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); display: grid; place-items: center; padding: var(--space-4); animation: fadeIn .2s var(--ease); }
.modal { width: 100%; max-width: 480px; background: var(--surface-solid); border: 1px solid var(--border-strong); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); padding: var(--space-6); animation: modalIn .3s var(--ease); }
[data-theme="light"] .modal { background: #fff; }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: none; } }
[hidden] { display: none !important; }

/* Tooltip via title is fine; kbd styling */
kbd { font-family: var(--font-mono); font-size: 12px; padding: 2px 7px; border-radius: 6px; background: var(--surface-3); border: 1px solid var(--border-strong); box-shadow: 0 1px 0 var(--border-strong); color: var(--text-secondary); }

/* Scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-muted); background-clip: content-box; }

/* ===================== Utilities ===================== */
.row { display: flex; gap: var(--space-4); }
.col { display: flex; flex-direction: column; gap: var(--space-4); }
.between { justify-content: space-between; }
.center { align-items: center; }
.middle { align-items: center; justify-content: center; }
.wrap { flex-wrap: wrap; }
.gap-2 { gap: var(--space-2); } .gap-3 { gap: var(--space-3); } .gap-6 { gap: var(--space-6); }
.flex-1 { flex: 1; }
.grid { display: grid; gap: var(--space-4); }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.mono { font-family: var(--font-mono); }
.text-c { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fade-in { animation: fadeIn .4s var(--ease) both; }
.rise { animation: rise .5s var(--ease) both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.gradient-text { background: var(--gradient-brand); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent; }
.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; }
.app-footer { text-align: center; color: var(--text-muted); font-size: 13px; padding: var(--space-12) 0 var(--space-8); }
.app-footer a { color: var(--text-secondary); }

/* Empty state */
.empty { text-align: center; color: var(--text-muted); padding: var(--space-10) var(--space-4); }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: var(--space-3); }

/* ===================== Accessibility & motion ===================== */
:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
@media (max-width: 720px) {
  .container { padding-inline: var(--space-4); }
  .hide-sm { display: none !important; }
  .topbar { flex-wrap: wrap; }
}
