/* CablePLC — design Systèmes MB (repris de Tâche MB) : noir + orange #F26223, coins arrondis */
:root {
  --bg: #F1F1F2;
  --panel: #0C0D0E;
  --panel-2: #1B1D1F;
  --surface: #FFFFFF;
  --ink: #1B1D1F;
  --muted: #62686D;
  --line: #D9DCDE;
  --accent: #F26223;
  --accent-dark: #D14F14;
  --accent-soft: rgba(242, 98, 35, .10);
  --ok: #2F9E63;
  --warn: #DFA400;
  --late: #D6453D;
  --radius: 12px;
  --font-ui: 'Barlow', system-ui, sans-serif;
  --font-display: 'Barlow Semi Condensed', 'Barlow', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --bottomnav-h: 0px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--accent-dark); }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); font-size: 13px; }
.nowrap { white-space: nowrap; }

/* ---------- Barre supérieure ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); color: #ECEEF0;
  padding: 0 18px; height: 54px;
  padding-top: env(safe-area-inset-top);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand img { height: 24px; display: block; }
.brand .brand-name {
  font-family: var(--font-display); font-weight: 600;
  text-transform: uppercase; letter-spacing: .12em; font-size: 13.5px;
  border-left: 1px solid #3A3E42; padding-left: 12px; color: #C9CDD1;
}
.topnav { display: flex; gap: 4px; margin-left: 10px; }
.topnav a {
  color: #AEB3B8; text-decoration: none; padding: 6px 12px; border-radius: 999px; font-size: 13.5px;
}
.topnav a:hover { color: #fff; }
.topnav a.active { color: #fff; background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--accent); }
.topbar .spacer { flex: 1; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: #fff; border: 0; text-decoration: none;
  border-radius: 999px; padding: 8px 16px; font-weight: 600; font-size: 13.5px;
  transition: background .12s, transform .08s; white-space: nowrap;
}
.btn:hover { background: var(--accent-dark); }
.btn:active { transform: scale(.97); }
.btn.secondary { background: #E5E7E9; color: var(--ink); }
.btn.secondary:hover { background: #D8DBDD; }
.btn.danger { background: var(--late); }
.btn.danger:hover { background: #B83931; }
.btn.small { padding: 5px 12px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-ghost {
  display: inline-flex; align-items: center; text-decoration: none;
  background: transparent; color: #C9CDD1; border: 1px solid #3A3E42;
  border-radius: 999px; padding: 6px 14px; font-size: 13px; white-space: nowrap;
}
.btn-ghost:hover { border-color: var(--accent); color: #fff; }
.btn-link { background: none; border: 0; color: var(--accent-dark); padding: 0; font-size: inherit; text-decoration: underline; }
.icon-btn {
  background: none; border: 1px solid var(--line); border-radius: 999px; color: var(--muted);
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; font-size: 15px;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent-dark); }
.icon-btn.danger:hover { border-color: var(--late); color: var(--late); }

/* ---------- Page ---------- */
main { outline: none; }
.page { padding: 22px 26px 40px; max-width: 1240px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 2px 0 16px; }
.page-head h1 {
  font-family: var(--font-display); text-transform: uppercase;
  letter-spacing: .1em; font-size: 19px; font-weight: 600; margin: 0;
  display: flex; align-items: center; gap: 12px;
}
.page-head .count { font-family: var(--font-mono); font-size: 13px; color: var(--muted); font-weight: 400; letter-spacing: 0; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px;
  margin-bottom: 16px;
}
.panel > h2, .section-title {
  margin: 0 0 12px; font-family: var(--font-display); text-transform: uppercase;
  letter-spacing: .1em; font-size: 13px; color: var(--muted); font-weight: 600;
}
.loading { padding: 40px; text-align: center; color: var(--muted); }
.empty {
  padding: 30px 16px; text-align: center; color: var(--muted);
  border: 2px dashed #C6CACD; border-radius: 16px;
}

/* ---------- Recherche ---------- */
.search-big { position: relative; margin-bottom: 12px; }
.search-big input {
  width: 100%; font-size: 16px; padding: 12px 18px 12px 44px;
  border: 1px solid var(--line); border-radius: 999px; background: #fff; outline: none;
  box-shadow: 0 1px 3px rgba(12,13,14,.06);
}
.search-big input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-big .s-ico { position: absolute; left: 17px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 18px; pointer-events: none; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; align-items: center; }
.filters select {
  border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; background: #fff; max-width: 220px;
}
.filters select.set { border-color: var(--accent); background: var(--accent-soft); }
.filters .btn-link { font-size: 13px; }

