/* ===== Tarticom — Styles principaux ===== */

:root {
  --navy: #1a2744;
  --navy-light: #243255;
  --navy-dark: #111b33;
  --gold: #f5a623;
  --gold-light: #fbbf24;
  --gold-dark: #d97706;
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --sidebar-w: 260px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 8px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 8px rgba(0,0,0,.2);
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  min-height: 100vh;
  transition: background .2s, color .2s;
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  transition: transform .3s ease;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-logo img {
  height: 40px;
  width: auto;
  object-fit: contain;
}

.sidebar-logo .logo-text {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--gold);
  letter-spacing: .5px;
}

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

.nav-section-label {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.35);
  padding: 16px 20px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: rgba(255,255,255,.7);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  border-radius: 0;
  transition: background .15s, color .15s;
  position: relative;
}

.nav-link:hover {
  background: rgba(255,255,255,.07);
  color: #fff;
}

.nav-link.active {
  background: rgba(245,166,35,.12);
  color: var(--gold);
  font-weight: 600;
}

.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--gold);
  border-radius: 0 2px 2px 0;
}

.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .8; }
.nav-link.active svg { opacity: 1; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: rgba(255,255,255,.55);
  text-decoration: none;
  font-size: .8rem;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.logout-btn:hover { background: rgba(255,255,255,.06); color: rgba(255,255,255,.85); }

/* ===== Main layout ===== */
.main-wrapper {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}

.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text-muted);
}

.search-wrap {
  flex: 1;
  max-width: 440px;
  position: relative;
}

.search-wrap input {
  width: 100%;
  padding: 8px 36px 8px 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: .875rem;
  outline: none;
  transition: border-color .15s;
}
.search-wrap input:focus { border-color: var(--navy); }
.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  width: 16px; height: 16px;
}

#search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  overflow: hidden;
  display: none;
}
#search-results.show { display: block; }

.search-group-label {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-light);
  padding: 8px 12px 4px;
}

.search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  text-decoration: none;
  color: var(--text);
  font-size: .85rem;
  transition: background .1s;
}
.search-item:hover { background: var(--bg); }

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

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  transition: background .15s, border-color .15s;
}
.theme-toggle:hover { background: var(--bg); }

.page-content {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.card-body { padding: 20px; }

/* ===== Stat cards ===== */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}

.stat-sub {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .02em;
  white-space: nowrap;
}

