/* ============================================================
   Valley — Unified Design System
   Apple-inspired. Conservative effects. Smooth motion.
   ============================================================ */

:root {
  --bg: #000000;
  --bg-elevated: #1c1c1e;
  --bg-elevated-2: #2c2c2e;
  --surface: rgba(28, 28, 30, 0.72);
  --surface-solid: #1c1c1e;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f5f5f7;
  --text-secondary: #a1a1a6;
  --text-tertiary: #6e6e73;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --accent-press: #0066cc;
  --green: #30d158;
  --red: #ff453a;
  --orange: #ff9f0a;
  --blue: #0a84ff;
  --purple: #bf5af2;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, monospace;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="light"] {
  --bg: #f5f5f7;
  --bg-elevated: #ffffff;
  --bg-elevated-2: #f2f2f7;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #ffffff;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.15);
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-press: #0058b0;
  --green: #28a745;
  --red: #d70015;
  --orange: #c93400;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.47;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  overflow-x: hidden;
}

h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.02em; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }
p { color: var(--text-secondary); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.tabular { font-variant-numeric: tabular-nums; letter-spacing: 0; }

.wrap { max-width: 980px; margin: 0 auto; padding: 32px 24px 80px; }
.wrap-wide { max-width: 1200px; margin: 0 auto; padding: 32px 24px 80px; }

/* ---------- Header / Nav ---------- */
header.nav {
  position: sticky; top: 0; z-index: 50;
  background: var(--surface);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  display: flex; align-items: center; gap: 16px;
}
header.nav .brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; font-size: 16px; color: var(--text);
  text-decoration: none;
}
header.nav .brand:hover { text-decoration: none; }
header.nav .brand .mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
}
header.nav .nav-links { display: flex; gap: 4px; margin-left: 8px; }
header.nav .nav-links a {
  color: var(--text-secondary); font-size: 13.5px; padding: 6px 12px;
  border-radius: 8px; transition: color 0.15s, background 0.15s;
}
header.nav .nav-links a:hover { color: var(--text); background: rgba(255,255,255,0.06); text-decoration: none; }
[data-theme="light"] header.nav .nav-links a:hover { background: rgba(0,0,0,0.05); }
header.nav .spacer { flex: 1; }

