/* ============================================================
   VENDIGO — Authentication, Authorization & User Management
   Standalone access layer. Scoped under ven-* / #vendigo-auth-*
   so it never collides with the application shell.
   Ported from the Symmetra auth system and rebranded to the
   Vendigo blue accent. Soft shadows, rounded panels, compact
   spacing.
   ============================================================ */

#vendigo-auth-root,
#vendigo-auth-root *,
#vendigo-auth-gate,
#vendigo-auth-gate * {
  box-sizing: border-box;
}

:root {
  --ven-accent: #175fe6;
  --ven-accent-strong: #124ec0;
  --ven-accent-deep: #0f3f9c;
  --ven-accent-soft: #e9f1ff;
  --ven-accent-softer: #f3f8ff;
  --ven-accent-ring: rgba(23, 95, 230, 0.26);
  --ven-accent-grad: linear-gradient(135deg, #175fe6 0%, #3b82f6 100%);
  --ven-ink: #08172f;
  --ven-muted: #475b75;
  --ven-line: #dbe6f3;
  --ven-line-soft: #e8f0f9;
  --ven-surface: #ffffff;
  --ven-surface-2: #f5f9ff;
  --ven-danger: #d92d20;
  --ven-danger-soft: #fff0ee;
  --ven-success: #138a58;
  --ven-radius-sm: 10px;
  --ven-radius: 14px;
  --ven-radius-lg: 20px;
  --ven-radius-xl: 26px;
  --ven-shadow-sm: 0 2px 8px rgba(23, 56, 96, 0.06);
  --ven-shadow: 0 14px 34px rgba(23, 56, 96, 0.1);
  --ven-shadow-lg: 0 28px 70px rgba(23, 56, 96, 0.18);
  --ven-font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}

/* ============================================================
   LOGIN GATE
   Lives as a child of <html> so the app's body re-renders never
   destroy it.
   ============================================================ */
#vendigo-auth-gate {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  font-family: var(--ven-font);
  color: var(--ven-ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(23, 95, 230, 0.2), transparent 42%),
    radial-gradient(circle at 86% 88%, rgba(59, 130, 246, 0.16), transparent 40%),
    linear-gradient(180deg, #f4f8ff 0%, #e9f1fb 100%);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
#vendigo-auth-gate[hidden] { display: none !important; }

/* Hide the app shell while the gate is locked so the login screen never
   flickers the workspace behind it. */
body.vendigo-auth-locked .workspace-shell,
body.vendigo-auth-pending .workspace-shell {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.ven-login-card {
  width: 100%;
  max-width: 392px;
  overflow: hidden;
  background: linear-gradient(180deg, #eef4fd 0%, #f4f8ff 40%, #ffffff 64%);
  border: 1px solid var(--ven-line);
  border-radius: var(--ven-radius-xl);
  box-shadow: var(--ven-shadow-lg);
  padding: 0 34px 26px;
  animation: ven-pop 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes ven-pop {
  from { opacity: 0; transform: translateY(12px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.ven-login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0;
  margin: 0 -34px;
  padding: 0;
  min-height: 0;
  position: relative;
  background: transparent;
}

.ven-login-logo {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #d7d7da 0%, #ececed 56%, #f8f8f8 78%, #ffffff 100%);
  box-shadow: none;
  isolation: isolate;
  position: relative;
}

.ven-login-logo::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 56px;
  pointer-events: none;
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0) 0%,
      rgba(242, 242, 244, 0.22) 28%,
      rgba(249, 249, 250, 0.72) 72%,
      rgba(255, 255, 255, 1) 100%);
}

.ven-login-logo img,
.ven-login-logo video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.ven-login-logo-start,
.ven-login-logo-freeze {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
}

.ven-login-logo-start {
  opacity: 1;
  transition: opacity 0.12s ease;
}

.ven-login-logo-freeze {
  opacity: 0;
  pointer-events: none;
}

.ven-login-logo-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: inherit;
  background: transparent;
  object-fit: cover;
  object-position: center center;
  opacity: 0;
  transition: opacity 0.12s ease;
}

#vendigo-auth-gate.ven-login-video-ready .ven-login-logo-start {
  opacity: 0;
}

#vendigo-auth-gate.ven-login-video-ready .ven-login-logo-video {
  opacity: 1;
}

#vendigo-auth-gate.ven-login-video-frozen .ven-login-logo-video {
  opacity: 0;
}

