/* TrésoPro - Thème sombre identique à l'app Python */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --bg:#0f1117; --surface:#1a1d27; --surface2:#232636; --border:#2e3347;
  --accent:#4f7cff; --accent2:#7c4fff;
  --green:#22c55e; --red:#ef4444; --orange:#f59e0b;
  --text:#e2e8f0; --muted:#8b93a7;
  --sw:230px;
}
* { box-sizing:border-box; margin:0; padding:0; }
body { font-family:'IBM Plex Sans',sans-serif; background:var(--bg); color:var(--text); min-height:100vh; display:flex; }

/* SIDEBAR */
.sidebar { width:var(--sw); background:var(--surface); border-right:1px solid var(--border); display:flex; flex-direction:column; position:fixed; top:0; left:0; bottom:0; z-index:100; overflow-y:auto; }
.sidebar-logo { padding:16px 14px 12px; border-bottom:1px solid var(--border); flex-shrink:0; }
.soc-badge { display:flex; align-items:center; gap:10px; margin-bottom:6px; }
.soc-icon { width:30px; height:30px; background:linear-gradient(135deg,var(--accent),var(--accent2)); border-radius:7px; display:flex; align-items:center; justify-content:center; font-size:13px; flex-shrink:0; }
.soc-name { font-size:11px; font-weight:600; line-height:1.3; max-width:160px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.soc-selector select { width:100%; font-size:11px; padding:4px 7px; background:var(--surface2); }

nav { padding:6px 0; flex:1; }
.nav-group-btn { display:flex; align-items:center; justify-content:space-between; padding:9px 14px; color:var(--muted); font-size:12px; font-weight:600; cursor:pointer; user-select:none; border:none; background:none; width:100%; text-align:left; transition:all .15s; }
.nav-group-btn:hover { background:var(--surface2); color:var(--text); }
.nav-group-btn.open { color:var(--text); }
.nav-group-btn .arrow { font-size:10px; transition:transform .2s; }
.nav-group-btn.open .arrow { transform:rotate(90deg); }
.nav-sub { display:none; background:rgba(0,0,0,.15); }
.nav-sub.open { display:block; }
.nav-sub a { display:flex; align-items:center; gap:8px; padding:7px 14px 7px 36px; text-decoration:none; color:var(--muted); font-size:12px; font-weight:500; transition:all .15s; }
.nav-sub a:hover { background:var(--surface2); color:var(--text); }
.nav-sub a.active { background:rgba(79,124,255,.12); color:var(--accent); }
.nav-direct { display:flex; align-items:center; gap:8px; padding:9px 14px; text-decoration:none; color:var(--muted); font-size:12px; font-weight:600; transition:all .15s; }
.nav-direct:hover { background:var(--surface2); color:var(--text); }
.nav-direct.active { background:rgba(79,124,255,.12); color:var(--accent); }
.nav-sep { height:1px; background:var(--border); margin:4px 0; }
.nav-deconnexion { display:flex; align-items:center; gap:8px; padding:10px 14px; text-decoration:none; color:var(--muted); font-size:12px; font-weight:600; transition:all .15s; border-top:1px solid var(--border); margin-top:auto; }
.nav-deconnexion:hover { color:var(--red); }

/* MAIN */
.main { margin-left:var(--sw); flex:1; display:flex; flex-direction:column; }
.topbar { background:var(--surface); border-bottom:1px solid var(--border); padding:0 22px; height:52px; display:flex; align-items:center; justify-content:space-between; position:sticky; top:0; z-index:50; }
.topbar h2 { font-size:15px; font-weight:600; }
.topbar .actions { display:flex; gap:8px; }
.content { padding:22px; flex:1; }

/* CARDS, STATS, TABLES */
.card { background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:18px; }
.card-title { font-size:11px; font-weight:600; text-transform:uppercase; letter-spacing:.08em; color:var(--muted); margin-bottom:14px; display:flex; justify-content:space-between; align-items:center; }
.stats-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(155px,1fr)); gap:14px; margin-bottom:20px; }
.stat-card { background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:16px; }
.stat-label { font-size:10px; color:var(--muted); font-weight:600; text-transform:uppercase; letter-spacing:.06em; }
.stat-value { font-size:22px; font-weight:600; margin-top:5px; font-family:'IBM Plex Mono',monospace; }
.stat-icon { font-size:15px; margin-bottom:7px; }

