/* ============================================================
   FacturX Manager — Feuille de style principale
   ============================================================ */

:root {
  --primary:      #1a5abf;
  --primary-dark: #134a9f;
  --primary-light:#e8f0fe;
  --success:      #1e7e34;
  --success-light:#e6f4ea;
  --danger:       #c62828;
  --danger-light: #fce8e6;
  --warning:      #f57c00;
  --warning-light:#fff8e1;
  --gray-50:      #fafafa;
  --gray-100:     #f5f5f5;
  --gray-200:     #eeeeee;
  --gray-400:     #bdbdbd;
  --gray-600:     #757575;
  --gray-800:     #424242;
  --text:         #212121;
  --sidebar-w:    240px;
  --radius:       8px;
  --shadow:       0 1px 4px rgba(0,0,0,.10);
  --shadow-md:    0 4px 16px rgba(0,0,0,.12);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--gray-100);
  display: flex;
  min-height: 100vh;
}

/* ─── SIDEBAR ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: #0f2744;
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-logo  { font-size: 24px; }
.sidebar-title { font-size: 15px; font-weight: 700; line-height: 1.2; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.nav-section {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.4);
  padding: 16px 16px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: rgba(255,255,255,.8);
  text-decoration: none;
  border-radius: 0;
  transition: background .15s, color .15s;
  cursor: pointer;
}
.nav-item:hover    { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active   { background: var(--primary); color: #fff; }
.nav-item-action   { color: rgba(100,180,255,.9); }
.nav-item-danger   { color: rgba(255,120,100,.9); }
.nav-icon          { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer    { border-top: 1px solid rgba(255,255,255,.1); padding: 14px 16px; }
.sidebar-user      { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 32px; height: 32px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}
.user-name  { font-weight: 600; font-size: 13px; }
.user-role  { font-size: 11px; color: rgba(255,255,255,.5); }

/* ─── MAIN ──────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky; top: 0; z-index: 50;
}
.sidebar-toggle { display: none; background: none; border: none; font-size: 22px; cursor: pointer; }
.topbar-right   { margin-left: auto; color: var(--gray-600); font-size: 13px; }
.page-content   { padding: 24px; }

/* ─── PAGE HEADER ───────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-header h2 { font-size: 20px; font-weight: 700; }

/* ─── CARDS ──────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--gray-200);
}
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body      { padding: 20px; }
.card-body.p-0  { padding: 0; }
.mb-4           { margin-bottom: 20px; }

/* ─── KPI ────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.kpi-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.kpi-value  { font-size: 20px; font-weight: 700; }
.kpi-label  { font-size: 12px; color: var(--gray-600); }
.kpi-danger { border-left: 3px solid var(--danger); }
.kpi-mini-grid { display: flex; gap: 16px; flex-wrap: wrap; }
.kpi-mini {
  background: #fff;
  border-radius: var(--radius);
  padding: 10px 18px;
  box-shadow: var(--shadow);
  font-size: 14px;
}

/* ─── DASHBOARD GRID ─────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
}
@media (max-width:900px) { .dashboard-grid { grid-template-columns: 1fr; } }

/* ─── TABLES ─────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; text-align: left; }
.table th { font-size: 12px; font-weight: 600; text-transform: uppercase;
            letter-spacing: .05em; color: var(--gray-600);
            background: var(--gray-50); border-bottom: 1px solid var(--gray-200); }
.table td { border-bottom: 1px solid var(--gray-200); vertical-align: middle; }
.table-hover tbody tr:hover { background: var(--primary-light); }
.text-right { text-align: right !important; }
.text-center{ text-align: center !important; }
.row-danger { background: #fff8f8; }

/* ─── BADGES ─────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-draft     { background: var(--gray-200);      color: var(--gray-800); }
.badge-sent      { background: #e3f2fd;               color: #1565c0; }
.badge-paid      { background: var(--success-light);  color: var(--success); }
.badge-late      { background: var(--danger-light);   color: var(--danger); }
.badge-cancelled { background: var(--gray-200);        color: var(--gray-600); }
.badge-avoir     { background: #f3e5f5;                color: #6a1b9a; }
.badge-b2b       { background: #e3f2fd;                color: #1565c0; }
.badge-b2c       { background: #fce4ec;                color: #c62828; }
.badge-admin     { background: var(--primary-light);   color: var(--primary-dark); }
.badge-user      { background: var(--gray-200);         color: var(--gray-800); }

/* ─── BUTTONS ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 8px 16px;
  border-radius: 6px; border: none; cursor: pointer;
  font-size: 13px; font-weight: 500;
  text-decoration: none; white-space: nowrap;
  transition: background .15s, opacity .15s;
}
.btn-primary  { background: var(--primary);  color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline  { background: #fff; color: var(--gray-800); border: 1px solid var(--gray-400); }
.btn-outline:hover { background: var(--gray-100); }
.btn-success  { background: var(--success); color: #fff; }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-full     { width: 100%; }
.btn-sm       { padding: 4px 10px; font-size: 12px; }
.btn-icon     { background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px; }

/* ─── FORMS ──────────────────────────────────────────────── */
.form-group    { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.form-group-lg { flex: 2; }
.form-row      { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--gray-600); }
.form-control {
  padding: 8px 12px;
  border: 1px solid var(--gray-400);
  border-radius: 6px;
  font-size: 14px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,90,191,.12); }
