/* =================================================================
   GoTrakX ERP — Branding + Layout
   Palette : orange #f37321 / dark #0a0a0a / sidebar #111418
   ================================================================= */
:root {
  --brand: #f37321;
  --brand-dark: #d85d10;
  --dark: #0a0a0a;
  --sidebar: #111418;
  --sidebar-hover: #1a1f26;
  --sidebar-active: #f37321;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f4f6fa;
  --card: #ffffff;
  --success: #16a34a;
  --error: #dc2626;
  --warning: #f59e0b;
  --info: #2563eb;
  --shadow: 0 4px 16px rgba(15,23,42,.05);
  --radius: 8px;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  min-height: 100vh;
}

/* ============ SIDEBAR ============ */
.sidebar {
  width: 240px;
  background: var(--sidebar);
  color: #d1d5db;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.brand {
  padding: 18px 20px 14px;
  border-bottom: 1px solid #1f242c;
  display: flex;
  align-items: baseline;
  gap: 8px;
  text-decoration: none;
  color: #fff;
}
.brand img { height: 34px; width: auto; display: block; filter: brightness(0) invert(1); }
.brand-sub {
  font-size: 11px;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: 2px;
}
.nav {
  padding: 10px 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
}

/* Lien direct au top niveau (Tableau de bord) */
.nav-link-top {
  display: flex; align-items: center;
  padding: 10px 14px;
  color: #d1d5db;
  text-decoration: none;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 600;
  transition: all .12s;
  margin: 2px 4px 8px;
}
.nav-link-top:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link-top.active {
  background: rgba(243, 115, 33, 0.15);
  color: var(--brand);
  box-shadow: inset 3px 0 0 var(--brand);
}

