/* ── OTP System Design Tokens ───────────────── */
:root, [data-theme="light"] {
  --color-bg:             #f7f6f2;
  --color-surface:        #f9f8f5;
  --color-surface-2:      #fbfbf9;
  --color-surface-offset: #edeae5;
  --color-divider:        #dcd9d5;
  --color-border:         #d4d1ca;
  --color-text:           #28251d;
  --color-text-muted:     #7a7974;
  --color-text-faint:     #bab9b4;
  --color-primary:        #01696f;
  --color-primary-hover:  #0c4e54;
  --color-primary-highlight: #cedcd8;
  --color-error:          #a12c7b;
  --color-error-highlight:#e0ced7;
  --color-success:        #437a22;
  --color-success-highlight: #d4dfcc;
  --color-warning:        #964219;
  --color-warning-highlight: #ddcfc6;
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px oklch(0.2 0.01 80 / 0.06);
  --shadow-md: 0 4px 12px oklch(0.2 0.01 80 / 0.08);
  --shadow-lg: 0 12px 32px oklch(0.2 0.01 80 / 0.12);
  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --font-body: 'Inter', 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}
[data-theme="dark"] {
  --color-bg:             #171614;
  --color-surface:        #1c1b19;
  --color-surface-2:      #201f1d;
  --color-surface-offset: #22211f;
  --color-divider:        #262523;
  --color-border:         #393836;
  --color-text:           #cdccca;
  --color-text-muted:     #797876;
  --color-text-faint:     #5a5957;
  --color-primary:        #4f98a3;
  --color-primary-hover:  #227f8b;
  --color-primary-highlight: #313b3b;
  --color-error:          #d163a7;
  --color-error-highlight: #4c3d46;
  --color-success:        #6daa45;
  --color-success-highlight: #3a4435;
  --color-warning:        #bb653b;
  --color-warning-highlight: #564942;
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.2);
  --shadow-md: 0 4px 12px oklch(0 0 0 / 0.3);
  --shadow-lg: 0 12px 32px oklch(0 0 0 / 0.4);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg:#171614;--color-surface:#1c1b19;--color-surface-2:#201f1d;
    --color-surface-offset:#22211f;--color-divider:#262523;--color-border:#393836;
    --color-text:#cdccca;--color-text-muted:#797876;--color-text-faint:#5a5957;
    --color-primary:#4f98a3;--color-primary-hover:#227f8b;--color-primary-highlight:#313b3b;
    --color-error:#d163a7;--color-error-highlight:#4c3d46;
    --color-success:#6daa45;--color-success-highlight:#3a4435;
    --color-warning:#bb653b;--color-warning-highlight:#564942;
  }
}

/* ── Base ───────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; scroll-behavior: smooth; }

.otp-wrap {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 60vh;
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

/* ── Header ─────────────────────────────────── */
.otp-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.875rem 1.5rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  flex-wrap: wrap;
}
.otp-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--color-text);
  font-size: var(--text-base);
}
.otp-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  flex: 1;
}
.otp-breadcrumb a { color: var(--color-primary); text-decoration: none; }
.otp-breadcrumb a:hover { text-decoration: underline; }
.otp-header-actions { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; }
.otp-user-badge {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  background: var(--color-surface-offset);
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
}

/* ── Main ───────────────────────────────────── */
.otp-main { padding: 1.5rem; display: flex; flex-direction: column; gap: 1.5rem; }

/* ── Panels ─────────────────────────────────── */
.otp-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}
.otp-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.otp-panel h2 {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
}
.otp-sub-section {
  background: var(--color-surface-2);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.otp-sub-section h3, .otp-sub-section h4 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Role Cards (Dashboard) ─────────────────── */
.otp-role-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--color-primary-highlight);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  flex-wrap: wrap;
}
.otp-role-card h3 { font-size: var(--text-base); font-weight: 600; }
.otp-role-card p  { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 2px; }
.otp-role-icon {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  color: var(--color-primary);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.otp-role-card .otp-btn { margin-left: auto; }

/* ── Grid ───────────────────────────────────── */
.otp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr));
  gap: 1rem;
}
.otp-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}
.otp-card:hover { box-shadow: var(--shadow-md); }
.otp-card h4 { font-size: var(--text-base); font-weight: 600; }
.otp-card-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-surface-offset);
  border-radius: var(--radius-md);
  color: var(--color-primary);
  margin-bottom: 0.25rem;
}
.otp-meta { font-size: var(--text-xs); color: var(--color-text-muted); }

