/* Winsward Tech — Premium SaaS design system (mobile-first) */

:root {
  /* Primitives */
  --green-50: #F0FDF4;
  --green-100: #DCFCE7;
  --green-200: #BBF7D0;
  --green-500: #22C55E;
  --green-600: #16A34A;
  --green-700: #15803D;
  --green-800: #166534;
  --white: #FFFFFF;
  --slate-50: #F8FAFC;
  --slate-100: #F1F5F9;
  --slate-200: #E2E8F0;
  --slate-300: #CBD5E1;
  --slate-400: #94A3B8;
  --slate-500: #64748B;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1E293B;
  --slate-900: #0F172A;
  --red-50: #FEF2F2;
  --red-600: #DC2626;
  --amber-50: #FFFBEB;
  --amber-700: #B45309;

  /* Semantic — content first; green is accent (~5%) */
  --color-bg: #F8FAFC;
  --color-surface: #FFFFFF;
  --color-surface-2: var(--slate-100);
  --color-text: #111827;
  --color-text-secondary: var(--slate-600);
  --color-text-muted: #64748B;
  --color-border: #E2E8F0;
  --color-border-strong: var(--slate-300);
  --color-brand: #16A34A;
  --color-brand-dark: #15803D;
  --color-brand-soft: #DCFCE7;
  --color-primary: var(--color-brand);
  --color-primary-hover: var(--color-brand-dark);
  --color-primary-ink: #166534;
  --color-primary-soft: #F0FDF4;
  --color-primary-tint: var(--color-brand-soft);
  --color-danger: var(--red-600);
  --color-warning: var(--amber-700);
  --color-overlay: rgba(15, 23, 42, 0.4);

  /* Type */
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --text-xs: 0.75rem;      /* 12px */
  --text-sm: 0.875rem;     /* 14px */
  --text-base: 0.9375rem;  /* 15px */
  --text-lg: 1.125rem;     /* 18px */
  --text-xl: 1.5rem;       /* 24px */
  --text-2xl: 1.75rem;
  --text-3xl: 2rem;
  --leading-tight: 1.25;
  --leading-normal: 1.55;

  /* Space (4px rhythm) */
  --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;

  /* Icons — never decorative blow-ups for UI chrome */
  --icon-sm: 16px;
  --icon-md: 18px;
  --icon-lg: 20px;
  --icon-box: 32px;
  --icon-box-lg: 36px;

  /* Shape */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 999px;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 2px 8px -4px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px -6px rgba(15, 23, 42, 0.12);
  --shadow-lg: 0 12px 28px -12px rgba(15, 23, 42, 0.16);

  --sidebar-w: 232px;
  --sidebar-w-collapsed: 68px;
  --header-h: 64px;
  --touch: 44px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --duration: 180ms;

  --btn-primary-bg: var(--color-primary);
  --btn-primary-fg: var(--white);
  --card-radius: var(--radius-md);
  --card-shadow: var(--shadow-sm);
}

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

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

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img { display: block; max-width: 100%; height: auto; }
/* UI icons stay fixed; charts keep responsive width */
.ui-icon,
svg.ui-icon {
  display: block;
  width: var(--icon-md);
  height: var(--icon-md);
  max-width: none;
  flex-shrink: 0;
}
.chart-svg { display: block; width: 100%; height: auto; max-width: 100%; }
button, input, select, textarea { font: inherit; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-hover); }

.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;
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ---------- Typography ---------- */
.eyebrow {
  margin: 0 0 var(--space-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-primary);
}

h1, .page-title {
  margin: 0;
  font-size: clamp(1.35rem, 2.5vw, var(--text-2xl));
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: var(--leading-tight);
  color: var(--color-text);
}

h2, .section-title {
  margin: 0 0 var(--space-3);
  font-size: var(--text-lg);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0 0 var(--space-6);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.6;
}
.lede.tight { margin-bottom: var(--space-4); }

