/* ── Tokens ──────────────────────────────────────────────────────────────────── */
:root {
  --sidebar-w: 224px;
  --header-h: 56px;

  /* Sidebar */
  --sb-bg:          #0f172a;
  --sb-border:      rgba(255,255,255,.07);
  --sb-text:        rgba(255,255,255,.55);
  --sb-text-bright: rgba(255,255,255,.88);
  --sb-hover:       rgba(255,255,255,.055);
  --sb-active-bg:   rgba(59,130,246,.18);
  --sb-active-text: #93c5fd;
  --sb-section:     rgba(255,255,255,.28);

  /* Content */
  --bg:      #f1f5f9;
  --white:   #ffffff;
  --border:  #e2e8f0;
  --border-l:#f1f5f9;

  /* Typography */
  --text:    #0f172a;
  --text-2:  #334155;
  --muted:   #64748b;
  --subtle:  #94a3b8;

  /* Accent */
  --blue:       #3b82f6;
  --blue-h:     #2563eb;
  --blue-light: #eff6ff;
  --blue-bd:    #bfdbfe;

  /* Status */
  --green:    #16a34a;
  --green-bg: #f0fdf4;
  --green-bd: #bbf7d0;
  --red:      #dc2626;
  --red-bg:   #fef2f2;
  --red-bd:   #fecaca;
  --amber:    #d97706;
  --amber-bg: #fffbeb;
  --amber-bd: #fde68a;

  /* Misc */
  --radius:  6px;
  --radius-l:10px;
  --shadow-s: 0 1px 2px rgba(0,0,0,.05);
  --shadow:   0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-m: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -1px rgba(0,0,0,.05);
}

/* ── Reset ───────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Login ───────────────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  padding: 24px;
}

.login-box {
  background: var(--white);
  border-radius: var(--radius-l);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  width: 100%; max-width: 380px;
  overflow: hidden;
}

.login-brand {
  background: var(--sb-bg);
  padding: 28px 32px 24px;
  text-align: center;
}

.login-logo {
  font-size: 1.75rem; font-weight: 700; letter-spacing: -.03em;
  color: var(--white);
}
.login-logo span { color: var(--blue); }

.login-tagline {
  font-size: .78rem; color: rgba(255,255,255,.4);
  margin-top: 6px; letter-spacing: .02em;
}

.login-body { padding: 28px 32px; }

.login-title {
  font-size: 1rem; font-weight: 600; color: var(--text);
  margin-bottom: 20px;
}

.login-error {
  background: var(--red-bg); border: 1px solid var(--red-bd);
  color: var(--red); font-size: .8rem; padding: 10px 12px;
  border-radius: var(--radius); margin-bottom: 16px;
}

/* ── App layout ──────────────────────────────────────────────────────────────── */
.app-layout {
  display: flex; min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sb-bg);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 50;
  border-right: 1px solid var(--sb-border);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0;
}

.sidebar-logo {
  font-size: 1.3rem; font-weight: 700; letter-spacing: -.03em;
  color: var(--white); cursor: pointer; display: block;
}
.sidebar-logo span { color: var(--blue); }

.sidebar-company {
  font-size: .7rem; color: var(--sb-text); margin-top: 4px;
  letter-spacing: .02em;
}

.sidebar-nav { flex: 1; padding: 12px 10px; }

.nav-section {
  font-size: .65rem; font-weight: 600; color: var(--sb-section);
  text-transform: uppercase; letter-spacing: .1em;
  padding: 12px 8px 4px;
}

.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: var(--radius);
  font-size: .825rem; font-weight: 500;
  color: var(--sb-text); cursor: pointer;
  transition: color .12s, background .12s;
  text-decoration: none; margin-bottom: 1px;
  user-select: none;
}
.nav-item:hover { color: var(--sb-text-bright); background: var(--sb-hover); }
.nav-item.active { color: var(--sb-active-text); background: var(--sb-active-bg); }
.nav-item.sub { padding-left: 30px; font-size: .8rem; }