/* ── Buttons ────────────────────────────────── */
.otp-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  min-height: 36px;
}
.otp-btn-primary   { background: var(--color-primary); color: #fff; }
.otp-btn-primary:hover { background: var(--color-primary-hover); }
.otp-btn-secondary { background: var(--color-surface-offset); color: var(--color-text); border: 1px solid var(--color-border); }
.otp-btn-secondary:hover { background: var(--color-divider); }
.otp-btn-ghost     { background: transparent; color: var(--color-text-muted); }
.otp-btn-ghost:hover { background: var(--color-surface-offset); color: var(--color-text); }
.otp-btn-danger    { background: var(--color-error-highlight); color: var(--color-error); border: 1px solid oklch(from var(--color-error) l c h / 0.25); }
.otp-btn-danger:hover { background: var(--color-error); color: #fff; }
.otp-btn-sm        { padding: 0.3rem 0.625rem; font-size: var(--text-xs); min-height: 28px; }
.otp-icon-btn      { background: none; border: none; cursor: pointer; color: var(--color-text-muted); display: flex; align-items: center; min-height: 36px; min-width: 36px; justify-content: center; border-radius: var(--radius-md); }
.otp-icon-btn:hover { background: var(--color-surface-offset); color: var(--color-text); }

/* ── Forms ──────────────────────────────────── */
.otp-form-inline {
  display: flex;
  align-items: flex-end;
  gap: 0.625rem;
  flex-wrap: wrap;
}
.otp-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
  min-width: 160px;
}
.otp-field label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.otp-input, .otp-field input[type="text"],
.otp-field input[type="email"] {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  transition: border-color var(--transition), box-shadow var(--transition);
  min-height: 36px;
}
.otp-input:focus, .otp-field input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px oklch(from var(--color-primary) l c h / 0.15);
}
.otp-input-readonly { background: var(--color-surface-offset); color: var(--color-text-muted); }
.otp-input-mono { font-family: var(--font-mono); letter-spacing: 0.05em; }
.otp-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
  padding-bottom: 0.1rem;
}

/* ── Tables ─────────────────────────────────── */
.otp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
}
.otp-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--color-divider);
}
.otp-table td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--color-divider);
  vertical-align: middle;
}
.otp-table tr:last-child td { border-bottom: none; }
.otp-table tr:hover td { background: var(--color-surface-offset); }
.otp-empty-row td { color: var(--color-text-faint); font-style: italic; }

/* ── Badges ─────────────────────────────────── */
.otp-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  background: var(--color-surface-offset);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.otp-badge-primary { background: var(--color-primary-highlight); color: var(--color-primary); border-color: oklch(from var(--color-primary) l c h / 0.25); }
.otp-badge-admin   { background: var(--color-warning-highlight); color: var(--color-warning); border-color: oklch(from var(--color-warning) l c h / 0.25); }

/* ── Team Cards ─────────────────────────────── */
.otp-team-list { display: flex; flex-direction: column; gap: 1rem; }
.otp-team-card {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}
.otp-team-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.otp-team-title-wrap { display: flex; align-items: center; gap: 0.375rem; }
.otp-team-name { font-size: var(--text-base); font-weight: 600; }
.otp-team-stats { display: flex; gap: 0.5rem; }

/* ── Flash / Alerts ─────────────────────────── */
.otp-flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
}
.otp-flash.success { background: var(--color-success-highlight); color: var(--color-success); border: 1px solid oklch(from var(--color-success) l c h / 0.3); }
.otp-flash.error   { background: var(--color-error-highlight);   color: var(--color-error);   border: 1px solid oklch(from var(--color-error) l c h / 0.3); }
.otp-alert { padding: 0.75rem 1rem; border-radius: var(--radius-md); font-size: var(--text-sm); margin-bottom: 1rem; }
.otp-alert-error   { background: var(--color-error-highlight); color: var(--color-error); }