table.list {
  width: 100%; border-collapse: separate; border-spacing: 0; background: #fff;
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
}
table.list th {
  font-family: var(--font-display); text-transform: uppercase; letter-spacing: .08em;
  font-size: 11px; color: var(--muted); text-align: left; padding: 10px 14px;
  border-bottom: 2px solid var(--accent); font-weight: 600; white-space: nowrap;
}
table.list td { padding: 9px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr.clickable { cursor: pointer; }
table.list tbody tr.clickable:hover td { background: #FAFAFA; }
table.list td.actions { white-space: nowrap; text-align: right; width: 1%; }
.table-wrap { overflow-x: auto; border-radius: 14px; }

.chip {
  display: inline-block; font-family: var(--font-mono); font-size: 11.5px; border-radius: 999px;
  padding: 1.5px 8px; background: #EFF0F1; color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap; margin: 1px 2px 1px 0;
}
.chip.accent { background: var(--accent-soft); color: var(--accent-dark); border-color: rgba(242,98,35,.35); }
.chip.dark { background: var(--panel); color: #E5E7E9; border-color: var(--panel); font-family: var(--font-ui); }
.chip.ok { background: rgba(47,158,99,.12); color: #22794B; border-color: rgba(47,158,99,.35); }

/* Cartes de résultats (mobile) */
.cards { display: none; flex-direction: column; gap: 10px; }
.rcard {
  display: block; text-decoration: none; color: inherit;
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 14px; padding: 12px 14px;
}
.rcard:active { background: #FAFAFA; }
.rcard .rc-client { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-family: var(--font-display); }
.rcard .rc-title { font-weight: 600; font-size: 16px; margin: 1px 0 6px; }
.rcard .rc-line { font-size: 13.5px; margin-top: 3px; }
.rcard .rc-line .mono { font-size: 12.5px; }

/* ---------- Fiche machine ---------- */
.fiche-head h1 { font-size: 22px; letter-spacing: .06em; }
.meta-line { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 16px; }
.auto-card {
  background: #fff; border: 1px solid var(--line); border-radius: 16px; margin-bottom: 14px; overflow: hidden;
}
.auto-card .ac-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 2px solid var(--accent); background: #FBFBFB;
}
.auto-card .ac-role { font-family: var(--font-display); text-transform: uppercase; letter-spacing: .08em; font-size: 12px; color: var(--muted); }
.auto-card .ac-title { font-weight: 600; font-size: 17px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0; }
.kv > div { padding: 10px 16px; border-bottom: 1px solid #EEF0F1; min-width: 0; }
.kv dt { font-family: var(--font-display); text-transform: uppercase; letter-spacing: .08em; font-size: 10.5px; color: var(--muted); font-weight: 600; }
.kv dd { margin: 2px 0 0; font-size: 14.5px; overflow-wrap: anywhere; }
.kv dd.mono { font-size: 14px; }
.copyable {
  background: none; border: 0; padding: 0; font: inherit; color: var(--ink); cursor: copy;
  border-bottom: 1px dashed var(--accent); text-align: left;
}
.copyable:hover { color: var(--accent-dark); }
.ac-block { padding: 12px 16px; border-top: 1px solid #EEF0F1; }
.ac-block h4 { margin: 0 0 8px; font-family: var(--font-display); text-transform: uppercase; letter-spacing: .08em; font-size: 10.5px; color: var(--muted); }
.cable-row {
  display: flex; align-items: baseline; gap: 10px; padding: 7px 0; border-bottom: 1px dashed #E3E5E7; cursor: pointer;
}
.cable-row:last-child { border-bottom: 0; }
.cable-row .code { font-family: var(--font-mono); font-weight: 600; color: var(--accent-dark); min-width: 38px; }
.cable-row .desc { flex: 1; }
.cable-row .where { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.notes { white-space: pre-wrap; font-size: 14px; }

/* ---------- Formulaires ---------- */
.form-row { margin-bottom: 13px; min-width: 0; }
.form-row label, .field-label {
  display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 4px; color: var(--muted);
}
.form-row input[type=text], .form-row input[type=password], .form-row input[type=number],
.form-row input[type=search], .form-row select, .form-row textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: #fff;
}
.form-row textarea { min-height: 80px; resize: vertical; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.form-row .req { color: var(--accent-dark); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 14px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
.with-add { display: flex; gap: 6px; }
.with-add select { flex: 1; min-width: 0; }
.with-add .icon-btn { flex: 0 0 38px; height: 38px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.form-actions.account-actions { justify-content: flex-start; }
.check-line { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; user-select: none; }
.check-line input { width: 17px; height: 17px; accent-color: var(--accent); }
.fieldset-title {
  grid-column: 1 / -1; margin: 6px 0 10px; padding-top: 10px; border-top: 1px dashed var(--line);
  font-family: var(--font-display); text-transform: uppercase; letter-spacing: .1em; font-size: 11.5px; color: var(--muted); font-weight: 600;
}
.auto-form { border: 1px solid var(--line); border-radius: 16px; background: #fff; margin-bottom: 14px; }
.auto-form .af-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 2px solid var(--accent);
}
.auto-form .af-head .af-num { font-family: var(--font-display); text-transform: uppercase; letter-spacing: .1em; font-size: 12px; color: var(--muted); }
.auto-form .af-head .af-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auto-form .af-body { padding: 14px 14px 4px; }
.cable-picked { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.cable-pill {
  display: inline-flex; align-items: center; gap: 6px; background: var(--panel); color: #EDEFF1;
  border-radius: 999px; padding: 4px 6px 4px 11px; font-size: 13px;
}
.cable-pill b { font-family: var(--font-mono); color: #FFB48F; font-weight: 600; }
.cable-pill button { background: #3A3E42; color: #fff; border: 0; border-radius: 999px; width: 22px; height: 22px; line-height: 1; }
.cable-pill button:hover { background: var(--late); }
.sticky-save {
  position: sticky; bottom: calc(var(--bottomnav-h) + 10px); z-index: 20;
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
  background: rgba(241,241,242,.92); backdrop-filter: blur(4px);
  padding: 10px; border-radius: 999px; border: 1px solid var(--line); margin-top: 10px;
}
.form-error {
  background: rgba(214,69,61,.1); color: #A7322B; border: 1px solid rgba(214,69,61,.35);
  border-radius: 12px; padding: 9px 12px; margin-bottom: 12px; font-size: 13.5px;
}

/* ---------- Onglets ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; scrollbar-width: none; }
.tabs a {
  text-decoration: none; color: var(--muted); border: 1px solid var(--line); background: #fff;
  border-radius: 999px; padding: 6px 14px; font-size: 13.5px; white-space: nowrap;
}
.tabs a.active { background: var(--panel); color: #fff; border-color: var(--panel); }

/* ---------- Checklist PLC compatibles ---------- */
.plc-groups { max-height: 340px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; background: #fff; }
.plc-groups .pg-title { font-family: var(--font-display); text-transform: uppercase; letter-spacing: .08em; font-size: 11px; color: var(--muted); margin: 10px 0 4px; }
.plc-groups label { display: inline-flex; align-items: center; gap: 6px; margin: 3px 14px 3px 0; font-size: 13.5px; cursor: pointer; }
.plc-groups input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- Historique ---------- */
.hist-row { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px dashed #DEE0E2; align-items: baseline; flex-wrap: wrap; }
.hist-row .h-time { font-family: var(--font-mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.hist-row .h-label { flex: 1; min-width: 180px; }
.h-action { font-family: var(--font-mono); font-size: 11px; font-weight: 600; border-radius: 999px; padding: 1px 8px; }
.h-action.create { background: rgba(47,158,99,.14); color: #22794B; }
.h-action.update { background: var(--accent-soft); color: var(--accent-dark); }
.h-action.delete { background: rgba(214,69,61,.12); color: #A7322B; }
pre.json { background: var(--panel); color: #DDE1E4; padding: 12px; border-radius: 12px; overflow: auto; font-size: 12px; max-height: 50vh; }
.diff-table td { font-size: 13px; }
.diff-table td.old { color: #A7322B; text-decoration: line-through; }
.diff-table td.new { color: #22794B; }

/* ---------- Modales ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(8,9,10,.6); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px;
  overflow-y: auto; backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg); border-radius: 18px; width: 100%; max-width: 720px;
  box-shadow: 0 24px 70px rgba(0,0,0,.45); padding: 18px 22px 22px;
}
.modal.narrow { max-width: 460px; }
.modal-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 18px; flex: 1; font-weight: 600; }
.modal-close { background: none; border: 0; font-size: 24px; color: var(--muted); line-height: 1; padding: 0 4px; }
.modal-close:hover { color: var(--ink); }

.toast {
  position: fixed; bottom: calc(22px + var(--bottomnav-h)); left: 50%; transform: translateX(-50%);
  background: var(--panel); color: #fff; border-radius: 999px; max-width: calc(100% - 32px);
  padding: 10px 20px; font-size: 13.5px; z-index: 200; box-shadow: 0 10px 28px rgba(0,0,0,.35);
}
.toast.error { background: var(--late); }

/* ---------- Connexion ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: #0A0A0B;
  background-image: radial-gradient(ellipse at 50% -10%, rgba(242,98,35,.22) 0%, transparent 55%);
}
.login-card {
  background: var(--surface); border-radius: 20px; padding: 30px 32px;
  width: 100%; max-width: 390px; box-shadow: 0 24px 70px rgba(0,0,0,.6);
}
.login-logo { background: var(--panel); border-radius: 14px; padding: 20px 24px; display: flex; justify-content: center; margin-bottom: 18px; }
.login-logo img { width: 200px; max-width: 100%; display: block; }
.login-card .tagline {
  font-family: var(--font-display); text-transform: uppercase; letter-spacing: .14em;
  font-size: 12.5px; color: var(--muted); text-align: center; margin-bottom: 22px;
}
.login-error { color: var(--late); font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.login-foot { text-align: center; margin: 14px 0 0; font-size: 12.5px; }

/* ---------- Navigation du bas (mobile) ---------- */
.bottomnav { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Écrans larges : tableau ; étroits : cartes ---------- */
@media (max-width: 900px) {
  .topnav a { padding: 6px 9px; }
  .brand .brand-name { display: none; }
}

@media (max-width: 760px) {
  :root { --bottomnav-h: calc(62px + env(safe-area-inset-bottom)); }
  body { font-size: 15px; padding-bottom: var(--bottomnav-h); }
  input, textarea, select { font-size: 16px; } /* évite le zoom automatique d'iOS */

  .topbar { height: auto; min-height: 52px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); gap: 8px; }
  .brand .brand-name { display: inline; font-size: 12.5px; }
  .brand img { height: 21px; }
  .topnav, .top-new { display: none; }
  #userChip { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
  .topbar .btn-ghost { padding: 7px 11px; font-size: 12.5px; }

  .bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: var(--panel); border-top: 1px solid #25282B;
    padding-bottom: env(safe-area-inset-bottom); height: var(--bottomnav-h);
  }
  .bottomnav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: #9EA4A9; text-decoration: none; font-size: 11px; height: 62px;
  }
  .bottomnav a .bn-ico { font-size: 21px; line-height: 1; }
  .bottomnav a.active { color: #fff; }
  .bottomnav a.active .bn-ico { color: var(--accent); }
  .bottomnav a.bn-new .bn-ico {
    background: var(--accent); color: #fff; width: 40px; height: 30px; border-radius: 999px;
    display: flex; align-items: center; justify-content: center; font-size: 19px;
  }

  .page { padding: 14px 12px 24px; }
  .page-head h1 { font-size: 17px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; }
  .panel { padding: 14px; border-radius: 14px; }

  .desktop-only { display: none !important; }
  .cards { display: flex; }
  .filters { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; margin-left: -12px; margin-right: -12px; padding-left: 12px; padding-right: 12px; scrollbar-width: none; }
  .filters select { flex: 0 0 auto; max-width: 180px; }

  .kv { grid-template-columns: 1fr 1fr; }
  .kv > div { padding: 9px 14px; }
  .form-grid { grid-template-columns: 1fr 1fr; gap: 0 10px; }
  .form-grid .span-2 { grid-column: 1 / -1; }
  .form-grid .full-mobile { grid-column: 1 / -1; }

  .overlay { padding: 0; align-items: flex-end; }
  .modal {
    border-radius: 18px 18px 0 0; max-width: 100%; max-height: 92vh; overflow-y: auto;
    padding: 16px 14px calc(24px + env(safe-area-inset-bottom));
  }
  .modal.narrow { max-width: 100%; }
  .btn, .btn-ghost { min-height: 38px; }
  .icon-btn { width: 38px; height: 38px; }
  .sticky-save { border-radius: 16px; }
  .account-actions { flex-direction: column; align-items: stretch; }
  .sticky-save .btn { flex: 1; }
  table.list td, table.list th { padding: 9px 10px; }
}

@media (max-width: 420px) {
  .kv { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (min-width: 761px) {
  .mobile-only { display: none !important; }
}
