:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242736;
  --border: #2e3148;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --primary: #635bff;
  --primary-hover: #7c75ff;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 10px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

/* --- Top loading bar (created by Vault.loading) ---
   Lives at the very top of the viewport. We don't toggle display so the bar
   can fade in and out smoothly with a CSS transition. The indeterminate
   animation runs only while .active is set. */
#vault-loading-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 2px; pointer-events: none; z-index: 9999;
  background: transparent; opacity: 0;
  transition: opacity .15s ease;
}
#vault-loading-bar.active { opacity: 1; }
#vault-loading-bar.active::before {
  content: ''; display: block; height: 100%; width: 30%;
  background: linear-gradient(90deg, transparent, var(--primary) 40%, var(--primary-hover) 60%, transparent);
  animation: vault-loading-slide 1.1s linear infinite;
  will-change: transform;
}
@keyframes vault-loading-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

/* --- Auth screens --- */
.auth-container {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.auth-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 40px; width: 100%; max-width: 420px;
}
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }
.auth-card .subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }
.auth-card .logo { font-size: 32px; margin-bottom: 16px; display: block; }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.form-group input {
  width: 100%; padding: 11px 14px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 15px; outline: none; transition: border-color .2s;
}
.form-group input:focus { border-color: var(--primary); }
.btn-primary {
  width: 100%; padding: 12px; background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius); font-size: 15px;
  font-weight: 600; cursor: pointer; transition: background .2s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.auth-links { margin-top: 18px; text-align: center; font-size: 13px; color: var(--text-muted); }
.auth-links a { color: var(--primary); text-decoration: none; cursor: pointer; }
.auth-links a:hover { text-decoration: underline; }
.auth-msg { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; display: none; }
.auth-msg.error { display: block; background: rgba(239,68,68,.12); color: var(--danger); border: 1px solid rgba(239,68,68,.25); }
.auth-msg.success { display: block; background: rgba(34,197,94,.12); color: var(--success); border: 1px solid rgba(34,197,94,.25); }

/* --- Dashboard layout --- */
.app { display: none; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 14px 28px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }

/* --- Sidebar toggle (hamburger) --- */
.sidebar-toggle {
  background: transparent; border: 1px solid var(--border); color: var(--text-muted);
  padding: 6px 12px; border-radius: var(--radius); cursor: pointer;
  font-size: 18px; line-height: 1; transition: all .2s;
  display: inline-flex; align-items: center; justify-content: center;
}
.sidebar-toggle:hover { border-color: var(--primary); color: var(--primary); }
.sidebar-toggle:active { transform: scale(.96); }
.topbar-left h1 { font-size: 18px; font-weight: 700; }
.topbar-left span { font-size: 12px; background: var(--primary); color: #fff; padding: 3px 10px; border-radius: 20px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-right .user-name { font-size: 14px; color: var(--text-muted); }
.btn-logout {
  padding: 7px 16px; background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-muted); font-size: 13px;
  cursor: pointer; transition: all .2s;
}
.btn-logout:hover { border-color: var(--danger); color: var(--danger); }

/* --- App body (sidebar + main) --- */
.app-body { display: flex; align-items: stretch; min-height: calc(100vh - 61px); }

/* --- Sidebar (vertical nav) --- */
.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px;
  transition: width .25s ease, padding .25s ease, opacity .2s ease;
  overflow-x: hidden; overflow-y: auto;
  align-self: stretch;
}
.sidebar.collapsed {
  width: 0; padding: 18px 0; border-right: none; opacity: 0;
}

.main { flex: 1; padding: 28px; min-width: 0; }