/* ── Token Cards ────────────────────────────── */
.otp-tokens-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
  gap: 1.25rem;
}
.otp-token-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--shadow-md);
  transition: box-shadow var(--transition);
}
.otp-token-card:hover { box-shadow: var(--shadow-lg); }
.otp-token-name {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.otp-token-code {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-primary);
  letter-spacing: 0.15em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.otp-token-progress-wrap {
  height: 4px;
  background: var(--color-surface-offset);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.otp-token-progress {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  transition: width 1s linear;
}
.otp-token-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.otp-countdown { font-variant-numeric: tabular-nums; min-width: 28px; }
.otp-refresh-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  background: var(--color-surface-offset);
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

/* ── Modal ──────────────────────────────────── */
.otp-modal { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; }
.otp-modal-overlay { position: absolute; inset: 0; background: oklch(0.1 0 0 / 0.5); backdrop-filter: blur(4px); }
.otp-modal-box {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  min-width: 300px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.otp-modal-header { display: flex; align-items: center; justify-content: space-between; }
.otp-modal-header h3 { font-size: var(--text-lg); font-weight: 600; }
.otp-modal-body { display: flex; flex-direction: column; align-items: center; gap: 0.75rem; }
.otp-modal-hint { font-size: var(--text-xs); color: var(--color-text-muted); }

/* ── Empty States ───────────────────────────── */
.otp-empty {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; padding: 4rem 2rem; color: var(--color-text-muted);
  gap: 0.75rem;
}
.otp-empty svg { color: var(--color-text-faint); }
.otp-empty h3  { color: var(--color-text); font-size: var(--text-lg); }
.otp-empty p   { font-size: var(--text-sm); max-width: 36ch; }
.otp-empty-sm  { font-size: var(--text-sm); color: var(--color-text-faint); font-style: italic; padding: 0.75rem 0; }

/* ── Section ────────────────────────────────── */
.otp-section { display: flex; flex-direction: column; gap: 1rem; }
.otp-section h2 { font-size: var(--text-lg); font-weight: 600; }

/* ── Utility ────────────────────────────────── */
.otp-hidden { display: none !important; }

/* ── Responsive ─────────────────────────────── */
@media (max-width: 600px) {
  .otp-main     { padding: 1rem; }
  .otp-header   { padding: 0.75rem 1rem; }
  .otp-form-inline { flex-direction: column; align-items: stretch; }
  .otp-role-card { flex-direction: column; }
  .otp-role-card .otp-btn { margin-left: 0; width: 100%; }
  .otp-token-code { font-size: 1.5rem; }
  
}
/* ── Stats Bar (Org Admin) ──────────────────── */
.otp-stats-bar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}
.otp-stat {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 64px;
}
.otp-stat-value {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.otp-stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.otp-capacity-wrap {
  flex: 1;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}
.otp-capacity-label {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.otp-capacity-bar-wrap {
  height: 6px;
  background: var(--color-surface-offset);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.otp-capacity-bar {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}
.otp-capacity-bar.otp-capacity-mid  { background: var(--color-warning); }
.otp-capacity-bar.otp-capacity-warn { background: var(--color-error); }

/* ── Team header right cluster ──────────────── */
.otp-team-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* ── Table wrap (horizontal scroll on mobile) ─ */
.otp-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 600px) {
  .otp-stats-bar  { gap: 1rem; padding: 0.875rem 1rem; }
  .otp-stat-value { font-size: var(--text-base); }
  .otp-team-header-right { gap: 0.5rem; }
}
/* ── QR Scanner ─────────────────────────────── */
.otp-base32-wrap {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex: 1;
  min-width: 200px;
}
.otp-base32-wrap .otp-input { flex: 1; min-width: 0; }

.otp-scanner-box {
  width: min(420px, 95vw);
}
.otp-scanner-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.otp-scanner-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
}
#otp-scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Animated corner frame */
.otp-scanner-overlay-frame {
  position: absolute;
  inset: 15%;
  pointer-events: none;
}
.otp-scanner-corner {
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: var(--color-primary);
  border-style: solid;
}
.otp-scanner-corner-tl { top: 0; left: 0;  border-width: 3px 0 0 3px; border-radius: 3px 0 0 0; }
.otp-scanner-corner-tr { top: 0; right: 0; border-width: 3px 3px 0 0; border-radius: 0 3px 0 0; }
.otp-scanner-corner-bl { bottom: 0; left: 0;  border-width: 0 0 3px 3px; border-radius: 0 0 0 3px; }
.otp-scanner-corner-br { bottom: 0; right: 0; border-width: 0 3px 3px 0; border-radius: 0 0 3px 0; }

/* Animated scanning line */
.otp-scanner-line {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--color-primary), transparent);
  animation: scanner-sweep 2s ease-in-out infinite;
  top: 0;
}
@keyframes scanner-sweep {
  0%   { top: 0%;   opacity: 1; }
  50%  { top: 100%; opacity: 1; }
  51%  { opacity: 0; }
  100% { top: 0%;   opacity: 0; }
}

.otp-scanner-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: center;
  transition: color var(--transition);
}

/* Result panel */
.otp-scanner-result {
  background: var(--color-success-highlight);
  border: 1px solid oklch(from var(--color-success) l c h / 0.3);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.otp-scanner-result-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-success);
}
.otp-scanner-result-value {
  font-family: var(--font-mono);
  font-size: var(--text-base);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--color-text);
  word-break: break-all;
}
.otp-scanner-result-name {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.otp-scanner-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
  flex-wrap: wrap;
}

@media (prefers-reduced-motion: reduce) {
  .otp-scanner-line { animation: none; top: 50%; }
}
@media (max-width: 600px) {
  .otp-scanner-box { width: 95vw; }
  .otp-base32-wrap { flex-wrap: wrap; }
}