/* ==========================================================================
   Vouchly dashboard — dark theme per docs/DESIGN.md
   ========================================================================== */

:root {
  --bg: #0b0d12;
  --surface: #12151d;
  --surface-2: #1a1f2b;
  --border: #252b3b;
  --text: #e8eaf2;
  --muted: #98a0b3;
  --primary: #6d5cff;
  --primary-soft: #8b7dff;
  --accent: #22d3ee;
  --success: #34d399;
  --warning: #f5a623;
  --danger: #f87171;
  --star: #fbbf24;
  --gradient: linear-gradient(135deg, #6d5cff, #22d3ee);
  --radius-card: 14px;
  --radius-ctl: 10px;
  --shadow-cta: 0 10px 40px rgba(109, 92, 255, 0.25);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

/* ---------- base ---------- */

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

html { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

h1, h2, h3 {
  margin: 0;
  letter-spacing: -0.02em;
  font-weight: 800;
  line-height: 1.2;
}
h1 { font-size: 26px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; font-weight: 700; }
p { margin: 0; }

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

.muted { color: var(--muted); }
.small { font-size: 13px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 100;
  padding: 8px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  transition: top 180ms ease-out;
}
.skip-link:focus { top: 12px; }

.noscript-note {
  margin: 48px auto;
  max-width: 480px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  text-align: center;
  color: var(--muted);
}

/* ---------- app shell ---------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  z-index: 30;
  flex: 0 0 228px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  height: 100vh;
  padding: 22px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.wordmark {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  padding: 2px 10px;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  width: max-content;
}
.wordmark:hover { text-decoration: none; }

.side-nav { display: flex; flex-direction: column; gap: 4px; }

.side-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-ctl);
  color: var(--muted);
  font-weight: 600;
  transition: background 180ms ease-out, color 180ms ease-out;
}
.side-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.side-nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.side-nav a[aria-current="page"] .nav-ico { color: var(--primary-soft); }

.nav-ico { width: 16px; height: 16px; fill: currentColor; color: inherit; flex: none; }

.workspace-chip {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  background: var(--surface-2);
  min-width: 0;
}
.ws-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 34px clamp(16px, 4vw, 44px) 72px;
}

body:not(.with-shell) .main { padding: 0; }

.view {
  max-width: 960px;
  margin: 0 auto;
}

@media (prefers-reduced-motion: no-preference) {
  .view {
    animation: view-in 240ms ease-out both;
  }
  @keyframes view-in {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

/* ---------- pills & badges ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  flex: none;
}
.pill-free { background: var(--surface); border: 1px solid var(--border); color: var(--muted); }
.pill-pro { background: var(--gradient); color: #fff; border: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  white-space: nowrap;
}
.badge-success { color: var(--success); background: rgba(52, 211, 153, 0.1); border-color: rgba(52, 211, 153, 0.35); }
.badge-warning { color: var(--warning); background: rgba(245, 166, 35, 0.1); border-color: rgba(245, 166, 35, 0.35); }
.badge-muted { color: var(--muted); background: rgba(152, 160, 179, 0.08); border-color: var(--border); }

/* ---------- buttons ---------- */

button { font: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-ctl);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 180ms ease-out, box-shadow 180ms ease-out,
              background 180ms ease-out, border-color 180ms ease-out, color 180ms ease-out;
}
.btn:hover { transform: translateY(-1px); background: #202636; }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--gradient);
  border: 0;
  color: #fff;
  box-shadow: var(--shadow-cta);
}
.btn-primary:hover { background: var(--gradient); box-shadow: 0 14px 46px rgba(109, 92, 255, 0.38); }

.btn-danger {
  background: transparent;
  border-color: rgba(248, 113, 113, 0.4);
  color: var(--danger);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.12); }

.btn-danger-solid {
  background: var(--danger);
  border-color: var(--danger);
  color: #16090b;
}
.btn-danger-solid:hover { background: #fa8b8b; }

.btn-success {
  background: transparent;
  border-color: rgba(52, 211, 153, 0.4);
  color: var(--success);
}
.btn-success:hover { background: rgba(52, 211, 153, 0.12); }

.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }

.btn.busy { opacity: 0.75; pointer-events: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 180ms ease-out, color 180ms ease-out;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.copy-btn.copied {
  border-color: rgba(52, 211, 153, 0.5);
  color: var(--success);
}

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

.space-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--text);
  cursor: pointer;
  transition: transform 200ms ease-out, box-shadow 200ms ease-out, border-color 200ms ease-out;
}
.space-card:hover {
  transform: translateY(-3px);
  border-color: rgba(109, 92, 255, 0.55);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
  text-decoration: none;
}
.space-card .slug {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.space-dot {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex: none;
  display: inline-block;
}
.space-card-head { display: flex; align-items: center; gap: 9px; min-width: 0; }
.space-card-head h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }

