/* ============================================
   MerakiFactu — Design System
   Brand: #2099E0 (blue) | #0A0910 (dark) | #FEFFFE (white)
   ============================================ */

:root {
  --blue: #2099E0;
  --blue-dark: #1780C0;
  --blue-light: #E8F4FD;
  --dark: #0A0910;
  --dark-2: #1A1828;
  --dark-3: #2D2B3D;
  --gray-1: #F4F6FA;
  --gray-2: #E8EBF2;
  --gray-3: #C5CADA;
  --gray-4: #8892A4;
  --text: #1A1828;
  --text-muted: #6B7280;
  --white: #FFFFFF;
  --success: #22C55E;
  --warning: #F59E0B;
  --danger: #EF4444;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --sidebar-w: 240px;
}

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

html { font-size: 15px; }
body { font-family: 'Inter', system-ui, sans-serif; background: var(--gray-1); color: var(--text); }

a { color: inherit; text-decoration: none; }

/* ---- LAYOUT ---- */
.layout { display: flex; min-height: 100vh; }

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--dark);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 24px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.logo-img { width: 140px; display: block; border-radius: 4px; }
.logo-tag {
  display: block;
  color: var(--blue);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-top: 8px;
}

.sidebar-nav { padding: 16px 10px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,.6);
  font-size: 14px;
  font-weight: 500;
  transition: all .15s;
  margin-bottom: 2px;
}
.nav-item svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; flex-shrink: 0; }
.nav-item:hover { background: rgba(32,153,224,.12); color: var(--blue); }
.nav-item.active { background: rgba(32,153,224,.18); color: var(--blue); }

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

.btn-new-invoice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--blue);
  color: white;
  padding: 11px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  transition: background .15s;
}
.btn-new-invoice svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.5; }
.btn-new-invoice:hover { background: var(--blue-dark); }

/* ---- MAIN ---- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-2);
  padding: 0 32px;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.page-title { font-size: 18px; font-weight: 700; color: var(--dark); }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 1px; }

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

/* ---- CARDS ---- */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.card-title { font-size: 15px; font-weight: 700; color: var(--dark); }

/* ---- STAT CARDS ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}
.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--blue-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; fill: none; stroke: var(--blue); stroke-width: 1.8; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--dark); line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ---- TABLES ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  background: var(--gray-1);
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--gray-2);
}
tbody tr { border-bottom: 1px solid var(--gray-2); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--gray-1); }
tbody td { padding: 12px 14px; }

/* ---- BADGES / STATUS ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-issued  { background: #EFF6FF; color: #1D4ED8; }
.badge-sent    { background: #F0FDF4; color: #15803D; }
.badge-draft   { background: #F9FAFB; color: #6B7280; }
.badge-cancelled { background: #FEF2F2; color: #DC2626; }
.badge-recurring { background: var(--blue-light); color: var(--blue); }
.badge-sporadic  { background: #F5F3FF; color: #7C3AED; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
}
.btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; }
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { background: var(--gray-2); color: var(--text); }
.btn-secondary:hover { background: var(--gray-3); }
.btn-danger { background: #FEF2F2; color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }
.btn-ghost { background: transparent; color: var(--blue); border: 1.5px solid var(--blue); }
.btn-ghost:hover { background: var(--blue-light); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon { padding: 8px; border-radius: 8px; background: var(--gray-1); color: var(--text-muted); border: none; cursor: pointer; }
.btn-icon:hover { background: var(--gray-2); color: var(--dark); }
.btn-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; display: block; }

/* ---- FORMS ---- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 600; color: var(--dark); }
input[type=text], input[type=email], input[type=number], input[type=date],
select, textarea {
  padding: 9px 12px;
  border: 1.5px solid var(--gray-2);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  transition: border-color .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(32,153,224,.12);
}
textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 12px; color: var(--text-muted); }

.section-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0 16px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.section-divider::before, .section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--gray-2);
}

/* Toggle switch */
.toggle-wrap { display: flex; align-items: center; gap: 10px; }
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: var(--gray-3);
  border-radius: 22px;
  cursor: pointer;
  transition: background .2s;
}
.slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform .2s;
}
input:checked + .slider { background: var(--blue); }
input:checked + .slider::before { transform: translateX(18px); }

/* ---- INVOICE LINES TABLE ---- */
.lines-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.lines-table th {
  background: var(--dark);
  color: rgba(255,255,255,.7);
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: left;
}
.lines-table td { padding: 10px 12px; border-bottom: 1px solid var(--gray-2); }
.lines-table tfoot td {
  border-top: 2px solid var(--gray-2);
  font-weight: 600;
  padding: 10px 12px;
}
.lines-table input { border: 1.5px solid var(--gray-2); border-radius: 6px; padding: 6px 8px; font-size: 13px; width: 100%; }
.lines-table input:focus { outline: none; border-color: var(--blue); }

/* ---- VERIFACTU BADGE ---- */
.verifactu-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--dark);
  color: var(--blue);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
}

/* ---- HASH CHAIN ---- */
.hash-chain { font-family: 'Courier New', monospace; font-size: 12px; }
.hash-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-left: 2px solid var(--blue);
  margin-bottom: 8px;
  background: var(--gray-1);
  border-radius: 0 6px 6px 0;
}
.hash-num { font-weight: 700; color: var(--blue); min-width: 60px; font-family: 'Inter', sans-serif; font-size: 13px; }
.hash-val { color: var(--text-muted); word-break: break-all; font-size: 11px; }

/* ---- ALERTS ---- */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: #F0FDF4; color: #15803D; }
.alert-danger  { background: #FEF2F2; color: #DC2626; }
.alert-info    { background: var(--blue-light); color: var(--blue-dark); }

/* ---- UTILS ---- */
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-blue  { color: var(--blue); }
.font-mono  { font-family: 'Courier New', monospace; }
.font-bold  { font-weight: 700; }
.mt-4  { margin-top: 16px; }
.mt-6  { margin-top: 24px; }
.mb-4  { margin-bottom: 16px; }
.flex  { display: flex; }
.flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

/* ---- TOTALS BOX ---- */
.totals-box {
  background: var(--dark);
  border-radius: var(--radius);
  padding: 20px 24px;
  color: white;
  min-width: 260px;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 4px 0;
  color: rgba(255,255,255,.7);
}
.totals-total {
  display: flex;
  justify-content: space-between;
  font-size: 22px;
  font-weight: 700;
  color: var(--blue);
  padding-top: 12px;
  margin-top: 8px;
  border-top: 1px solid rgba(255,255,255,.12);
}

/* ---- DETAIL SECTIONS ---- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }
.detail-block { }
.detail-block h3 { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px; }
.detail-row { display: flex; gap: 8px; font-size: 14px; padding: 3px 0; }
.detail-row span:first-child { color: var(--text-muted); min-width: 120px; }
.detail-row span:last-child { font-weight: 500; }

/* ---- TIMELINE / AUDIT ---- */
.timeline { }
.timeline-item {
  display: flex;
  gap: 12px;
  padding-bottom: 16px;
  position: relative;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: 15px;
  top: 30px;
  bottom: 0;
  width: 1px;
  background: var(--gray-2);
}
.timeline-item:last-child::before { display: none; }
.timeline-dot {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--blue-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  z-index: 1;
}
.timeline-dot svg { width: 14px; height: 14px; fill: none; stroke: var(--blue); stroke-width: 2; }
.timeline-content { flex: 1; padding-top: 4px; }
.timeline-desc { font-size: 14px; color: var(--text); }
.timeline-time { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

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