/* Menu collapsible <details> */
.nav-menu {
  margin: 0 4px;
  border-radius: 6px;
  overflow: hidden;
}
.nav-menu[open] {
  background: rgba(255,255,255,0.02);
}
.nav-menu-head {
  cursor: pointer;
  list-style: none;
  display: flex; align-items: center;
  padding: 10px 12px;
  color: #d1d5db;
  font-size: 13px;
  font-weight: 600;
  border-radius: 6px;
  user-select: none;
  transition: background .12s, color .12s;
}
.nav-menu-head::-webkit-details-marker { display: none; }
.nav-menu-head:hover { background: var(--sidebar-hover); color: #fff; }
.nav-chevron {
  display: inline-block;
  width: 14px;
  font-size: 11px;
  color: #6b7280;
  margin-right: 8px;
  transition: transform .15s ease;
  transform: rotate(0deg);
}
.nav-menu[open] > .nav-menu-head .nav-chevron {
  transform: rotate(90deg);
  color: var(--brand);
}
.nav-menu-label { flex: 1; }

/* Sous-items dans un menu ouvert */
.nav-menu-body { padding: 2px 0 6px 0; }
.nav-sublink {
  display: block;
  padding: 7px 14px 7px 34px;
  color: #9ca3af;
  text-decoration: none;
  font-size: 12.5px;
  border-radius: 5px;
  margin: 1px 4px;
  transition: background .1s, color .1s;
}
.nav-sublink:hover { background: var(--sidebar-hover); color: #fff; }
.nav-sublink.active {
  background: rgba(243, 115, 33, 0.18);
  color: var(--brand);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--brand);
}

/* === Menu Nouveau (accent orange) === */
.nav-menu-accent .nav-menu-head {
  color: var(--brand);
  font-weight: 700;
  background: rgba(243, 115, 33, 0.08);
}
.nav-menu-accent[open] {
  background: rgba(243, 115, 33, 0.06);
  border: 1px solid rgba(243, 115, 33, 0.2);
}
.nav-menu-accent .nav-chevron { color: var(--brand); }
.nav-menu-accent .nav-sublink { color: #fbbf85; padding-left: 38px; }
.nav-menu-accent .nav-sublink::before {
  content: "+ ";
  color: var(--brand);
  font-weight: 700;
  margin-left: -16px;
  margin-right: 6px;
}
.nav-menu-accent .nav-sublink:hover {
  background: rgba(243, 115, 33, 0.2);
  color: #fff;
}
.nav-menu-accent .nav-sublink.active {
  background: var(--brand);
  color: #fff;
  box-shadow: none;
}
.nav-menu-accent .nav-sublink.active::before { color: #fff; }

/* compat ancienne classe */
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  color: #9ca3af; text-decoration: none;
  border-radius: 6px;
  font-size: 13px; font-weight: 500;
}
.nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link.active { background: rgba(243,115,33,0.15); color: var(--brand); font-weight: 600; }
.nav-icon { width: 18px; text-align: center; font-size: 13px; opacity: .7; }
.sidebar-foot {
  padding: 14px 14px 18px;
  border-top: 1px solid #1f242c;
}
.user { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.user-name { color: #fff; font-size: 13px; font-weight: 600; }
.user-role { color: #6b7280; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }

/* ============ MAIN ============ */
.main {
  flex: 1;
  padding: 28px 32px;
  min-width: 0;
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 20px;
  flex-wrap: wrap;
}
.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--dark);
  margin: 0;
  letter-spacing: -.2px;
}
.page-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

/* ============ CARDS ============ */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 20px;
}
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: #fafbfd;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.card-title { font-size: 14px; font-weight: 700; color: var(--dark); margin: 0; }
.card-body { padding: 16px 18px; }

/* ============ STATS ============ */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.stat::before {
  content:''; position:absolute; left:0; top:0; bottom:0;
  width: 3px; background: var(--brand);
}
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.2px; font-weight: 600; }
.stat-value { font-size: 24px; font-weight: 800; color: var(--dark); margin-top: 6px; letter-spacing: -.3px; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ============ TABLE ============ */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th, .table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 1px;
  font-weight: 700;
  background: #fafbfd;
}
.table tbody tr:hover { background: #fafbfd; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table a { color: var(--brand); text-decoration: none; font-weight: 600; }
.table a:hover { text-decoration: underline; }
.empty {
  text-align: center; padding: 40px 20px;
  color: var(--muted); font-size: 14px;
}

/* ============ BADGES ============ */
.badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e5e7eb;
  color: #374151;
}
.badge-draft     { background: #e5e7eb; color: #374151; }
.badge-sent      { background: #dbeafe; color: #1e40af; }
.badge-confirmed { background: #dbeafe; color: #1e40af; }
.badge-shipped   { background: #fef3c7; color: #92400e; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-accepted  { background: #d1fae5; color: #065f46; }
.badge-paid      { background: #d1fae5; color: #065f46; }
.badge-received  { background: #d1fae5; color: #065f46; }
.badge-rejected  { background: #fee2e2; color: #991b1b; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }
.badge-overdue   { background: #fee2e2; color: #991b1b; }
.badge-void      { background: #f3f4f6; color: #6b7280; }
.badge-converted { background: #ede9fe; color: #5b21b6; }
.badge-invoiced  { background: #ede9fe; color: #5b21b6; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px; font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  transition: all .12s;
  font-family: inherit;
}
.btn:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-primary {
  background: var(--brand); color: #fff; border-color: var(--brand);
}
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #15803d; border-color: #15803d; }
.btn-danger { background: var(--error); color: #fff; border-color: var(--error); }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============ FORMS ============ */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1px;
}
.field input, .field select, .field textarea {
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .12s, box-shadow .12s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(243,115,33,.15);
}
.field textarea { resize: vertical; min-height: 90px; font-family: inherit; }
.field .hint { font-size: 11px; color: var(--muted); }
.field-full { grid-column: 1 / -1; }

/* ============ LINE ITEMS ============ */
.lines {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 8px;
}
.lines th, .lines td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.lines th { font-size: 10.5px; text-transform: uppercase; color: var(--muted); letter-spacing: 1px; font-weight: 700; background: #fafbfd; }
.lines input, .lines select, .lines textarea {
  width: 100%; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 5px;
  font-size: 13px; font-family: inherit;
}
.lines textarea.line-description {
  resize: none;
  overflow: hidden;
  line-height: 1.45;
  min-height: 30px;
}
.lines input.num { text-align: right; }
.lines td.num, .lines th.num { text-align: right; font-variant-numeric: tabular-nums; }
.lines td.col-product { width: 240px; }
.lines td.col-qty { width: 80px; }
.lines td.col-price { width: 120px; }
.lines td.col-total { width: 110px; font-weight: 600; }
.lines td.col-rm { width: 30px; text-align: center; }
.btn-rm-line {
  background: transparent; border: 0; color: var(--error);
  font-size: 18px; cursor: pointer; padding: 0;
}

/* ============ TOTALS ============ */
.totals {
  margin-left: auto;
  width: 320px;
  font-size: 13px;
}
.totals .row {
  display: flex; justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.totals .row.grand {
  border-bottom: 0; border-top: 2px solid var(--dark);
  font-size: 16px; font-weight: 800; padding-top: 10px; margin-top: 4px;
  color: var(--dark);
}

/* ============ DOCUMENT VIEW ============ */
.doc-paper {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px;
  margin-bottom: 20px;
}
.doc-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 28px; gap: 24px;
  border-bottom: 3px solid var(--brand); padding-bottom: 18px;
}
.doc-logo img { height: 60px; }
.doc-meta { text-align: right; }
.doc-meta h1 {
  font-size: 26px; margin: 0 0 4px;
  text-transform: uppercase; letter-spacing: 2px; color: var(--dark);
}
.doc-meta .num { font-size: 15px; font-weight: 700; color: var(--brand); }
.doc-meta .date { font-size: 12px; color: var(--muted); margin-top: 4px; }

.doc-parties {
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px;
  margin-bottom: 22px;
}
.doc-parties h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--muted); margin: 0 0 6px;
}
.doc-parties .name { font-size: 15px; font-weight: 700; color: var(--dark); }
.doc-parties .addr { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.55; }

.doc-notes {
  margin-top: 22px;
  background: #f8fafc;
  border-left: 3px solid var(--brand);
  padding: 12px 16px;
  font-size: 13px; color: var(--text);
}
.doc-notes h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--muted); margin: 0 0 4px;
}

/* ============ FLASH ============ */
.flash-stack { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.flash {
  padding: 11px 14px; border-radius: 6px; font-size: 13.5px;
  border-left: 3px solid;
}
.flash-success { background: #ecfdf5; color: #065f46; border-left-color: var(--success); }
.flash-error   { background: #fef2f2; color: #991b1b; border-left-color: var(--error); }
.flash-info    { background: #eff6ff; color: #1e40af; border-left-color: var(--info); }
.flash-warning { background: #fffbeb; color: #92400e; border-left-color: var(--warning); }

/* ============ MISC ============ */
.search-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.search-bar input { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13.5px; }
.muted { color: var(--muted); }
.text-right { text-align: right; }
.gap-8 { gap: 8px; }
.mt-12 { margin-top: 12px; }
.mt-20 { margin-top: 20px; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

/* ============ MODAL ENVOI COURRIEL (style Outlook) ============ */
.modal {
  display: none;
  position: fixed; inset: 0;
  z-index: 1000;
  align-items: center; justify-content: center;
}
.modal.open { display: flex; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}
.modal-panel {
  position: relative;
  background: #fff;
  border-radius: 10px;
  width: 720px; max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  display: flex; flex-direction: column;
  overflow: hidden;
  font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
}
.modal-head {
  background: #0a0a0a; color: #fff;
  padding: 14px 22px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-eyebrow {
  font-size: 10px; font-weight: 700; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--brand);
}
.modal-title { font-size: 16px; font-weight: 700; margin-top: 2px; }
.modal-x {
  background: transparent; border: 0; color: #9ca3af;
  font-size: 28px; line-height: 1; cursor: pointer;
  padding: 0 4px;
}
.modal-x:hover { color: #fff; }
.modal-body {
  padding: 18px 22px;
  overflow-y: auto;
  flex: 1;
}
.modal-field {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 12px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid #f3f4f6;
}
.modal-field:last-child { border-bottom: 0; }
.modal-field > label {
  font-size: 12px; font-weight: 600; color: #6b7280;
  text-transform: uppercase; letter-spacing: 1px;
  padding-top: 8px;
}
.modal-field > input,
.modal-field > textarea,
.modal-field .modal-from {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 5px;
  font-size: 13.5px;
  font-family: inherit;
  color: #1f2937;
  background: #fff;
}
.modal-field > input:focus,
.modal-field > textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(243,115,33,.15);
}
.modal-field > textarea {
  resize: vertical;
  min-height: 200px;
  line-height: 1.55;
  font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
}
.modal-field .modal-from {
  background: #f8fafc;
  color: #6b7280;
  font-style: italic;
}
.modal-attach {
  margin-top: 10px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px dashed #e5e7eb;
  border-radius: 6px;
  font-size: 13px;
}
.modal-foot {
  padding: 14px 22px;
  background: #fafbfd;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
