/* ============================================================
   Tim Solutions — Design System
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --primary:        #16a34a;
  --primary-dark:   #15803d;
  --primary-light:  #dcfce7;
  --primary-text:   #166534;
  --success:        #059669;
  --success-light:  #D1FAE5;
  --warning:        #D97706;
  --warning-light:  #FEF3C7;
  --danger:         #DC2626;
  --danger-light:   #FEE2E2;
  --info:           #0284C7;
  --info-light:     #E0F2FE;
  --sidebar-bg:     #14532d;
  --sidebar-hover:  #166534;
  --sidebar-active: rgba(22,163,74,.18);
  --sidebar-border: rgba(255,255,255,.07);
  --sidebar-text:   #86efac;
  --sidebar-white:  #f0fdf4;
  --sidebar-width:  252px;
  --topbar-h:       62px;
  --bg-main:        #F1F5F9;
  --bg-card:        #FFFFFF;
  --border:         #E2E8F0;
  --border-light:   #F1F5F9;
  --text-1:         #0F172A;
  --text-2:         #475569;
  --text-3:         #94A3B8;
  --shadow-sm:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:      0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -1px rgba(0,0,0,.04);
  --radius:         10px;
  --radius-sm:      6px;
  --radius-lg:      14px;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text-1);
  background: var(--bg-main);
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

.sidebar-logo-text {
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.3px;
  line-height: 1.2;
}

.sidebar-logo-sub {
  color: var(--sidebar-text);
  font-size: 11px;
  font-weight: 400;
}

.sidebar-nav { padding: 8px 0; flex: 1; }

.sidebar-section {
  padding: 18px 18px 4px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(134,239,172,.45);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 450;
  border-left: 3px solid transparent;
  transition: all .15s;
  margin: 1px 0;
}

.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-white);
}

.sidebar-link.active {
  background: var(--sidebar-active);
  color: #86efac;
  border-left-color: var(--primary);
  font-weight: 600;
}

.sidebar-link i {
  width: 18px; text-align: center; font-size: 14px; opacity: .85;
}

.sidebar-link.active i { opacity: 1; }

.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding: 12px;
}

.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  color: var(--sidebar-text); font-size: 13px;
  text-decoration: none; transition: background .15s;
}
.sidebar-user:hover { background: var(--sidebar-hover); color: var(--sidebar-white); }
.sidebar-user-avatar {
  width: 32px; height: 32px; background: var(--primary);
  border-radius: 50%; display: flex; align-items: center;
  justify-content: center; color: #fff; font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
.main-wrap {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex; flex-direction: column;
}

.topbar {
  position: sticky; top: 0; z-index: 100;
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.topbar-breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-2);
}
.topbar-breadcrumb a { color: var(--text-2); text-decoration: none; }
.topbar-breadcrumb a:hover { color: var(--primary); }
.topbar-breadcrumb .sep { color: var(--text-3); }
.topbar-title {
  font-size: 16px; font-weight: 700; color: var(--text-1);
}

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

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

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border-light);
  padding: 14px 20px;
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; font-size: 14px;
}
.card-body { padding: 20px; }
.card-footer {
  background: transparent;
  border-top: 1px solid var(--border-light);
  padding: 12px 20px;
}

/* Stat cards */
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  display: flex; align-items: center; gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-icon {
  width: 52px; height: 52px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.stat-value { font-size: 26px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.stat-trend { font-size: 11px; margin-top: 4px; }

/* ============================================================
   TABLES
   ============================================================ */
.table-card { overflow: hidden; }
.table-card .card-header { background: #fff; }

.tbl { width: 100%; border-collapse: collapse; }
.tbl thead th {
  font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text-3);
  background: #FAFBFC; border-bottom: 1px solid var(--border);
  padding: 11px 16px; white-space: nowrap;
}
.tbl tbody td {
  padding: 13px 16px; border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover td { background: rgba(22,163,74,.025); }
.tbl-actions { display: flex; gap: 4px; }

/* ============================================================
   FORMS
   ============================================================ */
.form-label {
  font-size: 12.5px; font-weight: 600; color: var(--text-1);
  margin-bottom: 5px; display: block;
}
.form-control, .form-select {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13.5px; padding: 8px 12px;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22,163,74,.12);
  outline: none;
}
.form-control-sm, .form-select-sm { padding: 5px 9px; font-size: 12.5px; }
.form-text { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }
.input-group-text { border-color: var(--border); font-size: 13.5px; }

/* Sections de formulaire */
.form-section {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 18px;
}
.form-section-title {
  font-size: 13px; font-weight: 700; color: var(--text-1);
  margin: 0 0 16px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; gap: 8px;
}
.form-section-title i { color: var(--primary); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  font-size: 13.5px; font-weight: 500; font-family: inherit;
  border-radius: var(--radius-sm); padding: 8px 16px;
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; border: 1px solid transparent;
  transition: all .15s; text-decoration: none; line-height: 1.4;
}
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-icon { padding: 7px 9px; }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }

.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #047857; color: #fff; }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #B91C1C; color: #fff; }

.btn-warning { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-warning:hover { background: #B45309; color: #fff; }

.btn-outline-primary { color: var(--primary); border-color: var(--primary); background: transparent; }
.btn-outline-primary:hover { background: var(--primary); color: #fff; }

.btn-outline-secondary { color: var(--text-2); border-color: var(--border); background: transparent; }
.btn-outline-secondary:hover { background: var(--bg-main); color: var(--text-1); }

.btn-outline-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-outline-danger:hover { background: var(--danger); color: #fff; }

.btn-light { background: var(--bg-main); color: var(--text-1); border-color: var(--border); }
.btn-light:hover { background: var(--border); }

/* ============================================================
   BADGES
   ============================================================ */
.badge, .badge-statut {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; line-height: 1.4;
}
.bg-primary   { background: var(--primary-light) !important; color: var(--primary-text) !important; }
.bg-success   { background: var(--success-light) !important; color: var(--success) !important; }
.bg-warning   { background: var(--warning-light) !important; color: var(--warning) !important; }
.bg-danger    { background: var(--danger-light)  !important; color: var(--danger) !important; }
.bg-info      { background: var(--info-light)    !important; color: var(--info) !important; }
.bg-secondary { background: #F1F5F9 !important; color: var(--text-2) !important; }

/* ============================================================
   ALERTS & FLASH
   ============================================================ */
.alert {
  border-radius: var(--radius); padding: 13px 18px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px; border: none; margin-bottom: 16px;
}
.alert-success { background: var(--success-light); color: #065F46; }
.alert-danger  { background: var(--danger-light);  color: #991B1B; }
.alert-warning { background: var(--warning-light); color: #92400E; }
.alert-info    { background: var(--info-light);    color: #075985; }

/* ============================================================
   DEVIS / FACTURE LINES TABLE
   ============================================================ */
.lines-table { border-collapse: collapse; width: 100%; }
.lines-table thead th {
  background: #FAFBFC; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px; color: var(--text-3);
  padding: 9px 10px; border-bottom: 1px solid var(--border);
}
.lines-table tbody td { padding: 7px 6px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.lines-table tbody tr:hover td { background: rgba(22,163,74,.02); }

.totals-block {
  background: #FAFBFC; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px;
}
.totals-block .total-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0; font-size: 13.5px;
}
.totals-block .total-row.total-ttc {
  font-size: 16px; font-weight: 700; border-top: 1px solid var(--border);
  margin-top: 6px; padding-top: 10px; color: var(--primary);
}

/* ============================================================
   MISC
   ============================================================ */
.text-primary { color: var(--primary) !important; }
.text-muted   { color: var(--text-2) !important; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}

.divider { border: none; border-top: 1px solid var(--border); margin: 0; }

.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-3);
}
.empty-state i { font-size: 48px; margin-bottom: 12px; display: block; }
.empty-state p { font-size: 14px; margin: 0; }

.search-bar { display: flex; gap: 8px; flex-wrap: wrap; }

/* Chantier progress */
.progress-bar-wrap {
  background: var(--border); border-radius: 20px; height: 6px; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; border-radius: 20px; background: var(--primary);
  transition: width .3s;
}

/* Login page */
.login-page {
  min-height: 100vh; background: linear-gradient(135deg, #052e16 0%, #14532d 50%, #166534 100%);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: #fff; border-radius: 18px; padding: 44px 40px;
  width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-logo {
  width: 160px; height: 80px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 24px;
}

/* Responsive */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .main-wrap { margin-left: 0; }
}

/* Print */
@media print {
  .sidebar, .topbar { display: none !important; }
  .main-wrap { margin-left: 0; }
  .page-body { padding: 0; }
}
