/**
 * KAIros Web UI — Shared Design System
 * apps/ui/assets/kairos.css
 *
 * Provides: design tokens, reset, wallpaper/glow layers,
 *           glassmorphic header, shared components (btn, chip,
 *           card, toast, toolbar, inputs, spinner, toggle),
 *           and base responsive utilities.
 *
 * Load BEFORE any page-specific <style> block.
 * Depends on: utils.js for theme init (data-theme attribute).
 */

/* ═══════════════════════════════════════════════════
   1. DESIGN TOKENS — colours, type, easing, wallpaper
   ═══════════════════════════════════════════════════ */
:root {
  /* Backgrounds */
  --bg: #000000;
  --bg-soft: #050505;
  --card: #0a0a0a;
  --card-2: #080808;
  --muted: #1a1a1a;

  /* Text */
  --text: #f5f5f5;
  --text-dim: #999999;
  --text-secondary: rgba(245, 245, 245, 0.6);
  --text-muted: rgba(245, 245, 245, 0.35);

  /* Accent / brand */
  --accent: #ed1e79;
  --accent-rgb: 237, 30, 121;
  --accent-glow: rgba(237, 30, 121, 0.4);
  --accent-2: #f5f5f5;
  --accent-3: #a78bfa;

  /* Status */
  --good:    #10b981;
  --success: #10b981;
  --success-rgb: 16, 185, 129;
  --warn:    #f59e0b;
  --warning: #f59e0b;
  --warning-rgb: 245, 158, 11;
  --bad:     #ef4444;
  --danger:  #ef4444;
  --danger-rgb: 239, 68, 68;

  /* Shadows / borders */
  --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  --radius: 16px;
  --glass-bg:     linear-gradient(135deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, .02));
  --glass-border: rgba(255, 255, 255, .08);
  --glass-highlight: rgba(255, 255, 255, .06);

  /* Typography */
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body:    'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono:    'Fira Code', 'JetBrains Mono', 'SFMono-Regular', Menlo, Consolas, monospace;

  /* Easing */
  --spring:   cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* Wallpaper (controlled by utils.js initWallpaper) */
  --bg-image:   none;
  --bg-blur:    0px;
  --bg-opacity: 1;
}

/* Light theme overrides */
[data-theme="light"] {
  --bg:      #f5f5f5;
  --bg-soft: #eeeeee;
  --card:    #ffffff;
  --card-2:  #ffffff;
  --muted:   #e0e0e0;
  --text:      #0a0a0a;
  --text-dim:  #666666;
  --text-secondary: rgba(10, 10, 10, 0.55);
  --text-muted:     rgba(10, 10, 10, 0.30);
  --shadow:    0 10px 30px rgba(0, 0, 0, .07);
  --glass-bg:     linear-gradient(135deg, rgba(255, 255, 255, .8), rgba(255, 255, 255, .5));
  --glass-border: rgba(0, 0, 0, .08);
  --glass-highlight: rgba(255, 255, 255, .9);
}

/* ═══════════════════════════════════════════════════
   2. RESET & BASE
   ═══════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font: 14px / 1.5 var(--font-body);
  color: var(--text);
  background: var(--bg);
  position: relative;
  overflow-x: hidden;
}

/* ═══════════════════════════════════════════════════
   3. WALLPAPER LAYER (restored by utils.js)
   ═══════════════════════════════════════════════════ */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  filter: blur(var(--bg-blur));
  opacity: var(--bg-opacity);
  transform: scale(1.02);
}

/* Accent glow overlay */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(var(--accent-rgb), .10), transparent 55%),
    radial-gradient(800px  400px at 110% 10%, rgba(167, 139, 250, .07), transparent 50%);
}

/* Noise grain overlay (opt-in via .noise-grain element) */
.noise-grain {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

/* ═══════════════════════════════════════════════════
   4. GLASSMORPHIC HEADER
   ═══════════════════════════════════════════════════ */
header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(180deg, rgba(0, 0, 0, .75), rgba(0, 0, 0, .45));
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-bottom: 1px solid var(--glass-border);
}

