/* ============================================
   GUIBOUT AMÉNAGEMENT EXTÉRIEUR — Styles
   Propulsé par Klaro
   ============================================ */

/* ---- VARIABLES ---- */
:root {
  --olive: #6B7C3E;
  --olive-dark: #566431;
  --olive-light: #E8F0DE;
  --olive-50: rgba(107,124,62,0.08);
  --olive-100: rgba(107,124,62,0.15);
  --white: #FFFFFF;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;
  --red: #DC2626;
  --red-light: #FEE2E2;
  --orange: #F59E0B;
  --orange-light: #FEF3C7;
  --green: #10B981;
  --green-light: #D1FAE5;
  --blue: #3B82F6;
  --blue-light: #DBEAFE;
  --sidebar-width: 260px;
  --header-height: 64px;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --transition: 0.2s ease;
}

/* ---- RESET ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  overflow-x: hidden;
}
a { color: var(--olive); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ============================================
   COOKIE BANNER
   ============================================ */
.cookie-banner {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--gray-900); color: var(--white);
  padding: 16px 24px; z-index: 9999;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; font-size: 0.9rem;
}
.cookie-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ============================================
   LOGIN
   ============================================ */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--gray-50) 0%, var(--olive-light) 100%);
  padding: 20px;
}
.login-card {
  background: var(--white); border-radius: 16px; padding: 48px 40px;
  box-shadow: var(--shadow-lg); width: 100%; max-width: 400px; text-align: center;
}
.login-logo { width: 80px; height: 80px; object-fit: contain; margin-bottom: 16px; }
.login-card h1 { font-size: 1.8rem; font-weight: 700; color: var(--olive); letter-spacing: 2px; }
.login-subtitle { color: var(--gray-500); font-style: italic; margin-bottom: 32px; font-size: 0.9rem; }
.login-form { text-align: left; }
.login-error {
  background: var(--red-light); color: var(--red); padding: 10px 14px;
  border-radius: var(--radius-sm); font-size: 0.85rem; margin-bottom: 12px;
}
.login-footer { margin-top: 32px; font-size: 0.8rem; color: var(--gray-400); }
.login-footer a { color: var(--olive); font-weight: 600; }

/* ============================================
   LAYOUT
   ============================================ */
.app-container { display: flex; min-height: 100vh; }

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-width); background: var(--white); border-right: 1px solid var(--gray-200);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100; transition: transform var(--transition);
}
.sidebar-header {
  padding: 20px 16px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--gray-200);
}
.sidebar-logo { width: 40px; height: 40px; object-fit: contain; }
.sidebar-brand { display: flex; flex-direction: column; }
.brand-name { font-weight: 700; font-size: 0.95rem; color: var(--olive); letter-spacing: 1.5px; }
.brand-sub { font-size: 0.65rem; color: var(--gray-500); font-style: italic; }
.sidebar-close { display: none; background: none; border: none; cursor: pointer; color: var(--gray-400); font-size: 1.2rem; margin-left: auto; }

/* Nav */
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: var(--radius-sm); color: var(--gray-600); font-size: 0.88rem;
  font-weight: 500; transition: all var(--transition); text-decoration: none; position: relative;
}
.nav-item:hover { background: var(--olive-50); color: var(--olive); text-decoration: none; }
.nav-item.active { background: var(--olive-light); color: var(--olive); font-weight: 600; }
.nav-item svg { flex-shrink: 0; }
.nav-badge {
  position: absolute; right: 10px; background: var(--olive); color: var(--white);
  font-size: 0.7rem; padding: 1px 7px; border-radius: 10px; font-weight: 600;
}
.nav-badge.badge-danger { background: var(--red); }
.nav-separator { height: 1px; background: var(--gray-200); margin: 8px 12px; }

/* Footer */
.sidebar-footer { padding: 16px; border-top: 1px solid var(--gray-200); }
.btn-logout {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 12px;
  background: none; border: 1px solid var(--gray-200); border-radius: var(--radius-sm);
  color: var(--gray-600); cursor: pointer; font-size: 0.85rem; transition: all var(--transition);
}
.btn-logout:hover { border-color: var(--red); color: var(--red); }
.sidebar-klaro {
  margin-top: 12px; font-size: 0.7rem; color: var(--gray-400); text-align: center;
  font-family: 'JetBrains Mono', monospace;
}
.sidebar-klaro a { color: var(--olive); font-weight: 600; }

