:root {
  --brand: #1d3c8a;
  --brand-hover: #16306f;
  --brand-tint: #e8edf8;
  --brand-text: #1d3c8a;
  --sidebar-bg: #1d3c8a;
  --sidebar-text: #ffffff;
  --sidebar-muted: rgba(255, 255, 255, 0.72);
  --sidebar-active: rgba(255, 255, 255, 0.16);

  --page-bg: #f3f5f9;
  --surface: #ffffff;
  --surface-muted: #f7f8fb;
  --text: #1c2333;
  --text-secondary: #5b6477;
  --text-muted: #8a93a6;
  --border: #dde3ee;
  --border-strong: #c5cddc;

  --success-bg: #e6f4ea; --success-text: #1e6b34;
  --error-bg: #fdecec;   --error-text: #a12a2a;
  --info-bg: #e8edf8;    --info-text: #1d3c8a;
  --warning-bg: #fdf1dc; --warning-text: #8a5300;

  --radius: 8px;
  --radius-lg: 12px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

/* Thème sombre : data-theme est posé par le script de _head.html
   (choix mémorisé, sinon réglage du système) */
:root[data-theme="dark"] {
  --brand: #4f78d6;
  --brand-hover: #6a8de0;
  --brand-tint: #1c2a4d;
  --brand-text: #9db6ee;
  --sidebar-bg: #152b63;
  --sidebar-active: rgba(255, 255, 255, 0.12);

  --page-bg: #0f131b;
  --surface: #171c27;
  --surface-muted: #1c2230;
  --text: #e6e9f0;
  --text-secondary: #a4acbd;
  --text-muted: #778097;
  --border: #2a3142;
  --border-strong: #3a4357;

  --success-bg: #173222; --success-text: #8fd6a4;
  --error-bg: #3a1a1a;   --error-text: #f2a3a3;
  --info-bg: #1c2a4d;    --info-text: #9db6ee;
  --warning-bg: #3a2c12; --warning-text: #f0c070;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--page-bg);
}
a { color: var(--brand-text); }
h1 { font-size: 22px; font-weight: 600; margin: 0; }
h2 { font-size: 17px; font-weight: 600; margin: 0 0 12px; }

/* ---------- Mise en page ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-logo { display: block; padding: 4px 8px 22px; }
.sidebar-logo img { width: 120px; height: auto; display: block; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-muted);
  padding: 16px 10px 6px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
}
.nav-link i { font-size: 19px; }
.nav-link:hover { background: var(--sidebar-active); }
.nav-link.active { background: var(--sidebar-active); font-weight: 600; }
.nav-link.soon { color: var(--sidebar-muted); }
.nav-link .badge { margin-left: auto; }
.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.sidebar-bottom form { margin: 0; }
.sidebar-bottom button.nav-link { width: 100%; background: none; border: 0; cursor: pointer; font: inherit; font-size: 14px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar-title { font-weight: 600; }
.user-chip { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-secondary); text-decoration: none; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-tint); color: var(--brand-text);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.theme-toggle {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 50%;
  background: var(--surface); color: var(--text-secondary);
  font-size: 18px; cursor: pointer;
}
.theme-toggle:hover { color: var(--brand-text); border-color: var(--brand); }
/* Affiche l'icône du thème vers lequel on bascule */
.theme-toggle .icon-light { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-light { display: inline; }
:root[data-theme="dark"] .theme-toggle .icon-dark { display: none; }
.auth-panel { position: relative; }
.auth-theme { position: absolute; top: 16px; right: 16px; }
.menu-toggle { display: none; background: none; border: 0; color: var(--text); font-size: 24px; cursor: pointer; padding: 0; }
.content { padding: 28px; max-width: 1200px; width: 100%; }

/* ---------- Accueil ---------- */
.welcome { margin-bottom: 24px; }
.welcome p { margin: 4px 0 0; color: var(--text-secondary); }
.tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.tool-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text);
  text-decoration: none;
  transition: border-color .15s, transform .15s;
}
a.tool-card:hover { border-color: var(--brand); transform: translateY(-2px); }
.tool-card i { font-size: 28px; color: var(--brand-text); }
.tool-card strong { font-size: 16px; }
.tool-card span { color: var(--text-secondary); font-size: 13px; }
.tool-card.soon { border-left-color: var(--border-strong); border-style: dashed; border-left-style: solid; background: var(--surface-muted); }
.tool-card.soon i, .tool-card.soon strong { color: var(--text-muted); }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--brand-tint);
  color: var(--brand-text);
  font-weight: 600;
}
.sidebar .badge { background: rgba(255,255,255,.14); color: var(--sidebar-muted); }
.badge.muted { background: var(--surface-muted); color: var(--text-muted); border: 1px solid var(--border); }
.badge.danger { background: var(--error-bg); color: var(--error-text); }

