@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@500;600;700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --surface-alt: #F7F9FC;
  --ink: #16233A;
  --ink-soft: #5B6472;
  --border: #E3E6EB;
  --border-soft: #ECEFF3;
  --sidebar: #0F2D4F;
  --sidebar-hover: #163E68;
  --primary: #2263AF;
  --accent: #ED7C2F;
  --danger: #D64545;
  --success: #2E9E6D;
  --warning: #E0873E;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}
h1, h2, h3, .display { font-family: 'Oswald', sans-serif; font-weight: 600; }
a { color: var(--primary); text-decoration: none; }
::-webkit-scrollbar { height: 8px; width: 8px; }
::-webkit-scrollbar-thumb { background: #D8DCE3; border-radius: 4px; }

/* ---------------- Layout ---------------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 226px; background: var(--sidebar); flex-shrink: 0;
  display: flex; flex-direction: column; padding: 18px 0;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { padding: 14px 18px 18px; border-bottom: 1px solid #1B3F66; margin-bottom: 10px; display: flex; flex-direction: column; gap: 10px; }
.sidebar-brand .logo-chip { background: #fff; border-radius: 8px; padding: 8px 12px; display: inline-flex; align-items: center; width: fit-content; }
.sidebar-brand .logo-chip img { height: 26px; width: auto; display: block; }
.sidebar-brand .tag { color: #7E97B5; font-size: 10px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.sidebar-nav { flex: 1; overflow-y: auto; }
.nav-group-label { padding: 14px 18px 4px; font-size: 10px; font-weight: 700; color: #5B6472; text-transform: uppercase; letter-spacing: .06em; }
.nav-group-label:first-child { padding-top: 6px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 18px;
  color: #C4CAD4; font-size: 13.5px; font-weight: 500; border-left: 3px solid transparent;
}
.sidebar-nav a:hover { background: var(--sidebar-hover); }
.sidebar-nav a.active { background: var(--sidebar-hover); color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.sidebar-nav .icon { width: 16px; text-align: center; }
.sidebar-foot { padding: 12px 18px 0; border-top: 1px solid #262F3D; margin-top: 10px; font-size: 11px; color: #5B6472; }

.main { flex: 1; min-width: 0; }
.topbar { display: none; background: var(--sidebar); color: #fff; padding: 10px 16px; align-items: center; gap: 10px; }
.content { padding: 24px clamp(14px, 1.8vw, 32px) 60px; max-width: 2200px; width: 100%; }

@media (max-width: 880px) {
  .sidebar { display: none; position: fixed; z-index: 50; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .sidebar.open { display: flex; }
  .topbar { display: flex; }
  .content { padding: 16px; }
}

/* ---------------- Header ---------------- */
.page-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.eyebrow { font-size: 11.5px; font-weight: 700; color: var(--accent); letter-spacing: .08em; text-transform: uppercase; margin-bottom: 3px; }
.page-header h1 { font-size: 24px; margin: 0; color: var(--ink); }

/* ---------------- Cards / KPIs ---------------- */
.kpi-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; flex: 1 1 190px; min-width: 170px; border-top: 3px solid var(--primary); }
.kpi .label { font-size: 11.5px; color: #7A8394; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpi .value { font-family: 'Oswald', sans-serif; font-size: 26px; font-weight: 600; color: var(--ink); margin-top: 4px; }
.kpi .sub { font-size: 12px; color: #8891A0; margin-top: 3px; }

.group-label { font-size: 12px; font-weight: 700; color: #7A8394; text-transform: uppercase; letter-spacing: .05em; margin: 4px 0 10px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 16px; }
.card-title { font-weight: 600; font-size: 14px; margin-bottom: 12px; color: var(--ink); }

/* ---------------- Buttons ---------------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border-radius: 7px; padding: 9px 16px; font-weight: 600; font-size: 13.5px; cursor: pointer; border: 1px solid transparent; font-family: 'Inter', sans-serif; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-accent { background: var(--accent); color: var(--ink); border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--primary); border-color: #C7D2E0; }
.btn-danger { background: #fff; color: var(--danger); border-color: #F3C4C4; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: none; cursor: pointer; color: #5B6472; padding: 4px; }
.icon-btn.danger { color: var(--danger); }

/* ---------------- Forms ---------------- */
.grid { display: grid; gap: 0 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.field { margin-bottom: 13px; }
.field.span-2 { grid-column: span 2; }
.field.span-3 { grid-column: span 3; }
.field label { display: block; font-size: 12px; font-weight: 600; color: #5B6472; margin-bottom: 5px; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], input[type=email], select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 6px; border: 1px solid #D8DCE3; font-size: 13.5px;
  font-family: 'Inter', sans-serif; color: var(--ink); background: #fff;
}
textarea { min-height: 70px; resize: vertical; }
input:disabled, select:disabled { background: #F0F2F5; color: #9AA3B0; }
.help { font-size: 11.5px; color: #8891A0; margin-top: 4px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.checkbox-row { display: flex; align-items: center; gap: 6px; font-size: 12.5px; margin-top: 8px; }

.toolbar { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search-box { position: relative; flex: 1 1 260px; max-width: 340px; }
.search-box input { padding-left: 32px; }
.search-box .icon { position: absolute; left: 10px; top: 10px; color: #9AA3B0; }

/* ---------------- Table ---------------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data thead tr { background: var(--surface-alt); border-bottom: 1px solid var(--border); }
table.data th { text-align: left; padding: 10px 14px; font-size: 11px; font-weight: 700; color: #7A8394; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
table.data td { padding: 10px 14px; color: #2B3442; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
table.data tbody tr:hover { background: #FAFBFC; cursor: pointer; }
table.data td.right, table.data th.right { text-align: right; }
table.data-compact { font-size: 11.5px; }
table.data-compact th { padding: 7px 5px; font-size: 9.5px; }
table.data-compact td { padding: 6px 5px; }
table.data-compact .plate { font-size: 10px; padding: 2px 5px; letter-spacing: 0; }
table.data-compact .badge { font-size: 9.5px; padding: 2px 6px; }
.col-hidden { display: none !important; }

.col-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0,0,0,.12); padding: 14px 16px; width: 300px;
}
.col-panel-title { font-size: 11px; font-weight: 700; color: #7A8394; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.col-panel label { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 5px 0; cursor: pointer; color: var(--ink); }
.col-panel input[type=checkbox] { flex-shrink: 0; }
.empty-state { padding: 48px 20px; text-align: center; color: #8891A0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }

/* ---------------- Badges / Plates ---------------- */
.badge { font-weight: 600; font-size: 11.5px; padding: 3px 9px; border-radius: 20px; display: inline-flex; align-items: center; gap: 6px; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.badge-green { background: #E4F5EC; color: #1C7A4C; }
.badge-blue { background: #E7EEF7; color: #2A5688; }
.badge-amber { background: #FCF1DF; color: #96650F; }
.badge-orange { background: #FBEADF; color: #A85A17; }
.badge-red { background: #FBE4E4; color: #B23838; }
.badge-purple { background: #EDEBF7; color: #5B4EA3; }
.badge-grey { background: #ECEFF3; color: #5B6472; }

.plate {
  background: #0F2D4F; color: var(--accent); border: 1px solid #1E4E7D;
  font-family: 'IBM Plex Mono', monospace; font-weight: 600; font-size: 12px;
  letter-spacing: .06em; padding: 3px 8px; border-radius: 3px; white-space: nowrap; display: inline-block;
}

/* ---------------- Info blocks / mini stats ---------------- */
.info-block { margin-bottom: 12px; }
.info-block .lbl { font-size: 11px; color: #8891A0; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.info-block .val { font-size: 13.5px; color: var(--ink); margin-top: 2px; }

.mini-stat { background: var(--surface-alt); border: 1px solid var(--border-soft); border-radius: 8px; padding: 9px 13px; min-width: 120px; display: inline-block; margin: 0 8px 8px 0; }
.mini-stat .lbl { font-size: 10.5px; color: #8891A0; font-weight: 600; text-transform: uppercase; }
.mini-stat .val { font-size: 15px; font-weight: 700; color: var(--ink); font-family: 'IBM Plex Mono', monospace; }
.mini-stat .val.danger { color: var(--danger); }

/* ---------------- Cost box (transport) ---------------- */
.cost-box { background: #171D26; border-radius: 10px; padding: 16px; color: #fff; margin-top: 10px; }
.cost-box .title { font-size: 11.5px; color: var(--accent); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }
.cost-line { display: flex; justify-content: space-between; font-size: 13.5px; padding: 4px 0; color: #D8DCE3; }
.cost-line .sub { color: #7A8394; font-size: 11.5px; }
.cost-line .val { font-family: 'IBM Plex Mono', monospace; }
.cost-total { border-top: 1px solid #2B3442; margin-top: 10px; padding-top: 10px; display: flex; justify-content: space-between; font-size: 16px; font-weight: 700; }
.cost-total .val { color: var(--accent); font-family: 'IBM Plex Mono', monospace; }

/* ---------------- Status stepper (OT) ---------------- */
.stepper { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.stepper a { font-size: 11px; padding: 5px 9px; border-radius: 6px; border: 1px solid #D8DCE3; color: #7A8394; font-weight: 600; }
.stepper a.done { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------------- Alerts ---------------- */
.alert-list { display: flex; flex-direction: column; gap: 8px; }
.alert-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 8px; font-size: 13px; border: 1px solid; }
.alert-item.retard { background: #FBE4E4; border-color: #F3C4C4; color: #8A2A2A; }
.alert-item.proche { background: #FCF1DF; border-color: #F2DDB0; color: #7A5210; }
.alert-item .tag { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; opacity: .75; }

select[multiple] { padding: 4px; }
select[multiple] option { padding: 6px 8px; border-radius: 4px; }
select[multiple] option:checked { background: #2263AF; color: #fff; }

/* ---------------- Chips (multi-select machines) ---------------- */
.chip-select { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip-select label { display: flex; align-items: center; gap: 6px; border: 1px solid #D8DCE3; background: #fff; border-radius: 7px; padding: 6px 10px; cursor: pointer; font-size: 12.5px; }
.chip-select label.checked { border-color: var(--primary); background: #EAF1FA; }

/* ---------------- Login ---------------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--sidebar); }
.login-box { background: #fff; border-radius: 12px; padding: 34px 32px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-box .logo-row { display: flex; align-items: center; margin-bottom: 22px; }
.login-box .logo-row img { height: 40px; width: auto; display: block; }
.login-box h2 { margin: 0; font-size: 19px; }
.login-box .tag { color: #8891A0; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }

/* ---------------- Flash messages ---------------- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.flash-success { background: #E4F5EC; color: #1C7A4C; }
.flash-error { background: #FBE4E4; color: #B23838; }

/* ---------------- Chart placeholder bars ---------------- */
.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 200px; padding-top: 10px; }
.bar-chart .bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar-chart .bars { display: flex; gap: 3px; align-items: flex-end; height: 160px; }
.bar-chart .bar { width: 14px; border-radius: 3px 3px 0 0; }
.bar-chart .label { font-size: 10px; color: #8891A0; }
.legend-row { display: flex; gap: 16px; font-size: 12px; color: #5B6472; margin-top: 8px; }
.legend-row .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }


/* =====================================================================
   RESPONSIVE
   ===================================================================== */

/* Grilles de formulaires : se replient progressivement */
@media (max-width: 1200px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 980px)  { .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px)  {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .field.span-2, .field.span-3 { grid-column: auto; }
  .page-header h1 { font-size: 20px; }
  .kpi { flex: 1 1 100%; }
}

/* Barre d'outils / filtres : les boutons passent à la ligne */
.page-header > div:last-child { flex-wrap: wrap; }

/* Tableau des OT : colonne OT figée + défilement interne si besoin */
.table-scroll { -webkit-overflow-scrolling: touch; }
table.data-sticky th:first-child,
table.data-sticky td:first-child { position: sticky; left: 0; z-index: 2; background: #fff; box-shadow: 1px 0 0 var(--border-soft); }
table.data-sticky thead th:first-child { background: var(--surface-alt); z-index: 3; }
table.data-sticky tbody tr:hover td:first-child { background: #FAFBFC; }

/* Cellules texte : passent sur 2 lignes au lieu d'être tronquées */
table.data-compact td.cell-wrap { white-space: normal; word-break: normal; overflow-wrap: normal; hyphens: none; min-width: 64px; max-width: 170px; line-height: 1.25; }
.cell-sub { display: block; font-size: .88em; color: #7A8394; }
@media (max-width: 720px) { .cell-sub { display: inline; margin-left: 6px; } }

/* Niveaux de compaction automatiques (ajustés par JS selon la largeur dispo) */
table.fit-1 { font-size: 10.5px; }
table.fit-1 th { padding: 6px 4px; font-size: 9px; }
table.fit-1 td { padding: 5px 4px; }
table.fit-1 .plate { font-size: 9.5px; padding: 2px 4px; }
table.fit-1 .badge { font-size: 9px; padding: 2px 5px; }
table.fit-2 { font-size: 9.5px; }
table.fit-2 th { padding: 5px 3px; font-size: 8.5px; letter-spacing: 0; }
table.fit-2 td { padding: 4px 3px; }
table.fit-2 td.cell-wrap { min-width: 50px; max-width: 120px; }
table.fit-2 .plate { font-size: 9px; padding: 1px 3px; }
table.fit-2 .badge { font-size: 8.5px; padding: 1px 4px; }

/* Mobile : chaque OT devient une carte lisible (toutes les colonnes visibles) */
@media (max-width: 720px) {
  table.data-cards, table.data-cards tbody { display: block; width: 100%; }
  table.data-cards thead { display: none; }
  table.data-cards tr { display: block; background: #fff; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 8px 12px; }
  table.data-cards tr:hover { background: #fff; }
  table.data-cards td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 5px 0 !important; border-bottom: 1px dashed var(--border-soft); white-space: normal !important; max-width: none !important; text-align: right; }
  table.data-cards td:last-child { border-bottom: 0; justify-content: flex-end; }
  table.data-cards td::before { content: attr(data-label); font-size: 10px; font-weight: 700; color: #7A8394; text-transform: uppercase; letter-spacing: .04em; text-align: left; flex-shrink: 0; }
  table.data-cards td.no-label::before { content: none; }
  table.data-cards td:first-child { position: static; box-shadow: none; }
  .table-wrap { background: transparent; border: 0; }
  .col-panel { position: fixed; left: 12px; right: 12px; top: 70px; width: auto; max-height: 75vh; overflow-y: auto; }
}

/* Filtres : repliables sur mobile uniquement */
.filters-toggle { display: none; margin-bottom: 10px; }
@media (max-width: 720px) {
  .filters-toggle { display: inline-flex; }
  form.card[method="get"] { display: none; }
  form.card[method="get"].filters-open { display: block; }
}