.greeting {
  margin: 0 0 var(--space-1);
  font-size: clamp(1.25rem, 3vw, 1.65rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}
.greeting-sub {
  margin: 0 0 var(--space-6);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* ---------- Buttons ---------- */
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-ghost,
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--touch);
  padding: 0.65rem 1.05rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--duration) var(--ease), border-color var(--duration) var(--ease), transform var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.btn-primary {
  color: var(--btn-primary-fg);
  background: var(--btn-primary-bg);
  box-shadow: 0 1px 0 rgba(255,255,255,0.12) inset;
}
.btn-primary:hover { background: var(--color-primary-hover); color: var(--white); }
.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
  color: var(--color-text);
  background: var(--color-surface);
  border-color: var(--color-border);
}
.btn-secondary:hover { border-color: var(--color-border-strong); background: var(--slate-50); color: var(--color-text); }

.btn-danger {
  color: var(--color-danger);
  background: var(--red-50);
  border-color: transparent;
  min-height: 36px;
  padding: 0.4rem 0.75rem;
  font-size: var(--text-xs);
}
.btn-danger:hover { background: #FEE2E2; }

.btn-ghost {
  color: var(--color-text-secondary);
  background: transparent;
  min-height: 40px;
}
.btn-ghost:hover { background: var(--slate-100); color: var(--color-text); }

.btn-icon {
  width: var(--touch);
  height: var(--touch);
  padding: 0;
  background: transparent;
  color: var(--slate-600);
}
.btn-icon:hover { background: var(--slate-100); color: var(--color-text); }
.btn-icon .ui-icon,
.btn-icon svg {
  width: var(--icon-lg);
  height: var(--icon-lg);
}

.btn-block { width: 100%; }

button:disabled, .btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* ---------- Forms ---------- */
.stack-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.stack-form label,
.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--slate-700);
}

.field-hint {
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--color-text-muted);
}

.stack-form input[type="text"],
.stack-form input[type="email"],
.stack-form input[type="password"],
.stack-form input[type="url"],
.stack-form input[type="tel"],
.stack-form input[type="search"],
.stack-form input[type="date"],
.stack-form select,
.stack-form textarea,
.filters input,
.filters select,
.search-input,
.auth-input {
  width: 100%;
  min-height: var(--touch);
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--color-text);
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.stack-form textarea { min-height: 120px; resize: vertical; }

.stack-form input:focus,
.stack-form select:focus,
.stack-form textarea:focus,
.filters input:focus,
.filters select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15);
  outline: none;
}

.stack-form input[type="color"] {
  width: 100%;
  height: 44px;
  padding: 4px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--white);
  cursor: pointer;
}

.color-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: var(--text-sm);
  font-weight: 500;
  min-height: 40px;
}
.check-row input { width: 18px; height: 18px; accent-color: var(--color-primary); }

.error-msg { color: var(--color-danger); font-size: var(--text-sm); margin: 0; }
.ok-msg { color: var(--color-primary-ink); font-size: var(--text-sm); margin: 0; }
.form-footer { margin: var(--space-5) 0 0; font-size: var(--text-sm); color: var(--color-text-muted); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border-radius: var(--radius-full);
  padding: 0.2rem 0.6rem;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.01em;
  text-transform: capitalize;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}