/* --- Sections --- */
.section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; margin-bottom: 24px;
}
.section h2 { font-size: 18px; margin-bottom: 4px; }
.section .desc { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.key-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.key-grid.full { grid-template-columns: 1fr; }
.key-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .5px; }
.key-field input {
  width: 100%; padding: 10px 12px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 14px; font-family: 'SF Mono', 'Fira Code', monospace; outline: none;
}
.key-field input:focus { border-color: var(--primary); }
.section-actions { margin-top: 18px; display: flex; gap: 10px; align-items: center; }
.btn {
  padding: 9px 20px; border-radius: var(--radius); font-size: 13px;
  font-weight: 600; cursor: pointer; border: none; transition: all .2s;
}
.btn-save { background: var(--primary); color: #fff; }
.btn-save:hover { background: var(--primary-hover); }
.btn-sm { padding: 7px 14px; font-size: 12px; }
.btn-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.status-msg { font-size: 13px; color: var(--success); margin-left: 8px; }

/* --- License table --- */
.license-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.license-header h2 { margin-bottom: 0; }
.license-table { width: 100%; border-collapse: collapse; }
.license-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); padding: 10px 12px; border-bottom: 1px solid var(--border); }
.license-table td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
.license-table tr:last-child td { border-bottom: none; }
.license-key { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; background: var(--surface2); padding: 4px 8px; border-radius: 6px; user-select: all; }
.badge { padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-active { background: rgba(34,197,94,.15); color: var(--success); }
.badge-revoked { background: rgba(239,68,68,.15); color: var(--danger); }
.sites-list { font-size: 12px; color: var(--text-muted); }

/* --- New license form --- */
.new-license-row { display: flex; gap: 10px; align-items: end; }
.new-license-row .form-group { margin-bottom: 0; flex: 1; }
.new-license-row input { padding: 9px 12px; }

/* --- Tabs (vertical sidebar nav) --- */
.tab-nav {
  display: flex; flex-direction: column; gap: 2px;
  background: transparent; border-radius: 0; padding: 0; margin: 0;
  align-items: stretch;
}
.tab-btn {
  padding: 10px 14px; border: none; background: transparent; color: var(--text-muted);
  font-size: 13px; font-weight: 600; border-radius: 8px; cursor: pointer;
  transition: all .2s; text-align: left; white-space: nowrap;
}
.tab-btn.active { background: var(--primary); color: #fff; }
.tab-btn:not(.active):hover { color: var(--text); background: var(--surface2); }
.tab-group-label {
  display: block;
  font-size: 10px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-muted); opacity: .6;
  padding: 14px 14px 6px;
  font-weight: 700; user-select: none; white-space: nowrap;
}
.tab-nav > .tab-group-label:first-child { padding-top: 4px; }
.tab-separator {
  width: auto; height: 1px; background: var(--border);
  margin: 10px 6px; flex-shrink: 0;
}
.page { display: none; }
.page.active { display: block; }

/* --- Activity/Monitoring tables --- */
.mono { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; }
.badge-activate { background: rgba(34,197,94,.15); color: var(--success); }
.badge-deactivate { background: rgba(239,68,68,.15); color: var(--danger); }
.empty-state { color: var(--text-muted); font-size: 14px; text-align: center; padding: 32px; }
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px;
}
.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.stat-card .value { font-size: 28px; font-weight: 700; }
@media (max-width: 640px) { .stat-cards { grid-template-columns: 1fr; } }

/* --- Modal --- */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.6); display: none; align-items: center;
  justify-content: center; z-index: 100;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; width: 100%; max-width: 400px;
}
.modal h3 { margin-bottom: 6px; }
.modal p { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* --- Action cards --- */
.action-cards { display: flex; flex-direction: column; gap: 14px; }
.action-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px 24px; transition: border-color .2s;
}
.action-card:hover { border-color: var(--primary); }
.action-card-header { display: flex; align-items: center; gap: 16px; }
.action-card-icon { font-size: 28px; flex-shrink: 0; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: var(--surface); border-radius: 10px; }
.action-card-info { flex: 1; }
.action-card-info h3 { font-size: 15px; font-weight: 600; margin-bottom: 3px; }
.action-card-info p { font-size: 12px; color: var(--text-muted); line-height: 1.5; margin: 0; }
.action-card-status { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); }
.action-status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.action-status-dot.on { background: var(--success); box-shadow: 0 0 6px rgba(34,197,94,.4); }
.action-status-dot.off { background: var(--danger); box-shadow: 0 0 6px rgba(239,68,68,.4); }
/* Inline post-PUT confirmation under each toggle. Hidden until populated by
   actions.js (it sets the className based on success/error/pending). */
.action-card-feedback { font-size: 12px; line-height: 1.4; margin-top: 8px; min-height: 0; }
.action-card-feedback:empty { display: none; }
.action-card-feedback.success { color: var(--success); }
.action-card-feedback.error { color: var(--danger); }
.action-card-feedback.pending { color: var(--text-muted); font-style: italic; }

/* --- Toggle switch --- */
.toggle-switch { position: relative; display: inline-block; width: 48px; height: 26px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border); border-radius: 26px; transition: background .3s;
}
.toggle-slider::before {
  content: ''; position: absolute; height: 20px; width: 20px;
  left: 3px; bottom: 3px; background: #fff; border-radius: 50%;
  transition: transform .3s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--success); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(22px); }
.toggle-switch input:disabled + .toggle-slider { opacity: .5; cursor: not-allowed; }
/* Variante compacte utilisée dans les cards produit (l'échelle reste
   reconnaissable mais on tient sur la même ligne que les boutons Éditer /
   Supprimer). */
.toggle-switch-sm { width: 38px; height: 20px; }
.toggle-switch-sm .toggle-slider { border-radius: 20px; }
.toggle-switch-sm .toggle-slider::before {
  height: 14px; width: 14px; left: 3px; bottom: 3px;
}
.toggle-switch-sm input:checked + .toggle-slider::before { transform: translateX(18px); }