/* ---------- page headers ---------- */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.page-head .sub { margin-top: 5px; color: var(--muted); }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 14px;
}
.back-link:hover { color: var(--text); text-decoration: none; }

.stack { display: flex; flex-direction: column; gap: 18px; }

/* ---------- forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field .hint { font-size: 12.5px; color: var(--muted); }

input[type="text"],
input[type="email"],
input[type="password"],
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-ctl);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  transition: border-color 180ms ease-out, box-shadow 180ms ease-out;
}
input::placeholder, textarea::placeholder { color: #6b7387; }
input[type="text"]:focus-visible,
input[type="email"]:focus-visible,
input[type="password"]:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(109, 92, 255, 0.25);
}
textarea { resize: vertical; min-height: 74px; }

input[type="color"] {
  width: 46px;
  height: 34px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 15px;
}
.field-inline label { font-size: 14px; font-weight: 600; cursor: pointer; }

.form-error {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-ctl);
  border: 1px solid rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.1);
  color: var(--danger);
  font-size: 13.5px;
}

.form-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- auth screens ---------- */

.auth-wrap.view { max-width: none; }

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  background:
    radial-gradient(700px 380px at 70% -10%, rgba(109, 92, 255, 0.16), transparent 65%),
    radial-gradient(560px 320px at 10% 100%, rgba(34, 211, 238, 0.08), transparent 60%),
    var(--bg);
}
.auth-card {
  width: min(408px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 30px 26px;
}
.auth-card .wordmark { display: block; margin: 0 auto 6px; font-size: 28px; padding: 2px 6px; }
.auth-title { text-align: center; font-size: 20px; margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--muted); font-size: 13.5px; margin-bottom: 20px; }
.auth-switch { margin-top: 18px; text-align: center; font-size: 13.5px; color: var(--muted); }
.auth-card .btn { width: 100%; margin-top: 4px; }

/* ---------- share & embed ---------- */

