:root {
  --navy: #0f172a;
  --navy-2: #111827;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #f97316;
  --teal: #0f9aa6;
  --text: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f8fafc;
  --white: #ffffff;
  --shadow: 0 18px 55px rgba(15, 23, 42, 0.08);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--blue); text-decoration: none; }
button, input, textarea, select { font: inherit; }
.login-page { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at top left, rgba(15,154,166,.2), transparent 30%), linear-gradient(135deg, #0f172a, #111827 55%, #0b1220); padding: 24px; }
.login-card { width: min(420px, 100%); background: white; padding: 34px; border-radius: 28px; box-shadow: var(--shadow); }
.login-logo { width: 105px; height: 105px; display: block; object-fit: contain; margin: 0 auto 14px; border-radius: 24px; }
.login-card h1 { text-align: center; margin: 0; color: var(--navy); }
.login-card p { text-align: center; color: var(--muted); margin-bottom: 22px; }
.login-help { margin-top: 16px; padding: 12px; background: var(--blue-soft); border-radius: 14px; color: var(--navy); font-size: 13px; }
label { display: block; font-weight: 700; font-size: 13px; margin-bottom: 7px; color: var(--navy); }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; outline: none; background: white; color: var(--text); }
textarea { min-height: 95px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(37, 99, 235, .11); }
form label + input, form label + textarea, form label + select { margin-bottom: 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: 14px; padding: 11px 16px; font-weight: 800; cursor: pointer; gap: 8px; transition: .2s; white-space: nowrap; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: linear-gradient(135deg, var(--blue), #1d4ed8); color: white; box-shadow: 0 10px 25px rgba(37,99,235,.2); }
.btn-soft { background: #eef2ff; color: var(--navy); }
.btn-danger { background: #fee2e2; color: var(--red); }
.btn-icon { width: 38px; height: 38px; padding: 0; flex: 0 0 auto; border-radius: 12px; }
.btn-icon .action-icon { display: block; width: 20px; height: 20px; pointer-events: none; }
.btn-icon:focus-visible { outline: 3px solid #60a5fa; outline-offset: 3px; }
.w-full { width: 100%; }
.app-shell { display: grid; grid-template-columns: 286px 1fr; min-height: 100vh; }
.sidebar { background: #08111f; color: white; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 22px; }
.brand { display: flex; gap: 13px; align-items: center; padding-bottom: 22px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand img { width: 58px; height: 58px; object-fit: contain; border-radius: 16px; background: white; padding: 3px; }
.brand strong { display: block; font-size: 18px; letter-spacing: .3px; }
.brand span, .user-card span { display: block; color: #94a3b8; font-size: 12px; margin-top: 3px; }
.menu { padding: 24px 0; display: grid; gap: 8px; }
.menu a { color: #cbd5e1; padding: 13px 14px; border-radius: 16px; font-weight: 750; }
.menu a.active, .menu a:hover { background: rgba(37,99,235,.22); color: white; }
.sidebar-footer { margin-top: auto; display: grid; gap: 12px; }
.user-card { padding: 14px; background: rgba(255,255,255,.06); border-radius: 18px; }
.logout { color: #fecaca; font-weight: 800; padding: 10px 14px; text-align: left; }
.content { padding: 26px; overflow-x: hidden; }
.topbar { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin-bottom: 22px; }
.topbar h1 { margin: 0 0 4px; color: var(--navy); font-size: 28px; }
.topbar p { margin: 0; color: var(--muted); }
.top-actions, .inline-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.cards-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card, .panel { background: white; border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.stat-card { padding: 20px; min-height: 135px; position: relative; overflow: hidden; }
.stat-card:after { content: ''; position: absolute; right: -35px; top: -35px; width: 110px; height: 110px; border-radius: 999px; background: rgba(37,99,235,.08); }
.stat-card span { color: var(--muted); font-size: 13px; font-weight: 800; text-transform: uppercase; }
.stat-card strong { display: block; color: var(--navy); font-size: 26px; margin: 14px 0 4px; }
.stat-card small { color: var(--muted); }
.panel { margin-top: 18px; padding: 20px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 16px; }
.panel-header h2 { margin: 0; color: var(--navy); font-size: 19px; }
.panel-header p { margin: 4px 0 0; color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); background: #f8fafc; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
td small { color: var(--muted); }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 6px 10px; font-size: 11px; font-weight: 900; }
.badge.en_attente_paiement { background: #fff7ed; color: #c2410c; }
.badge.paye { background: #dcfce7; color: #15803d; }
.badge.libere { background: #dbeafe; color: #1d4ed8; }
.badge.annule { background: #fee2e2; color: #b91c1c; }
.form-panel { max-width: 980px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.span-2 { grid-column: span 2; }
.form-actions { margin-top: 8px; }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 10px; margin-bottom: 16px; align-items: end; }
.filters-wide { grid-template-columns: 2fr 1fr 1fr 1.2fr 1.1fr auto; }
.origin-summary { display: flex; gap: 10px; flex-wrap: wrap; margin: 0 0 16px; }
.origin-chip { border: 1px solid var(--line); background: #f8fafc; border-radius: 16px; padding: 10px 13px; min-width: 160px; }
.origin-chip strong { display: block; color: var(--navy); }
.origin-chip span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.mini-form { display: grid; grid-template-columns: 110px 140px auto; gap: 8px; align-items: center; }
.mini-form input { padding: 9px 10px; border-radius: 12px; margin: 0; }
.detail-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.detail-grid div { background: #f8fafc; border: 1px solid var(--line); border-radius: 18px; padding: 14px; }
.detail-grid span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; margin-bottom: 6px; }
.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.two-columns { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; }
.activity-list { display: grid; gap: 10px; }
.activity-item { padding: 12px; background: #f8fafc; border: 1px solid var(--line); border-radius: 16px; }
.activity-item span { color: var(--muted); font-size: 12px; }
.activity-item strong { display: block; color: var(--navy); margin-top: 3px; }
.activity-item p { margin: 4px 0 0; color: var(--text); }
.activity-dropdown { align-self: start; padding: 0; overflow: hidden; }
.activity-dropdown-summary { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 20px; cursor: pointer; list-style: none; user-select: none; }
.activity-dropdown-summary::-webkit-details-marker { display: none; }
.activity-dropdown-summary:focus-visible { outline: 3px solid rgba(37, 99, 235, .28); outline-offset: -3px; border-radius: 24px; }
.activity-dropdown-summary strong { display: block; color: var(--navy); font-size: 19px; }
.activity-dropdown-summary small { display: block; color: var(--muted); margin-top: 4px; }
.activity-dropdown-toggle { display: inline-flex; align-items: center; gap: 8px; color: var(--blue); font-size: 13px; font-weight: 800; }
.activity-dropdown-toggle:after { content: ''; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translateY(-2px); transition: transform .2s ease; }
.activity-dropdown[open] .activity-dropdown-toggle { font-size: 0; }
.activity-dropdown[open] .activity-dropdown-toggle:before { content: 'Masquer'; font-size: 13px; }
.activity-dropdown[open] .activity-dropdown-toggle:after { transform: rotate(225deg) translate(-2px, -2px); }
.activity-dropdown-content { padding: 0 20px 20px; border-top: 1px solid var(--line); }
.activity-dropdown-actions { display: flex; justify-content: flex-end; padding: 16px 0; }
.activity-dropdown-actions form { margin: 0; }
.alert { padding: 14px 16px; border-radius: 16px; margin: 0 0 16px; font-weight: 750; transition: .4s; }
.alert.hide { opacity: 0; transform: translateY(-4px); }
.alert-success { background: #dcfce7; color: #166534; }
.alert-danger { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-sensitive { display: grid; gap: 7px; border: 1px solid #86efac; }
.alert-expiry { color: inherit; opacity: .8; font-weight: 700; }
.muted-row { opacity: .55; }
.error-page { min-height: 100vh; display: grid; place-content: center; text-align: center; gap: 14px; }

.row-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.sensitive-inline-form { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sensitive-inline-form input { width: 180px; padding: 9px 10px; margin: 0; border-radius: 12px; }
.link-button { border: none; background: transparent; color: var(--blue); font-weight: 800; cursor: pointer; padding: 0; }
.link-button:hover { text-decoration: underline; }
.print-link { font-weight: 800; color: var(--green); }
.print-link:hover { text-decoration: underline; }
.status-help { display: inline-flex; align-items: center; padding: 11px 14px; border-radius: 14px; font-weight: 800; }
.status-help.warning { background: #fef3c7; color: #92400e; }
.status-help.success { background: #dcfce7; color: #166534; }

@media (max-width: 1100px) { .cards-4 { grid-template-columns: repeat(2, 1fr); } .two-columns { grid-template-columns: 1fr; } .filters, .filters-wide { grid-template-columns: 1fr 1fr; } .detail-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 820px) { .app-shell { grid-template-columns: 1fr; } .sidebar { position: relative; height: auto; } .topbar { flex-direction: column; align-items: flex-start; } .cards-4 { grid-template-columns: 1fr; } .form-grid, .detail-grid { grid-template-columns: 1fr; } .span-2 { grid-column: span 1; } .filters, .filters-wide, .mini-form { grid-template-columns: 1fr; } }
.dev-reset-box { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; border-radius: 16px; padding: 12px; margin-bottom: 14px; word-break: break-all; font-size: 13px; }
.dev-reset-box a { color: #1d4ed8; font-weight: 800; }
.otp-input { text-align: center; font-size: 26px; font-weight: 900; letter-spacing: .35em; margin-bottom: 14px; }
.checkbox-row { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 16px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #f8fafc; cursor: pointer; }
.checkbox-row input { width: 18px; height: 18px; margin: 2px 0 0; flex: 0 0 auto; accent-color: var(--blue); }
.checkbox-row span { font-weight: 800; line-height: 1.35; }
.checkbox-row small { display: block; margin-top: 4px; color: var(--muted); font-weight: 600; }
.otp-resend { margin-top: 14px; text-align: center; }
.maintenance-counts { margin-bottom: 20px; }
.danger-zone { border: 1px solid #fecaca; background: #fff7f7; border-radius: 18px; padding: 18px; }
.danger-zone h3 { color: var(--red); margin: 0 0 6px; }
.danger-zone p { color: var(--muted); margin: 0 0 16px; }

/* Historique et édition des colis */
.history-list { display: grid; gap: 14px; }
.history-item { border: 1px solid var(--line); background: #f8fafc; border-radius: 18px; padding: 15px; }
.history-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 8px; }
.history-head strong { color: var(--navy); }
.history-head span { color: var(--muted); font-size: 12px; }
.history-item p { margin: 6px 0 10px; }
.history-item ul { margin: 0; padding-left: 20px; display: grid; gap: 5px; }
.old-value { color: var(--red); text-decoration: line-through; }
.new-value { color: var(--green); font-weight: 800; }
.empty-state { color: var(--muted); margin: 0; }
.payment-gap { margin-top: 18px; }

/* Dashboard: all period indicators share the same server-side selection. */
.dashboard-period { margin-top: 0; }
.dashboard-period .panel-header { align-items: flex-start; flex-wrap: wrap; }
.period-label { color: var(--navy); background: var(--blue-soft); padding: 9px 12px; border-radius: 12px; font-size: 13px; font-weight: 750; }
.dashboard-period-form { display: grid; grid-template-columns: 1fr 1fr 1.4fr auto; gap: 14px; align-items: end; }
.dashboard-period-form input, .dashboard-period-form select { margin: 0; min-width: 0; }
.period-shortcuts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.period-shortcut { border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px; color: var(--muted); font-size: 13px; font-weight: 700; }
.period-shortcut.active, .period-shortcut:hover { background: var(--blue-soft); color: var(--blue); border-color: #a5b4fc; }
.period-error { background: #fef3c7; color: #92400e; padding: 12px; border-radius: 12px; }
.dashboard-period-cards { margin-top: 18px; }
.dashboard-stock { display: flex; gap: 12px 24px; align-items: center; flex-wrap: wrap; background: #eef2f7; border: 1px solid var(--line); padding: 16px 20px; border-radius: 18px; margin-top: 18px; color: var(--muted); font-size: 14px; }
.dashboard-stock strong, .dashboard-stock b { color: var(--navy); }
.evolution-chart-legend { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 10px 24px; margin: 0 0 16px; }
.evolution-chart-legend li { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; font-weight: 700; }
.evolution-chart-series-blue { color: #2563eb; }
.evolution-chart-series-teal { color: #0f766e; }
.evolution-chart-series-orange { color: #c2410c; }
.evolution-chart-key { width: 22px; height: 4px; display: inline-block; border-top: 3px solid currentColor; }
.evolution-chart-series-teal.evolution-chart-key { border-top-style: dashed; }
.evolution-chart-series-orange.evolution-chart-key { border-top-style: dotted; }
.evolution-chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.evolution-chart-grid { stroke: #e2e8f0; stroke-width: 1; }
.evolution-chart-axis { stroke: #94a3b8; stroke-width: 1; }
.evolution-chart-tick, .evolution-chart-label { fill: #475569; font-size: 12px; }
.evolution-chart-line { stroke: currentColor; stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.evolution-chart-series-teal .evolution-chart-line { stroke-dasharray: 7 4; }
.evolution-chart-series-orange .evolution-chart-line { stroke-dasharray: 2 5; }
.evolution-chart-dot { fill: currentColor; stroke: #ffffff; stroke-width: 1; }
.evolution-chart-empty { padding: 55px 16px; text-align: center; border: 1px dashed var(--line); border-radius: 16px; background: #f8fafc; }
.evolution-chart-details { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.evolution-chart-details summary { color: var(--blue); cursor: pointer; font-size: 13px; font-weight: 750; padding: 8px 0; }
.evolution-chart-details caption { text-align: left; padding: 12px; color: var(--muted); font-size: 13px; }
.evolution-chart-details .table-wrap { max-height: 360px; }
.chart-period-note { font-size: 12px; color: var(--muted); line-height: 1.6; margin-bottom: 0; }
@media (max-width: 820px) {
  .dashboard-period-form { grid-template-columns: 1fr 1fr; }
  .dashboard-evolution { overflow-x: auto; }
  .evolution-chart-svg { min-width: 620px; }
}
@media (max-width: 480px) { .dashboard-period-form { grid-template-columns: 1fr; } }
