/* Overlive — Application Shell (sidebar + main) — sept 2026 */
/* Loaded only on the SaaS instance (saas_enabled=true). The classic 3-tab
   layout remains intact in the public (prod 8002) instance. */

:root {
  --shell-sidebar-w: 240px;
  --shell-sidebar-bg: #0f172a;
  --shell-sidebar-fg: #cbd5e1;
  --shell-sidebar-fg-active: #ffffff;
  --shell-sidebar-active-bg: rgba(37, 99, 235, .14);
  --shell-topbar-h: 64px;
  --shell-mobile-breakpoint: 900px;
}

html, body { height: 100%; margin: 0; padding: 0; }
body.shell { overflow: hidden; margin: 0; padding: 0; background: var(--background-dark); }
/* Hard reset against base_clean.css `body { padding: var(--spacing-md); }` (16px).
   Use a class+element selector to win specificity (0,1,1 > 0,0,1). */
body.shell.shell { margin: 0 !important; padding: 0 !important; }

.shell-layout {
  display: grid;
  grid-template-columns: var(--shell-sidebar-w) 1fr;
  grid-template-rows: var(--shell-topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  height: 100vh;
  width: 100vw;
  background: var(--background-dark);
}

/* ===== Sidebar (desktop) ===== */
.shell-sidebar {
  grid-area: sidebar;
  background: var(--shell-sidebar-bg);
  color: var(--shell-sidebar-fg);
  display: flex; flex-direction: column;
  border-right: 1px solid rgba(255,255,255,.04);
  overflow-y: auto;
}
.shell-sidebar .brand {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px;
  font-size: 16px; font-weight: 700;
  color: #fff; letter-spacing: -.01em;
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}
.shell-sidebar .brand .brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 16px; box-shadow: 0 4px 12px rgba(37,99,235,.35);
}
.shell-sidebar .nav-section {
  padding: 14px 12px 4px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: #64748b; font-weight: 700;
}
.shell-sidebar .nav {
  display: flex; flex-direction: column;
  padding: 4px 10px 12px; gap: 2px;
}
.shell-sidebar .nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: 8px;
  color: var(--shell-sidebar-fg); font-size: 14px; font-weight: 500;
  cursor: pointer; text-decoration: none;
  transition: background .12s, color .12s;
  border: none; background: transparent;
  width: 100%; text-align: left; font-family: inherit;
}
.shell-sidebar .nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.shell-sidebar .nav-item.active {
  background: var(--shell-sidebar-active-bg);
  color: var(--shell-sidebar-fg-active);
  font-weight: 600;
}
.shell-sidebar .nav-item i { width: 18px; text-align: center; font-size: 14px; opacity: .9; }
.shell-sidebar .nav-item .badge {
  margin-left: auto;
  font-size: 10.5px; font-weight: 700;
  background: var(--tertiary); color: #fff;
  padding: 2px 7px; border-radius: 10px;
}
.shell-sidebar .nav-item .badge.pro { background: var(--primary); }
.shell-sidebar .nav-item .badge.warn { background: var(--danger); }
.shell-sidebar .user-card {
  margin-top: auto; padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex; align-items: center; gap: 10px;
  font-size: 13px;
}
.shell-sidebar .user-card .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px;
  flex-shrink: 0;
}
.shell-sidebar .user-card .user-info { flex: 1; min-width: 0; line-height: 1.25; }
.shell-sidebar .user-card .user-info .name { color: #fff; font-weight: 600; }
.shell-sidebar .user-card .user-info .role { color: #64748b; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; }
/* v1.4.5 — color the sidebar plan badge based on the effective plan.
   paintSidebarPlan() toggles these classes. */
.shell-sidebar .user-card .user-info .role.plan-paid { color: #10b981; font-weight: 600; }
.shell-sidebar .user-card .user-info .role.plan-trial { color: #f59e0b; }
.shell-sidebar .user-card .user-info .role.plan-expired { color: #ef4444; }
.shell-sidebar .user-card .user-info .role.plan-none { color: #64748b; }
.shell-sidebar .user-card .logout {
  background: transparent; border: none; cursor: pointer; color: #94a3b8;
  padding: 6px; border-radius: 6px; font-size: 14px;
}
.shell-sidebar .user-card .logout:hover { background: rgba(239,68,68,.12); color: var(--danger); }

/* ===== Topbar ===== */
.shell-topbar {
  grid-area: topbar;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, .04);
}
.shell-topbar .page-title {
  font-size: 18px; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 10px;
  margin: 0;
}
.shell-topbar .page-title i { color: var(--primary); font-size: 18px; }
.shell-topbar .spacer { flex: 1; }
.shell-topbar .conn-status, .shell-topbar .ver-badge, .shell-topbar .btn-logout {
  /* keep using existing styles — but slightly smaller */
  font-size: 11.5px !important;
}
.shell-hamburger {
  display: none;
  background: transparent; border: 1px solid var(--border); cursor: pointer;
  width: 38px; height: 38px; border-radius: 8px;
  color: var(--text); font-size: 16px;
  align-items: center; justify-content: center;
}

/* ===== Main area ===== */
.shell-main {
  grid-area: main;
  overflow-y: auto;
  padding: 24px 28px 40px;
}
.shell-page { display: none; }
.shell-page.active { display: block; }
.shell-page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px; gap: 16px; flex-wrap: wrap;
}
.shell-page-header h1 {
  margin: 0; font-size: 22px; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 10px;
}
.shell-page-header h1 i { color: var(--primary); }
.shell-page-header .subtitle { color: var(--text-muted); font-size: 13.5px; margin-top: 4px; }

/* ===== Account section ===== */
.account-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.account-card {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--border-radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.account-card h2 {
  margin: 0 0 6px; font-size: 16px; font-weight: 700;
  display: flex; align-items: center; gap: 10px; color: var(--text);
}
.account-card h2 i { color: var(--primary); }
.account-card .muted { color: var(--text-muted); font-size: 13px; margin: 0 0 16px; }
.account-card .kv {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-top: 1px solid var(--border);
  font-size: 14px;
}
.account-card .kv:first-of-type { border-top: none; }
.account-card .kv .k { color: var(--text-muted); }
.account-card .kv .v { font-weight: 600; color: var(--text); }
.account-card .kv .v.trial { color: var(--tertiary); }
.account-card .kv .v.paid { color: var(--success); }
.account-card .kv .v.expired { color: var(--danger); }
.account-card .kv .v.warn { color: var(--tertiary); font-weight: 700; }
.account-card .pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 20px;
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
}
.account-card .pill.trial { background: rgba(245,158,11,.12); color: var(--tertiary-dark); border: 1px solid rgba(245,158,11,.3); }
.account-card .pill.paid { background: rgba(16,185,129,.12); color: var(--success-dark); border: 1px solid rgba(16,185,129,.3); }
.account-card .pill.expired { background: rgba(239,68,68,.12); color: var(--danger-dark); border: 1px solid rgba(239,68,68,.3); }
.account-card .pill.admin { background: rgba(139,92,246,.14); color: #6d28d9; border: 1px solid rgba(139,92,246,.35); }
.account-card .cta {
  margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap;
}

/* ===== Mobile / drawer ===== */
@media (max-width: 900px) {
  .shell-layout {
    grid-template-columns: 1fr;
    grid-template-rows: var(--shell-topbar-h) 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }
  .shell-sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: 280px; z-index: 60;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 6px 0 24px rgba(0,0,0,.15);
  }
  body.shell-drawer-open .shell-sidebar { transform: translateX(0); }
  .shell-topbar { padding: 0 12px 0 8px; }
  .shell-hamburger { display: inline-flex; }
  .shell-main { padding: 16px 14px 28px; }
  .account-grid { grid-template-columns: 1fr; }
  .shell-page-header h1 { font-size: 18px; }
}
.shell-drawer-backdrop {
    display: none;
    position: fixed; inset: 0; background: rgba(15,23,42,.45);
    z-index: 55;
}
body.shell-drawer-open .shell-drawer-backdrop { display: block; }
@media (min-width: 901px) {
    .shell-drawer-backdrop { display: none !important; }
}

/* ===== Billing plans (Mon Compte) ===== */
.billing-plans {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 16px;
}
@media (max-width: 500px) {
    .billing-plans { grid-template-columns: 1fr; }
}
.billing-plan {
    background: #ffffff;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px 14px 14px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    color: #0f172a;
    display: flex; flex-direction: column; gap: 6px;
    transition: all 0.18s;
    position: relative;
    overflow: hidden;
}
.billing-plan:hover {
    border-color: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.12);
}
.billing-plan:active { transform: translateY(0); }
.billing-plan-best {
    border-color: #f59e0b;
    background: linear-gradient(180deg, #fffbeb 0%, #ffffff 60%);
}
.billing-plan-best:hover { border-color: #d97706; }
.billing-plan-head {
    display: flex; align-items: center; gap: 7px;
    font-size: 12px; font-weight: 700;
    color: #475569; text-transform: uppercase; letter-spacing: 0.05em;
}
.billing-plan-head i { color: #2563eb; font-size: 13px; }
.billing-plan-best .billing-plan-head i { color: #f59e0b; }
.billing-plan-name { flex: 1; }
.billing-plan-badge {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #ffffff; font-size: 10px; font-weight: 800;
    padding: 2px 7px; border-radius: 999px;
    letter-spacing: 0.02em;
}
.billing-plan-price {
    display: flex; align-items: baseline; gap: 2px;
    margin: 2px 0;
}
.billing-plan-price .amount {
    font-size: 30px; font-weight: 800; color: #0f172a; line-height: 1;
}
.billing-plan-price .currency {
    font-size: 18px; font-weight: 700; color: #475569;
}
.billing-plan-best .billing-plan-price .amount { color: #92400e; }
.billing-plan-period {
    font-size: 11.5px; color: #64748b; font-weight: 500;
}
.billing-plan-period .muted { color: #94a3b8; }
.billing-plan-cta {
    margin-top: 8px;
    padding-top: 10px;
    border-top: 1px dashed #e2e8f0;
    font-size: 12px; font-weight: 700; color: #2563eb;
    display: flex; align-items: center; gap: 5px;
}
.billing-plan-best .billing-plan-cta { color: #d97706; }
.billing-plan:hover .billing-plan-cta i { transform: translateX(3px); }
.billing-plan-cta i { transition: transform 0.18s; }

/* ============================================================
   Historique des paiements — carte dédiée
   ============================================================ */
.card-history {
    margin-top: 18px;
    padding: 0;
    overflow: hidden;
}
.card-history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 18px 22px 16px;
    border-bottom: 1px solid #eef2f7;
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
}
.card-history-title {
    display: flex; align-items: center; gap: 14px;
    min-width: 0;
}
.card-history-title .icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.22);
}
.card-history-title .icon i { font-size: 17px; }
.card-history-title h2 {
    margin: 0;
    font-size: 15.5px;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.01em;
}
.card-history-title .subtitle {
    margin: 2px 0 0;
    font-size: 12px;
    color: #64748b;
}
.card-history-meta {
    flex-shrink: 0;
}
.card-history-count {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 11px;
    border-radius: 999px;
    background: #eff6ff;
    color: #1e40af;
    font-size: 11.5px;
    font-weight: 600;
    border: 1px solid #dbeafe;
}
.card-history-body {
    padding: 0;
    overflow-x: auto;
}

/* ============================================================
   Historique de paiements — style SaaS moderne (Linear/Stripe)
   ============================================================ */
.card-history {
    margin-top: 20px;
    padding: 0;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.card-history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 20px 24px;
    border-bottom: 1px solid #f1f5f9;
}
.card-history-title {
    display: flex; align-items: center; gap: 14px;
    min-width: 0;
}
.card-history-title .icon {
    width: 38px; height: 38px;
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    background: #0f172a;
    color: #fff;
    flex-shrink: 0;
}
.card-history-title .icon i { font-size: 16px; }
.card-history-title h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #0f172a;
    letter-spacing: -0.01em;
}
.card-history-title .subtitle {
    margin: 2px 0 0;
    font-size: 12.5px;
    color: #64748b;
}
.card-history-meta {
    flex-shrink: 0;
}
.card-history-count {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px;
    border-radius: 6px;
    background: #f1f5f9;
    color: #475569;
    font-size: 11.5px;
    font-weight: 500;
}
.card-history-body {
    padding: 0;
}

/* ============================================================
   Tableau des factures — style sobre et lisible
   ============================================================ */
.invoice-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    color: #0f172a;
}
.invoice-table thead th {
    text-align: left;
    font-size: 11.5px;
    font-weight: 500;
    color: #64748b;
    padding: 12px 24px;
    background: #fafbfc;
    border-bottom: 1px solid #f1f5f9;
    white-space: nowrap;
}
.invoice-table thead th.col-amount { text-align: right; }
.invoice-table thead th.col-actions { text-align: right; }
.invoice-table tbody tr {
    transition: background 0.12s;
}
.invoice-table tbody tr + tr td {
    border-top: 1px solid #f1f5f9;
}
.invoice-table tbody tr:hover {
    background: #fafbfc;
}
.invoice-table tbody td {
    padding: 14px 24px;
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
}
.invoice-table .col-amount { text-align: right; }
.invoice-table .col-actions { text-align: left; white-space: normal; gap: 6px; }
.invoice-table .col-id {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 12px;
    color: #94a3b8;
    letter-spacing: -0.01em;
}

/* Cellule date — texte simple, pas de bloc coloré */
.invoice-table .cell-date {
    color: #1e293b;
    font-weight: 500;
    font-size: 13px;
}
.invoice-table .cell-date .date-time {
    font-size: 11px; color: #64748b; font-weight: 500; margin-top: 2px;
}

/* Montant */
.invoice-amount {
    font-weight: 600;
    color: #0f172a;
    font-size: 13.5px;
    letter-spacing: -0.01em;
}
.invoice-amount .currency {
    font-size: 10.5px;
    font-weight: 500;
    color: #94a3b8;
    margin-left: 3px;
    text-transform: uppercase;
}

/* Badge statut — pastilles discrètes */
.invoice-badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px;
    border-radius: 6px;
    font-weight: 500;
    font-size: 11.5px;
    letter-spacing: 0.1px;
    white-space: nowrap;
}
.invoice-badge i { font-size: 9px; }
.invoice-badge.inv-paid { background: #ecfdf5; color: #047857; }
.invoice-badge.inv-paid i { color: #10b981; }
.invoice-badge.inv-open { background: #fffbeb; color: #b45309; }
.invoice-badge.inv-open i { color: #f59e0b; }
.invoice-badge.inv-failed { background: #fef2f2; color: #b91c1c; }
.invoice-badge.inv-failed i { color: #ef4444; }
.invoice-badge.inv-void { background: #f1f5f9; color: #475569; }
.invoice-badge.inv-draft { background: #f8fafc; color: #64748b; }
.invoice-badge.inv-unknown { background: #f8fafc; color: #64748b; }

/* Période */
.invoice-period {
    color: #475569;
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
}
.invoice-period .arrow {
    color: #cbd5e1;
    margin: 0 6px;
    font-weight: 400;
}

/* Boutons d'action — icônes rondes sobres */
.invoice-actions {
    display: inline-flex; gap: 4px;
    justify-content: flex-end;
    align-items: center;
}
.invoice-link {
    display: inline-block; align-items: center; justify-content: center; gap: 3px;
    min-width: 120px; height: 36px; padding: 4px 12px;
    border-radius: 6px; font-size: 14px; font-weight: 700; white-space: nowrap;
    overflow: visible; line-height: 1.2;
    color: #0f172a;
    text-decoration: none;
    background: #ffffff;
    border: 2px solid #475569;
    position: relative;
    cursor: pointer;
}
.invoice-link i { font-size: 14px; }
.invoice-link:hover {
    background: #f1f5f9;
    color: #0f172a;
    border-color: #e2e8f0;
}
.invoice-link.is-view:hover {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
}
.invoice-link[aria-disabled="true"] {
    opacity: 0.4;
    pointer-events: none;
}

/* Tooltip natif via title (style simple) */
.invoice-link[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    bottom: -28px; right: 50%;
    transform: translateX(50%);
    background: #0f172a;
    color: #ffffff;
    font-size: 11px;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 5px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}
.invoice-link:hover[data-tip]::after { opacity: 1; }

/* Empty state */
.billing-empty {
    padding: 56px 22px;
    text-align: center;
    color: #94a3b8;
    font-size: 13px;
    background: #ffffff;
}
.billing-empty i {
    font-size: 36px;
    opacity: 0.35;
    display: block;
    margin-bottom: 14px;
    color: #94a3b8;
}
.billing-empty .empty-title {
    font-size: 14px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 4px;
}
.billing-empty .empty-sub {
    font-size: 12.5px;
    color: #94a3b8;
}

/* Responsive mobile */
@media (max-width: 720px) {
    .card-history-head {
        padding: 16px 18px;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .invoice-table thead { display: none; }
    .invoice-table, .invoice-table tbody, .invoice-table tr, .invoice-table td {
        display: block;
        width: 100%;
    }
    .invoice-table tbody tr {
        border-bottom: 1px solid #f1f5f9;
    }
    .invoice-table tbody tr:last-child { border-bottom: none; }
    .invoice-table tbody td {
        padding: 10px 18px;
        text-align: left !important;
        border: none !important;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
    }
    .invoice-table tbody td::before {
        content: attr(data-label);
        font-size: 11px;
        font-weight: 500;
        color: #94a3b8;
        flex-shrink: 0;
    }
    .invoice-table .col-actions::before { display: none !important; }
    .invoice-actions { width: auto; }
}