.share-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 11px 0;
}
.share-row + .share-row { border-top: 1px solid var(--border); }
.share-label { flex: 0 0 130px; font-size: 13px; font-weight: 600; color: var(--muted); }
.share-value {
  flex: 1 1 220px;
  min-width: 0;
  font-family: var(--mono);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-value a { color: var(--accent); }

.code-block {
  flex: 1 1 100%;
  margin: 4px 0 0;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  overflow-x: auto;
}
.code-block code {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--accent);
  white-space: pre;
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 13.5px;
  padding: 6px 15px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 180ms ease-out, color 180ms ease-out;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

/* ---------- testimonials ---------- */

.t-list { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }

.t-card { display: flex; flex-direction: column; gap: 9px; }

.t-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.t-who { min-width: 0; }
.t-name { font-weight: 700; }
.t-title { color: var(--muted); font-size: 13px; }
.t-content { color: var(--text); overflow-wrap: anywhere; }

.t-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.t-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.stars { display: inline-flex; gap: 1px; font-size: 15px; line-height: 1; }
.star { color: #2c3347; }
.star.on { color: var(--star); }

/* ---------- empty / loading states ---------- */

.empty-state {
  text-align: center;
  padding: 46px 22px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-card);
  background: rgba(18, 21, 29, 0.5);
}
.empty-state .glyph {
  display: inline-block;
  font-size: 26px;
  margin-bottom: 8px;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.empty-state h3 { margin-bottom: 6px; }
.empty-state p { color: var(--muted); max-width: 420px; margin: 0 auto 16px; }

.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  padding: 26px 4px;
  font-size: 14px;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  flex: none;
}

.skeleton {
  border-radius: 8px;
  background: var(--surface-2);
}
.skeleton-title { height: 18px; width: 55%; margin-bottom: 12px; }
.skeleton-line { height: 12px; width: 90%; margin-bottom: 8px; }
.skeleton-line.short { width: 60%; }

@media (prefers-reduced-motion: no-preference) {
  .spinner { animation: spin 800ms linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }

  .skeleton {
    background: linear-gradient(100deg, var(--surface-2) 40%, #232a3a 50%, var(--surface-2) 60%);
    background-size: 220% 100%;
    animation: shimmer 1.3s ease-in-out infinite;
  }
  @keyframes shimmer { from { background-position: 130% 0; } to { background-position: -30% 0; } }
}

/* ---------- meters (billing) ---------- */

.meter { margin-bottom: 20px; }
.meter:last-child { margin-bottom: 0; }
.meter-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  font-size: 13.5px;
}
.meter-top .meter-label { font-weight: 600; }
.meter-top .meter-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.meter-track {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 240ms ease-out;
}
.meter-fill.maxed { background: linear-gradient(90deg, var(--warning), var(--danger)); }

.feature-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.feature-list li { display: flex; align-items: baseline; gap: 9px; }
.feature-list .tick { color: var(--success); font-weight: 700; flex: none; }

.plan-price { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.plan-price .per { font-size: 14px; font-weight: 600; color: var(--muted); }

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 6, 10, 0.68);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  overflow-y: auto;
}
.modal {
  width: min(500px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 22px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}
@media (prefers-reduced-motion: no-preference) {
  .modal { animation: modal-in 200ms ease-out both; }
  @keyframes modal-in {
    from { opacity: 0; transform: translateY(14px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
  }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}
body.modal-open { overflow: hidden; }

/* ---------- toasts ---------- */

.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-width: min(360px, calc(100vw - 36px));
}
.toast {
  padding: 11px 15px;
  border-radius: var(--radius-ctl);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
  font-size: 13.5px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms ease-out, transform 200ms ease-out;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); color: #fca9a9; }

/* ---------- settings ---------- */

.settings-card h2 { margin-bottom: 4px; }
.settings-card .card-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 16px; }
.danger-zone { border-color: rgba(248, 113, 113, 0.3); }

/* ---------- responsive: sidebar -> top bar ---------- */

@media (max-width: 820px) {
  .app { flex-direction: column; }

  .sidebar {
    flex: none;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .wordmark { font-size: 20px; padding: 2px 4px; }
  .side-nav { flex-direction: row; gap: 2px; margin-left: auto; }
  .side-nav a { padding: 8px 10px; font-size: 13.5px; }
  .side-nav .nav-ico { display: none; }
  .workspace-chip { margin: 0; padding: 0; border: 0; background: transparent; }
  .ws-name { display: none; }

  .main { padding: 22px 16px 56px; }
  h1 { font-size: 22px; }
}

@media (max-width: 480px) {
  .share-label { flex-basis: 100%; padding-bottom: 0; }
  .card { padding: 16px; }
  .page-head .head-actions { width: 100%; }
  .toast-root { right: 12px; bottom: 12px; }

  .sidebar { padding: 10px; gap: 6px; }
  .wordmark { font-size: 18px; }
  .side-nav a { padding: 7px 8px; font-size: 13px; }
}

/* ---------- reduced motion: calm everything ---------- */

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