/* ============================================================================
   LegiTag Battery Passport -- Common CSS
   Inspire du design tr_ (palette bleu #2583f7, Arial, sidebar 72/270px)
============================================================================ */

:root{
  --txt:#212225;
  --muted:#575c62;
  --br:#d3d5d8;
  --br-light:#e5e7eb;
  --hover:#f8fafc;
  --bg:#f6f9fcd0;
  --blue:#2583f7;
  --blue-dark:#1766c9;
  --green:#56a90a;
  --red:#bb0b0a;
  --orange:#f59e0b;
  --yellow:#f6db55;
  --shadow:0 12px 30px rgba(15,23,42,.06);
  --shadow-sm:0 2px 8px rgba(15,23,42,.05);
  --radius:14px;
  --radius-sm:10px;
  --radius-lg:16px;
  --sb-open-w: 270px;
  --sb-closed-w: 72px;
}

*,*::before,*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: Arial, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 24px 80px 96px;
  transition: padding-left .18s ease;
}
body.sb-open .container { padding-left: 294px; }

h1 { margin: 10px 0 20px; font-size: 28px; font-weight: 900; letter-spacing: -.2px; }
h2 { margin: 24px 0 12px; font-size: 20px; font-weight: 800; }
h3 { margin: 16px 0 8px; font-size: 16px; font-weight: 700; }

.muted { color: var(--muted); }

.breadcrumb {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; color: var(--muted); margin-bottom: 8px;
}
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--txt); }
.breadcrumb .sep { color: var(--muted); }

/* ============ SIDEBAR ============ */
.sb {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sb-closed-w);
  background: #fff;
  border-right: 1px solid var(--br-light);
  transition: width .18s ease;
  z-index: 9998;
  display: flex; flex-direction: column;
}
.sb-header {
  padding: 12px 10px;
  display: flex; align-items: center; justify-content: center;
  min-height: 52px;
  border-bottom: 1px solid var(--br-light);
}
.sb-logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 900; font-size: 18px; color: var(--txt);
  text-decoration: none;
}
.sb-logo-icon {
  width: 32px; height: 32px;
  background: var(--blue); color: #fff;
  border-radius: 8px; display: grid; place-items: center;
  font-weight: 900; font-size: 14px; letter-spacing: -.5px;
  flex-shrink: 0;
}
.sb-logo-text { display: none; white-space: nowrap; }
body.sb-open .sb-logo-text { display: inline; }

.sb-inner {
  flex: 1;
  overflow-x: hidden; overflow-y: auto;
  padding: 14px 10px;
}
.sb-inner::-webkit-scrollbar { display: none; }
.sb-inner { -ms-overflow-style: none; scrollbar-width: none; }