.form-control-sm { padding: 5px 8px; font-size: 13px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--gray-200); }
.input-suffix  { display: flex; align-items: center; gap: 4px; }
.input-suffix span { color: var(--gray-600); font-size: 13px; }
.section-title { font-size: 14px; font-weight: 600; color: var(--primary); margin: 20px 0 12px;
                 padding-bottom: 6px; border-bottom: 2px solid var(--primary-light); }

/* ─── FILTER BAR ─────────────────────────────────────────── */
.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filter-bar .form-control { width: auto; flex: 1; min-width: 160px; }

/* ─── ALERTS ─────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin: 0 24px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.alert button { background: none; border: none; cursor: pointer; font-size: 18px; line-height: 1; }
.alert-success { background: var(--success-light); color: var(--success); border-left: 4px solid var(--success); }
.alert-error   { background: var(--danger-light);  color: var(--danger);  border-left: 4px solid var(--danger); }
.alert-warning { background: var(--warning-light); color: var(--warning); border-left: 4px solid var(--warning); }
.alert-info    { background: var(--primary-light); color: var(--primary); border-left: 4px solid var(--primary); }

/* ─── TABS ────────────────────────────────────────────────── */
.tabs  { display: flex; gap: 4px; border-bottom: 2px solid var(--gray-200); }
.tab   { padding: 8px 16px; text-decoration: none; color: var(--gray-600);
         border-radius: 6px 6px 0 0; font-size: 13px; font-weight: 500; }
.tab:hover { background: var(--gray-100); }
.tab.active { color: var(--primary); border-bottom: 2px solid var(--primary); margin-bottom: -2px; background: #fff; }

/* ─── INVOICE FORM LAYOUT ─────────────────────────────────── */
.invoice-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  align-items: start;
}
.invoice-sidebar .sticky-card { position: sticky; top: 60px; }
.total-recap { display: flex; flex-direction: column; gap: 8px; }
.total-line  { display: flex; justify-content: space-between; font-size: 14px; }
.total-line-tva { font-size: 13px; color: var(--gray-600); }
.total-line-main {
  font-size: 18px; font-weight: 700; color: var(--primary);
  border-top: 2px solid var(--primary);
  padding-top: 8px; margin-top: 4px;
}
.drag-handle { cursor: grab; color: var(--gray-400); font-size: 18px; }
.ligne-total { min-width: 100px; }
@media (max-width: 900px) {
  .invoice-layout { grid-template-columns: 1fr; }
}

/* ─── INVOICE PREVIEW ─────────────────────────────────────── */
.invoice-preview {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 40px;
  max-width: 900px;
}
.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
  gap: 20px;
}
.preview-logo      { max-height: 70px; max-width: 180px; object-fit: contain; }
.preview-company-name { font-size: 20px; font-weight: 700; color: var(--primary); }
.preview-seller-info { font-size: 12px; color: var(--gray-600); margin-top: 6px; line-height: 1.7; }
.preview-docinfo   { text-align: right; }
.preview-doc-type  { font-size: 28px; font-weight: 800; color: var(--primary); margin-bottom: 8px; }
.preview-meta      { margin-left: auto; font-size: 13px; }
.preview-meta td   { padding: 2px 8px 2px 0; text-align: left; }
.preview-client-box {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  padding: 12px 16px;
  margin-top: 14px;
  text-align: left;
  min-width: 200px;
}
.preview-client-label { font-size: 10px; font-weight: 700; text-transform: uppercase;
                         color: var(--gray-600); letter-spacing: .08em; margin-bottom: 4px; }
.preview-client-name  { font-size: 15px; font-weight: 700; margin-bottom: 4px; }