.nav-item-icon { font-size: 1rem; flex-shrink: 0; opacity: .7; }
.nav-item.active .nav-item-icon { opacity: 1; }

.nav-item-badge {
  margin-left: auto; font-size: .65rem; font-weight: 600;
  background: var(--blue); color: white;
  padding: 1px 6px; border-radius: 99px;
}

.sidebar-footer {
  border-top: 1px solid var(--sb-border);
  padding: 14px 16px;
  flex-shrink: 0;
}
.sidebar-user {
  font-size: .78rem; color: var(--sb-text); margin-bottom: 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Main content ────────────────────────────────────────────────────────────── */
.app-main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex; flex-direction: column;
  min-height: 100vh;
}

.page-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 40;
  flex-shrink: 0;
}

.page-header-left { display: flex; flex-direction: column; gap: 1px; }
.page-title { font-size: .95rem; font-weight: 600; color: var(--text); }
.page-subtitle { font-size: .75rem; color: var(--muted); }

.page-header-right { display: flex; align-items: center; gap: 8px; }

.page-body { padding: 24px 28px; flex: 1; }

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--white); border-radius: var(--radius-l);
  border: 1px solid var(--border); box-shadow: var(--shadow-s);
}

.card-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: .875rem; font-weight: 600; color: var(--text); }
.card-body   { padding: 18px; }

/* ── Filter bar ──────────────────────────────────────────────────────────────── */
.filter-bar {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius-l); padding: 12px 18px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 18px; box-shadow: var(--shadow-s);
}
.filter-bar label { font-size: .8rem; color: var(--muted); white-space: nowrap; }

/* ── Company group ───────────────────────────────────────────────────────────── */
.company-group {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius-l); margin-bottom: 12px;
  overflow: hidden; box-shadow: var(--shadow-s);
}

