/* ============================================================
   Configurateur CNC - Design system
   Palette : anthracite + cuivre brule
   Typo : Instrument Serif (display), Geist (body), JetBrains Mono (technique)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=JetBrains+Mono:wght@400;500;600;700&display=swap');
@import url('https://cdn.jsdelivr.net/npm/geist@1.4.0/dist/fonts/geist-sans/style.css');

/* ============================================================ Variables ============================================================ */
:root {
  /* Dark (default) */
  --bg-base: #0a0b0d;
  --bg-surface: #14161a;
  --bg-elevated: #1c1f24;
  --bg-input: #0f1114;

  --border: #2a2e35;
  --border-strong: #3a3f48;
  --border-accent: rgba(217, 120, 71, 0.4);

  --text-primary: #e8e6e3;
  --text-secondary: #9a9690;
  --text-muted: #5c5853;
  --text-inverse: #0a0b0d;

  --accent: #d97847;
  --accent-bright: #ed8a52;
  --accent-dim: #8a4828;
  --accent-glow: rgba(217, 120, 71, 0.15);

  --success: #7ab85d;
  --warning: #d4a017;
  --danger: #c4543e;
  --info: #5fa3c4;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.6);
  --shadow-glow: 0 0 24px rgba(217, 120, 71, 0.15);

  --radius: 4px;
  --radius-lg: 8px;

  --font-display: 'Instrument Serif', Georgia, serif;
  --font-body: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
}

[data-theme="light"] {
  --bg-base: #f4f1ec;
  --bg-surface: #ffffff;
  --bg-elevated: #faf8f4;
  --bg-input: #f7f4ef;

  --border: #d6d1c9;
  --border-strong: #b8b1a4;
  --border-accent: rgba(217, 120, 71, 0.5);

  --text-primary: #1a1816;
  --text-secondary: #5c5853;
  --text-muted: #8a857d;
  --text-inverse: #faf8f4;

  --accent: #b85c2d;
  --accent-bright: #d97847;
  --accent-dim: #6b3a1e;
  --accent-glow: rgba(184, 92, 45, 0.12);

  --success: #5a8a3e;
  --warning: #b8851a;
  --danger: #a8442f;
  --info: #4a8aa8;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);
  --shadow-glow: 0 0 16px rgba(184, 92, 45, 0.18);
}

/* ============================================================ Reset ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background-image:
    radial-gradient(circle at 15% 0%, rgba(217, 120, 71, 0.04) 0%, transparent 50%),
    radial-gradient(circle at 85% 100%, rgba(217, 120, 71, 0.03) 0%, transparent 50%);
  background-attachment: fixed;
}

/* Grain overlay - tres subtil */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='0.9' numOctaves='3' /%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23n)' /%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

/* ============================================================ Layout ============================================================ */
.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
  position: relative;
  z-index: 2;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 0 2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}

header.topbar .brand {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

header.topbar h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

header.topbar h1 em {
  font-style: italic;
  color: var(--accent);
  margin-left: 0.25rem;
}

header.topbar .version {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 100px;
}

header.topbar .actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}
.btn-icon:hover { color: var(--accent); border-color: var(--border-accent); background: var(--accent-glow); }

/* ============================================================ Grille principale ============================================================ */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: 2rem;
  align-items: start;
}
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
}