.sb-group { margin-bottom: 4px; }
.sb-group-btn {
  width: 100%; display: flex; align-items: center; gap: 12px;
  background: transparent; border: 0; padding: 10px 12px;
  cursor: pointer; border-radius: 10px;
  transition: background .15s ease;
  text-decoration: none; color: var(--txt);
  font-family: inherit; font-size: 14px; font-weight: 500;
}
.sb-group-btn:hover { background: #f1f5f9; }
.sb-group.active .sb-group-btn { background: #e6f0fe; color: var(--blue); }
.sb-group.active .sb-label { font-weight: 700; }
.sb-ico {
  width: 22px; height: 22px; flex: 0 0 22px;
  display: grid; place-items: center;
}
.sb-ico svg { width: 22px; height: 22px; }
.sb-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1; text-align: left;
}
body.sb-collapsed .sb-label { display: none !important; }
body.sb-collapsed .sb { width: var(--sb-closed-w); }
body.sb-open .sb { width: var(--sb-open-w); }

.sb-toggle {
  position: fixed;
  left: var(--sb-closed-w);
  top: 50%;
  transform: translate(-50%, -50%);
  width: 28px; height: 28px;
  border-radius: 999px;
  border: 1px solid var(--br-light);
  background: #fff;
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 9999;
  transition: left .18s ease;
}
.sb-toggle:hover { background: #f9fafb; }
.sb-toggle svg {
  width: 14px; height: 14px;
  stroke: #6b7280; stroke-width: 2.5; fill: none;
  transition: transform .18s ease;
}
body.sb-open .sb-toggle { left: var(--sb-open-w); }
body.sb-open .sb-toggle svg { transform: rotate(180deg); }

.sb-user-section {
  border-top: 1px solid var(--br-light);
  padding: 12px 10px;
}
.sb-user-btn {
  width: 100%; display: flex; align-items: center; gap: 10px;
  background: transparent; border: 0; padding: 8px;
  border-radius: 10px; cursor: pointer; font-family: inherit;
  transition: background .15s ease;
}
.sb-user-btn:hover { background: #f3f4f6; }
.user-badge {
  width: 36px; height: 36px; border-radius: 999px;
  background: var(--blue); color: #fff;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 800;
  flex-shrink: 0;
}
.sb-user-name {
  font-weight: 600; font-size: 14px; color: var(--txt);
  text-align: left; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
body.sb-collapsed .sb-user-name { display: none; }
.sb-user-dropdown {
  display: none;
  padding: 8px 12px; background: #f9fafb;
  border-radius: 8px; margin-top: 8px;
}
.sb-user-dropdown.show { display: block; }
.sb-dropdown-item { padding: 6px 4px; font-size: 13px; color: #374151; }
.sb-dropdown-divider { height: 1px; background: var(--br-light); margin: 8px 0; }
.sb-logout-btn {
  padding: 6px 4px; font-size: 13px; color: var(--red);
  cursor: pointer; font-weight: 600; background: transparent; border: 0; width: 100%; text-align: left; font-family: inherit;
}
.sb-logout-btn:hover { color: #8b0808; }
body.sb-collapsed .sb-user-dropdown { display: none !important; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer;
  font-size: 14px; font-weight: 600; font-family: inherit;
  transition: all .15s ease;
  text-decoration: none;
}
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn-secondary { background: #fff; color: var(--txt); border-color: var(--br); }
.btn-secondary:hover { background: var(--hover); border-color: var(--blue); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { background: #8b0808; border-color: #8b0808; }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { background: var(--hover); color: var(--txt); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-icon-only { padding: 8px; width: 36px; height: 36px; justify-content: center; }

/* ============ CARDS ============ */
.card {
  background: #fff;
  border: 1px solid var(--br-light);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-title { font-size: 16px; font-weight: 700; margin: 0 0 12px; }

/* ============ KPI ============ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.kpi-card {
  background: #fff;
  border: 1px solid var(--br-light);
  border-radius: var(--radius);
  padding: 20px;
}
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 28px; font-weight: 900; margin: 6px 0 0; color: var(--txt); }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ============ TABLES ============ */
.table-wrap {
  background: #fff; border: 1px solid var(--br-light);
  border-radius: var(--radius); overflow: hidden;
}
table {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
thead th {
  text-align: left; padding: 12px 16px;
  background: #f9fafb; font-weight: 700; color: var(--muted);
  border-bottom: 1px solid var(--br-light);
  font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
}
tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--br-light);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--hover); }
tbody tr.clickable { cursor: pointer; }

/* ============ FORMS ============ */
label {
  display: block;
  font-size: 13px; font-weight: 600; color: var(--muted);
  margin: 14px 0 6px;
}
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="url"],
input[type="tel"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--br);
  border-radius: 8px;
  font-family: inherit; font-size: 14px;
  background: #fff; color: var(--txt);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,131,247,.15);
}
textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.required::after { content: " *"; color: var(--red); }

/* ============ BADGES ============ */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .2px;
}
.badge-draft { background: #e5e7eb; color: #374151; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: #fef3c7; color: #92400e; }
.badge-archived { background: #f3e8ff; color: #6b21a8; }
.badge-ev { background: #dbeafe; color: #1e40af; }
.badge-lmt { background: #fef3c7; color: #92400e; }
.badge-industrial { background: #fee2e2; color: #991b1b; }
.badge-stationary { background: #d1fae5; color: #065f46; }
.badge-high { background: #fee2e2; color: #991b1b; }
.badge-medium { background: #fef3c7; color: #92400e; }
.badge-low { background: #dcfce7; color: #166534; }
.badge-compliant { background: #dcfce7; color: #166534; }
.badge-non_compliant, .badge-non-compliant { background: #fee2e2; color: #991b1b; }

.class-A { background: #059669; color: #fff; padding: 4px 12px; border-radius: 6px; font-weight: 800; }
.class-B { background: #65a30d; color: #fff; padding: 4px 12px; border-radius: 6px; font-weight: 800; }
.class-C { background: #eab308; color: #fff; padding: 4px 12px; border-radius: 6px; font-weight: 800; }
.class-D { background: #f97316; color: #fff; padding: 4px 12px; border-radius: 6px; font-weight: 800; }
.class-E { background: #dc2626; color: #fff; padding: 4px 12px; border-radius: 6px; font-weight: 800; }

/* ============ ALERTS & TOAST ============ */
.alert {
  padding: 12px 16px; border-radius: 10px;
  margin: 12px 0; font-size: 14px;
}
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-warn { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }

#toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--txt); color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 14px;
  opacity: 0; transform: translateY(10px);
  transition: all .2s ease;
  pointer-events: none;
  z-index: 10000;
  max-width: 400px;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { background: var(--red); }
#toast.success { background: var(--green); }

/* ============ LOADING ============ */
.loader {
  display: inline-block;
  width: 20px; height: 20px;
  border: 3px solid var(--br);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { text-align: center; padding: 40px; color: var(--muted); }

/* ============ TABS ============ */
.tabs {
  display: flex; gap: 0;
  border-bottom: 2px solid var(--br-light);
  margin-bottom: 24px;
  overflow-x: auto;
}
.tab {
  padding: 12px 20px;
  background: transparent; border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--muted); cursor: pointer;
  white-space: nowrap;
  transition: all .15s ease;
}
.tab:hover { color: var(--txt); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============ SEARCH + TOP BAR ============ */
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 20px;
}
.search-box {
  display: flex; align-items: center;
  background: #fff; border: 1px solid var(--br);
  border-radius: 10px; padding: 0 12px; height: 42px;
}
.search-box input {
  border: 0; outline: none; font-size: 14px;
  width: 240px; background: transparent;
}
.search-box svg { width: 18px; height: 18px; color: var(--muted); margin-right: 8px; }

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  display: none;
  align-items: center; justify-content: center;
  z-index: 9999;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 560px; width: calc(100% - 32px);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,.2);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.modal-title { font-size: 20px; font-weight: 800; margin: 0; }
.modal-close {
  background: transparent; border: 0; cursor: pointer;
  padding: 6px; border-radius: 8px;
  color: var(--muted);
}
.modal-close:hover { background: var(--hover); color: var(--txt); }
.modal-footer {
  display: flex; gap: 12px; justify-content: flex-end;
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--br-light);
}

/* ============ UTILITIES ============ */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-24 { gap: 24px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.w-full { width: 100%; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.hidden { display: none !important; }

.progress {
  width: 100%; height: 8px; background: var(--br-light);
  border-radius: 4px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--blue), #60a5fa);
  transition: width .3s ease;
}
.progress-fill.ok { background: linear-gradient(90deg, var(--green), #86efac); }
.progress-fill.warn { background: linear-gradient(90deg, var(--orange), #fbbf24); }
.progress-fill.danger { background: linear-gradient(90deg, var(--red), #f87171); }

.gauge {
  display: flex; align-items: center; gap: 10px;
}
.gauge-label { font-size: 13px; color: var(--muted); flex: 0 0 120px; }
.gauge-bar { flex: 1; }
.gauge-value { flex: 0 0 80px; text-align: right; font-weight: 700; font-size: 13px; }

/* ============ LinkedSelect ============ */
.linked-select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232583f7' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 14px;
  padding-right: 36px !important;
}
/* Inline-create modal is z-index above regular modals */
.inline-create-modal { z-index: 10001 !important; }

/* ============ SmartTable ============ */
.smart-table-wrap { background: #fff; }
.smart-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  background: #fff;
  border: 1px solid var(--br-light);
  border-radius: 10px;
  overflow: hidden;
}
.smart-table thead th {
  text-align: left; padding: 10px 12px;
  background: #f9fafb; color: var(--muted);
  font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  border-bottom: 1px solid var(--br-light);
}
.smart-table tbody td {
  padding: 6px;
  border-bottom: 1px solid var(--br-light);
  vertical-align: middle;
}
.smart-table tbody tr:last-child td { border-bottom: 0; }
.smart-table input, .smart-table select, .smart-table textarea {
  width: 100%; padding: 6px 10px; font-size: 13px;
  border: 1px solid var(--br); border-radius: 6px;
  background: #fff;
}
.smart-table input:focus, .smart-table select:focus, .smart-table textarea:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px rgba(37,131,247,.12);
}
.smart-table .btn-icon-only {
  width: 28px; height: 28px; padding: 0;
  color: var(--red);
}
.smart-table .btn-icon-only:hover { background: #fee2e2; }