.company-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; cursor: pointer;
  background: #fafbff; border-bottom: 1px solid transparent;
  transition: background .12s;
  user-select: none;
}
.company-row:hover { background: #f1f5fb; }
.company-row.open  { border-bottom-color: var(--border); }

.company-check { flex-shrink: 0; }
.company-name  { font-weight: 600; font-size: .875rem; flex: 1; }
.company-meta  { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.chevron { font-size: .7rem; color: var(--subtle); transition: transform .2s; flex-shrink: 0; }
.chevron.open { transform: rotate(90deg); }

.company-body { display: none; }
.company-body.open { display: block; }

/* ── Ticket row ──────────────────────────────────────────────────────────────── */
.ticket-section { border-bottom: 1px solid var(--border-l); }
.ticket-section:last-child { border-bottom: none; }

.ticket-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 18px; cursor: pointer;
  background: var(--white);
  transition: background .12s;
  user-select: none;
}
.ticket-row:hover { background: #fafbff; }
.ticket-row.open  { border-bottom: 1px solid var(--border-l); }

.ticket-check  { flex-shrink: 0; margin-top: 2px; }
.ticket-info   { flex: 1; }
.ticket-number { font-size: .78rem; font-weight: 600; color: var(--blue); }
.ticket-title  { font-size: .82rem; color: var(--text-2); margin-top: 1px; }

.ticket-right  { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ticket-amount { font-size: .875rem; font-weight: 600; color: var(--text); }
.ticket-chevron { font-size: .65rem; color: var(--subtle); transition: transform .2s; }
.ticket-chevron.open { transform: rotate(90deg); }

.ticket-actions { display: flex; gap: 6px; }

/* ── Item rows ───────────────────────────────────────────────────────────────── */
.items-table { width: 100%; border-collapse: collapse; }
.items-table td {
  padding: 7px 18px; font-size: .8rem; color: var(--text-2);
  border-bottom: 1px solid var(--border-l);
}
.items-table tr:last-child td { border-bottom: none; }
.items-table tr { background: #fafafa; }
.items-table tr:hover { background: #f5f7fb; }

.item-date   { white-space: nowrap; color: var(--muted); width: 90px; }
.item-tech   { width: 130px; }
.item-desc   { color: var(--muted); font-size: .76rem; }
.item-amount { white-space: nowrap; font-weight: 500; text-align: right; width: 80px; }

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 99px;
  font-size: .7rem; font-weight: 500; white-space: nowrap;
}
.badge-distance { background: var(--blue-light); color: var(--blue-h); }
.badge-site     { background: var(--amber-bg);   color: var(--amber); border: 1px solid var(--amber-bd); }
.badge-green    { background: var(--green-bg);   color: var(--green); }
.badge-red      { background: var(--red-bg);     color: var(--red); }
.badge-gray     { background: #f1f5f9; color: var(--muted); }

/* ── Sticky generate bar ─────────────────────────────────────────────────────── */
.generate-bar {
  position: sticky; bottom: 0; z-index: 30;
  background: var(--sb-bg); border-top: 1px solid rgba(255,255,255,.08);
  padding: 14px 28px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
}
.generate-info { color: rgba(255,255,255,.7); font-size: .82rem; }
.generate-info strong { color: white; font-size: .9rem; }

/* ── Forms ───────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-group:last-child { margin-bottom: 0; }

.form-label {
  font-size: .75rem; font-weight: 500; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}

.form-input, .form-select, .form-textarea {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: inherit; font-size: .875rem; color: var(--text);
  background: var(--white); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}
.form-input::placeholder { color: var(--subtle); }
.form-textarea { resize: vertical; min-height: 72px; }

.form-hint { font-size: .75rem; color: var(--muted); margin-top: 2px; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 16px; border-radius: var(--radius);
  font-family: inherit; font-size: .825rem; font-weight: 500;
  cursor: pointer; border: 1px solid transparent;
  transition: all .15s; white-space: nowrap;
  line-height: 1.4;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary  { background: var(--blue); color: white; border-color: var(--blue); }
.btn-primary:hover:not(:disabled) { background: var(--blue-h); border-color: var(--blue-h); }

.btn-secondary { background: var(--white); color: var(--text-2); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: #f8fafc; }

.btn-ghost    { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: #f1f5f9; color: var(--text); }

.btn-danger   { background: var(--red-bg); color: var(--red); border-color: var(--red-bd); }
.btn-danger:hover:not(:disabled) { background: var(--red-bd); }

.btn-success  { background: var(--green); color: white; border-color: var(--green); }
.btn-success:hover:not(:disabled) { background: #15803d; }

.btn-sm { padding: 4px 10px; font-size: .775rem; }
.btn-lg { padding: 10px 22px; font-size: .9rem; }

.btn-white { background: white; color: var(--text); border-color: var(--border); }
.btn-white:hover:not(:disabled) { background: #f8fafc; }

/* ── Table ───────────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 9px 14px;
  font-size: .72rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  background: #f8fafc; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 14px; font-size: .845rem;
  border-bottom: 1px solid var(--border-l); color: var(--text-2);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #fafbff; }
.data-table td.mono { font-family: 'JetBrains Mono', monospace; font-size: .78rem; }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-mask {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15,23,42,.55); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}

.modal {
  background: var(--white); border-radius: var(--radius-l);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 100%; max-width: 520px; max-height: 90vh;
  overflow-y: auto; animation: modalIn .18s ease;
}
.modal-lg { max-width: 700px; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: .95rem; font-weight: 600; color: var(--text); }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 1.1rem; padding: 2px 6px;
  border-radius: 4px; line-height: 1;
}
.modal-close:hover { background: var(--border-l); }

.modal-body   { padding: 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Settings table ──────────────────────────────────────────────────────────── */
.settings-table { width: 100%; border-collapse: collapse; }
.settings-table th {
  padding: 8px 10px; font-size: .72rem; font-weight: 600; color: var(--muted);
  text-align: left; background: #f8fafc; border-bottom: 1px solid var(--border);
}
.settings-table td { padding: 5px 6px; border-bottom: 1px solid var(--border-l); }
.settings-table tr:last-child td { border-bottom: none; }
.settings-table input {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 4px; font-size: .82rem; font-family: inherit;
  background: var(--white); color: var(--text);
}
.settings-table input:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 2px rgba(59,130,246,.1); }

/* ── Results ─────────────────────────────────────────────────────────────────── */
.result-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border-l);
}
.result-item:last-child { border-bottom: none; }
.result-icon { font-size: 1.1rem; margin-top: 1px; flex-shrink: 0; }
.result-name { font-weight: 600; font-size: .875rem; }
.result-msg  { font-size: .8rem; color: var(--muted); margin-top: 3px; }

/* ── History ─────────────────────────────────────────────────────────────────── */
.history-filter { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

/* ── Toast ───────────────────────────────────────────────────────────────────── */
.toast-wrap {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px; z-index: 1000;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius);
  font-size: .845rem; font-weight: 500;
  box-shadow: var(--shadow-m);
  animation: toastIn .2s ease;
  min-width: 240px; max-width: 360px;
}
@keyframes toastIn { from { opacity:0; transform: translateX(10px); } to { opacity:1; transform: translateX(0); } }
.toast-ok  { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-bd); }
.toast-err { background: var(--red-bg);   color: var(--red);   border: 1px solid var(--red-bd); }
.toast-info{ background: var(--blue-light); color: var(--blue-h); border: 1px solid var(--blue-bd); }

/* ── Spinner ─────────────────────────────────────────────────────────────────── */
.spinner-wrap { display: flex; justify-content: center; align-items: center; padding: 48px; }
.spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--border); border-top-color: var(--blue);
  border-radius: 50%; animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 60px 24px;
  color: var(--muted); font-size: .875rem;
}
.empty-icon  { font-size: 2.5rem; margin-bottom: 12px; }
.empty-title { font-size: 1rem; font-weight: 600; color: var(--text); margin-bottom: 6px; }