/* ============================================================ Carte / Card ============================================================ */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.card-header h2 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 400;
  letter-spacing: -0.01em;
}
.card-header .meta {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.card-body { padding: 1.25rem; }

/* ============================================================ Sections d'input ============================================================ */
.section {
  border-bottom: 1px solid var(--border);
}
.section:last-child { border-bottom: none; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  cursor: pointer;
  user-select: none;
  background: transparent;
  transition: background 0.15s ease;
}
.section-head:hover { background: var(--bg-elevated); }
.section-head h3 {
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.section-head h3::before {
  content: '';
  display: block;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 100px;
  box-shadow: 0 0 8px var(--accent);
}
.section-head .toggle {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 1rem;
  transition: transform 0.2s ease;
}
.section[data-open="false"] .toggle { transform: rotate(-90deg); }
.section[data-open="false"] .section-body { display: none; }

.section-body { padding: 0.5rem 1.25rem 1.25rem; }

/* ============================================================ Form controls ============================================================ */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.field-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.75rem;
}

.field label {
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.field label .unit {
  font-family: var(--font-mono);
  font-weight: 400;
  text-transform: none;
  color: var(--text-muted);
  letter-spacing: 0;
}
.field label .help {
  cursor: help;
  color: var(--text-muted);
  font-weight: 400;
}

input[type="text"], input[type="number"], select, textarea {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  padding: 0.55rem 0.7rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius);
  width: 100%;
  transition: all 0.12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input[type="number"] {
  font-variant-numeric: tabular-nums;
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239a9690' stroke-width='2'%3e%3cpolyline points='6 9 12 15 18 9'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 1rem;
  padding-right: 2rem;
}

/* Toggle switch */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
}
.toggle-switch input { display: none; }
.toggle-switch .track {
  width: 32px;
  height: 18px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 100px;
  position: relative;
  transition: all 0.15s ease;
}
.toggle-switch .track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  background: var(--text-secondary);
  border-radius: 100px;
  transition: all 0.15s ease;
}
.toggle-switch input:checked + .track {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle-switch input:checked + .track::after {
  left: 16px;
  background: var(--text-inverse);
}

/* Radio group "pills" */
.radio-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  background: var(--bg-input);
  padding: 0.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.radio-pills label {
  flex: 1;
  text-align: center;
  padding: 0.45rem 0.6rem;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--text-secondary);
  transition: all 0.12s ease;
  min-width: 0;
  justify-content: center;
}
.radio-pills input { display: none; }
.radio-pills label:hover { color: var(--text-primary); }
.radio-pills input:checked + span,
.radio-pills label:has(input:checked) {
  background: var(--accent);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}

/* Bouton */
.btn {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.12s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.btn:hover { background: var(--bg-surface); border-color: var(--border-strong); }
.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--accent-bright);
  border-color: var(--accent-bright);
  box-shadow: var(--shadow-glow);
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
}
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: var(--text-inverse); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ============================================================ Resultats ============================================================ */
.results-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}
.result-cell {
  padding: 1.25rem;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.result-cell .label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
}
.result-cell .value {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.result-cell .value .unit {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 0.25rem;
}
.result-cell .sub {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}
.result-cell.featured {
  background: linear-gradient(135deg, var(--bg-elevated) 0%, var(--bg-surface) 100%);
}
.result-cell.featured .value {
  color: var(--accent);
  font-size: 2rem;
}
.result-cell.featured::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px;
  height: 100%;
  background: var(--accent);
}

/* Secondaires - plus petits */
.results-secondary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
}
.results-secondary .result-cell {
  padding: 0.85rem 1rem;
}
.results-secondary .result-cell .value { font-size: 1.1rem; }
.results-secondary .result-cell .label { font-size: 0.65rem; }

@media (max-width: 700px) {
  .results-grid, .results-secondary { grid-template-columns: 1fr 1fr; }
  .result-cell .value { font-size: 1.4rem; }
}

/* ============================================================ Jauge / Bar gauge ============================================================ */
.gauge {
  margin-top: 0.5rem;
  height: 4px;
  background: var(--bg-input);
  border-radius: 100px;
  overflow: hidden;
  position: relative;
}
.gauge .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 100px;
  transition: width 0.3s ease, background 0.2s ease;
}
.gauge .fill.warn { background: var(--warning); }
.gauge .fill.crit { background: var(--danger); }
.gauge .marker {
  position: absolute;
  top: -2px;
  width: 1px;
  height: 8px;
  background: var(--text-muted);
}

/* ============================================================ Alertes ============================================================ */
.alerts {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.25rem;
}
.alert {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  border-left: 3px solid var(--info);
  background: rgba(95, 163, 196, 0.08);
  font-size: 0.85rem;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}