#vendigo-auth-gate.ven-login-video-frozen .ven-login-logo-freeze {
  opacity: 1;
}

.ven-login-title {
  font-size: 22px;
  font-weight: 850;
  letter-spacing: -0.01em;
  color: var(--ven-ink);
}
.ven-login-byline {
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ven-accent-strong);
  margin-top: 3px;
}

.ven-login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  z-index: 1;
  margin-top: -10px;
  padding-top: 20px;
  background: linear-gradient(180deg, rgba(247, 247, 248, 0.92) 0%, rgba(252, 252, 253, 0.98) 18%, #ffffff 54%);
}
.ven-field { display: flex; flex-direction: column; gap: 6px; }
.ven-field label {
  font-size: 11.5px;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ven-muted);
}
.ven-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--ven-line);
  border-radius: var(--ven-radius-sm);
  background: var(--ven-surface-2);
  font: 600 14px/1 var(--ven-font);
  color: var(--ven-ink);
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}
.ven-input::placeholder { color: #9fb0c8; font-weight: 500; }
.ven-input:focus {
  border-color: var(--ven-accent);
  background: #fff;
  box-shadow: 0 0 0 4px var(--ven-accent-ring);
}
.ven-input-wrap { position: relative; }
.ven-input-wrap .ven-input { padding-right: 44px; }
.ven-reveal {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--ven-muted);
  border-radius: 8px;
  cursor: pointer;
}
.ven-reveal:hover { background: var(--ven-accent-soft); color: var(--ven-accent-strong); }

.ven-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--ven-radius-sm);
  font: 750 13.5px/1 var(--ven-font);
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.16s ease, background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
  white-space: nowrap;
}
.ven-btn:active { transform: translateY(1px); }
.ven-btn--primary {
  background: var(--ven-accent-grad);
  color: #fff;
  box-shadow: 0 12px 26px var(--ven-accent-ring);
}
.ven-btn--primary:hover { box-shadow: 0 16px 32px var(--ven-accent-ring); }
.ven-btn--block { width: 100%; height: 46px; font-size: 14.5px; margin-top: 4px; }
.ven-btn--ghost {
  background: #fff;
  border-color: var(--ven-line);
  color: var(--ven-ink);
}
.ven-btn--ghost:hover { border-color: var(--ven-accent); color: var(--ven-accent-strong); background: var(--ven-accent-softer); }
.ven-btn--soft {
  background: var(--ven-accent-soft);
  color: var(--ven-accent-deep);
}
.ven-btn--soft:hover { background: #dbe9ff; }
.ven-btn--danger {
  background: #fff;
  border-color: var(--ven-danger-soft);
  color: var(--ven-danger);
}
.ven-btn--danger:hover { background: var(--ven-danger-soft); }
.ven-btn--sm { height: 32px; padding: 0 12px; font-size: 12px; border-radius: 9px; }
.ven-btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }

.ven-login-error {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--ven-radius-sm);
  background: var(--ven-danger-soft);
  color: var(--ven-danger);
  font-size: 12.5px;
  font-weight: 650;
}
.ven-login-error.is-shown { display: flex; animation: ven-shake 0.3s; }
@keyframes ven-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

.ven-login-switch {
  text-align: center;
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--ven-muted);
}
.ven-login-switch a {
  color: var(--ven-accent-strong);
  font-weight: 750;
  text-decoration: none;
}
.ven-login-switch a:hover { text-decoration: underline; }

.ven-login-foot {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--ven-line-soft);
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: #8595ad;
  letter-spacing: 0.02em;
}

/* ============================================================
   SIDEBAR PROFILE DOCK + WEBSITE OWNER BUTTON
   Injected as the last children of .shell-sidebar.
   ============================================================ */