/* ── Misc ────────────────────────────────────────────────────────────────────── */
.checkbox { cursor: pointer; accent-color: var(--blue); width: 15px; height: 15px; }
input[type="date"] {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  font-family: inherit; font-size: .825rem; color: var(--text); background: var(--white);
}
input[type="date"]:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px rgba(59,130,246,.1); }

.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--muted); }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-blue   { color: var(--blue); }
.mono        { font-family: 'Courier New', monospace; }
.fw-600      { font-weight: 600; }
.gap-8       { gap: 8px; }
.flex        { display: flex; align-items: center; }
.flex-1      { flex: 1; }
.mt-4        { margin-top: 4px; }
.mb-16       { margin-bottom: 16px; }
.section-title { font-size: .875rem; font-weight: 600; color: var(--text); margin-bottom: 10px; }
.section-hint  { font-size: .78rem; color: var(--muted); margin-bottom: 14px; line-height: 1.5; }

/* ── Tabs ── */
.tab-btn { background:none;border:none;border-bottom:2px solid transparent;padding:10px 20px;font-size:.875rem;font-weight:500;color:var(--muted);cursor:pointer;margin-bottom:-2px;transition:color .15s,border-color .15s; }
.tab-btn:hover { color:var(--text); }
.tab-btn.active { color:var(--blue);border-bottom-color:var(--blue); }

/* ── Badges statut ── */
.badge-en_cours  { font-size:.75rem;padding:2px 8px;border-radius:99px;background:#f0fdf4;color:#16a34a;font-weight:500 }
.badge-suspendu  { font-size:.75rem;padding:2px 8px;border-radius:99px;background:#fefce8;color:#ca8a04;font-weight:500 }
.badge-termine   { font-size:.75rem;padding:2px 8px;border-radius:99px;background:#fef2f2;color:#dc2626;font-weight:500 }
.badge-actif     { font-size:.75rem;padding:2px 8px;border-radius:99px;background:#f0fdf4;color:#16a34a;font-weight:500 }
