/* ============================================================
   SAV Tracker — Valused
   Aesthetic: Industrial terminal / Brutalist utility
   Font: IBM Plex Mono + IBM Plex Sans
   ============================================================ */

:root {
  /* Core palette */
  --bg-base:       #0f1117;
  --bg-surface:    #161b26;
  --bg-elevated:   #1e2535;
  --bg-hover:      #242d3f;

  /* Borders */
  --border:        #2a3347;
  --border-strong: #3a4a66;

  /* Text */
  --text-primary:  #e2e8f0;
  --text-secondary:#8899b4;
  --text-muted:    #4a5a74;
  --text-mono:     #a8c4e0;

  /* Accent: amber/orange for Valused */
  --accent:        #f59e0b;
  --accent-dim:    rgba(245, 158, 11, 0.15);
  --accent-text:   #fcd34d;

  /* Status colors */
  --status-pending:  #3b82f6;
  --status-active:   #f59e0b;
  --status-resolved: #10b981;
  --status-closed:   #6b7280;
  --status-relance:  #ef4444;

  /* Dimensions */
  --sidebar-w: 220px;
  --topbar-h:  56px;
  --radius:    4px;
  --radius-lg: 8px;
}

/* ─── Thème clair ──────────────────────────────────────────── */
[data-theme="light"] {
  --bg-base:       #f4f6fb;
  --bg-surface:    #ffffff;
  --bg-elevated:   #eef1f8;
  --bg-hover:      #e4e8f2;

  --border:        #d0d7e8;
  --border-strong: #b0bcd4;

  --text-primary:  #1a2033;
  --text-secondary:#4a5a74;
  --text-muted:    #8899b4;
  --text-mono:     #2a4a6e;

  --accent:        #d97706;
  --accent-dim:    rgba(217, 119, 6, 0.12);
  --accent-text:   #92400e;

  --status-pending:  #2563eb;
  --status-active:   #d97706;
  --status-resolved: #059669;
  --status-closed:   #6b7280;
  --status-relance:  #dc2626;
}

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

html, body {
  height: 100%;
  font-family: 'IBM Plex Sans', sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

/* ─── Layout ───────────────────────────────────────────────── */
body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 24px;
  color: var(--accent);
  line-height: 1;
}

.logo-title {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}

.logo-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.sidebar-nav {
  padding: 12px 8px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
  position: relative;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent-text);
  border-left: 2px solid var(--accent);
  padding-left: 8px;
}

.nav-icon {
  font-size: 14px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--status-relance);
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  font-family: 'IBM Plex Mono', monospace;
  display: none;
}

.nav-badge.show { display: block; }

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.ms-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  flex: 1;
  overflow: hidden;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status-dot.connected { background: var(--status-resolved); }
.status-dot.error { background: var(--status-relance); }

/* ─── Main content ─────────────────────────────────────────── */
.main-content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar-right { display:flex; align-items:center; gap:8px; }
.topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

.page-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.3px;
}

.view {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.view.active { display: block; }

/* ─── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #0f1117;
  border: none;
  padding: 7px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif;
  transition: all 0.15s;
}

.btn-primary:hover { background: #fcd34d; }

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif;
  transition: all 0.15s;
}

.btn-secondary:hover { border-color: var(--text-secondary); color: var(--text-primary); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  transition: color 0.15s;
  border-radius: var(--radius);
}

.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }

.btn-danger {
  background: transparent;
  color: var(--status-relance);
  border: 1px solid var(--status-relance);
  padding: 5px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif;
  transition: all 0.15s;
}

.btn-danger:hover { background: rgba(239,68,68,0.1); }

/* ─── Status badges ────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.badge-pending   { background: rgba(59,130,246,0.15); color: #60a5fa; border: 1px solid rgba(59,130,246,0.3); }
.badge-active    { background: rgba(245,158,11,0.15); color: #fcd34d; border: 1px solid rgba(245,158,11,0.3); }
.badge-resolved  { background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.3); }
.badge-closed    { background: rgba(107,114,128,0.15); color: #9ca3af; border: 1px solid rgba(107,114,128,0.3); }
.badge-relance   { background: rgba(239,68,68,0.15); color: #f87171; border: 1px solid rgba(239,68,68,0.3); }
.badge-waiting   { background: rgba(59,130,246,0.1);  color: #93c5fd; border: 1px solid rgba(59,130,246,0.2); }
.badge-replied   { background: rgba(16,185,129,0.1);  color: #6ee7b7; border: 1px solid rgba(16,185,129,0.2); }
.badge-sav       { background: rgba(168,85,247,0.15); color: #c084fc; border: 1px solid rgba(168,85,247,0.3); }
.badge-sdc       { background: rgba(6,182,212,0.15);  color: #67e8f9; border: 1px solid rgba(6,182,212,0.3); }
.badge-backoffice { background: rgba(251,191,36,0.15);color: #fde68a; border: 1px solid rgba(251,191,36,0.3); }

/* ─── Table ────────────────────────────────────────────────── */
.table-container {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: var(--bg-elevated);
}

th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

td {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
}

.td-mono {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--text-mono);
}

