:root {
  /* -- Palette de base -- */
  --bg-app: #f8fafc;       /* Slate 50 */
  --bg-panel: #ffffff;     /* White */
  --bg-input: #e2e8f0;     /* Slate 200 */
  --text-main: #0f172a;    /* Slate 900 */
  --text-muted: #64748b;   /* Slate 500 */
  --border: #cbd5e1;       /* Slate 300 */
  
  /* -- Couleurs d'accentuation -- */
  --primary: #4f46e5;      /* Indigo 600 */
  --primary-hover: #4338ca;/* Indigo 700 */
  --accent: #0ea5e9;       /* Sky 500 */
  
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
}

/* THÈME SOMBRE (Activé par data-theme="dark") */
body[data-theme="dark"] {
  --bg-app: #0f172a;       /* Slate 900 */
  --bg-panel: #1e293b;     /* Slate 800 */
  --bg-input: #334155;     /* Slate 700 */
  --text-main: #f1f5f9;    /* Slate 100 */
  --text-muted: #94a3b8;   /* Slate 400 */
  --border: #334155;       /* Slate 700 */
  --primary: #818cf8;      /* Indigo 400 */
  --primary-hover: #6366f1;/* Indigo 500 */
}

/* THÈME CLAIR (Explicite) */
body[data-theme="light"] {
  --bg-app: #f8fafc;
  --bg-panel: #ffffff;
  --bg-input: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #cbd5e1;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  overflow: hidden;
  transition: background-color 0.3s, color 0.3s;
}

/* --- SIDEBAR --- */
.sidebar {
  width: 340px;
  background-color: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  overflow-y: auto;
  box-shadow: 4px 0 24px rgba(0,0,0,0.05);
  z-index: 10;
}

h1 {
  font-size: 1.25rem;
  font-weight: 800;
  margin: 0 0 1.5rem 0;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin: 1.5rem 0 1rem 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
  font-weight: 700;
}

/* --- INFO BULLES (TOOLTIPS) --- */
.tooltip-icon {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 16px;
  height: 16px;
  background: var(--bg-input);
  color: var(--text-muted);
  border-radius: 50%;
  font-size: 10px;
  font-weight: bold;
  cursor: help;
  margin-left: 6px;
  position: relative;
}

.tooltip-icon:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-main);
  color: var(--bg-panel);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px;
  white-space: pre; /* Pour gérer les sauts de ligne si besoin */
  width: max-content;
  max-width: 200px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 1000;
  pointer-events: none;
  text-align: center;
  font-weight: normal;
}

/* --- TABS --- */
.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  background: var(--bg-input);
  padding: 0.25rem;
  border-radius: var(--radius);
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: calc(var(--radius) - 4px);
  transition: all 0.2s;
}

.tab-btn.active {
  background-color: var(--bg-panel);
  color: var(--primary);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.tab-content { display: none; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* --- CONTROLS --- */
.control-group {
  margin-bottom: 1.25rem;
}

label {
  display: flex;
  align-items: center;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  color: var(--text-main);
  font-weight: 500;
}

label span[id$="Mm"] {
  margin-left: auto;
  color: var(--primary);
  font-weight: 600;
  font-family: monospace;
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8rem;
}

/* SLIDERS */
input[type=range] {
  -webkit-appearance: none;
  width: 100%;
  background: transparent;
  margin: 5px 0;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg-panel);
  cursor: pointer;
  margin-top: -6px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  transition: transform 0.1s;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  cursor: pointer;
  background: var(--bg-input);
  border-radius: 2px;
}

/* INPUTS NUMBER */
input[type=number], select {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.2s;
}
input[type=number]:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--bg-input);
}

/* BUTTONS */
.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white;
  border: none;
  padding: 0.85rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  transition: filter 0.2s, transform 0.1s;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:active { transform: translateY(1px); }

/* TOP BAR (Export) */
.top-bar {
  background-color: var(--bg-panel);
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.btn-sm {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid transparent;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-sm:hover {
  background: var(--bg-panel);
  border-color: var(--primary);
  color: var(--primary);
}

/* --- MAIN AREA --- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.workspace {
  flex: 1;
  display: flex;
  position: relative;
  /* Fond subtil quadrillé */
  background-color: var(--bg-app);
  background-image: 
    radial-gradient(var(--border) 1px, transparent 1px);
  background-size: 20px 20px;
}

.view-3d, .view-2d {
  flex: 1;
  position: relative;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: transparent;
}

.view-header {
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: var(--bg-panel);
  padding: 0.35rem 0.85rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  z-index: 5;
  border: 1px solid var(--border);
  text-transform: uppercase;
}

/* CANVAS & SVG */
#c3d { width: 100%; height: 100%; display: block; }

.svg-container {
  flex: 1;
  width: 100%;
  height: 100%;
  padding: 2rem;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden; 
}

#svgPreview svg {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.1));
}
#svgPreview path {
  stroke: var(--text-main);
  stroke-width: 1.5px;
  vector-effect: non-scaling-stroke;
}

/* STATUS BAR */
#status {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--bg-panel);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  border: 1px solid var(--border);
  transform: translateY(150%);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
}
#status.visible { transform: translateY(0); }
#status.ok { border-left: 4px solid #10b981; color: #065f46; }
#status.error { border-left: 4px solid #ef4444; color: #991b1b; }
#status.warn { border-left: 4px solid #f59e0b; color: #92400e; }

/* CHECKBOX CUSTOM */
input[type=checkbox] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
}
