:root{
  font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif;
  color-scheme:dark;

  --bg:#0b1220;
  --bg-soft:#0f172a;
  --surface:#111827;
  --surface-2:#172033;
  --surface-3:#1e293b;
  --border:#2a374c;
  --border-soft:#233047;

  --text:#e8eef8;
  --text-strong:#ffffff;
  --muted:#94a3b8;

  --primary:#3b82f6;
  --primary-hover:#2563eb;
  --secondary:#475569;
  --danger:#dc2626;

  --input:#0f172a;
  --shadow:0 10px 28px rgba(0,0,0,.22);

  --tag:#24324d;
  --status-order:#123c2c;
  --status-lost:#4b1d24;
  --status-wait:#4a3714;
  --status-done:#242d55;

  --info-bg:#10213b;
  --info-border:#245292;
  --warning-bg:#362c12;
  --warning-border:#a16207;
  --error-bg:#451a1a;
  --error-text:#fecaca;
  --note-bg:#111c2e;
  --note-extra-bg:#33280f;
}

html[data-theme="light"]{
  color-scheme:light;

  --bg:#f3f5f7;
  --bg-soft:#f8fafc;
  --surface:#ffffff;
  --surface-2:#f8fafc;
  --surface-3:#eef2f7;
  --border:#e5e7eb;
  --border-soft:#e5e7eb;

  --text:#1f2937;
  --text-strong:#111827;
  --muted:#6b7280;

  --primary:#2563eb;
  --primary-hover:#1d4ed8;
  --secondary:#374151;
  --danger:#b91c1c;

  --input:#ffffff;
  --shadow:0 2px 10px rgba(0,0,0,.035);

  --tag:#eef2ff;
  --status-order:#dcfce7;
  --status-lost:#fee2e2;
  --status-wait:#fef3c7;
  --status-done:#e0e7ff;

  --info-bg:#eff6ff;
  --info-border:#bfdbfe;
  --warning-bg:#fffbeb;
  --warning-border:#fbbf24;
  --error-bg:#fee2e2;
  --error-text:#991b1b;
  --note-bg:#f8fafc;
  --note-extra-bg:#fffbeb;
}

*{box-sizing:border-box}

html,body{
  background:var(--bg);
  color:var(--text);
}

body{
  margin:0;
  min-height:100vh;
}

header{
  background:#08111f;
  color:#fff;
  padding:14px 24px;
  display:flex;
  gap:25px;
  align-items:center;
  justify-content:space-between;
  position:sticky;
  top:0;
  z-index:5;
  border-bottom:1px solid #1f2a3d;
  box-shadow:0 4px 20px rgba(0,0,0,.16);
}

html[data-theme="light"] header{
  background:#101827;
  border-bottom:0;
}