/* Overlay */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 99; backdrop-filter: blur(2px);
}

/* ---- MAIN ---- */
.main-content {
  margin-left: var(--sidebar-width); flex: 1; min-height: 100vh;
  display: flex; flex-direction: column;
}
.main-header {
  height: var(--header-height); padding: 0 24px; background: var(--white);
  border-bottom: 1px solid var(--gray-200); display: flex;
  align-items: center; justify-content: space-between; position: sticky;
  top: 0; z-index: 50;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-left h2 { font-size: 1.15rem; font-weight: 600; color: var(--gray-800); }
.menu-toggle { display: none; background: none; border: none; cursor: pointer; color: var(--gray-600); }
.header-right { display: flex; align-items: center; gap: 12px; }
.sync-indicator { display: flex; align-items: center; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.user-name { font-size: 0.85rem; color: var(--gray-600); font-weight: 500; }

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

/* ============================================
   COMPOSANTS COMMUNS
   ============================================ */

/* ---- BOUTONS ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 10px 18px;
  border-radius: var(--radius-sm); font-weight: 500; font-size: 0.88rem;
  border: none; cursor: pointer; transition: all var(--transition);
  text-decoration: none;
}
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-primary { background: var(--olive); color: var(--white); }
.btn-primary:hover { background: var(--olive-dark); }
.btn-outline { background: var(--white); color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-outline:hover { border-color: var(--olive); color: var(--olive); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-danger:hover { background: #B91C1C; }
.btn-success { background: var(--green); color: var(--white); }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- FORMULAIRES ---- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--gray-700); margin-bottom: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="tel"], input[type="search"], select, textarea {
  width: 100%; padding: 10px 14px; border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm); font-size: 0.9rem; transition: border var(--transition);
  background: var(--white); color: var(--gray-800);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--olive); box-shadow: 0 0 0 3px var(--olive-50); }
textarea { resize: vertical; min-height: 80px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

/* ---- CARDS ---- */
.card {
  background: var(--white); border-radius: var(--radius); border: 1px solid var(--gray-200);
  padding: 20px; box-shadow: var(--shadow-sm);
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-header h3 { font-size: 1rem; font-weight: 600; }

/* ---- KPI CARDS ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card {
  background: var(--white); border-radius: var(--radius); border: 1px solid var(--gray-200);
  padding: 20px; box-shadow: var(--shadow-sm);
}
.kpi-label { font-size: 0.78rem; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.kpi-value { font-size: 1.6rem; font-weight: 700; color: var(--gray-800); font-family: 'JetBrains Mono', monospace; }
.kpi-sub { font-size: 0.78rem; color: var(--gray-400); margin-top: 4px; }
.kpi-card.alert { border-left: 4px solid var(--red); }
.kpi-card.warning { border-left: 4px solid var(--orange); }
.kpi-card.success { border-left: 4px solid var(--green); }

/* ---- TABLES ---- */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
thead th {
  text-align: left; padding: 10px 14px; font-weight: 600; font-size: 0.78rem;
  text-transform: uppercase; letter-spacing: 0.5px; color: var(--gray-500);
  border-bottom: 2px solid var(--gray-200); background: var(--gray-50);
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--gray-100); }
tbody tr:hover { background: var(--olive-50); }
tbody tr { cursor: pointer; transition: background var(--transition); }
.td-mono { font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; }
.td-right { text-align: right; }

/* ---- BADGES ---- */
.badge {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
}
.badge-green { background: var(--green-light); color: #065F46; }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-orange { background: var(--orange-light); color: #92400E; }
.badge-blue { background: var(--blue-light); color: #1E40AF; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }
.badge-olive { background: var(--olive-light); color: var(--olive-dark); }

/* ---- SEARCH BAR ---- */
.search-bar {
  display: flex; align-items: center; gap: 12px; margin-bottom: 20px;
  flex-wrap: wrap;
}
.search-input {
  flex: 1; min-width: 200px; padding: 10px 14px 10px 40px;
  border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
  background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%239CA3AF' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 12px center;
  font-size: 0.9rem;
}
.search-input:focus { border-color: var(--olive); outline: none; }

/* ---- FILTER TABS ---- */
.filter-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.filter-tab {
  padding: 6px 14px; border-radius: 20px; font-size: 0.8rem; font-weight: 500;
  border: 1px solid var(--gray-200); background: var(--white); color: var(--gray-600);
  cursor: pointer; transition: all var(--transition);
}
.filter-tab:hover { border-color: var(--olive); color: var(--olive); }
.filter-tab.active { background: var(--olive); color: var(--white); border-color: var(--olive); }

/* ---- EMPTY STATE ---- */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--gray-400);
}
.empty-state svg { margin-bottom: 16px; opacity: 0.3; }
.empty-state p { font-size: 0.95rem; margin-bottom: 16px; }

/* ---- ALERT CARDS ---- */
.alert-card {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px;
  border-radius: var(--radius-sm); margin-bottom: 12px; font-size: 0.88rem;
}
.alert-card.alert-danger { background: var(--red-light); color: var(--red); }
.alert-card.alert-warning { background: var(--orange-light); color: #92400E; }
.alert-card.alert-success { background: var(--green-light); color: #065F46; }
.alert-card.alert-info { background: var(--blue-light); color: #1E40AF; }

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 10000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 14px 20px; border-radius: var(--radius-sm); background: var(--gray-800);
  color: var(--white); font-size: 0.88rem; box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease; min-width: 280px;
}
.toast.toast-success { background: #065F46; }
.toast.toast-error { background: var(--red); }
.toast.toast-warning { background: #92400E; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================
   MODAL
   ============================================ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--white); border-radius: var(--radius); width: 100%; max-width: 600px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--gray-400); font-size: 1.3rem; }
.modal-close:hover { color: var(--gray-700); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 8px; }

/* ============================================
   PAGE SPECIFIC
   ============================================ */

/* Dashboard alerts row */
.dashboard-alerts { margin-bottom: 24px; }

/* Stats toggle */
.stats-toggle {
  display: flex; gap: 2px; background: var(--gray-100); border-radius: 6px; padding: 2px;
}
.stats-toggle button {
  padding: 4px 10px; font-size: 0.72rem; font-weight: 600; border: none;
  background: transparent; border-radius: 4px; cursor: pointer; color: var(--gray-500);
  transition: all var(--transition);
}
.stats-toggle button.active { background: var(--white); color: var(--olive); box-shadow: var(--shadow-sm); }

/* Product grid */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.product-card {
  background: var(--white); border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 16px; cursor: pointer; transition: all var(--transition);
}
.product-card:hover { border-color: var(--olive); box-shadow: var(--shadow-md); }
.product-card .product-name { font-weight: 600; color: var(--gray-800); margin-bottom: 4px; }
.product-card .product-ref { font-family: 'JetBrains Mono', monospace; font-size: 0.78rem; color: var(--gray-400); }
.product-card .product-stock { margin-top: 8px; display: flex; justify-content: space-between; align-items: center; }
.product-card .product-price { font-family: 'JetBrains Mono', monospace; font-weight: 600; color: var(--olive); }
.stock-low { color: var(--red); font-weight: 600; }
.stock-ok { color: var(--green); }

/* Devis / Facture lines */
.doc-lines { margin: 20px 0; }
.doc-line {
  display: grid; grid-template-columns: 2fr 80px 80px 100px 100px 40px;
  gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--gray-100);
}
.doc-line input, .doc-line select { padding: 8px 10px; font-size: 0.85rem; }
.doc-line-remove { background: none; border: none; color: var(--gray-400); cursor: pointer; font-size: 1.2rem; }
.doc-line-remove:hover { color: var(--red); }
.doc-totals {
  margin-top: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
}
.doc-total-row { display: flex; gap: 20px; font-size: 0.9rem; }
.doc-total-row.total-final { font-weight: 700; font-size: 1.05rem; color: var(--olive); padding-top: 8px; border-top: 2px solid var(--gray-200); }
.doc-total-label { color: var(--gray-500); min-width: 120px; text-align: right; }
.doc-total-value { font-family: 'JetBrains Mono', monospace; min-width: 100px; text-align: right; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .sidebar-overlay.active { display: block; }
  .main-content { margin-left: 0; }
  .menu-toggle { display: block; }
  .page-content { padding: 16px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .doc-line { grid-template-columns: 1fr; gap: 4px; }
  .search-bar { flex-direction: column; }
  .filter-tabs { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .product-grid { grid-template-columns: 1fr; }
  .main-header { padding: 0 16px; }
  .header-right .user-name { display: none; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .login-card { padding: 32px 24px; }
}