.badge-active, .badge-sent, .badge-Admin { background: var(--green-100); color: var(--green-800); }
.badge-pending, .badge-Reader { background: var(--amber-50); color: var(--amber-700); }
.badge-suspended { background: #FFEDD5; color: #9A3412; }
.badge-disabled, .badge-failed { background: var(--slate-100); color: var(--slate-700); }
.badge-new { background: #DBEAFE; color: #1D4ED8; }
.badge-Platform\ Admin { background: var(--slate-100); color: var(--slate-800); }
.role-badge {
  background: var(--green-100);
  color: var(--green-800);
}
.role-badge.reader { background: var(--slate-100); color: var(--slate-700); }
.role-badge.platform { background: var(--slate-800); color: var(--white); }

/* ---------- Cards / KPI ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--card-radius);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  box-shadow: var(--card-shadow);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.card-head h2 { margin: 0; }

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.kpi {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--card-radius);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--card-shadow);
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--duration) var(--ease), transform var(--duration) var(--ease);
}
.kpi:hover { box-shadow: var(--shadow-sm); border-color: var(--color-border-strong); }
.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.kpi .label {
  margin: 0;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.kpi .value {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--color-text);
}
.kpi .trend {
  margin: var(--space-2) 0 0;
  font-size: var(--text-xs);
  font-weight: 550;
  color: var(--color-primary-ink);
}
.kpi .trend.flat { color: var(--color-text-muted); }
.kpi-icon {
  width: var(--icon-box);
  height: var(--icon-box);
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--color-primary-soft);
  color: var(--color-primary-ink);
  flex-shrink: 0;
}
.kpi-icon .ui-icon,
.kpi-icon svg {
  width: var(--icon-md);
  height: var(--icon-md);
}

.dash-grid {
  display: grid;
  gap: var(--space-4);
}

/* ---------- Auth / marketing ---------- */
.wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(var(--space-6), env(safe-area-inset-top)) var(--space-4) max(var(--space-6), env(safe-area-inset-bottom));
  gap: var(--space-4);
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(22, 163, 74, 0.12), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(22, 101, 52, 0.06), transparent 50%),
    var(--color-bg);
}

.box-card {
  width: 100%;
  max-width: 440px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  padding: var(--space-8) var(--space-6) var(--space-6);
}
.panel-card { max-width: 520px; }

.home-hero { max-width: 560px; }
.home-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.footnote {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.tenant-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  margin-bottom: var(--space-4);
  background: var(--color-primary-soft);
}

.char-count { font-size: var(--text-xs); color: var(--color-text-muted); }

.logo-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.logo-field-label {
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--color-text);
}
.logo-upload {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.logo-preview-wrap {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
}
.logo-preview,
.logo-preview-fallback {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  border: 1px solid var(--color-border);
  object-fit: contain;
  background: #fff;
}
.logo-preview-fallback {
  display: grid;
  place-items: center;
  background: var(--color-brand-soft);
  color: var(--color-primary-ink);
  font-weight: 700;
  font-size: 14px;
}
.logo-upload-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  flex: 1;
}
.logo-file-btn { cursor: pointer; margin: 0; }
.help-text {
  width: 100%;
  margin: 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.logo-url-label { margin-top: var(--space-1); }

.privacy-note {
  margin: var(--space-3) 0 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: center;
}
.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-3);
  gap: var(--space-3);
  flex-wrap: wrap;
}

button#submit-btn {
  min-height: var(--touch);
  padding: 0.7rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--brand-primary, var(--color-primary));
  color: #fff;
  font-weight: 650;
  cursor: pointer;
}
button#submit-btn:hover { filter: brightness(0.96); }
button#submit-btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- Public question box (tenant-facing) ---------- */
.qbox-page {
  background: var(--color-bg);
}

.qbox-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  gap: var(--space-4);
  background:
    radial-gradient(ellipse 70% 45% at 0% 0%, rgba(22, 163, 74, 0.07), transparent 55%),
    radial-gradient(ellipse 50% 35% at 100% 100%, rgba(22, 101, 52, 0.04), transparent 50%),
    var(--color-bg);
}

.qbox-card {
  width: 100%;
  max-width: 640px;
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.qbox-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: var(--space-5);
}

.qbox-header-text {
  min-width: 0;
  flex: 1;
}

.qbox-tenant {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  line-height: 1.3;
}

.qbox-title {
  margin: 0 0 8px;
  font-size: clamp(1.75rem, 5vw, 2.15rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.15;
  color: var(--color-text);
}

.qbox-lede {
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text-muted);
}

.qbox-logo-slot {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
}

.qbox-logo,
.qbox-logo-fallback {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  border: 1px solid var(--color-border);
  background: #fff;
  object-fit: contain;
  display: block;
}

.qbox-logo-fallback {
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: clip;
  white-space: nowrap;
  line-height: 1;
}

.qbox-form { margin: 0; }