[data-theme="light"] header {
  background: linear-gradient(180deg, rgba(245, 245, 245, .85), rgba(245, 245, 245, .65));
  border-bottom-color: rgba(0, 0, 0, .06);
}

/* ═══════════════════════════════════════════════════
   5. LAYOUT UTILITIES
   ═══════════════════════════════════════════════════ */
.wrap    { max-width: 1100px; margin: 0 auto; padding: 16px; }
.wrap-lg { max-width: 1400px; margin: 0 auto; padding: 16px; }

/* ═══════════════════════════════════════════════════
   6. TOOLBAR
   ═══════════════════════════════════════════════════ */
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════════════════
   7. CARDS
   ═══════════════════════════════════════════════════ */
.card {
  background: var(--glass-bg), var(--card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  backdrop-filter: saturate(150%) blur(12px);
  -webkit-backdrop-filter: saturate(150%) blur(12px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ═══════════════════════════════════════════════════
   8. CHIPS / BADGES
   ═══════════════════════════════════════════════════ */
.chip {
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--glass-border);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: border-color .3s ease;
}
[data-theme="light"] .chip { background: rgba(0, 0, 0, .03); }

/* ═══════════════════════════════════════════════════
   9. BUTTONS
   ═══════════════════════════════════════════════════ */
.btn {
  appearance: none;
  border: 1px solid var(--glass-border);
  background: linear-gradient(180deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, .02)), rgba(20, 20, 20, .8);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 12px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
  transition: transform .12s ease, filter .2s ease, box-shadow .3s ease;
}
.btn:hover:not(:disabled) {
  filter: brightness(1.1);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
  filter: brightness(0.95);
}
.btn:disabled { opacity: .4; cursor: not-allowed; }

[data-theme="light"] .btn {
  background: linear-gradient(180deg, rgba(255, 255, 255, .9), rgba(255, 255, 255, .7));
  border-color: rgba(0, 0, 0, .1);
  color: #0a0a0a;
}

/* Accent (pink) variant */
.btn-pink, .btn.accent {
  background: linear-gradient(135deg, var(--accent) 0%, #d4145a 100%);
  border-color: rgba(var(--accent-rgb), .4);
  color: #fff;
  box-shadow: 0 4px 20px rgba(var(--accent-rgb), .25);
}
.btn-pink:hover:not(:disabled), .btn.accent:hover:not(:disabled) {
  box-shadow: 0 0 15px rgba(var(--accent-rgb), .5);
  filter: brightness(1.08);
}

/* Red/danger variant */
.btn-red {
  background: linear-gradient(135deg, var(--danger) 0%, #b91c1c 100%);
  border-color: rgba(var(--danger-rgb), .4);
  color: #fff;
}
.btn-red:hover:not(:disabled) {
  box-shadow: 0 0 15px rgba(var(--danger-rgb), .5);
}

/* ═══════════════════════════════════════════════════
   10. FORM INPUTS
   ═══════════════════════════════════════════════════ */
select, input[type="text"], input[type="url"], input[type="password"],
input[type="number"], textarea {
  background: rgba(255, 255, 255, .04);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 40px;
  font-family: var(--font-body);
  font-size: 14px;
  transition: border-color .3s ease, box-shadow .3s ease;
}
select:focus, input:focus, textarea:focus {
  border-color: rgba(var(--accent-rgb), .4);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .1);
  outline: none;
}
[data-theme="light"] select,
[data-theme="light"] input[type="text"],
[data-theme="light"] input[type="url"],
[data-theme="light"] input[type="password"],
[data-theme="light"] input[type="number"],
[data-theme="light"] textarea {
  background: rgba(0, 0, 0, .02);
  border-color: rgba(0, 0, 0, .1);
}

textarea { resize: vertical; }

/* ═══════════════════════════════════════════════════
   11. TOGGLE SWITCH
   ═══════════════════════════════════════════════════ */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  background: rgba(255, 255, 255, .15);
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .2);
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .3s ease, border-color .3s ease;
}
.toggle i {
  position: absolute;
  inset: 3px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #fff;
  transition: transform .3s var(--spring);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}
.toggle[data-on="1"] i { transform: translateX(20px); }
.toggle[data-on="1"] {
  background: rgba(var(--accent-rgb), .3);
  border-color: rgba(var(--accent-rgb), .4);
}

/* ═══════════════════════════════════════════════════
   12. TOAST NOTIFICATIONS
   ═══════════════════════════════════════════════════ */
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: rgba(10, 10, 10, .95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #f5f5f5;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
  border-left: 3px solid var(--accent);
  opacity: 0;
  transform: translateY(12px) scale(0.95);
  transition: all .35s var(--spring);
  font-weight: 500;
  z-index: 200;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.toast.err { border-left-color: var(--danger); }

/* ═══════════════════════════════════════════════════
   13. SPINNER
   ═══════════════════════════════════════════════════ */
.spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, .15);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: ks-spin .8s linear infinite;
  margin-left: 6px;
  vertical-align: middle;
}
@keyframes ks-spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════════
   14. SECTION LABELS
   ═══════════════════════════════════════════════════ */
.section-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ═══════════════════════════════════════════════════
   15. SHARED ANIMATIONS
   ═══════════════════════════════════════════════════ */
@keyframes ks-fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes ks-pulse {
  0%   { box-shadow: 0 0 8px rgba(239, 68, 68, .5), 0 0 0 0 rgba(239, 68, 68, .4); }
  70%  { box-shadow: 0 0 8px rgba(239, 68, 68, .5), 0 0 0 12px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 8px rgba(239, 68, 68, .5), 0 0 0 0 rgba(239, 68, 68, 0); }
}
@keyframes ks-pulseGreen {
  0%   { box-shadow: 0 0 10px rgba(16, 185, 129, .5), 0 0 0 0 rgba(16, 185, 129, .4); }
  70%  { box-shadow: 0 0 10px rgba(16, 185, 129, .5), 0 0 0 12px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 10px rgba(16, 185, 129, .5), 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* ═══════════════════════════════════════════════════
   16. MODAL / OVERLAY
   ═══════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-overlay.show { display: flex; }

.modal-box {
  width: min(540px, 92vw);
  background: var(--glass-bg), rgba(10, 10, 10, .9);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: saturate(150%) blur(16px);
  -webkit-backdrop-filter: saturate(150%) blur(16px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: ks-fadeUp .3s var(--ease-out) both;
}
[data-theme="light"] .modal-box {
  background: rgba(255, 255, 255, .92), var(--glass-bg);
  border-color: rgba(0, 0, 0, .12);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--glass-border);
}

.modal-header h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 4px;
}

/* ═══════════════════════════════════════════════════
   17. SETTINGS DRAWER (shared slide-out panel)
   ═══════════════════════════════════════════════════ */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}
.drawer::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity .25s ease;
}
.drawer .panel {
  position: absolute;
  top: 0;
  right: -100%;
  width: min(420px, 100vw);
  height: 100%;
  padding: 16px;
  overflow: auto;
  background: var(--glass-bg), rgba(10, 10, 10, .85);
  border-left: 1px solid var(--glass-border);
  box-shadow: -16px 0 40px rgba(0, 0, 0, .4);
  backdrop-filter: saturate(150%) blur(16px);
  -webkit-backdrop-filter: saturate(150%) blur(16px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.drawer.show { opacity: 1; pointer-events: auto; }
.drawer.show::before { opacity: 1; }
.drawer.show .panel { right: 0; transition: right .3s var(--ease-out); }

[data-theme="light"] .drawer .panel {
  background: var(--glass-bg), rgba(240, 240, 240, .95);
  border-left-color: rgba(0, 0, 0, .15);
}

/* ═══════════════════════════════════════════════════
   18. REDUCED MOTION
   ═══════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