.ven-profile-dock {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--ven-line);
  border-radius: var(--ven-radius);
  background: linear-gradient(180deg, #ffffff, #f5f9ff);
  box-shadow: var(--ven-shadow-sm);
  cursor: pointer;
  text-align: left;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
  font-family: var(--ven-font);
}
.ven-profile-dock:hover {
  transform: translateY(-1px);
  border-color: var(--ven-accent);
  box-shadow: 0 12px 26px var(--ven-accent-ring);
}
.ven-avatar {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
  background: var(--ven-accent-grad);
  background-size: cover;
  background-position: center;
  overflow: hidden;
  user-select: none;
}
.ven-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ven-profile-dock__copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  min-width: 0;
  flex: 1;
}
.ven-profile-dock__name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
  color: var(--ven-ink);
  white-space: normal;
  overflow-wrap: anywhere;
  overflow: hidden;
}
.ven-profile-dock__role {
  display: block;
  font-size: 10px;
  font-weight: 750;
  line-height: 1.2;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ven-accent-deep);
}
.ven-profile-dock__chev { color: var(--ven-muted); flex: 0 0 auto; }

.ven-owner-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 8px;
  padding: 9px 12px;
  border: 1px solid var(--ven-line);
  border-radius: var(--ven-radius);
  background: #fff;
  color: var(--ven-ink);
  font: 750 12.5px/1 var(--ven-font);
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
}
.ven-owner-btn:hover { border-color: var(--ven-accent); background: var(--ven-accent-softer); color: var(--ven-accent-strong); }
.ven-owner-btn__icon { display: inline-flex; }

/* ============================================================
   ROLE BADGE
   ============================================================ */
.ven-role-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: var(--ven-accent-soft);
  color: var(--ven-accent-deep);
}
.ven-role-badge[data-role="admin"] { background: var(--ven-accent-soft); color: var(--ven-accent-deep); }
.ven-role-badge[data-role="controller"] { background: #e0f2fe; color: #0369a1; }
.ven-role-badge[data-role="viewer"] { background: #dcfce7; color: #15803d; }
.ven-role-badge[data-role="superadmin"] { background: #08172f; color: #fff; }

/* ============================================================
   MODALS (profile + user management + owner + signup/reset)
   Lives under #vendigo-auth-root on <html>.
   ============================================================ */
.ven-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2147483100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  /* A global performance rule forces backdrop-filter:none, so the blur does nothing;
     a 0.42 tint then let the overview read clearly THROUGH the backdrop (looked like the
     owner modal "overlapped" the page). Dim harder so the modal reads as a proper layer. */
  background: rgba(8, 23, 47, 0.62);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  font-family: var(--ven-font);
  color: var(--ven-ink);
}
.ven-modal-backdrop[hidden] { display: none !important; }
.ven-modal {
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--ven-surface);
  border-radius: var(--ven-radius-lg);
  box-shadow: var(--ven-shadow-lg);
  overflow: hidden;
  animation: ven-pop 0.26s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.ven-modal--wide { max-width: 680px; }
.ven-modal__head {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--ven-line-soft);
}
.ven-modal__head .ven-avatar { width: 46px; height: 46px; font-size: 17px; }
.ven-modal__head-copy { flex: 1; min-width: 0; }
.ven-modal__title { font-size: 16px; font-weight: 850; margin: 0; }
.ven-modal__subtitle { font-size: 12px; color: var(--ven-muted); margin: 2px 0 0; }
.ven-modal__close {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 9px;
  background: var(--ven-surface-2);
  color: var(--ven-muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.ven-modal__close:hover { background: var(--ven-danger-soft); color: var(--ven-danger); }
.ven-modal__body {
  padding: 18px 20px;
  overflow-y: auto;
}
.ven-modal__foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--ven-line-soft);
  background: var(--ven-surface-2);
}
.ven-modal__foot .ven-spacer { margin-right: auto; }

.ven-section-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ven-muted);
  margin: 18px 0 10px;
}
.ven-section-label:first-child { margin-top: 0; }

.ven-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ven-form-grid .ven-field--full { grid-column: 1 / -1; }
@media (max-width: 520px) { .ven-form-grid { grid-template-columns: 1fr; } }

.ven-readonly-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--ven-line-soft);
  border-radius: var(--ven-radius-sm);
  background: var(--ven-surface-2);
  margin-bottom: 8px;
}
.ven-readonly-row__label { font-size: 11.5px; font-weight: 700; color: var(--ven-muted); }
.ven-readonly-row__value { font-size: 13.5px; font-weight: 700; }

/* Compact workspace management (Website Owner panel). Each workspace is a single tidy
   row: a status dot + name/meta on the left, the plan select + lifecycle actions aligned
   to the right — so many workspaces fit without the old oversized stacked cards. */