.user-menu { position: relative; }
.avatar-btn {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; cursor: pointer; padding: 4px 8px 4px 4px;
  border-radius: 20px; transition: background 0.15s; color: var(--text);
  font-family: var(--font); font-size: 13.5px;
}
.avatar-btn:hover { background: rgba(255,255,255,0.06); }
[data-theme="light"] .avatar-btn:hover { background: rgba(0,0,0,0.05); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: #fff;
  background: var(--accent); flex-shrink: 0;
}
.dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  min-width: 200px; padding: 6px; z-index: 100;
  opacity: 0; transform: translateY(-6px) scale(0.97);
  pointer-events: none; transition: opacity 0.18s var(--ease), transform 0.18s var(--ease);
}
.dropdown.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.dropdown a, .dropdown button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 12px; border-radius: 8px;
  background: none; border: none; cursor: pointer;
  color: var(--text); font-size: 14px; font-family: var(--font);
  text-align: left; text-decoration: none;
}
.dropdown a:hover, .dropdown button:hover { background: rgba(255,255,255,0.06); text-decoration: none; }
[data-theme="light"] .dropdown a:hover, [data-theme="light"] .dropdown button:hover { background: rgba(0,0,0,0.05); }
.dropdown .divider { height: 1px; background: var(--border); margin: 5px 8px; }
.dropdown .user-info { padding: 10px 12px 8px; }
.dropdown .user-info .name { font-weight: 600; font-size: 14px; }
.dropdown .user-info .sub { font-size: 12px; color: var(--text-tertiary); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 980px;
  padding: 10px 20px; font-size: 14.5px; font-weight: 500;
  font-family: var(--font); cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn:active { transform: scale(0.97); background: var(--accent-press); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.secondary { background: var(--bg-elevated-2); color: var(--text); }
.btn.secondary:hover { background: var(--border-strong); }
.btn.ghost { background: transparent; color: var(--accent); padding: 10px 14px; }
.btn.ghost:hover { background: rgba(10, 132, 255, 0.1); text-decoration: none; }
.btn.danger { background: #d70015; }
.btn.danger:hover { background: #ff1a23; }
.btn.small { padding: 7px 14px; font-size: 13px; }
.btn.large { padding: 14px 28px; font-size: 16px; }
.btn.block { width: 100%; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  transition: border-color 0.2s;
}
.card:hover { border-color: var(--border-strong); }
.card h2 { margin-bottom: 6px; font-size: 17px; }
.card .subtitle { color: var(--text-secondary); font-size: 13.5px; margin-bottom: 16px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; color: var(--text-secondary); margin: 14px 0 6px; font-weight: 500; }
input, select, textarea {
  width: 100%; background: var(--bg-elevated-2);
  border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 11px 14px;
  font-size: 15px; font-family: var(--font); outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
::placeholder { color: var(--text-tertiary); }

/* ---------- Pills / Badges ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 500; padding: 3px 10px;
  border-radius: 980px; background: var(--bg-elevated-2);
  color: var(--text-secondary); border: 1px solid var(--border);
}
.pill.online { color: var(--green); background: rgba(48, 209, 88, 0.12); border-color: rgba(48, 209, 88, 0.2); }
.pill.offline { color: var(--text-tertiary); }
.pill.paused { color: var(--orange); background: rgba(255, 159, 10, 0.12); border-color: rgba(255, 159, 10, 0.2); }
.pill.admin { color: var(--accent); background: rgba(10, 132, 255, 0.12); border-color: rgba(10, 132, 255, 0.2); }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-tertiary); display: inline-block;
}
.status-dot.online { background: var(--green); }
.status-dot.paused { background: var(--orange); }
@keyframes pulse-soft { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* ---------- Progress ---------- */
.progress { height: 6px; background: var(--bg-elevated-2); border-radius: 980px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 980px; width: 0; transition: width 0.5s var(--ease-out); }
.progress.green > div { background: var(--green); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-solid); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 980px;
  padding: 11px 22px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow); z-index: 1000;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease-out);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
  padding: 24px;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px;
  max-width: 440px; width: 100%; position: relative;
  transform: scale(0.95) translateY(10px);
  transition: transform 0.25s var(--ease-out);
  max-height: 85vh; overflow-y: auto;
}
.modal-backdrop.open .modal { transform: scale(1) translateY(0); }
.modal .close {
  position: absolute; top: 14px; right: 16px;
  background: none; border: none; color: var(--text-tertiary);
  font-size: 22px; cursor: pointer; line-height: 1; padding: 4px;
}
.modal .close:hover { color: var(--text); }

/* ---------- Animations ---------- */
.fade-in { animation: fadeIn 0.5s var(--ease-out) both; }
.fade-up { animation: fadeUp 0.5s var(--ease-out) both; }
.stagger > * { opacity: 0; animation: fadeUp 0.5s var(--ease-out) forwards; }
.stagger > *:nth-child(1) { animation-delay: 0.05s; }
.stagger > *:nth-child(2) { animation-delay: 0.1s; }
.stagger > *:nth-child(3) { animation-delay: 0.15s; }
.stagger > *:nth-child(4) { animation-delay: 0.2s; }
.stagger > *:nth-child(5) { animation-delay: 0.25s; }
.stagger > *:nth-child(6) { animation-delay: 0.3s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

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

/* ---------- Landing page ---------- */
.hero { text-align: center; padding: 80px 24px 60px; max-width: 760px; margin: 0 auto; }
.hero h1 {
  font-size: clamp(36px, 6vw, 56px); font-weight: 700;
  letter-spacing: -0.03em; line-height: 1.15; margin-bottom: 18px;
  padding-bottom: 4px;
  background: linear-gradient(180deg, var(--text) 30%, var(--text-secondary) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.hero p { font-size: 19px; color: var(--text-secondary); margin-bottom: 32px; line-height: 1.5; }
.hero .cta-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.stats-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1px; background: var(--border);
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border); margin: 40px 0;
}
.stats-strip .stat { background: var(--surface-solid); padding: 24px 20px; text-align: center; }
.stats-strip .stat .val { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.stats-strip .stat .lbl { font-size: 12.5px; color: var(--text-tertiary); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.05em; }

.feature-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px; margin: 40px 0;
}
.feature {
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 26px;
  transition: border-color 0.2s, transform 0.2s var(--ease);
}
.feature:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.feature .ico { font-size: 28px; margin-bottom: 14px; }
.feature h3 { margin-bottom: 6px; font-size: 16px; }
.feature p { font-size: 14px; }

/* ---------- Onboarding wizard ---------- */
.wizard { max-width: 560px; margin: 0 auto; padding: 48px 24px 80px; }
.wizard .steps { display: flex; gap: 6px; margin-bottom: 36px; }
.wizard .steps .seg {
  flex: 1; height: 3px; border-radius: 980px;
  background: var(--bg-elevated-2); transition: background 0.4s var(--ease);
}
.wizard .steps .seg.done { background: var(--accent); }
.wizard .step { display: none; animation: fadeUp 0.4s var(--ease-out); }
.wizard .step.active { display: block; }
.wizard h2 { font-size: 26px; margin-bottom: 10px; letter-spacing: -0.02em; }
.wizard .step-desc { color: var(--text-secondary); font-size: 15px; margin-bottom: 28px; }
.wizard .big-copy {
  width: 100%; padding: 18px; font-size: 16px; font-weight: 600;
  border-radius: var(--radius); margin-top: 8px;
}
.wizard .system-card {
  background: var(--bg-elevated-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 20px;
  display: flex; align-items: center; gap: 16px;
}
.wizard .system-card .os-ico { font-size: 32px; }
.wizard .system-card .os-name { font-weight: 600; font-size: 16px; }
.wizard .system-card .os-sub { font-size: 13px; color: var(--text-secondary); }
.wizard .system-card select { margin-left: auto; width: auto; padding: 7px 12px; font-size: 13px; }
.wizard .nav-row { display: flex; gap: 10px; margin-top: 28px; align-items: center; }
.wizard .nav-row .spacer { flex: 1; }

.connecting-indicator { display: flex; flex-direction: column; align-items: center; padding: 40px 0; gap: 20px; }
.connecting-ring {
  width: 64px; height: 64px; border-radius: 50%;
  border: 3px solid var(--bg-elevated-2); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.connecting-ring.connected {
  border: none; background: var(--green);
  animation: pop 0.5s var(--ease-out);
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; color: #fff;
}
@keyframes pop { 0% { transform: scale(0.5); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }

/* ---------- Account page ---------- */
.account-grid { display: grid; grid-template-columns: 220px 1fr; gap: 32px; margin-top: 24px; }
.account-tabs { display: flex; flex-direction: column; gap: 2px; }
.account-tabs button {
  text-align: left; padding: 10px 14px; border-radius: 10px;
  background: none; border: none; color: var(--text-secondary);
  font-size: 14px; font-family: var(--font); cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.account-tabs button:hover { background: rgba(255,255,255,0.05); color: var(--text); }
[data-theme="light"] .account-tabs button:hover { background: rgba(0,0,0,0.04); }
.account-tabs button.active { background: var(--bg-elevated-2); color: var(--text); font-weight: 500; }
.account-panel { display: none; }
.account-panel.active { display: block; animation: fadeUp 0.3s var(--ease-out); }

.accent-swatches { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.accent-swatch {
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  border: 3px solid transparent; transition: transform 0.15s, border-color 0.15s;
}
.accent-swatch:hover { transform: scale(1.1); }
.accent-swatch.selected { border-color: var(--text); }

/* ---------- Dashboard ---------- */
.dash-hud {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.dash-hud .hud-card {
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
}
.dash-hud .hud-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-tertiary); font-weight: 600; margin-bottom: 4px;
}
.dash-hud .hud-val { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.dash-hud .hud-sub { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }

.client-card {
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 12px;
  transition: border-color 0.2s;
}
.client-card:hover { border-color: var(--border-strong); }
.client-card .client-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.client-card .client-head .name { font-weight: 600; font-size: 15px; }
.client-card .client-head .spacer { flex: 1; }
.client-card .client-stats {
  display: flex; gap: 18px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--text-secondary); margin-top: 8px;
}
.client-card .client-stats span { display: flex; align-items: center; gap: 5px; }
.client-card .controls { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }

.two-col { display: grid; grid-template-columns: 1fr 1.1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 36px; width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
}
.auth-card .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.auth-card .brand .mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
}
.auth-card .brand h1 { font-size: 20px; }
.auth-card .brand .sub { font-size: 13px; color: var(--text-secondary); }
.auth-tabs {
  display: flex; gap: 6px; margin-bottom: 22px;
  background: var(--bg-elevated-2); padding: 4px; border-radius: 10px;
}
.auth-tabs button {
  flex: 1; padding: 8px; border-radius: 7px; background: none;
  border: none; color: var(--text-secondary); font-size: 14px;
  font-family: var(--font); cursor: pointer; font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.auth-tabs button.active { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- 404 ---------- */
.error-page {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 24px;
}
.error-page .code {
  font-size: clamp(80px, 16vw, 140px); font-weight: 800;
  letter-spacing: -0.04em; line-height: 1;
  background: linear-gradient(180deg, var(--text) 20%, var(--text-tertiary) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.error-page h2 { font-size: 22px; margin: 12px 0 8px; }
.error-page p { color: var(--text-secondary); margin-bottom: 28px; max-width: 360px; }

/* ---------- Home / app launcher ---------- */
.app-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px; margin-top: 20px;
}
.app-tile {
  display: block; background: var(--surface-solid);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; color: var(--text); text-decoration: none;
  transition: border-color 0.2s, transform 0.2s var(--ease);
}
.app-tile:hover { border-color: var(--border-strong); transform: translateY(-2px); text-decoration: none; }
.app-tile .ico { font-size: 26px; margin-bottom: 10px; }
.app-tile h3 { font-size: 15px; margin-bottom: 4px; }
.app-tile p { font-size: 13px; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .wrap, .wrap-wide { padding: 20px 16px 60px; }
  header.nav { padding: 0 16px; }
  header.nav .nav-links { display: none; }
  .hero { padding: 48px 16px 40px; }
  .account-grid { grid-template-columns: 1fr; }
  .account-tabs { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .account-tabs button { white-space: nowrap; }
  .auth-card { padding: 24px; }
  .card { padding: 18px; }
}

/* ---------- Animations toggle ---------- */
html[data-animations="false"] *,
html[data-animations="false"] *::before,
html[data-animations="false"] *::after {
  animation: none !important;
  transition: none !important;
}