.preview-lines    { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.preview-lines th {
  background: var(--primary);
  color: #fff;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.preview-lines td { padding: 10px 12px; border-bottom: 1px solid var(--gray-200); font-size: 13px; }
.preview-lines tbody tr:nth-child(even) { background: var(--gray-50); }

.preview-totals {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.preview-tva-recap table { font-size: 12px; border-collapse: collapse; }
.preview-tva-recap th, .preview-tva-recap td { padding: 4px 12px 4px 0; }
.preview-tva-recap th { color: var(--gray-600); font-weight: 600; }
.preview-total-box { min-width: 240px; }
.total-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; border-bottom: 1px solid var(--gray-200); }
.total-row-main { font-size: 18px; font-weight: 800; color: var(--primary); border: none; padding-top: 10px; }

.preview-notes { font-size: 12px; color: var(--gray-600); margin-bottom: 8px; }
.preview-facturx-badge {
  margin-top: 20px;
  padding: 8px 14px;
  background: var(--primary-light);
  border-radius: 6px;
  font-size: 11px;
  color: var(--primary);
  font-weight: 500;
  text-align: center;
}

/* ─── LOGIN ───────────────────────────────────────────────── */
body.login-body { display: flex; align-items: center; justify-content: center;
                   background: #0f2744; min-height: 100vh; }
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo     { font-size: 48px; text-align: center; margin-bottom: 8px; }
.login-title    { font-size: 22px; font-weight: 800; text-align: center; margin-bottom: 4px; }
.login-subtitle { font-size: 13px; color: var(--gray-600); text-align: center; margin-bottom: 24px; }

/* ─── MISC ────────────────────────────────────────────────── */
.text-muted  { color: var(--gray-600); }
.text-danger { color: var(--danger); }
.text-small  { font-size: 12px; }
.mt-3        { margin-top: 12px; }
.mt-4        { margin-top: 20px; }
.py-4        { padding: 16px 0; }
.link-strong { font-weight: 600; color: var(--primary); text-decoration: none; }
.link-strong:hover { text-decoration: underline; }
code { background: var(--gray-100); padding: 2px 6px; border-radius: 4px; font-size: 12px; }

/* ─── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 720px) {
  .sidebar        { transform: translateX(-100%); }
  .sidebar.open   { transform: translateX(0); }
  .main-content   { margin-left: 0; }
  .sidebar-toggle { display: block; }
  .invoice-preview { padding: 20px; }
  .page-content   { padding: 16px; }
  .kpi-grid       { grid-template-columns: 1fr 1fr; }
}

/* ─── MODE DÉMO ──────────────────────────────────────────── */
.badge-demo   { background: #fff3cd; color: #856404; border: 1px solid #ffc107; }
.btn-demo     { background: #f57c00; color: #fff; }
.btn-demo:hover { background: #e65100; }

/* ─── SIREN LOOKUP ───────────────────────────────────────── */
.siren-lookup-bar {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  background: var(--primary-light);
  padding: 14px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.siren-result-box {
  background: #fff;
  border: 1px solid var(--gray-300, #ddd);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.siren-choice-btn {
  text-align: left;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  transition: background .15s;
  width: 100%;
}
.siren-choice-btn:hover { background: var(--primary-light); }

/* ─── 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; inset:0;
  background:var(--gray-400); border-radius:26px; transition:.3s;
}
.toggle-slider:before {
  content:''; position:absolute;
  width:20px; height:20px; left:3px; bottom:3px;
  background:#fff; border-radius:50%; transition:.3s;
}
.toggle-switch input:checked + .toggle-slider { background:var(--primary); }
.toggle-switch input:checked + .toggle-slider:before { transform:translateX(22px); }

/* ─── VIES VAT VALIDATION ────────────────────────────────── */
.vat-valid, .vat-invalid, .vat-unknown {
  padding: 10px 14px;
  border-radius: 6px;
  line-height: 1.6;
  font-size: 12px;
}
.vat-valid   { background: var(--success-light); color: var(--success);  border-left: 3px solid var(--success); }
.vat-invalid { background: var(--danger-light);  color: var(--danger);   border-left: 3px solid var(--danger); }
.vat-unknown { background: var(--warning-light); color: var(--warning);  border-left: 3px solid var(--warning); }

/* ─── VALIDATION CHECKS ──────────────────────────────────── */
.chk-item { padding:3px 0; font-size:12px; }
.chk-ok   { color: var(--success); }
.chk-ko   { color: var(--danger); }
.chk-warn { color: var(--warning); }

/* ─── MODAL ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-body   { padding: 20px; }
.modal-footer {
  padding: 14px 20px; border-top: 1px solid var(--gray-200);
  display: flex; gap: 10px; justify-content: flex-end;
}