.qbox-composer {
  display: block;
  width: 100%;
  min-height: 180px;
  margin: 0;
  padding: 16px 18px;
  border: 1px solid #E2E8F0;
  border-radius: 14px;
  background: #fff;
  color: var(--color-text);
  font-size: 15.5px;
  line-height: 1.55;
  resize: vertical;
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
.qbox-composer::placeholder {
  color: #94A3B8;
}
.qbox-composer:focus {
  outline: none;
}

.qbox-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  margin-top: 14px;
}

.qbox-count {
  font-size: 12.5px;
  color: var(--color-text-muted);
  font-weight: 500;
}
.qbox-count.is-warn { color: var(--amber-700); font-weight: 600; }
.qbox-count.is-limit { color: var(--color-danger); font-weight: 600; }

.qbox-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 50px;
  padding: 0 1.25rem;
  border: none;
  border-radius: 11px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: filter var(--duration) var(--ease), transform var(--duration) var(--ease), opacity var(--duration) var(--ease);
}
.qbox-submit:active { transform: translateY(1px); }
.qbox-submit:disabled { opacity: 0.55; cursor: default; transform: none; }

.qbox-privacy {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 18px 0 0;
  font-size: 13.5px;
  color: var(--color-text-muted);
  text-align: center;
}
.qbox-privacy .ui-icon {
  width: 16px;
  height: 16px;
  color: var(--slate-400);
  flex-shrink: 0;
}

.qbox-footnote {
  margin: 0;
  font-size: 12px;
  color: var(--slate-400);
  text-align: center;
}

.qbox-confirmation {
  text-align: center;
  padding: var(--space-6) 0 var(--space-2);
}
.qbox-confirm-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: var(--color-brand-soft);
  color: var(--color-primary-ink);
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  font-weight: 700;
}
.qbox-again {
  min-height: 48px;
  padding: 0 1.2rem;
  border: 1px solid var(--color-border);
  border-radius: 11px;
  background: #fff;
  color: var(--color-text);
  font-weight: 600;
  cursor: pointer;
}
.qbox-again:hover { background: var(--slate-50); }

@media (min-width: 480px) {
  .qbox-card { padding: 28px 32px 32px; }
  .qbox-logo-slot,
  .qbox-logo,
  .qbox-logo-fallback {
    width: 64px;
    height: 64px;
  }
  .qbox-composer { min-height: 200px; }
  .qbox-actions {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  .qbox-submit {
    width: auto;
    min-width: 160px;
    min-height: 48px;
  }
}

@media (min-width: 768px) {
  .qbox-wrap { padding: 40px 24px; }
  .qbox-card {
    max-width: 660px;
    padding: 36px 40px 40px;
    border-radius: 20px;
  }
  .qbox-header { gap: 24px; margin-bottom: 28px; }
  .qbox-composer {
    min-height: 230px;
    font-size: 16px;
    padding: 18px 20px;
  }
}

.confirmation { text-align: center; padding: var(--space-4) 0; }
.confirmation h2 { margin: 0 0 var(--space-2); font-size: var(--text-xl); }
.confirmation p { margin: 0 0 var(--space-5); color: var(--color-text-muted); font-size: var(--text-sm); }

#ask-another {
  min-height: var(--touch);
  padding: 0.65rem 1.1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  font-weight: 550;
}

/* ---------- App shell ---------- */
.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  background: var(--color-bg);
}

.app-shell.is-collapsed {
  --sidebar-w: var(--sidebar-w-collapsed);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: 40;
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}
.sidebar-backdrop.is-open {
  display: block;
  opacity: 1;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(86vw, 240px);
  max-width: 240px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-3);
  padding-top: max(var(--space-4), env(safe-area-inset-top));
  padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  transform: translateX(-105%);
  transition: transform var(--duration) var(--ease);
}
.sidebar.is-open { transform: none; }

