/* ── Sudinox Design System ── */
:root {
  --primary: #1a232f;
  --accent: #d73b37;
  --blue: #0088ff;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a232f;
  --muted: #5d6060;
  --border: #e2e5e9;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', system-ui, -apple-system, Arial, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }
.hidden { display: none !important; }
.screen { display: none; } .screen.active { display: block; }
.container { max-width: 1200px; margin: 0 auto; padding: 24px; }

/* ── Login ── */
.login-container { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--primary); }
.login-logo { text-align: center; margin-bottom: 32px; }
.logo-img { height: 48px; }
.login-tagline { display: block; color: rgba(255,255,255,0.6); font-size: 13px; letter-spacing: 2px; text-transform: uppercase; margin-top: 8px; }
.login-card { background: var(--surface); border-radius: 12px; padding: 36px 32px; width: 400px; box-shadow: var(--shadow-lg); }
.login-card h2 { font-size: 22px; font-weight: 600; margin-bottom: 20px; text-align: center; }
.error-msg { background: #fef2f2; color: var(--danger); padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 16px; }
.auth-toggle { text-align: center; margin-top: 20px; font-size: 13px; color: var(--muted); }
.auth-toggle a { color: var(--accent); text-decoration: none; font-weight: 500; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
.form-group input, .form-group select { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; font-family: inherit; transition: border-color 0.15s; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,136,255,0.1); }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px; border: none; border-radius: var(--radius); font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.15s; font-family: inherit; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #2a3545; }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: #c0312d; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-ghost { background: transparent; color: rgba(255,255,255,0.7); padding: 6px 12px; font-size: 13px; }
.btn-ghost:hover { color: white; }
.btn-full { width: 100%; justify-content: center; }
.btn-large { padding: 14px 40px; font-size: 16px; margin-top: 24px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Header ── */
.app-header { display: flex; align-items: center; background: var(--primary); padding: 0 24px; height: 56px; position: sticky; top: 0; z-index: 100; box-shadow: 0 1px 4px rgba(0,0,0,0.15); }
.header-left { display: flex; align-items: center; gap: 16px; }
.header-logo { height: 28px; }
.header-title { color: rgba(255,255,255,0.5); font-size: 13px; letter-spacing: 1px; text-transform: uppercase; }
.header-nav { display: flex; gap: 4px; margin-left: 40px; }
.nav-link { color: rgba(255,255,255,0.6); text-decoration: none; font-size: 14px; font-weight: 500; padding: 16px 16px; border-bottom: 2px solid transparent; transition: all 0.15s; }
.nav-link:hover { color: white; }
.nav-link.active { color: white; border-bottom-color: var(--accent); }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-badge { color: rgba(255,255,255,0.8); font-size: 13px; }

/* ── Upload ── */
.upload-section { text-align: center; }
.upload-section h1 { font-size: 28px; font-weight: 700; margin-bottom: 8px; }
.subtitle { color: var(--muted); margin-bottom: 32px; }
.upload-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 16px; }
.drop-zone { border: 2px dashed var(--border); border-radius: 12px; padding: 32px 16px; text-align: center; cursor: pointer; transition: all 0.2s; position: relative; background: var(--surface); }
.drop-zone:hover, .drop-zone.dragover { border-color: var(--blue); background: #f0f7ff; }
.drop-zone.has-file { border-color: var(--success); border-style: solid; background: #f0fdf4; }
.drop-required { border-color: var(--accent); }
.drop-icon { font-size: 36px; margin-bottom: 8px; }
.drop-label { font-size: 16px; font-weight: 600; }
.drop-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.drop-file { font-size: 13px; color: var(--success); font-weight: 500; margin-top: 8px; }
.file-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ── Client details ── */
.client-details { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); padding: 0; margin: 16px 0; text-align: left; }
.client-details summary { padding: 12px 16px; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--muted); }
.client-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 0 16px 16px; }

/* ── Progress ── */
.progress-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin: 32px 0 12px; }
.progress-fill { height: 100%; background: var(--accent); width: 0; border-radius: 3px; transition: width 0.3s; animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }
.progress-text { text-align: center; font-size: 14px; color: var(--muted); }

/* ── Results ── */
.results-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 20px; text-align: center; box-shadow: var(--shadow); border-top: 3px solid var(--border); }
.stat-auto { border-top-color: var(--success); } .stat-review { border-top-color: var(--warning); }
.stat-manual { border-top-color: var(--danger); } .stat-total { border-top-color: var(--primary); }
.stat-num { display: block; font-size: 32px; font-weight: 700; }
.stat-auto .stat-num { color: var(--success); } .stat-review .stat-num { color: var(--warning); }
.stat-manual .stat-num { color: var(--danger); }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.download-bar { display: flex; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }

/* ── Tables ── */
.table-container { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.results-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.results-table th { background: var(--primary); color: white; font-weight: 500; text-align: left; padding: 10px 12px; position: sticky; top: 0; white-space: nowrap; }
.results-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.results-table tr:hover { background: #f8f9fb; }
.results-table tr.expandable { cursor: pointer; }
.results-table tr.bom-row { background: #fafbfc; }
.results-table tr.bom-row td { padding: 6px 12px 6px 40px; font-size: 12px; color: var(--muted); }

/* ── Badges ── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.badge-auto { background: #dcfce7; color: #166534; }
.badge-review { background: #fef3c7; color: #92400e; }
.badge-manual { background: #fee2e2; color: #991b1b; }

/* ── Catalog ── */
.catalog-bar { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.search-input { padding: 10px 16px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; width: 300px; font-family: inherit; }
.search-input:focus { outline: none; border-color: var(--blue); }
.famille-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 14px; border-radius: 20px; font-size: 12px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; transition: all 0.15s; }
.chip:hover, .chip.active { background: var(--primary); color: white; border-color: var(--primary); }
.catalog-stats { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 16px; padding: 12px; }
.pagination button { padding: 6px 12px; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; cursor: pointer; font-size: 13px; }
.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ── Tab switching ── */
.tab-content { display: none; } .tab-content.active { display: block; }

/* ── Interactive badges & Alt panel ── */
.badge-btn { cursor: pointer; border: none; transition: all 0.15s; }
.badge-btn:hover { filter: brightness(0.9); transform: scale(1.05); }
.btn-icon { background: none; border: 1px solid var(--border); border-radius: 6px; width: 28px; height: 28px; cursor: pointer; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; transition: all 0.15s; }
.btn-confirm { color: var(--success); } .btn-confirm:hover { background: var(--success); color: white; }
.confirmed-icon { color: var(--success); font-size: 16px; font-weight: bold; }
.col-actions { white-space: nowrap; }
.col-expand { width: 24px; cursor: pointer; }
.expand-icon { cursor: pointer; color: var(--blue); font-size: 12px; transition: transform 0.2s; }

.alt-panel td { padding: 0 !important; }
.alt-container { background: #f8f9fb; border: 1px solid var(--border); border-radius: 8px; margin: 8px 12px; padding: 16px; }
.alt-header { font-size: 13px; color: var(--muted); margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.alt-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.alt-item { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: white; border-radius: 6px; border: 1px solid var(--border); font-size: 13px; transition: all 0.15s; cursor: pointer; }
.alt-item:hover { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(0,136,255,0.1); }
.alt-selected { border-color: var(--success); background: #f0fdf4; }
.alt-rank { font-weight: 700; color: var(--muted); min-width: 28px; }
.alt-main { flex: 1; display: flex; gap: 8px; align-items: center; }
.alt-main code { background: #eee; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.alt-lib { color: var(--text); }
.alt-meta { display: flex; gap: 10px; font-size: 12px; color: var(--muted); }
.alt-famille { background: var(--bg); padding: 2px 8px; border-radius: 10px; }
.alt-score { font-weight: 600; }
.btn-small { padding: 4px 12px; font-size: 12px; }
.btn-selected { background: var(--success); color: white; border-color: var(--success); }

.alt-search { border-top: 1px solid var(--border); padding-top: 12px; }
.alt-search-input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; font-family: inherit; }
.alt-search-input:focus { outline: none; border-color: var(--blue); }
.alt-search-results { margin-top: 6px; max-height: 240px; overflow-y: auto; }
.alt-catalog-item { border-color: var(--blue); border-style: dashed; }
.alt-catalog-item:hover { background: #f0f7ff; }

/* ── Admin ── */
.admin-layout { display: grid; grid-template-columns: 380px 1fr; gap: 32px; margin-top: 24px; }
.admin-section { background: var(--surface); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.admin-section h2 { font-size: 16px; margin-bottom: 16px; color: var(--primary); }
.admin-form .form-group { margin-bottom: 12px; }
.admin-form-msg { margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 13px; }
.admin-form-msg.ok { background: #dcfce7; color: #166534; }
.admin-form-msg.ko { background: #fee2e2; color: #991b1b; }
.role-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.role-admin { background: var(--accent); color: white; }
.role-user { background: var(--border); color: var(--text); }
.admin-actions { display: flex; gap: 4px; }
.admin-actions button { padding: 4px 8px; font-size: 11px; border: 1px solid var(--border); background: var(--surface); border-radius: 4px; cursor: pointer; transition: all 0.15s; }
.admin-actions button:hover { background: var(--bg); }
.admin-actions button.danger:hover { background: var(--danger); color: white; border-color: var(--danger); }

@media (max-width: 900px) {
  .admin-layout { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════════════════
   TABLETTE (< 900px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .header-title { display: none; }     /* "DEVIS AUTOMATIQUE" caché */
  .container { padding: 16px; }
}

/* ═══════════════════════════════════════════════════════════
   MOBILE (< 640px) — iPhone et Android courants
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 640px) {

  /* — Header responsive — */
  .app-header { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .header-left { flex: 1 1 auto; min-width: 0; }
  .header-logo { height: 24px; }
  .header-title { display: none; }
  .header-nav {
    order: 3; flex: 1 1 100%; margin-left: 0;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    white-space: nowrap; scrollbar-width: none;
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 2px 0 0;
  }
  .header-nav::-webkit-scrollbar { display: none; }
  .nav-link { padding: 10px 12px; font-size: 13px; flex-shrink: 0; }
  .user-badge { font-size: 11px; max-width: 120px; overflow: hidden;
                text-overflow: ellipsis; white-space: nowrap; }
  .btn-ghost { padding: 4px 8px; font-size: 11px; }

  /* — Container — */
  .container { padding: 12px; }

  /* — Login — */
  .login-card { width: calc(100% - 32px); padding: 24px 20px; }
  .login-card h2 { font-size: 20px; }
  .login-logo { margin-bottom: 20px; }

  /* — Upload zones — */
  .upload-section h1 { font-size: 22px; }
  .subtitle { font-size: 13px; }
  .upload-grid { grid-template-columns: 1fr; gap: 12px; }
  .drop-zone { padding: 20px 12px; }
  .drop-icon { font-size: 28px; }
  .drop-label { font-size: 15px; }

  /* — Formulaire client — */
  .client-grid { grid-template-columns: 1fr; }
  .client-details summary { padding: 14px 12px; }

  /* — Bouton principal — */
  .btn-large { padding: 14px 24px; font-size: 15px; width: 100%; margin-top: 16px; }

  /* — Stats — */
  .results-summary { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 12px 8px; }
  .stat-num { font-size: 24px; }
  .stat-label { font-size: 10px; }

  /* — Barre de téléchargement — */
  .download-bar { flex-direction: column; gap: 8px; }
  .download-bar .btn { width: 100%; justify-content: center; }

  /* — Tableau résultats : scroll horizontal explicite — */
  .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .results-table { min-width: 720px; font-size: 12px; }
  .results-table th, .results-table td { padding: 8px 8px; }
  .results-table .col-desig { max-width: 200px; }

  /* — Panneau alternatives — */
  .alt-container { margin: 6px 0; padding: 12px 10px; }
  .alt-item { flex-wrap: wrap; gap: 6px; }
  .alt-item .alt-main { flex: 1 1 100%; }
  .alt-item .alt-meta { flex: 1 1 auto; gap: 8px; font-size: 11px; }
  .alt-rank { min-width: 24px; font-size: 11px; }
  .btn-small { padding: 6px 10px; font-size: 12px; }

  /* — Catalogue — */
  .catalog-bar { flex-direction: column; align-items: stretch; }
  .search-input { width: 100%; }
  .famille-chips { overflow-x: auto; -webkit-overflow-scrolling: touch;
                   flex-wrap: nowrap; padding-bottom: 4px; }
  .famille-chips::-webkit-scrollbar { height: 4px; }
  .chip { flex-shrink: 0; }
  #catalog-table { min-width: 800px; }
  .pagination button { padding: 8px 10px; }

  /* — Admin — */
  .admin-layout { gap: 16px; }
  .admin-section { padding: 16px 12px; }
  #admin-users-table { min-width: 540px; font-size: 12px; }
  .admin-actions { flex-wrap: wrap; gap: 2px; }
  .admin-actions button { font-size: 10px; padding: 4px 6px; }

  /* — Progress — */
  .progress-text { font-size: 13px; }
}

/* ═══════════════════════════════════════════════════════════
   PETIT MOBILE (< 400px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 400px) {
  .upload-section h1 { font-size: 18px; }
  .drop-zone { padding: 16px 8px; }
  .stat-num { font-size: 20px; }
  .header-logo { height: 20px; }
}