.brand strong{font-size:20px}
.brand span{display:block;font-size:12px;color:#aeb8c7}

nav{
  display:flex;
  gap:15px;
  align-items:center;
  flex-wrap:wrap;
}

a{
  color:#60a5fa;
  text-decoration:none;
}

a:hover{color:#93c5fd}

nav a{color:#e5e7eb}
nav a:hover{color:#fff}

main{
  max-width:1550px;
  margin:0 auto;
  padding:24px;
}

.title-row{
  display:flex;
  justify-content:space-between;
  gap:20px;
  align-items:center;
  margin-bottom:18px;
}

h1{margin:0 0 4px;color:var(--text-strong)}
h2{margin-top:0;color:var(--text-strong)}
h3{color:var(--text-strong)}

.card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:12px;
  padding:18px;
  margin-bottom:18px;
  box-shadow:var(--shadow);
}

.inner-card{
  box-shadow:none;
  background:var(--surface-2);
  margin:0;
}

.button,button{
  background:var(--primary);
  color:white;
  border:0;
  border-radius:8px;
  padding:10px 14px;
  font-weight:650;
  cursor:pointer;
  display:inline-block;
  transition:.15s ease;
}

.button:hover,button:hover{
  background:var(--primary-hover);
  color:#fff;
}

.secondary{background:var(--secondary)}
.danger{background:var(--danger)}

.actions{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

.kpis{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:14px;
  margin-bottom:18px;
}

.small-kpis{
  grid-template-columns:repeat(auto-fit,minmax(160px,1fr));
}

.kpi{
  background:var(--surface);
  color:var(--text-strong);
  border:1px solid var(--border);
  border-radius:12px;
  padding:18px;
  box-shadow:var(--shadow);
}

.kpi span,.kpi small{
  display:block;
  color:var(--muted);
}

.kpi b{
  font-size:23px;
  display:block;
  margin:7px 0;
}

.table-wrap{overflow:auto}

table{
  width:100%;
  border-collapse:collapse;
  font-size:14px;
}

th,td{
  text-align:left;
  padding:10px 9px;
  border-bottom:1px solid var(--border);
  vertical-align:top;
}

th{
  color:var(--muted);
  font-size:11px;
  text-transform:uppercase;
  white-space:nowrap;
}

tbody tr:hover{
  background:rgba(148,163,184,.06);
}

.tag{
  background:var(--tag);
  color:var(--text);
  border-radius:999px;
  padding:3px 8px;
  font-size:12px;
  white-space:nowrap;
}

.status-commande{background:var(--status-order)}
.status-perdu{background:var(--status-lost)}
.status-en_attente{background:var(--status-wait)}
.status-termine{background:var(--status-done)}

.filters{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  margin-bottom:12px;
}

.filters a{
  background:var(--surface);
  border:1px solid var(--border);
  padding:8px 11px;
  border-radius:8px;
  color:var(--text);
}

.filters a:hover{
  background:var(--surface-3);
}

.filters a.active{
  background:var(--primary);
  color:#fff;
  border-color:var(--primary);
}

.search{
  display:flex;
  gap:8px;
  margin-bottom:12px;
  align-items:center;
}

.search input{max-width:420px}
.search select{max-width:180px}

.form-card{
  max-width:720px;
  margin:auto;
}

label{
  display:block;
  font-weight:600;
  margin-bottom:14px;
  color:var(--text);
}

input,select,textarea{
  width:100%;
  padding:10px;
  border:1px solid var(--border);
  border-radius:7px;
  background:var(--input);
  color:var(--text);
  margin-top:5px;
  font:inherit;
  outline:none;
}

input::placeholder,textarea::placeholder{
  color:#718096;
}

input:focus,select:focus,textarea:focus{
  border-color:#3b82f6;
  box-shadow:0 0 0 3px rgba(59,130,246,.14);
}

select option{
  background:var(--input);
  color:var(--text);
}

.check{
  display:flex;
  gap:8px;
  align-items:center;
}

.check input{
  width:auto;
  margin:0;
}

.inline{
  display:flex;
  gap:7px;
  align-items:end;
  margin:4px 0;
}

.inline label{margin:0}
.inline input{min-width:105px}

.smallbtn{
  padding:7px 9px;
  font-size:12px;
}

.actions-cell{min-width:180px}

.grid2{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:18px;
}

.contact{
  padding:10px 0;
  border-bottom:1px solid var(--border);
}

.contact summary{cursor:pointer}

.compact{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px;
}

.top-gap{margin-top:12px}

.rowform{
  display:grid;
  gap:8px;
  align-items:end;
  margin-bottom:16px;
}

.rowform.three{grid-template-columns:220px 1fr 120px}
.rowform.four{grid-template-columns:160px 120px 1fr 120px}
.rowform.six{grid-template-columns:150px 1fr 1.4fr 130px 220px 120px}
.rowform input,.rowform select{margin:0}

.summary{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:10px;
  margin-bottom:16px;
}

.summary div{
  background:var(--surface-2);
  border:1px solid var(--border-soft);
  border-radius:9px;
  padding:12px;
}

.summary span{
  display:block;
  color:var(--muted);
  font-size:12px;
}

.summary b{
  display:block;
  font-size:18px;
  margin-top:4px;
  color:var(--text-strong);
}

.tabs{
  display:flex;
  gap:8px;
  overflow:auto;
  margin-bottom:14px;
  position:sticky;
  top:60px;
  background:var(--bg);
  padding:8px 0;
  z-index:4;
}

.tabs a{
  white-space:nowrap;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:8px;
  padding:8px 10px;
  color:var(--text);
}

.note{
  border-left:4px solid var(--primary);
  padding:8px 12px;
  background:var(--note-bg);
  margin:8px 0;
}

.note-extra{
  border-left-color:#d97706;
  background:var(--note-extra-bg);
}

.muted{
  color:var(--muted);
  font-weight:400;
}

.negative{color:#f87171!important}

html[data-theme="light"] .negative{
  color:#b91c1c!important;
}

.error{
  background:var(--error-bg);
  padding:10px;
  border-radius:8px;
  color:var(--error-text);
}

.login{
  max-width:420px;
  margin:10vh auto;
}

.mobile-entry{
  max-width:720px;
  margin:auto;
}

.big{
  width:100%;
  font-size:18px;
  padding:14px;
}

.entry{
  display:flex;
  justify-content:space-between;
  gap:15px;
  align-items:center;
  padding:12px 0;
  border-bottom:1px solid var(--border);
}

.entry span{
  display:block;
  color:var(--muted);
  font-size:13px;
}

.soft-box,.info-box,.warning-box{
  padding:12px;
  border-radius:9px;
  margin:12px 0;
}

.soft-box,.info-box{
  background:var(--info-bg);
  border:1px solid var(--info-border);
}

.warning-box{
  background:var(--warning-bg);
  border:1px solid var(--warning-border);
}

.upload-form{
  display:flex;
  gap:8px;
  align-items:center;
  margin-bottom:14px;
}

.upload-form input{margin:0}

.file-list{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.file-list a,.file-chip{
  background:var(--surface-2);
  border:1px solid var(--border);
  padding:9px 10px;
  border-radius:8px;
}

.gallery{
  display:grid;
  grid-template-columns:repeat(auto-fill,minmax(140px,1fr));
  gap:10px;
}

.gallery a{display:block}

.gallery img{
  width:100%;
  height:130px;
  object-fit:cover;
  border-radius:9px;
  border:1px solid var(--border);
}

hr{
  border:0;
  border-top:1px solid var(--border);
  margin:24px 0;
}

.theme-toggle{
  width:38px;
  height:34px;
  min-width:38px;
  padding:0;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius:9px;
  background:#172033;
  border:1px solid #2a374c;
  color:#fff;
  font-size:17px;
}

.theme-toggle:hover{
  background:#233047;
}

@media(max-width:1050px){
  .kpis{grid-template-columns:1fr 1fr}
  .rowform.six{grid-template-columns:1fr 1fr 1fr}
  .summary{grid-template-columns:1fr 1fr}
}

@media(max-width:800px){
  header{
    align-items:flex-start;
    flex-direction:column;
    position:static;
  }
  nav{font-size:13px}
  .grid2{grid-template-columns:1fr}
  .rowform.three,.rowform.four,.rowform.six{grid-template-columns:1fr 1fr}
  .title-row{
    align-items:flex-start;
    flex-direction:column;
  }
  main{padding:14px}
  .tabs{top:0}
  .compact{grid-template-columns:1fr}
  .upload-form{
    align-items:stretch;
    flex-direction:column;
  }
}

@media(max-width:520px){
  .kpis{grid-template-columns:1fr}
  .summary{grid-template-columns:1fr 1fr}
  .rowform.three,.rowform.four,.rowform.six{grid-template-columns:1fr}
  .actions{
    width:100%;
    flex-direction:column;
  }
  .actions .button{
    width:100%;
    text-align:center;
  }
  .entry{align-items:flex-start}
  .gallery{grid-template-columns:repeat(2,1fr)}
}


/* Navigation retour */
.back-row {
  max-width: 1500px;
  margin: 14px auto -4px;
  padding: 0 18px;
}

.back-button {
  cursor: pointer;
  width: auto;
}