.ven-ws-list { display: flex; flex-direction: column; gap: 6px; }
.ven-ws-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 10px 7px 11px;
  border: 1px solid var(--ven-line-soft);
  border-radius: 10px;
  background: var(--ven-surface-2);
}
.ven-ws-main { display: flex; align-items: center; gap: 9px; min-width: 0; }
.ven-ws-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14); }
.ven-ws-row--disabled .ven-ws-dot { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.14); }
.ven-ws-row--deleted .ven-ws-dot { background: var(--ven-danger); box-shadow: 0 0 0 3px var(--ven-danger-soft); }
.ven-ws-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ven-ws-name { font-size: 13px; font-weight: 750; color: var(--ven-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ven-ws-meta { font-size: 10.5px; font-weight: 650; color: var(--ven-muted); text-transform: capitalize; }
.ven-ws-actions { display: flex; align-items: center; gap: 5px; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }
.ven-ws-tier {
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--ven-line);
  border-radius: 8px;
  background: #fff;
  font: 650 12px/1 var(--ven-font);
  color: var(--ven-ink);
  text-transform: capitalize;
  cursor: pointer;
}
.ven-ws-tier:focus { border-color: var(--ven-accent); outline: none; box-shadow: 0 0 0 3px var(--ven-accent-ring); }
.ven-ws-protected { font-size: 11px; font-weight: 700; color: var(--ven-muted); opacity: 0.72; padding: 0 6px; }
.ven-btn--xs { height: 28px; padding: 0 10px; font-size: 11.5px; border-radius: 8px; gap: 5px; }
.ven-ws-summary { margin-top: 9px; font-size: 11px; font-weight: 650; color: var(--ven-muted); text-align: right; }
@media (max-width: 560px) {
  .ven-ws-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .ven-ws-actions { justify-content: flex-start; }
}

.ven-photo-row { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.ven-photo-row .ven-avatar { width: 64px; height: 64px; font-size: 22px; }
.ven-photo-actions { display: flex; flex-direction: column; gap: 7px; }
.ven-hint { font-size: 11.5px; color: var(--ven-muted); }

/* User management table */
.ven-users-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.ven-users-table th {
  text-align: left;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ven-muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--ven-line);
}
.ven-users-table td {
  padding: 10px;
  border-bottom: 1px solid var(--ven-line-soft);
  vertical-align: middle;
}
.ven-users-table tr:last-child td { border-bottom: 0; }
.ven-user-cell { display: flex; align-items: center; gap: 10px; }
.ven-user-cell .ven-avatar { width: 32px; height: 32px; font-size: 12px; }
.ven-user-name { font-weight: 750; }
.ven-user-meta { font-size: 11px; color: var(--ven-muted); }
.ven-user-actions { display: flex; gap: 6px; justify-content: flex-end; }
.ven-status-dot {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700;
}
.ven-status-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ven-success); }
.ven-status-dot.is-off { color: var(--ven-muted); }
.ven-status-dot.is-off::before { background: #c2cfe0; }

.ven-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.ven-toolbar__title { font-size: 14px; font-weight: 850; }

.ven-empty {
  padding: 22px;
  text-align: center;
  color: var(--ven-muted);
  font-size: 13px;
  border: 1px dashed var(--ven-line);
  border-radius: var(--ven-radius);
  background: var(--ven-surface-2);
}

select.ven-input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23475b75' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 36px;
}

/* ============================================================
   TOASTS
   ============================================================ */
#vendigo-auth-toasts {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 2147483200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  font-family: var(--ven-font);
}
.ven-toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 16px;
  border-radius: 999px;
  background: #08172f;
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  box-shadow: var(--ven-shadow);
  animation: ven-toast-in 0.24s ease both;
}
.ven-toast--error { background: var(--ven-danger); }
.ven-toast--success { background: var(--ven-success); }
.ven-toast--info { background: var(--ven-accent-strong); }
@keyframes ven-toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ============================================================
   ROLE-BASED GATING HELPERS
   Applied by the enforcement pass.
   ============================================================ */
.ven-access-hidden { display: none !important; }
[data-ven-disabled="1"] {
  opacity: 0.55 !important;
  pointer-events: none !important;
  cursor: not-allowed !important;
  filter: grayscale(0.2);
}