.badge-gray    { background: #f1f5f9; color: #475569; }
.badge-blue    { background: #dbeafe; color: #1d4ed8; }
.badge-green   { background: #dcfce7; color: #15803d; }
.badge-red     { background: #fee2e2; color: #b91c1c; }
.badge-orange  { background: #ffedd5; color: #c2410c; }
.badge-yellow  { background: #fef3c7; color: #92400e; }
.badge-purple  { background: #ede9fe; color: #6d28d9; }

[data-theme="dark"] .badge-gray   { background: #334155; color: #94a3b8; }
[data-theme="dark"] .badge-blue   { background: #1e3a5f; color: #60a5fa; }
[data-theme="dark"] .badge-green  { background: #14532d; color: #4ade80; }
[data-theme="dark"] .badge-red    { background: #450a0a; color: #f87171; }
[data-theme="dark"] .badge-orange { background: #431407; color: #fb923c; }
[data-theme="dark"] .badge-yellow { background: #422006; color: #fbbf24; }
[data-theme="dark"] .badge-purple { background: #2e1065; color: #a78bfa; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all .15s;
  white-space: nowrap;
  line-height: 1.2;
}

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

.btn-gold {
  background: var(--gold);
  color: var(--navy-dark);
}
.btn-gold:hover { background: var(--gold-dark); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg); }

.btn-danger {
  background: #fee2e2;
  color: #b91c1c;
}
.btn-danger:hover { background: #fecaca; }

.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-xs { padding: 3px 8px; font-size: .75rem; }

.btn svg { width: 16px; height: 16px; }

/* ===== Tables ===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }

.data-table .amount { text-align: right; font-variant-numeric: tabular-nums; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  font-size: .875rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}

.form-control:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(26,39,68,.1);
}

.form-control::placeholder { color: var(--text-light); }

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

select.form-control { appearance: none; cursor: pointer; }

.form-hint {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Line items (devis/factures) ===== */
.line-table {
  width: 100%;
  border-collapse: collapse;
}

.line-table th {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  padding: 8px 8px 6px;
  text-align: left;
  border-bottom: 2px solid var(--border);
}

.line-table th.right { text-align: right; }

.line-table td {
  padding: 6px 8px;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.line-input {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: .875rem;
  outline: none;
  font-family: inherit;
  transition: border-color .15s, background .15s;
}

.line-input:focus, .line-input:hover {
  border-color: var(--border);
  background: var(--bg-card);
}

.line-input.right { text-align: right; }

.line-total {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 7px 8px;
  font-size: .875rem;
}

.remove-line-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color .15s, background .15s;
}
.remove-line-btn:hover { color: #ef4444; background: #fee2e2; }

/* ===== Totals ===== */
.totals-block {
  margin-left: auto;
  width: 280px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: .9rem;
}

.total-row.big {
  font-size: 1.1rem;
  font-weight: 800;
  padding-top: 10px;
  border-top: 2px solid var(--border);
  margin-top: 4px;
}

/* ===== Page header ===== */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  margin: 0;
  line-height: 1.2;
}

.page-subtitle {
  font-size: .875rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Flash messages ===== */
.flash-container {
  position: fixed;
  top: 72px;
  right: 20px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}

.flash {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  font-size: .875rem;
  font-weight: 500;
  animation: slideIn .2s ease;
  cursor: pointer;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.flash-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.flash-danger  { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.flash-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.flash-info    { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}

.tab-btn {
  padding: 10px 18px;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
  text-decoration: none;
  display: inline-block;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--navy); border-bottom-color: var(--navy); }
[data-theme="dark"] .tab-btn.active { color: var(--gold); border-bottom-color: var(--gold); }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 90%;
  max-width: 540px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  animation: fadeUp .2s ease;
}

@keyframes fadeUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 1rem; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 4px; border-radius: 4px; }
.modal-close:hover { background: var(--bg); }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state svg { width: 48px; height: 48px; margin: 0 auto 16px; opacity: .4; }
.empty-state p { margin: 0; font-size: .9rem; }

/* ===== Filters bar ===== */
.filters-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filter-badge {
  padding: 5px 12px;
  border-radius: 99px;
  border: 1px solid var(--border);
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-card);
  cursor: pointer;
  text-decoration: none;
  transition: all .15s;
}
.filter-badge:hover { border-color: var(--navy); color: var(--navy); }
.filter-badge.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ===== Grid ===== */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }

/* ===== Utils ===== */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .8rem; }
.font-bold { font-weight: 700; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.w-full { width: 100%; }

/* ===== Settings tabs ===== */
.settings-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  align-items: start;
}

.settings-nav { position: sticky; top: 84px; }
.settings-nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: background .15s, color .15s;
}
.settings-nav a:hover { background: var(--bg); color: var(--text); }
.settings-nav a.active { background: var(--navy); color: #fff; }

/* ===== Login ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  padding: 20px;
}

.login-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo img { height: 56px; width: auto; }

/* ===== Overlay sidebar mobile ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 99;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  .sidebar {
    transform: translateX(-260px);
    width: 260px;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  .main-wrapper { margin-left: 0; }
  .hamburger { display: flex; }
  .page-content { padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .grid-stats { grid-template-columns: repeat(2, 1fr); }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { position: static; }
  .topbar { padding: 0 14px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header .btn { width: 100%; justify-content: center; }
  .flash-container { left: 10px; right: 10px; }
  .modal { max-width: 100%; margin: 10px; border-radius: 12px; }
}

@media (max-width: 480px) {
  .grid-stats { grid-template-columns: 1fr 1fr; }
  .search-wrap { display: none; }
}

/* ===== Print ===== */
@media print {
  .sidebar, .topbar, .flash-container { display: none !important; }
  .main-wrapper { margin-left: 0 !important; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }
