/* Lumivex Admin — Stitch / mobile app design tokens */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap');

/* ── Dark (default, matches app) ── */
:root,
[data-theme="dark"] {
  --bg: #15121c;
  --bg-elevated: #100c17;
  --surface: rgba(33, 30, 41, 0.72);
  --surface-solid: #211e29;
  --surface-high: #2c2834;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(149, 141, 162, 0.35);
  --text: #e8dfef;
  --text-muted: #ccc3d9;
  --text-dim: #958da2;
  --primary: #d1bcff;
  --primary-strong: #7b2eff;
  --primary-dim: #731ef7;
  --on-primary: #3d0090;
  --accent: #4cd6ff;
  --accent-strong: #00d1ff;
  --accent-muted: #a6e6ff;
  --tertiary: #ffb68f;
  --danger: #ffb4ab;
  --danger-bg: rgba(147, 0, 10, 0.35);
  --success: #7dffb8;
  --success-bg: rgba(34, 197, 94, 0.15);
  --glass: rgba(21, 18, 28, 0.55);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --glow-primary: rgba(123, 46, 255, 0.35);
  --glow-accent: rgba(0, 209, 255, 0.2);
  --gradient-brand: linear-gradient(135deg, #d1bcff 0%, #7b2eff 45%, #00d1ff 100%);
  --gradient-btn: linear-gradient(135deg, #7b2eff 0%, #5800c8 50%, #004e60 100%);
  --input-bg: rgba(16, 12, 23, 0.65);
  --overlay: rgba(5, 5, 5, 0.65);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --font: "Space Grotesk", system-ui, sans-serif;
  --sidebar-w: 272px;
  color-scheme: dark;
}

/* ── Light ── */
[data-theme="light"] {
  --bg: #f3f0f8;
  --bg-elevated: #ffffff;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-solid: #ffffff;
  --surface-high: #ebe6f2;
  --border: rgba(29, 26, 37, 0.1);
  --border-strong: rgba(29, 26, 37, 0.18);
  --text: #1d1a25;
  --text-muted: #4a4456;
  --text-dim: #6b6478;
  --primary: #5800c8;
  --primary-strong: #731ef7;
  --primary-dim: #3d0090;
  --on-primary: #ffffff;
  --accent: #006b85;
  --accent-strong: #00a3c4;
  --accent-muted: #00566b;
  --tertiary: #a94a00;
  --danger: #93000a;
  --danger-bg: rgba(255, 180, 171, 0.35);
  --success: #166534;
  --success-bg: rgba(34, 197, 94, 0.12);
  --glass: rgba(255, 255, 255, 0.75);
  --shadow: 0 8px 32px rgba(29, 26, 37, 0.12);
  --glow-primary: rgba(115, 30, 247, 0.15);
  --glow-accent: rgba(0, 163, 196, 0.12);
  --gradient-brand: linear-gradient(135deg, #731ef7 0%, #5800c8 50%, #00a3c4 100%);
  --gradient-btn: linear-gradient(135deg, #731ef7 0%, #5800c8 55%, #006b85 100%);
  --input-bg: rgba(255, 255, 255, 0.95);
  --overlay: rgba(29, 26, 37, 0.4);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.25s ease, color 0.2s ease;
}

/* Ambient background */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, var(--glow-primary), transparent 55%),
    radial-gradient(ellipse 60% 40% at 90% 0%, var(--glow-accent), transparent 50%),
    var(--bg);
}

a { color: var(--accent-strong); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--primary); }

h1, h2, h3 { margin: 0 0 0.75rem; font-weight: 600; letter-spacing: -0.02em; }
h1 { font-size: clamp(1.5rem, 4vw, 2rem); }
h2 { font-size: 1.15rem; }
.muted { color: var(--text-muted); font-size: 0.875rem; }

/* ── Theme toggle ── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  transition: border-color 0.2s, background 0.2s;
}
.theme-toggle:hover {
  border-color: var(--border-strong);
  color: var(--text);
}
.theme-toggle svg { width: 18px; height: 18px; flex-shrink: 0; }
.theme-toggle .icon-sun,
[data-theme="light"] .theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: block; }

/* ── Shell layout ── */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.875rem;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: transform 0.3s ease;
  z-index: 100;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.75rem 1.5rem;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar .brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--gradient-btn);
  flex-shrink: 0;
  -webkit-text-fill-color: initial;
  display: grid;
  place-items: center;
  font-size: 1rem;
  color: #fff;
  box-shadow: 0 4px 16px var(--glow-primary);
}

.nav { flex: 1; }
.nav a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  margin-bottom: 0.2rem;
  font-weight: 500;
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s;
}
.nav a:hover {
  background: var(--surface-high);
  color: var(--text);
  text-decoration: none;
}
.nav a.active {
  background: linear-gradient(90deg, rgba(123, 46, 255, 0.25), rgba(0, 209, 255, 0.08));
  color: var(--primary);
  border: 1px solid var(--border);
}
[data-theme="light"] .nav a.active { color: var(--primary-strong); }