.alert .ico {
  font-family: var(--font-mono);
  font-weight: 700;
  flex-shrink: 0;
}
.alert.ok { border-color: var(--success); background: rgba(122, 184, 93, 0.08); }
.alert.warning { border-color: var(--warning); background: rgba(212, 160, 23, 0.1); }
.alert.critical { border-color: var(--danger); background: rgba(196, 84, 62, 0.12); }
.alert.info { border-color: var(--info); background: rgba(95, 163, 196, 0.08); }

/* ============================================================ Bloc copie code ============================================================ */
.code-block {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.7;
  white-space: pre;
  overflow-x: auto;
  color: var(--text-secondary);
  position: relative;
}
.code-block .key { color: var(--accent); }
.code-block .val { color: var(--text-primary); font-weight: 500; }
.code-block .comment { color: var(--text-muted); font-style: italic; }
.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.3rem 0.6rem;
  font-size: 0.7rem;
}

/* ============================================================ Modale ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 { font-family: var(--font-display); font-weight: 400; font-size: 1.4rem; }
.modal-body { padding: 1.25rem; }
.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ============================================================ Toast ============================================================ */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  color: var(--text-primary);
  padding: 0.7rem 1.2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 0.9rem;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; pointer-events: auto; }

/* ============================================================ Utilities ============================================================ */
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.mono { font-family: var(--font-mono); }
.small { font-size: 0.8rem; }
.tiny { font-size: 0.7rem; }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.divider { height: 1px; background: var(--border); margin: 1rem 0; }
.tag {
  display: inline-block;
  padding: 1px 6px;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-secondary);
}
.tag.accent { background: var(--accent-glow); color: var(--accent); border-color: var(--border-accent); }

/* Footer */
footer.foot {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}
footer.foot a { color: var(--text-secondary); text-decoration: none; }
footer.foot a:hover { color: var(--accent); }

/* ============================================================ Animations entry ============================================================ */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.card { animation: slideUp 0.3s ease both; }
.card:nth-child(2) { animation-delay: 0.05s; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.pulse { animation: pulse 1.5s ease-in-out infinite; }

/* ============================================================ Admin specifique ============================================================ */
.admin-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 800px) { .admin-layout { grid-template-columns: 1fr; } }

.admin-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.5rem;
  position: sticky;
  top: 1rem;
}
.admin-nav button {
  text-align: left;
  background: transparent;
  border: none;
  padding: 0.6rem 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius);
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-body);
}
.admin-nav button:hover { background: var(--bg-elevated); color: var(--text-primary); }
.admin-nav button.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-left: 2px solid var(--accent);
  padding-left: calc(0.8rem - 2px);
}
.admin-nav button .count {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 100px;
  color: var(--text-muted);
}

.admin-toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
  flex-wrap: wrap;
}
.admin-toolbar .search-box {
  flex: 1;
  min-width: 200px;
}

.data-table {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  overflow-x: auto;
}
.data-table table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table th {
  text-align: left;
  padding: 0.75rem 0.85rem;
  background: var(--bg-elevated);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  vertical-align: top;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: var(--bg-elevated); }
.data-table td.actions { text-align: right; white-space: nowrap; }
.data-table td.actions button { margin-left: 4px; padding: 4px 8px; font-size: 0.75rem; }
.data-table td.notes { font-family: var(--font-body); color: var(--text-muted); font-size: 0.78rem; max-width: 280px; }

.edit-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}
.edit-form .full { grid-column: 1 / -1; }
@media (max-width: 600px) { .edit-form { grid-template-columns: 1fr; } }

/* ============================================================ Onglet sticky (responsive) ============================================================ */
@media (min-width: 980px) {
  .input-col { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
  .input-col::-webkit-scrollbar { width: 6px; }
  .input-col::-webkit-scrollbar-track { background: transparent; }
  .input-col::-webkit-scrollbar-thumb { background: var(--border); border-radius: 100px; }
}