/* ---------- Cartes, formulaires, tableaux ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; margin-bottom: 20px; }
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-row label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.form-inline { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.form-inline .form-row { margin: 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
input[type=text], input[type=password] {
  height: 40px;
  padding: 0 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  width: 100%;
}
input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }
.field-error { color: var(--error-text); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px;
  font: inherit; font-weight: 600; font-size: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--surface-muted); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; }
td.actions { display: flex; gap: 6px; }
td.actions form { margin: 0; }

.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.flash { padding: 10px 14px; border-radius: var(--radius); font-size: 14px; }
.flash.success { background: var(--success-bg); color: var(--success-text); }
.flash.error { background: var(--error-bg); color: var(--error-text); }
.flash.info { background: var(--info-bg); color: var(--info-text); }

/* ---------- Connexion ---------- */
.auth-page { display: flex; min-height: 100vh; }
.auth-brand {
  flex: 1;
  background: var(--sidebar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.auth-brand img { width: min(360px, 80%); height: auto; }
.auth-panel { flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px 16px; background: var(--surface); }
.auth-box { width: 100%; max-width: 360px; }
.auth-box h1 { margin-bottom: 6px; }
.auth-box .lead { color: var(--text-secondary); margin: 0 0 24px; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; z-index: 20;
    transform: translateX(-100%);
    transition: transform .2s;
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .backdrop { display: block; }
  .backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 10; }
  .menu-toggle { display: inline-flex; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .user-chip .name { display: none; }
  .auth-page { flex-direction: column; }
  .auth-brand { flex: 0 0 auto; padding: 28px; }
  .auth-brand img { width: 200px; }
}

/* ---------- Éléments communs (formulaires longs, badges) ---------- */
textarea, select, input[type=date], input[type=email], input[type=tel] {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  width: 100%;
}
select, input[type=date] { height: 40px; padding: 0 10px; }
textarea { padding: 10px 12px; resize: vertical; min-height: 90px; }
textarea:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }
input[type=file] { font: inherit; font-size: 14px; color: var(--text-secondary); }
.fieldset { border: 0; padding: 0; margin: 0 0 22px; min-width: 0; }
.fieldset legend { font-weight: 600; font-size: 15px; margin-bottom: 10px; padding: 0; color: var(--brand-text); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }
.hint { font-size: 13px; color: var(--text-secondary); margin: 0 0 12px; }
.form-row .hint { margin: 0; }
.muted { color: var(--text-muted); }
.lead { color: var(--text-secondary); margin: 6px 0 20px; }
.wrap { white-space: normal; max-width: 260px; }
.radio-group { display: flex; gap: 10px; flex-wrap: wrap; }
.radio-card { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius); cursor: pointer; font-size: 14px; }
.radio-card:has(input:checked) { border-color: var(--brand); background: var(--brand-tint); color: var(--brand-text); font-weight: 600; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

.badge.info { background: var(--info-bg); color: var(--info-text); }
.badge.success { background: var(--success-bg); color: var(--success-text); }
.badge.warning { background: var(--warning-bg); color: var(--warning-text); }
.badge.big { font-size: 13px; padding: 4px 12px; vertical-align: middle; }

/* ---------- Tickets (interne) ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tab { display: inline-flex; align-items: center; gap: 6px; padding: 10px 14px; color: var(--text-secondary); text-decoration: none; font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand-text); border-bottom-color: var(--brand); font-weight: 600; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters select { width: auto; min-width: 180px; }
.filters input[type=text] { flex: 1; min-width: 220px; width: auto; }
.table-click tbody tr { cursor: pointer; }
.table-click tbody tr:hover { background: var(--surface-muted); }
.table-click a { color: inherit; text-decoration: none; }
td small { font-size: 12px; }
.empty { text-align: center; padding: 40px 20px; color: var(--text-secondary); }
.empty i { font-size: 40px; color: var(--text-muted); }
.empty p { margin: 6px 0; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; }

.ticket-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.ticket-head h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.copy-row { display: flex; gap: 8px; width: 100%; }
.copy-row input { flex: 1; min-width: 0; font-size: 13px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.facts { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 6px 12px; margin: 0 0 14px; font-size: 14px; }
.facts dt { color: var(--text-muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.description { white-space: pre-line; background: var(--surface-muted); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; }
.attachments { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.attachment { width: 120px; display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--text-secondary); font-size: 12px; }
.attachment img { width: 120px; height: 90px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--border); }
.attachment i { font-size: 40px; height: 90px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: var(--radius); }
.attachment span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.warranty { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; margin: 0 0 6px; }
.warranty i { font-size: 22px; }
.warranty.ok { color: var(--success-text); }
.warranty.ko { color: var(--warning-text); }
.warranty.unknown { color: var(--text-secondary); }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.timeline li { border-left: 3px solid var(--brand); padding: 6px 12px; background: var(--surface-muted); }
.timeline li.from-client { border-left-color: var(--success-text); }
.timeline li.internal { border-left-color: var(--border-strong); }
.timeline-meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.timeline-body { white-space: pre-line; font-size: 14px; margin-top: 2px; }

/* ---------- Pages publiques (clients) ---------- */
.public-header { background: var(--sidebar-bg); color: #fff; }
.public-header-inner { max-width: 820px; margin: 0 auto; padding: 14px 16px; display: flex; align-items: center; gap: 16px; }
.public-logo { height: 34px; width: auto; display: block; }
.public-title { font-weight: 600; font-size: 15px; border-left: 1px solid rgba(255,255,255,.35); padding-left: 16px; }
.public-header .theme-toggle { background: transparent; border-color: rgba(255,255,255,.35); color: #fff; }
.public-main { max-width: 820px; margin: 0 auto; padding: 28px 16px; }
.public-footer { text-align: center; color: var(--text-muted); font-size: 12px; padding: 0 16px 28px; }
.rma-number { font-size: 30px; font-weight: 700; letter-spacing: .04em; color: var(--brand-text); margin: 4px 0 12px; }

@media (max-width: 960px) {
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .public-title { display: none; }
  .facts { grid-template-columns: 110px minmax(0, 1fr); }
}