.td-secondary {
  color: var(--text-secondary);
  font-size: 12px;
}

/* ─── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

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

.card-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

/* ─── Stat cards ───────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  transition: border-color 0.2s;
}

.stat-card:hover { border-color: var(--border-strong); }

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

.stat-value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 28px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1;
}

.stat-value.accent { color: var(--accent); }
.stat-value.blue   { color: #60a5fa; }
.stat-value.green  { color: #34d399; }
.stat-value.red    { color: #f87171; }

.stat-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

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

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  gap: 8px;
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}

.search-box input {
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  outline: none;
  width: 100%;
}

.search-box input::placeholder { color: var(--text-muted); }

.search-icon { color: var(--text-muted); font-size: 14px; }

select, input[type="text"], input[type="email"], input[type="number"], textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  border-radius: var(--radius);
  padding: 6px 10px;
  outline: none;
  transition: border-color 0.15s;
}

select:focus, input:focus, textarea:focus {
  border-color: var(--accent);
}

select option { background: var(--bg-elevated); }

/* ─── Email thread ─────────────────────────────────────────── */
.thread-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.thread-label {
  font-size: 11px;
  font-weight: 600;
  font-family: 'IBM Plex Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.email-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}

.email-item.sent   { border-left: 3px solid var(--accent); }
.email-item.received { border-left: 3px solid var(--status-resolved); }
.email-item.relance  { border-left: 3px solid var(--status-relance); }

.email-header {
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  background: var(--bg-elevated);
}

.email-header:hover { background: var(--bg-hover); }

.email-direction {
  font-size: 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 2px;
  white-space: nowrap;
}

.dir-sent     { background: rgba(245,158,11,0.15); color: var(--accent-text); }
.dir-received { background: rgba(16,185,129,0.15); color: #34d399; }
.dir-relance  { background: rgba(239,68,68,0.15);  color: #f87171; }

.email-subject {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-date {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
  white-space: nowrap;
}

.email-body-preview {
  padding: 12px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  display: none;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
  line-height: 1.6;
}

.email-body-preview.open { display: block; }

.email-actions {
  padding: 8px 14px;
  display: none;
  gap: 8px;
  border-top: 1px solid var(--border);
}

.email-actions.open { display: flex; }

/* ─── Form ─────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-family: 'IBM Plex Mono', monospace;
  margin-bottom: 6px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-grid.col3 { grid-template-columns: 1fr 1fr 1fr; }

textarea {
  width: 100%;
  resize: vertical;
  min-height: 120px;
}

/* ─── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

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

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 640px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

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

.modal-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: color 0.15s;
}

.modal-close:hover { color: var(--text-primary); background: var(--bg-hover); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

/* ─── Toast ────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 0.2s ease;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  max-width: 340px;
}

.toast.success { border-left: 3px solid var(--status-resolved); }
.toast.error   { border-left: 3px solid var(--status-relance); }
.toast.info    { border-left: 3px solid var(--status-pending); }

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

/* ─── Detail view layout ───────────────────────────────────── */
.detail-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}

.detail-header-left { flex: 1; }

.detail-order-number {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent-text);
  margin-bottom: 4px;
}

.detail-product {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 10px;
}

.detail-meta {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meta-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-family: 'IBM Plex Mono', monospace;
}

.meta-value {
  font-size: 13px;
  color: var(--text-primary);
}

.threads-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* ─── Empty state ──────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

/* ─── Loading ──────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
}

.loading::before {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 10px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Back button ──────────────────────────────────────────── */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  margin-bottom: 16px;
  cursor: pointer;
  transition: color 0.15s;
  background: none;
  border: none;
  font-family: 'IBM Plex Sans', sans-serif;
}

.btn-back:hover { color: var(--text-primary); }

/* ─── Relance warning ──────────────────────────────────────── */
.relance-warning {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 12px;
  color: #fca5a5;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

/* ─── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Section title ────────────────────────────────────────── */
.section-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── Rule list ────────────────────────────────────────────── */
.rule-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.rule-item.disabled { opacity: 0.5; }

.rule-info { flex: 1; }

.rule-name {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
}

.rule-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
}