.treasury-hero { display:flex; justify-content:space-between; gap:16px; align-items:flex-end; padding:18px 20px; border:1px solid var(--border); border-radius:14px; background:linear-gradient(135deg, rgba(79,124,255,.15), rgba(34,197,94,.08)); }
.treasury-kicker { font-size:10px; font-weight:700; color:#9fb2ff; text-transform:uppercase; letter-spacing:.12em; margin-bottom:6px; }
.treasury-hero h3 { font-size:24px; margin-bottom:6px; }
.treasury-hero p { color:var(--muted); max-width:680px; }
.treasury-hero-links { display:flex; gap:8px; flex-wrap:wrap; }
.treasury-grid { grid-template-columns:repeat(auto-fit,minmax(180px,1fr)); }
.treasury-card { position:relative; overflow:hidden; }
.treasury-card-highlight { border-color:rgba(79,124,255,.45); box-shadow:0 0 0 1px rgba(79,124,255,.08) inset; }
.treasury-meta { margin-top:8px; color:var(--muted); font-size:12px; line-height:1.4; }
.treasury-alerts { display:flex; flex-direction:column; gap:10px; }
.treasury-alert-card { display:flex; justify-content:space-between; gap:16px; align-items:flex-start; padding:14px 16px; border:1px solid rgba(245,158,11,.28); border-radius:12px; background:linear-gradient(135deg, rgba(245,158,11,.12), rgba(239,68,68,.08)); }
.treasury-alert-title { font-size:11px; text-transform:uppercase; letter-spacing:.08em; color:#f8c36a; font-weight:700; margin-bottom:6px; }
.treasury-alert-text { color:var(--text); }
.treasury-alert-total { font-size:20px; font-weight:600; }
.dashboard-two-cols { display:grid; grid-template-columns:1.6fr 1fr; gap:16px; }
.bank-pressure-list { display:flex; flex-direction:column; gap:10px; }
.bank-pressure-item { display:flex; justify-content:space-between; gap:12px; align-items:flex-start; padding:12px 14px; border:1px solid var(--border); border-radius:10px; background:rgba(255,255,255,.02); }
.bank-pressure-name { font-weight:600; }
.bank-pressure-meta { margin-top:4px; color:var(--muted); font-size:12px; }
.bank-pressure-total { font-size:18px; font-weight:600; }
.treasury-split { display:grid; grid-template-columns:repeat(3,1fr); gap:10px; margin-top:16px; }
.treasury-split > div { padding:12px; border-radius:10px; background:rgba(255,255,255,.02); border:1px solid var(--border); }
.treasury-split-label { color:var(--muted); font-size:11px; text-transform:uppercase; letter-spacing:.06em; margin-bottom:6px; }
.treasury-split-value { font-size:18px; font-weight:600; }
.weekly-forecast-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:12px; }
.weekly-forecast-card { border:1px solid var(--border); border-radius:12px; padding:14px; background:rgba(255,255,255,.02); }
.weekly-forecast-head { display:flex; justify-content:space-between; gap:8px; align-items:center; margin-bottom:14px; }
.weekly-forecast-total { font-size:24px; font-weight:600; margin-bottom:6px; }
.weekly-forecast-meta { color:var(--muted); font-size:12px; }

.table-wrap { overflow-x:auto; }
table { width:100%; border-collapse:collapse; font-size:13px; }
th { text-align:left; padding:9px 11px; font-size:10px; font-weight:600; text-transform:uppercase; letter-spacing:.06em; color:var(--muted); border-bottom:1px solid var(--border); white-space:nowrap; }
td { padding:9px 11px; border-bottom:1px solid var(--border); }
tr:last-child td { border-bottom:none; }
tr:hover td { background:rgba(255,255,255,.02); }

.badge { display:inline-block; padding:2px 8px; border-radius:20px; font-size:11px; font-weight:600; }
.badge-blue { background:rgba(79,124,255,.15); color:var(--accent); }
.badge-green { background:rgba(34,197,94,.15); color:var(--green); }
.badge-orange { background:rgba(245,158,11,.15); color:var(--orange); }
.badge-red { background:rgba(239,68,68,.15); color:var(--red); }

.btn { display:inline-flex; align-items:center; gap:6px; padding:7px 13px; border-radius:8px; border:none; font-size:13px; font-weight:500; cursor:pointer; text-decoration:none; transition:all .15s; font-family:inherit; }
.btn-primary { background:var(--accent); color:#fff; } .btn-primary:hover { background:#3d6aff; }
.btn-success { background:var(--green); color:#fff; } .btn-success:hover { background:#16a34a; }
.btn-secondary { background:var(--surface2); color:var(--text); border:1px solid var(--border); }
.btn-secondary:hover { border-color:var(--accent); color:var(--accent); }
.btn-danger { background:rgba(239,68,68,.1); color:var(--red); border:1px solid rgba(239,68,68,.2); }
.btn-sm { padding:5px 9px; font-size:12px; }

.form-grid { display:grid; grid-template-columns:1fr 1fr; gap:14px; }
.form-grid-3 { display:grid; grid-template-columns:1fr 1fr 1fr; gap:14px; }
.form-group { margin-bottom:14px; }
.form-group.span2 { grid-column:span 2; }
label { display:block; font-size:11px; font-weight:600; color:var(--muted); margin-bottom:5px; text-transform:uppercase; letter-spacing:.04em; }
input,select,textarea { width:100%; background:var(--surface2); border:1px solid var(--border); border-radius:8px; padding:8px 11px; color:var(--text); font-size:13px; font-family:inherit; transition:border-color .15s; }
input:focus,select:focus,textarea:focus { outline:none; border-color:var(--accent); }
select option { background:var(--surface2); }
.filters { background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:12px 16px; margin-bottom:16px; display:flex; flex-wrap:wrap; gap:10px; align-items:flex-end; }
.filters .form-group { margin-bottom:0; min-width:120px; flex:1; }
.filters label { font-size:10px; }
.filters input,.filters select { padding:6px 9px; font-size:12px; }

.selection-toolbar { display:inline-flex; align-items:center; gap:10px; padding:7px 10px; border-radius:10px; border:1px solid var(--border); background:var(--surface); flex-wrap:wrap; }
.selection-summary { display:flex; align-items:center; gap:8px; color:var(--text); font-size:12px; }
.selection-total { color:var(--green); font-weight:600; font-family:'IBM Plex Mono',monospace; }
.selection-actions { display:flex; align-items:center; gap:6px; }
.btn-icon { width:34px; height:34px; padding:0; justify-content:center; }
.btn-icon i { margin:0; }
.btn:disabled, .btn[aria-disabled="true"] { opacity:.45; cursor:not-allowed; pointer-events:none; border-color:var(--border); color:var(--muted); }

.alert { padding:10px 14px; border-radius:8px; font-size:13px; margin-bottom:16px; }
.alert-success { background:rgba(34,197,94,.1); border:1px solid rgba(34,197,94,.3); color:var(--green); }
.alert-error { background:rgba(239,68,68,.1); border:1px solid rgba(239,68,68,.3); color:var(--red); }

a.link { color:var(--accent); text-decoration:none; }
.mono { font-family:'IBM Plex Mono',monospace; }
.text-muted { color:var(--muted); }
.text-right { text-align:right; }
.mb-16 { margin-bottom:16px; }
.flex { display:flex; } .gap-8 { gap:8px; } .gap-12 { gap:12px; }
.justify-end { justify-content:flex-end; }

/* LOGIN page (no sidebar) */
.auth-wrap { width:100%; min-height:100vh; display:flex; align-items:center; justify-content:center; padding:20px; }
.auth-stack { width:100%; max-width:420px; display:flex; flex-direction:column; align-items:stretch; gap:10px; }
.auth-card { width:100%; max-width:420px; background:var(--surface); border:1px solid var(--border); border-radius:14px; padding:28px; }
.auth-card h1 { font-size:20px; margin-bottom:6px; }
.auth-card p.subtitle { font-size:12px; color:var(--muted); margin-bottom:18px; }
.auth-card .links { margin-top:18px; font-size:12px; text-align:center; }
.auth-card .links a { color:var(--accent); text-decoration:none; }
.auth-alert { width:100%; margin-bottom:0; }

/* ─── HAMBURGER + OVERLAY (mobile/tablette) ─────────────────────── */
.sidebar-toggle {
  display:none; align-items:center; justify-content:center;
  width:38px; height:38px; border-radius:8px; border:1px solid var(--border);
  background:var(--surface2); color:var(--text); cursor:pointer;
  font-size:16px; margin-right:10px; transition:all .15s;
}
.sidebar-toggle:hover { color:var(--accent); border-color:var(--accent); }
.sidebar-overlay {
  display:none; position:fixed; inset:0; background:rgba(0,0,0,.55);
  z-index:90; backdrop-filter:blur(2px);
}
.sidebar-overlay.open { display:block; }
.sidebar .sidebar-close {
  display:none; position:absolute; top:10px; right:10px;
  width:32px; height:32px; border-radius:6px; border:none;
  background:transparent; color:var(--muted); cursor:pointer; font-size:18px;
}
.sidebar .sidebar-close:hover { color:var(--red); }

/* ═════════════════════════════════════════════════════════════════
   RESPONSIVE
   - Desktop (par défaut)                : ≥ 1025 px  — sidebar fixe 230 px
   - Tablette                            : 641-1024 px — sidebar fixe 200 px,
                                           grilles condensées
   - Mobile                              : ≤ 640 px  — sidebar en drawer,
                                           tout en colonne unique
   ═════════════════════════════════════════════════════════════════ */

/* ─── TABLETTE (641 – 1024 px) ─────────────────────────────────── */
@media (max-width: 1024px) {
  :root { --sw:200px; }
  .topbar { padding:0 14px; }
  .content { padding:16px; }
  .form-grid-3 { grid-template-columns:1fr 1fr; }
  .form-group.span2 { grid-column:span 2; }
  .stats-grid { grid-template-columns:repeat(auto-fit,minmax(140px,1fr)); gap:12px; }
  .stat-value { font-size:20px; }
  .dashboard-two-cols { grid-template-columns:1fr; }
  .treasury-hero { flex-direction:column; align-items:flex-start; }
  .weekly-forecast-grid { grid-template-columns:repeat(2,1fr); }
  .filters { padding:10px 12px; gap:8px; }
  .filters .form-group { min-width:110px; }
  .card { padding:14px; border-radius:10px; }
  .nav-direct, .nav-group-btn { font-size:11px; padding:8px 12px; }
  .nav-sub a { font-size:11px; padding:6px 12px 6px 32px; }
  .soc-name { max-width:130px; }
}

/* ─── MOBILE (≤ 640 px) ────────────────────────────────────────── */
@media (max-width: 640px) {
  body { display:block; }   /* on quitte le flex pour empiler */

  /* Sidebar devient un drawer hors écran, qu'on fait glisser */
  .sidebar {
    width:260px; max-width:80vw;
    transform:translateX(-100%);
    transition:transform .25s ease-out;
    box-shadow:2px 0 20px rgba(0,0,0,.5);
  }
  .sidebar.open { transform:translateX(0); }
  .sidebar .sidebar-close { display:block; }
  .sidebar-toggle { display:inline-flex; }

  /* Le contenu principal prend toute la largeur */
  .main { margin-left:0; }
  .topbar {
    padding:0 12px; height:52px;
    /* sticky garde l'accès au menu en scroll */
  }
  .topbar h2 { font-size:14px; line-height:1.3; max-width:calc(100vw - 70px); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .content { padding:12px; }

  /* Grilles : tout en une colonne */
  .form-grid, .form-grid-3 { grid-template-columns:1fr; gap:10px; }
  .form-group.span2 { grid-column:span 1; }
  .form-group { margin-bottom:10px; }

  .stats-grid { grid-template-columns:1fr 1fr; gap:10px; margin-bottom:14px; }
  .stat-card { padding:12px; }
  .stat-value { font-size:18px; }
  .stat-label { font-size:9px; }
  .treasury-hero { padding:14px; }
  .treasury-hero h3 { font-size:18px; }
  .treasury-split { grid-template-columns:1fr; }
  .weekly-forecast-grid { grid-template-columns:1fr; }

  /* Cards & boutons */
  .card { padding:12px; border-radius:10px; }
  .card-title { font-size:10px; margin-bottom:10px; flex-wrap:wrap; gap:6px; }
  .btn { padding:8px 12px; font-size:13px; }   /* zone tactile plus grande */
  .btn-sm { padding:7px 10px; font-size:12px; }

  /* Inputs : 16 px pour bloquer le zoom auto iOS */
  input, select, textarea { font-size:16px; padding:10px 12px; }
  label { font-size:11px; }

  /* Filtres : empilés verticalement */
  .filters { flex-direction:column; align-items:stretch; padding:10px; }
  .filters .form-group { width:100%; min-width:0; }
  .filters .btn { width:100%; justify-content:center; }
  .selection-toolbar { width:100%; justify-content:space-between; }

  /* Tables : fines + scroll horizontal, header colonne sticky */
  table { font-size:12px; }
  th, td { padding:7px 8px; }
  .table-wrap { -webkit-overflow-scrolling:touch; }

  /* Boutons d'action en ligne (flex justify-end) -> wrap */
  .flex.justify-end { flex-wrap:wrap; }
  .flex.justify-end .btn { flex:1 1 auto; justify-content:center; }

  /* Alertes */
  .alert { font-size:12px; padding:9px 12px; }

  /* Login : ajuste padding card */
  .auth-card { padding:22px; border-radius:12px; }
  .auth-card h1 { font-size:18px; }
}

/* ─── TRÈS PETIT (≤ 380 px) ─────────────────────────────────────── */
@media (max-width: 380px) {
  .stats-grid { grid-template-columns:1fr; }
  .topbar h2 { font-size:13px; }
  .content { padding:10px; }
}

/* ─── Cellule "Actions" : boutons alignés côte à côte ─────────── */
.actions-cell { white-space:nowrap; }
.actions-cell > *,
.actions-cell form { display:inline-flex; vertical-align:middle; margin:0 3px 0 0; }
.actions-cell form:last-child,
.actions-cell > *:last-child { margin-right:0; }

/* ─── Largeurs de colonnes (table PMC) ──────────────────────────── */
.col-organisme { max-width:140px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.col-montant   { min-width:120px; }
.col-actions   { min-width:140px; white-space:nowrap; }

/* ─── ACCESSIBILITÉ : respect prefers-reduced-motion ───────────── */
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition:none; }
  .btn, .nav-direct, .nav-sub a, .nav-group-btn, input, select, textarea { transition:none; }
}

/* ─── Header / footer pour l'impression (cachés à l'écran) ───────── */
.print-only { display:none; }

/* ─── IMPRESSION ────────────────────────────────────────────────── */
@media print {
  @page { size: A4; margin: 25mm 12mm 22mm 12mm; }

  /* Fond blanc, texte noir, pas d'ombres ni de bordures de cards */
  html, body { background:#fff !important; color:#000 !important;
               font-family: 'Helvetica', Arial, sans-serif; font-size:11px; }
  .sidebar, .sidebar-overlay, .topbar,
  .filters, .selection-toolbar,
  .no-print, .actions-cell, .col-actions,
  .nav-direct, .nav-group-btn, .nav-sub, .nav-sep,
  button, .btn,
  .flex.justify-end,
  form.filters, .alert,
  #exp-tbl-bordereaux, #exp-tbl-pmc, #exp-tbl-fournisseurs, #exp-tbl-users,
  #exp-tbl-bordereaux ~ *, /* exports bars  */
  [id^="exp-tbl"]                                 { display:none !important; }

  .main { margin:0 !important; padding:0 !important; width:100%; }
  .content { padding:0 !important; }
  .card { border:none !important; box-shadow:none !important;
          padding:8px 0 !important; background:transparent !important;
          page-break-inside:avoid; break-inside:avoid; }
  .card-title { color:#000 !important; font-size:13px; font-weight:700;
                border-bottom:1px solid #000; padding-bottom:4px; margin-bottom:8px; }

  /* Tables : bordures fines + impression compacte */
  table { width:100% !important; border-collapse:collapse !important;
          font-size:10px; color:#000 !important; }
  thead { display: table-header-group; }   /* répété sur chaque page */
  tfoot { display: table-footer-group; }
  tr, td, th { page-break-inside: avoid; break-inside: avoid; }
  th, td { border:0.5px solid #444 !important; padding:3px 5px !important;
           color:#000 !important; background:#fff !important; }
  thead th { background:#eee !important; font-weight:700; }
  .badge { border:0.5px solid #444; padding:1px 4px; background:#fff !important;
           color:#000 !important; border-radius:2px; }
  .text-right { text-align:right; }
  .mono { font-family: 'Courier New', monospace; }

  /* En-tête et pied de page imprimés (visibles seulement en print) */
  .print-only { display:block !important; }
  .print-header { position: fixed; top: 0; left: 0; right: 0;
                  height: 22mm; padding: 4mm 12mm 0 12mm;
                  display:flex; align-items:center; gap:8mm;
                  border-bottom: 0.5px solid #000;
                  background:#fff !important; }
  .print-header img { height: 18mm; width:auto; object-fit:contain; }
  .print-header h1 { margin:0; font-size:16pt; font-weight:700; letter-spacing:0.5px; }

  .print-footer { position: fixed; bottom: 0; left: 0; right: 0;
                  height: 18mm; padding: 3mm 12mm 4mm 12mm;
                  border-top: 0.5px solid #000;
                  background:#fff !important; font-size:8.5pt; color:#000; }
  .print-footer .print-footer-line1 { display:flex; justify-content:space-between; gap:8mm; }
  .print-footer .print-footer-line1 .left { font-weight:600; }
  .print-footer .print-footer-line1 .center { flex:1; text-align:center; }
  .print-footer .print-footer-line2 { margin-top:1mm; text-align:center; color:#444; font-size:8pt; }

  /* Cacher les éléments interactifs spécifiques aux pages */
  select, input[type="checkbox"] { display:none !important; }
  /* sauf cellules d'affichage non interactives */
  input[type="text"], input[type="date"], input[type="number"], textarea {
    border:0 !important; background:transparent !important; padding:0 !important;
    color:#000 !important; -webkit-print-color-adjust: exact;
  }

  a, a:visited { color:#000 !important; text-decoration:none !important; }

  /* Calendrier FullCalendar : forcer fond clair */
  #calendar, .fc, .fc-view-harness, .fc-daygrid-day, .fc-col-header-cell {
    background:#fff !important; color:#000 !important;
  }
  .fc-toolbar-chunk button { display:none !important; }
  .fc-event { color:#000 !important; border:0.5px solid #444 !important; }
}