/* --- Stripe subtabs (horizontal Live/Test under mode card) --- */
.stripe-subtab-nav {
  display: flex; gap: 6px; margin-bottom: 18px;
  border-bottom: 1px solid var(--border); padding: 0 4px;
}
.stripe-subtab-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border: none;
  background: transparent; color: var(--text-muted);
  font-size: 13px; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
  transition: color .2s, border-color .2s, background .2s;
}
.stripe-subtab-btn:hover { color: var(--text); background: var(--surface2); }
.stripe-subtab-btn.active {
  color: var(--text); border-bottom-color: var(--primary);
  background: var(--surface2);
}
.stripe-subtab-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.stripe-subtab-dot-live { background: var(--success); box-shadow: 0 0 6px rgba(34,197,94,.4); }
.stripe-subtab-dot-test { background: var(--warning); box-shadow: 0 0 6px rgba(245,158,11,.4); }
.stripe-subtab-panel { display: none; }
.stripe-subtab-panel.active { display: block; }

/* --- Product list cards (Stripe products) --- */
.product-list {
  display: flex; flex-direction: column; gap: 12px; margin-top: 18px;
}
.product-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 20px; transition: border-color .15s, opacity .15s;
}
.product-card:hover { border-color: var(--primary); }
/* Produit désactivé (switch off) : on grise la card pour signaler que la
   card publique est masquée côté /web. La toggle elle-même reste pleinement
   utilisable (c'est le seul moyen de réactiver le produit). */
.product-card-disabled {
  opacity: .55;
  border-style: dashed;
}
.product-card-disabled:hover { opacity: .85; }
.product-card-disabled .toggle-switch { opacity: 1; }
.product-card-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 14px;
  margin-bottom: 10px;
}
.product-card-title { font-size: 15px; font-weight: 600; color: var(--text); }
.product-card-slug { margin-top: 4px; }
.product-card-slug code,
.product-card-row code {
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px;
  background: var(--surface); padding: 2px 8px; border-radius: 6px;
  color: var(--text-muted); user-select: all;
}
.product-card-actions {
  display: flex; gap: 8px; flex-shrink: 0;
}
.product-card-body {
  display: flex; flex-direction: column; gap: 6px;
  padding-top: 10px; border-top: 1px solid var(--border);
}
.product-card-row {
  display: flex; align-items: center; gap: 10px; font-size: 13px;
}
.product-card-key {
  flex-shrink: 0; min-width: 100px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted);
}
.product-card-desc {
  font-size: 12px; color: var(--text-muted); font-style: italic;
  margin-top: 2px;
}
@media (max-width: 640px) {
  .product-card-head { flex-wrap: wrap; }
  .product-card-actions { width: 100%; }
}

/* --- Modal sub-tabs (used by the product modal: Clés Stripe / Contenu web) --- */
.modal-tabs {
  display: flex; gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.modal-tab-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border: none;
  background: transparent; color: var(--text-muted);
  font-size: 13px; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent;
  border-radius: 6px 6px 0 0;
  transition: color .2s, border-color .2s, background .2s;
}
.modal-tab-btn:hover { color: var(--text); background: var(--surface2); }
.modal-tab-btn.active {
  color: var(--text); border-bottom-color: var(--primary);
  background: var(--surface2);
}
.modal-tab-icon { font-size: 14px; line-height: 1; }
.modal-tab-panel { display: none; }
.modal-tab-panel.active { display: block; }
/* Le modal product est plus haut/large que les autres : on autorise le
   scroll vertical interne pour les longues listes de features. */
#stripe-product-modal .modal {
  max-height: 90vh; overflow-y: auto;
}
#stripe-product-modal textarea {
  width: 100%; padding: 10px 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 13px; resize: vertical;
  min-height: 64px;
}
#stripe-product-modal textarea:focus {
  outline: none; border-color: var(--primary);
}

/* --- Key reveal (eye button) --- */
.key-reveal { position: relative; }
.key-reveal input { padding-right: 40px; }
.key-reveal-btn {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  background: transparent; border: none; cursor: pointer;
  padding: 6px 8px; border-radius: 6px; color: var(--text-muted);
  font-size: 14px; line-height: 1; transition: background .15s, color .15s;
}
.key-reveal-btn:hover { background: var(--surface); color: var(--text); }
.key-reveal-btn.revealed { color: var(--primary); }

@media (max-width: 640px) {
  .key-grid { grid-template-columns: 1fr; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 10px; }
  .main { padding: 16px; }
  .license-table { font-size: 13px; }
  .action-card-header { flex-wrap: wrap; }
  /* Sidebar en overlay sur mobile */
  .sidebar {
    position: fixed; top: 61px; left: 0; bottom: 0; z-index: 40;
    box-shadow: 2px 0 12px rgba(0,0,0,.35);
  }
  .app-body { display: block; min-height: auto; }
  .main { width: 100%; }
}
