/* ===========================================================================
   TRUCK SUPPLY HUB - Feuille de style
   Palette industrielle bleu acier, themes clair et sombre.
   =========================================================================== */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --border: #d6dce2;
  --text: #16202a;
  --text-muted: #5f6e7c;
  --accent: #2f6f9f;
  --accent-strong: #235880;
  --accent-soft: #e4eef6;
  --danger: #b3261e;
  --ok: #1e7a4d;
  --warn: #9a6400;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 8px 24px rgba(16, 32, 48, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #11171d;
  --surface: #1a222b;
  --surface-2: #222c37;
  --border: #303d4a;
  --text: #e7edf2;
  --text-muted: #9aa8b5;
  --accent: #5a9dcd;
  --accent-strong: #7cb4dc;
  --accent-soft: #223544;
  --danger: #e8705f;
  --ok: #4cb183;
  --warn: #d6a13c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 19px; }
h3 { font-size: 17px; }

.muted { color: var(--text-muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* ------------------------------- Boutons ------------------------------- */
.btn {
  font: inherit;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { color: var(--danger); border-color: var(--border); }
.btn-danger:hover { background: rgba(179, 38, 30, .08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-small { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; margin-top: 8px; }

/* -------------------------- Champs de saisie -------------------------- */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 14px 0 5px;
}
input[type=text], input[type=email], input[type=password], input[type=search],
input[type=url], input[type=number], select, textarea {
  width: 100%;
  font: inherit;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
textarea { min-height: 72px; resize: vertical; }

.form-error {
  margin: 12px 0 0;
  padding: 9px 11px;
  border-radius: 8px;
  background: rgba(179, 38, 30, .1);
  color: var(--danger);
  font-size: 13.5px;
}
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; min-width: 0; }

/* ----------------------------- Connexion ----------------------------- */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(900px 420px at 15% -10%, var(--accent-soft), transparent),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.brand { display: flex; align-items: center; gap: 13px; margin-bottom: 6px; }
.brand-sub { margin: 3px 0 0; color: var(--text-muted); font-size: 13.5px; }
.brand-mark {
  width: 42px; height: 42px;
  flex: 0 0 auto;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  display: grid; place-items: center;
  letter-spacing: .5px;
}
.brand-mark.small { width: 28px; height: 28px; border-radius: 7px; font-size: 12px; }
.login-foot {
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-wrap: wrap;
}
.login-foot p { margin: 0; }

/* -------------------------- Langue et theme -------------------------- */
.lang-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang-switch button {
  font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 5px 10px;
  border: 0; background: transparent; color: var(--text-muted); cursor: pointer;
}
.lang-switch button.on { background: var(--accent); color: #fff; }

/* ----------------------------- Barre haute ----------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 9px; }
.topbar-nav { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tab {
  font: inherit; font-size: 14px;
  padding: 7px 13px;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--text-muted); cursor: pointer;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
:root[data-theme="dark"] .tab.active { color: var(--accent-strong); }
.who { display: flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--text-muted); }
.badge {
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 5px;
  background: var(--accent-soft); color: var(--accent-strong);
}
.badge.off { background: rgba(179, 38, 30, .12); color: var(--danger); }
.badge.on { background: rgba(30, 122, 77, .12); color: var(--ok); }
.badge.draft { background: rgba(154, 100, 0, .14); color: var(--warn); }

/* ------------------------------- Vues ------------------------------- */
.view { max-width: 1180px; margin: 0 auto; padding: 26px 20px 60px; }
.view-head {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  margin-bottom: 18px; flex-wrap: wrap;
}
.view-head p { margin: 0; }
.toolbar { margin-bottom: 14px; max-width: 380px; }
.empty {
  padding: 36px; text-align: center; color: var(--text-muted);
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
}

/* ---------------------------- Lanceur d'apps ---------------------------- */
.app-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}
.app-tile {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  transition: transform .12s, border-color .12s;
}
.app-tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.app-tile .tile-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.app-tile .tile-mark {
  width: 40px; height: 40px; flex: 0 0 auto;
  border-radius: 9px; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 15px;
}
.app-tile h3 { font-size: 16px; }
.app-tile p { margin: 0; color: var(--text-muted); font-size: 13.5px; }
.tile-foot {
  margin-top: 13px; padding-top: 11px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 12.5px; color: var(--text-muted);
}

/* ------------------------------ Tableaux ------------------------------ */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow);
}
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td {
  padding: 11px 13px; text-align: left;
  border-bottom: 1px solid var(--border); vertical-align: middle;
}
.table th {
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); background: var(--surface-2); white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .row-actions { display: flex; gap: 4px; justify-content: flex-end; white-space: nowrap; }
.table.matrix th:first-child, .table.matrix td:first-child {
  position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 190px;
}
.table.matrix th:first-child { background: var(--surface-2); }
.table.matrix td { text-align: center; }
.table.matrix td:first-child { text-align: left; }
.cell-stack { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.cell-stack select { font-size: 12px; padding: 3px 5px; max-width: 135px; }
.inactive td:first-child { opacity: .55; }

/* ----------------------------- Cartes apps ----------------------------- */
.card-list { display: grid; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.card-head { display: flex; align-items: flex-start; gap: 13px; }
.card-head .tile-mark {
  width: 40px; height: 40px; flex: 0 0 auto; border-radius: 9px;
  display: grid; place-items: center; color: #fff; font-weight: 700;
}
.card-head .grow { flex: 1; min-width: 0; }
.card-head .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.versions { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.versions table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.versions td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.versions tr:last-child td { border-bottom: 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

/* ------------------------------- Modale ------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 18, 26, .55);
  display: grid; place-items: center; padding: 18px;
}
.modal {
  width: 100%; max-width: 520px; max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 13px; box-shadow: var(--shadow);
}
.modal-head, .modal-foot {
  display: flex; align-items: center; gap: 10px; padding: 15px 18px;
}
.modal-head { border-bottom: 1px solid var(--border); justify-content: space-between; }
.modal-foot { border-top: 1px solid var(--border); justify-content: flex-end; }
.modal-body { padding: 4px 18px 18px; overflow-y: auto; }
.modal-body label:first-child { margin-top: 8px; }
.notice {
  margin-top: 14px; padding: 12px; border-radius: 8px;
  background: var(--accent-soft); font-size: 13.5px;
}
.secret {
  font-family: var(--mono); font-size: 16px; font-weight: 600;
  padding: 10px 12px; margin-top: 8px;
  background: var(--surface-2); border: 1px dashed var(--border); border-radius: 8px;
  user-select: all; word-break: break-all;
}

/* ------------------------ Double authentification ------------------------ */
.qr-box {
  margin: 16px 0 6px;
  padding: 14px;
  background: #fff;                 /* le QR doit rester lisible en theme sombre */
  border: 1px solid var(--border);
  border-radius: 10px;
  display: grid;
  place-items: center;
  min-height: 190px;
}
.qr-box svg, .qr-box img { width: 180px; height: 180px; display: block; }
details summary { cursor: pointer; color: var(--text-muted); }

/* ------------------------------- Toast ------------------------------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  z-index: 60; padding: 11px 18px; border-radius: 9px;
  background: var(--text); color: var(--bg); font-size: 14px;
  box-shadow: var(--shadow); max-width: 90vw;
}
.toast.err { background: var(--danger); color: #fff; }

/* ------------------------------ Mobile ------------------------------ */
@media (max-width: 760px) {
  .topbar { padding: 10px 16px; }
  .topbar-nav { order: 3; width: 100%; }
  .view { padding: 20px 16px 50px; }
  .who span:first-child { display: none; }
}