.nav-section {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 1rem 0.85rem 0.35rem;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--glass);
  backdrop-filter: blur(16px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.topbar-title {
  margin: 0;
  font-size: clamp(1rem, 3vw, 1.15rem);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.user-chip {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-toggle {
  display: none;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  line-height: 0;
}
.menu-toggle svg { width: 22px; height: 22px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.3s;
}

.content {
  padding: clamp(1rem, 3vw, 2rem);
  flex: 1;
}

/* ── Stats & cards ── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.35rem;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  transition: border-color 0.2s, transform 0.2s;
}
.stat-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}
.stat-card .value {
  font-size: clamp(1.5rem, 4vw, 1.85rem);
  font-weight: 700;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
}
.stat-card .label {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 0.35rem;
  font-weight: 500;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(1rem, 2.5vw, 1.5rem);
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.card h2 { margin-bottom: 1rem; }

/* ── Tables (responsive) ── */
.table-wrap { overflow-x: auto; margin: -0.25rem; padding: 0.25rem; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; min-width: 520px; }
th, td {
  text-align: left;
  padding: 0.85rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(123, 46, 255, 0.06); }
[data-theme="light"] tr:hover td { background: rgba(115, 30, 247, 0.06); }

@media (max-width: 640px) {
  .table-cards { display: block; }
  .table-cards thead { display: none; }
  .table-cards tbody tr {
    display: block;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--surface-high);
    border-radius: var(--radius);
    border: 1px solid var(--border);
  }
  .table-cards tbody td {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.4rem 0;
    border: none;
  }
  .table-cards tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-dim);
    font-size: 0.75rem;
    text-transform: uppercase;
  }
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(123, 46, 255, 0.22);
  color: var(--primary);
}
.badge.free { background: var(--success-bg); color: var(--success); }
.badge.premium { background: rgba(123, 46, 255, 0.3); color: var(--primary); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.15rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  color: #fff;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--gradient-btn);
  box-shadow: 0 4px 20px var(--glow-primary);
}
.btn-primary:hover { box-shadow: 0 6px 28px var(--glow-primary); color: #fff; text-decoration: none; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost:hover { border-color: var(--primary-strong); color: var(--primary); text-decoration: none; }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-block { width: 100%; }

.toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  align-items: center;
}
.toolbar form { display: flex; gap: 0.5rem; flex: 1; min-width: 200px; max-width: 360px; }
.toolbar input, .toolbar select { flex: 1; min-width: 0; }

/* ── Forms ── */
.form-group { margin-bottom: 1.1rem; }
form label, .form-label {
  display: block;
  margin: 0 0 0.4rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
form input, form textarea, form select,
.input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
form input:focus, form textarea:focus, form select:focus,
.input:focus {
  outline: none;
  border-color: var(--primary-strong);
  box-shadow: 0 0 0 3px var(--glow-primary);
}
form textarea { min-height: 110px; resize: vertical; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 0 1.5rem;
  max-width: 960px;
}
.form-actions {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.form-hint { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.35rem; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0;
  cursor: pointer;
}
.checkbox-row input { width: auto; accent-color: var(--primary-strong); }

.alert {
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert.success { background: var(--success-bg); border: 1px solid var(--success); color: var(--success); }
.alert.error { background: var(--danger-bg); border: 1px solid var(--danger); color: var(--danger); }
[data-theme="dark"] .alert.success { color: var(--success); }
[data-theme="dark"] .alert.error { color: var(--danger); }

/* ── Auth & install pages ── */
.standalone-page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 4vw, 2.5rem);
}

.standalone-top {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10;
  display: flex;
  gap: 0.5rem;
}

.auth-card, .install-card {
  width: 100%;
  max-width: 440px;
  padding: clamp(1.5rem, 4vw, 2.25rem);
  background: var(--glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.install-card { max-width: 560px; }

.brand-hero {
  text-align: center;
  margin-bottom: 1.75rem;
}
.brand-hero .logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  border-radius: 14px;
  background: var(--gradient-btn);
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 8px 28px var(--glow-primary);
}
.brand-hero h1 {
  margin: 0 0 0.35rem;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand-hero p { margin: 0; color: var(--text-muted); font-size: 0.9rem; }

.install-steps {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.install-step {
  flex: 1;
  min-width: 80px;
  text-align: center;
  padding: 0.5rem;
  border-radius: var(--radius);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--surface-high);
  border: 1px solid var(--border);
}
.install-step.active {
  color: var(--primary);
  border-color: var(--primary-strong);
  background: rgba(123, 46, 255, 0.12);
}

.form-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.form-section:last-of-type { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.form-section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.form-section-title::before {
  content: "";
  width: 4px;
  height: 1em;
  background: var(--gradient-btn);
  border-radius: 2px;
}

.success-panel {
  text-align: center;
  padding: 1rem 0;
}
.success-panel .check {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  background: var(--success-bg);
  border: 2px solid var(--success);
  display: grid;
  place-items: center;
  font-size: 1.75rem;
}

/* Landing index */
.landing-card {
  text-align: center;
  max-width: 420px;
  padding: 2.5rem;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(20px);
}
.landing-links { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; margin-top: 1.5rem; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .menu-toggle { display: inline-flex; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    height: 100vh;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.visible {
    display: block;
    opacity: 1;
  }
  .user-chip { display: none; }
}

@media (max-width: 480px) {
  .topbar { padding: 0.75rem 1rem; }
  .content { padding: 1rem; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar form { max-width: none; }
  .form-actions .btn { flex: 1; min-width: 120px; }
  th, td { padding: 0.65rem 0.5rem; font-size: 0.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