.brand-mark {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.25rem 0.5rem;
  text-decoration: none;
  color: var(--color-text);
  min-height: 44px;
}
.brand-mark strong {
  display: block;
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand-mark span {
  display: block;
  font-size: 11px;
  color: var(--color-text-muted);
  font-weight: 500;
  margin-top: 1px;
}
.brand-badge {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--color-brand);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: var(--space-3);
}
.nav-group:first-child { margin-top: 0; }
.nav-group-label {
  margin: 0 0 4px;
  padding: 0 0.7rem;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--slate-400);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  min-height: 40px;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--slate-600);
  font-size: 13.5px;
  font-weight: 500;
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
}
.nav-item .ui-icon,
.nav-item svg {
  width: var(--icon-sm);
  height: var(--icon-sm);
  flex-shrink: 0;
  opacity: 0.9;
}
.nav-item:hover {
  background: var(--slate-100);
  color: var(--color-text);
}
.nav-item.is-active {
  background: var(--color-brand-soft);
  color: var(--color-primary-ink);
  font-weight: 600;
}

.sidebar-foot { margin-top: auto; padding-top: var(--space-3); }

.sidebar-collapse {
  display: none;
  width: 100%;
}

.app-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--header-h);
  padding: 0 var(--space-4);
  padding-left: max(var(--space-4), env(safe-area-inset-left));
  padding-right: max(var(--space-4), env(safe-area-inset-right));
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.header-titles { min-width: 0; }
.header-titles .eyebrow { margin: 0; }
.header-titles h1 {
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

.account-wrap { position: relative; }

.account-trigger {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: var(--touch);
  padding: 0.25rem 0.4rem 0.25rem 0.25rem;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  background: transparent;
  cursor: pointer;
  color: var(--color-text);
}
.account-trigger:hover {
  background: var(--slate-100);
  border-color: var(--color-border);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: 10px;
}
.avatar-lg {
  width: 64px;
  height: 64px;
  font-size: 1.25rem;
}

.account-meta { display: none; text-align: left; }
.account-meta strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
}
.account-meta span {
  display: block;
  font-size: 11px;
  color: var(--color-text-muted);
}

.account-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: min(300px, calc(100vw - 24px));
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 60;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease), visibility var(--duration);
}
.account-menu.is-open {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.account-menu-head {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  padding: 2px 2px var(--space-3);
}
.account-menu-head strong {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
}
.account-menu-head span {
  display: block;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 1px;
}

.account-menu-meta {
  margin: 0;
  padding: var(--space-3) 2px;
  border-top: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.account-menu-meta dt {
  margin: 0;
  font-size: 10px;
  font-weight: 650;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.account-menu-meta dd {
  margin: 2px 0 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  word-break: break-word;
}

.account-menu-actions {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-top: var(--space-2);
}
.account-menu-actions button {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 44px;
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}
.account-menu-actions .menu-ico {
  display: grid;
  place-items: center;
  width: var(--icon-lg);
  height: var(--icon-lg);
  flex-shrink: 0;
  color: var(--slate-500);
}
.account-menu-actions .menu-ico .ui-icon,
.account-menu-actions .menu-ico svg {
  width: var(--icon-md);
  height: var(--icon-md);
}
.account-menu-actions button:hover { background: var(--slate-100); }
.account-menu-actions button:hover .menu-ico { color: var(--color-text); }
.account-menu-actions button.is-danger { color: var(--color-danger); }
.account-menu-actions button.is-danger .menu-ico { color: var(--color-danger); }

.app-main {
  padding: var(--space-4);
  padding-bottom: max(var(--space-10), env(safe-area-inset-bottom));
  flex: 1;
  min-width: 0;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}

.hidden { display: none !important; }

/* ---------- Tables → cards ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.filters input, .filters select {
  flex: 1 1 140px;
  min-width: 0;
}

.table-wrap { overflow: visible; }

table.data { display: none; }

.mobile-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.entity-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-xs);
}
.entity-card h3 {
  margin: 0 0 var(--space-1);
  font-size: var(--text-base);
  font-weight: 650;
}
.entity-card .meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-3);
}
.entity-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin: var(--space-3) 0;
  font-size: var(--text-sm);
}
.entity-stats span { color: var(--color-text-muted); display: block; font-size: 11px; }
.entity-stats strong { font-weight: 650; }
.entity-card .actions { margin-top: var(--space-3); }

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ---------- Questions ---------- */
.q-list { display: flex; flex-direction: column; gap: var(--space-3); }

.q-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--duration) var(--ease);
}
.q-card:hover { box-shadow: var(--shadow-sm); }
.q-card.is-read { opacity: 0.72; }
.q-body { min-width: 0; }
.q-text {
  margin: 0 0 var(--space-2);
  font-size: var(--text-base);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.q-time { margin: 0; font-size: var(--text-xs); color: var(--color-text-muted); }
.q-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.q-actions button {
  min-height: 36px;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--white);
  font-size: var(--text-xs);
  font-weight: 550;
  cursor: pointer;
}
.q-actions button:hover { border-color: var(--color-primary); color: var(--color-primary-ink); }
.q-actions button.delete:hover { border-color: var(--color-danger); color: var(--color-danger); }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.chip {
  min-height: 36px;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--white);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  color: var(--color-text-secondary);
}
.chip.is-active {
  background: var(--color-primary-soft);
  border-color: var(--green-200);
  color: var(--color-primary-ink);
}

/* ---------- Charts ---------- */
.chart-wrap {
  width: 100%;
  overflow: hidden;
  padding: var(--space-2) 0 var(--space-1);
}
.chart-svg {
  width: 100%;
  height: auto;
  max-height: 220px;
  display: block;
}
.chart-empty {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  padding: var(--space-8) var(--space-4);
  text-align: center;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.chart-legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 4px;
  background: var(--color-primary);
}

/* ---------- Empty / skeleton / error ---------- */
.empty-state {
  text-align: center;
  padding: var(--space-10) var(--space-5);
  color: var(--color-text-muted);
}
.empty-state .empty-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-4);
  border-radius: 14px;
  background: var(--color-primary-soft);
  color: var(--color-primary-ink);
  display: grid;
  place-items: center;
}
.empty-state .empty-icon .ui-icon,
.empty-state .empty-icon svg {
  width: 28px;
  height: 28px;
}
.empty-state h2 {
  color: var(--color-text);
  font-size: var(--text-lg);
  margin: 0 0 var(--space-2);
}
.empty-state p { margin: 0 0 var(--space-5); font-size: var(--text-sm); }

.skeleton {
  background: linear-gradient(90deg, var(--slate-100) 25%, var(--slate-50) 50%, var(--slate-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
  border-radius: 8px;
}
.skeleton-line { height: 12px; margin-bottom: 10px; }
.skeleton-line.lg { height: 28px; width: 40%; }
.skeleton-card { height: 96px; border-radius: var(--radius-md); }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.error-panel {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}
.error-panel h2 { margin: 0 0 var(--space-2); }
.error-panel p { margin: 0 0 var(--space-4); color: var(--color-text-muted); font-size: var(--text-sm); }

/* ---------- Detail / activity / team ---------- */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  font-size: var(--text-sm);
}
.detail-grid dt {
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}
.detail-grid dd { margin: 0.2rem 0 0; font-weight: 550; }

.tenant-id-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-weight: 500;
}
.tenant-id-row code {
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
  background: var(--color-primary-soft);
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
}
.tenant-id-row .btn-secondary {
  min-height: 36px;
  padding: 0.4rem 0.75rem;
  font-size: var(--text-xs);
}

.activity-item {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-sm);
}
.activity-item:last-child { border-bottom: 0; }
.activity-item time { color: var(--color-text-muted); font-size: var(--text-xs); }

.reader-list {
  list-style: none;
  margin: var(--space-5) 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.reader-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--slate-50);
}
.reader-list li strong { display: block; font-size: var(--text-sm); }
.reader-list li span { font-size: var(--text-xs); color: var(--color-text-muted); }
.empty-readers {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  border: none !important;
  background: transparent !important;
  padding-left: 0 !important;
}

.link-box {
  font-size: var(--text-sm);
  word-break: break-all;
  margin: 0 0 var(--space-3);
}
.link-box a { font-weight: 550; }

.profile-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  align-items: flex-start;
}
.profile-hero {
  display: flex;
  gap: var(--space-4);
  align-items: center;
}

/* Reader standalone */
.reader-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-4);
  padding-bottom: max(var(--space-10), env(safe-area-inset-bottom));
}
.reader-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
  gap: var(--space-3);
}
.reader-header h1 { font-size: var(--text-xl); margin: 0; }
.reader-count { font-size: var(--text-sm); color: var(--color-text-muted); }
.reader-meta { margin: 0.25rem 0 0; font-size: var(--text-sm); color: var(--color-text-muted); }
.reader-header-actions { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }

/* ---------- Toast ---------- */
.toast-host {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: max(var(--space-4), env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(420px, calc(100% - 24px));
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  background: var(--slate-900);
  color: #fff;
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  font-weight: 550;
  animation: toast-in 220ms var(--ease);
}
.toast.is-success { background: var(--green-800); }
.toast.is-error { background: #991B1B; }
.toast button {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--color-overlay);
  display: grid;
  place-items: end center;
  padding: var(--space-4);
  padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
}
.modal {
  width: min(440px, 100%);
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-md) var(--radius-md);
  padding: var(--space-6);
  box-shadow: var(--shadow-lg);
  animation: modal-in 220ms var(--ease);
}
.modal h2 { margin: 0 0 var(--space-2); font-size: var(--text-lg); }
.modal p { margin: 0 0 var(--space-5); color: var(--color-text-muted); font-size: var(--text-sm); }
.modal-form .modal-stack { margin-top: var(--space-4); }
.modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--color-text);
}
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: flex-end;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Mobile bottom nav (tenant) ---------- */
.mobile-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 35;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 0.35rem 0.5rem max(0.35rem, env(safe-area-inset-bottom));
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--color-border);
}
.mobile-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 52px;
  border: 0;
  background: transparent;
  color: var(--slate-500);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 10px;
}
.mobile-nav button svg { width: 20px; height: 20px; }
.mobile-nav button.is-active {
  color: var(--color-primary-ink);
  background: var(--color-primary-soft);
}

.app-shell.has-mobile-nav .app-main {
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

/* ---------- Breakpoints ---------- */
@media (min-width: 640px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .box-card { padding: var(--space-8); }
  .modal-backdrop { place-items: center; }
  .modal { border-radius: var(--radius-lg); }
}

@media (min-width: 900px) {
  .app-shell {
    grid-template-columns: var(--sidebar-w) 1fr;
    transition: grid-template-columns var(--duration) var(--ease);
  }

  .sidebar-backdrop { display: none !important; }
  .mobile-nav { display: none; }
  .menu-toggle { display: none !important; }
  .app-shell.has-mobile-nav .app-main { padding-bottom: var(--space-10); }

  .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    width: var(--sidebar-w);
    max-width: none;
    transform: none;
    box-shadow: none;
    transition: width var(--duration) var(--ease);
  }

  .sidebar-collapse { display: inline-flex; }

  .app-shell.is-collapsed .brand-mark div,
  .app-shell.is-collapsed .nav-item span,
  .app-shell.is-collapsed .sidebar-collapse span,
  .app-shell.is-collapsed .nav-group-label {
    display: none;
  }
  .app-shell.is-collapsed .nav-item {
    justify-content: center;
    padding-inline: 0.5rem;
  }
  .app-shell.is-collapsed .brand-mark { justify-content: center; }

  .account-meta { display: block; }

  .app-main { padding: var(--space-6) var(--space-8); }

  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .dash-grid { grid-template-columns: 1.4fr 1fr; }

  .detail-grid { grid-template-columns: 1fr 1fr; gap: var(--space-3) var(--space-6); }

  .q-card {
    flex-direction: row;
    align-items: flex-start;
  }
  .q-actions { flex-direction: column; flex-shrink: 0; }

  table.data {
    display: table;
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
  }
  table.data th, table.data td {
    text-align: left;
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
  }
  table.data th {
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  table.data code {
    font-family: var(--font-mono);
    font-size: 11px;
  }

  .mobile-cards { display: none; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

@media (min-width: 1280px) {
  .app-main { padding: var(--space-8) var(--space-10); }
  .kpi-grid { gap: var(--space-4); }
}

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