@import url('https://fonts.googleapis.com/css2?family=Exo+2:wght@300;400;500;600;700&family=Roboto+Mono:wght@400;500;600&display=swap');

/* =============================================================
   SIMULADOR DE QUÍMICA – 2n Batxillerat LOMLOE
   Fitxer:  css/styles.css
   Versió:  1.1
   =============================================================
   ÍNDEX:
   1.  Variables CSS (tokens de disseny)
   2.  Reset i base
   3.  Layout principal (header + sidebar + main)
   4.  Sidebar / navegació
   5.  Àrea de simulació
   6.  Panell de controls
   7.  Taula de dades
   8.  Gràfica
   9.  Panell d'activitat
   10. Taula periòdica (element grid)
   11. Targeta d'element
   12. Model de Bohr (canvas overlay)
   13. Botons i controls genèrics
   14. Modals
   15. Tooltip i notificació
   16. Mode fosc (dark theme)
   17. Responsive
   ============================================================= */

/* ──────────────────────────────────────────────────────────────
   1. VARIABLES CSS
   ────────────────────────────────────────────────────────────── */
:root {
  /* Paleta principal */
  --clr-primary:       #1a73e8;
  --clr-primary-dark:  #1557b0;
  --clr-primary-light: #e8f0fe;
  --clr-accent:        #00bcd4;
  --clr-success:       #34a853;
  --clr-warning:       #fbbc04;
  --clr-danger:        #ea4335;

  /* Categories d'elements */
  --clr-alkali:        #ff8a65;
  --clr-alkaline:      #ffcc80;
  --clr-transition:    #80cbc4;
  --clr-post:          #a5d6a7;
  --clr-metalloid:     #ce93d8;
  --clr-nonmetal:      #90caf9;
  --clr-halogen:       #f48fb1;
  --clr-noble:         #ffe082;
  --clr-lanthanide:    #ef9a9a;
  --clr-actinide:      #ffab91;
  --clr-unknown:       #bdbdbd;

  /* Fons i superfícies */
  --bg-body:           #f0f2f5;
  --bg-header:         #1a1f36;
  --bg-sidebar:        #1e2640;
  --bg-sidebar-hover:  #2d3561;
  --bg-sidebar-active: #3949ab;
  --bg-surface:        #ffffff;
  --bg-surface-2:      #f8f9fa;
  --bg-sim:            #0d1117;

  /* Text */
  --txt-primary:       #1a1a2e;
  --txt-secondary:     #5f6368;
  --txt-on-dark:       #e8eaed;
  --txt-on-primary:    #ffffff;

  /* Vores i ombres */
  --border:            #dadce0;
  --border-dark:       #5f6368;
  --shadow-sm:         0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md:         0 4px 6px rgba(0,0,0,.1), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:         0 10px 25px rgba(0,0,0,.15);

  /* Tipografia */
  --font-main:         'Exo 2', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:         'Roboto Mono', 'Consolas', 'Courier New', monospace;
  --fs-xs:             0.7rem;
  --fs-sm:             0.8rem;
  --fs-base:           0.9rem;
  --fs-md:             1rem;
  --fs-lg:             1.15rem;
  --fs-xl:             1.4rem;
  --fs-2xl:            1.8rem;

  /* Mides i espaiat */
  --header-h:          52px;
  --sidebar-w:         220px;
  --radius:            8px;
  --radius-sm:         4px;
  --radius-lg:         12px;
  --gap:               12px;
  --gap-lg:            20px;
  --transition:        0.2s ease;
}

/* ──────────────────────────────────────────────────────────────
   2. RESET I BASE
   ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: var(--font-main);
  background: var(--bg-body);
  color: var(--txt-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }
a { color: var(--clr-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

kbd {
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}

/* ──────────────────────────────────────────────────────────────
   3. LAYOUT PRINCIPAL
   ────────────────────────────────────────────────────────────── */
#app-header {
  height: var(--header-h);
  background: var(--bg-header);
  color: var(--txt-on-dark);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--gap-lg);
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-icon {
  display: flex;
  align-items: center;
  color: var(--clr-accent);
}
.brand-icon svg { stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.header-brand h1 {
  font-size: var(--fs-lg);
  font-weight: 700;
  white-space: nowrap;
}
.brand-sub {
  font-size: var(--fs-xs);
  color: #9aa0ac;
  margin-top: 2px;
}

.header-tools { display: flex; gap: 6px; }
.header-btn {
  background: rgba(255,255,255,.1);
  color: var(--txt-on-dark);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: var(--fs-sm);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background var(--transition), border-color var(--transition);
  white-space: nowrap;
}
.header-btn:hover {
  background: rgba(255,255,255,.2);
  border-color: rgba(255,255,255,.35);
}

/* Grid 2 columnes: sidebar | main */
#app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  flex: 1;
  overflow: hidden;
  transition: grid-template-columns 0.3s cubic-bezier(.4,0,.2,1);
}

/* Grid de main: 2×3 */
#main-content {
  display: grid;
  grid-template-columns: 1fr 280px;
  grid-template-rows: 1fr 200px 160px;
  grid-template-areas:
    "simulation controls"
    "data       graph"
    "activity   activity";
  gap: var(--gap);
  padding: var(--gap);
  overflow: hidden;
  background: var(--bg-body);
  transition: grid-template-columns 0.28s ease, grid-template-rows 0.28s ease;
}

/* ──────────────────────────────────────────────────────────────
   4. SIDEBAR
   ────────────────────────────────────────────────────────────── */
#sidebar {
  background: var(--bg-sidebar);
  color: var(--txt-on-dark);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 0;
  scrollbar-width: thin;
  scrollbar-color: #3949ab transparent;
}

.nav-section-title {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9aa0ac;
  padding: 10px 16px 4px;
  font-weight: 600;
}

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,.1);
  margin: 8px 12px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 16px;
  background: transparent;
  border: none;
  color: #c5cae9;
  font-size: var(--fs-sm);
  text-align: left;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
}
.nav-btn:hover {
  background: var(--bg-sidebar-hover);
  color: #fff;
}
.nav-btn.active {
  background: var(--bg-sidebar-active);
  color: #fff;
  border-left-color: var(--clr-accent);
  font-weight: 600;
}
.nav-icon { font-size: 1rem; flex-shrink: 0; }
.nav-text  { font-size: var(--fs-sm); line-height: 1.3; }

/* ──────────────────────────────────────────────────────────────
   5. ÀREA DE SIMULACIÓ
   ────────────────────────────────────────────────────────────── */
#simulation-area {
  grid-area: simulation;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sim-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-2);
  flex-shrink: 0;
  gap: 8px;
  overflow: visible;
}

#sim-title-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex-shrink: 1;
}
#sim-title {
  font-size: var(--fs-md);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#sim-subtitle { font-size: var(--fs-xs); color: var(--txt-secondary); }

#sim-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: nowrap;
}
#sim-playbar { display: flex; gap: 5px; }

.sim-btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 5px 14px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: #fff;
  transition: opacity var(--transition), transform 0.1s;
}
.sim-btn:active { transform: scale(0.96); }
.sim-btn.green  { background: var(--clr-success); }
.sim-btn.amber  { background: var(--clr-warning); color: #333; }
.sim-btn.red    { background: var(--clr-danger); }

#sim-mode-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.mode-btn {
  padding: 4px 12px;
  background: var(--bg-surface);
  border: none;
  font-size: var(--fs-xs);
  color: var(--txt-secondary);
  transition: background var(--transition);
}
.mode-btn:hover  { background: var(--bg-surface-2); }
.mode-btn.active { background: var(--clr-primary); color: #fff; font-weight: 600; }

#sim-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-sim);
}

#sim-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}

#sim-html-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  overflow: auto;
  background: transparent;
}

#sim-sub-nav {
  display: flex;
  gap: 4px;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface-2);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.sub-nav-btn {
  padding: 3px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: var(--fs-xs);
  color: var(--txt-secondary);
  transition: all var(--transition);
}
.sub-nav-btn:hover  { background: var(--clr-primary-light); color: var(--clr-primary); }
.sub-nav-btn.active { background: var(--clr-primary); color: #fff; border-color: var(--clr-primary); }

/* ──────────────────────────────────────────────────────────────
   6. CONTROLS PANEL
   ────────────────────────────────────────────────────────────── */
#controls-panel {
  grid-area: controls;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  overflow-x: hidden;
}

.panel-title {
  font-size: var(--fs-base);
  font-weight: 700;
  padding: 6px 8px 6px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
}

/* Botó toggle unificat per a tots els panells (controls, dades, gràfica) */
.panel-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.06);
  color: var(--txt-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  padding: 0;
  line-height: 1;
}
.panel-toggle-btn:hover {
  background: rgba(255,255,255,.14);
  color: var(--txt-primary);
  border-color: rgba(255,255,255,.22);
}
.panel-toggle-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  transition: transform 0.25s cubic-bezier(.4,0,.2,1);
}

/* Panell de controls col·lapsat */
#controls-panel {
  transition: padding 0.28s ease, min-width 0.28s ease;
  min-width: 0;
}
#controls-panel .panel-body-wrap {
  overflow: hidden;
  transition: opacity 0.2s ease;
}

body.controls-collapsed #main-content {
  grid-template-columns: 1fr 36px;
}
body.controls-collapsed #controls-panel {
  padding: 8px 4px;
  overflow: hidden !important;
}
body.controls-collapsed #controls-panel .panel-title {
  padding: 6px 4px;
  justify-content: center;
  border-bottom: none;
}
body.controls-collapsed #controls-panel .panel-title span,
body.controls-collapsed #controls-panel #controls-container,
body.controls-collapsed #controls-panel #element-info {
  display: none !important;
}
body.controls-collapsed #btn-collapse-controls svg {
  transform: rotate(-90deg);
}

.panel-hint {
  font-size: var(--fs-sm);
  color: var(--txt-secondary);
  text-align: center;
  margin-top: 20px;
}

#controls-container { display: flex; flex-direction: column; gap: 12px; }

/* Control individual (slider, dropdown, etc.) */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.control-label {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-sm);
  font-weight: 600;
}
.control-value {
  font-size: var(--fs-sm);
  color: var(--clr-primary);
  font-weight: 700;
  font-family: var(--font-mono);
}

input[type=range] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--clr-primary);
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.2); }

.control-select {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  font-size: var(--fs-sm);
}

/* Separador de grup de controls */
.control-separator {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

/* Capçalera de secció del panell de controls */
.control-section-header {
  background: var(--bg-surface-2);
  border-left: 3px solid var(--clr-primary);
  padding: 5px 8px 5px 10px;
  margin: 10px -12px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--txt-primary);
  border-radius: 0 4px 4px 0;
}

/* ──────────────────────────────────────────────────────────────
   7. TAULA DE DADES
   ────────────────────────────────────────────────────────────── */
#data-section {
  grid-area: data;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 4px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-2);
  flex-shrink: 0;
  min-height: 40px;
}
.section-header h3 { font-size: var(--fs-sm); font-weight: 700; }
.section-actions { display: flex; gap: 6px; align-items: center; }

.small-btn {
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  font-size: var(--fs-xs);
  color: var(--txt-secondary);
  transition: all var(--transition);
}
.small-btn:hover    { background: var(--bg-surface-2); }
.small-btn.primary  { background: var(--clr-primary); color: #fff; border-color: var(--clr-primary); }
.small-btn.primary:hover { background: var(--clr-primary-dark); }

.small-select {
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  background: var(--bg-surface);
}

#data-table-container {
  flex: 1;
  overflow: auto;
}

#data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-xs);
}
#data-table th {
  background: var(--bg-surface-2);
  padding: 5px 8px;
  text-align: left;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
#data-table td {
  padding: 4px 8px;
  border-bottom: 1px solid #f0f0f0;
  font-family: var(--font-mono);
}
#data-table tr:hover td { background: var(--clr-primary-light); }
.empty-row { text-align: center; color: var(--txt-secondary); font-family: var(--font-main); }

/* ──────────────────────────────────────────────────────────────
   8. GRÀFICA
   ────────────────────────────────────────────────────────────── */
#graph-section {
  grid-area: graph;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#graph-container {
  flex: 1;
  padding: 8px;
  position: relative;
}
#graph-canvas { width: 100% !important; height: 100% !important; }

/* ──────────────────────────────────────────────────────────────
   9. PANELL D'ACTIVITAT
   ────────────────────────────────────────────────────────────── */
#activity-section {
  grid-area: activity;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.activity-toggle { cursor: pointer; user-select: none; }
.activity-toggle:hover { background: var(--bg-surface-2); }

#activity-content {
  flex: 1;
  padding: 10px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#activity-instructions { font-size: var(--fs-sm); color: var(--txt-secondary); }

#activity-question {
  font-size: var(--fs-sm);
  font-weight: 600;
  background: var(--clr-primary-light);
  border-left: 4px solid var(--clr-primary);
  padding: 8px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

#activity-options { display: flex; flex-direction: column; gap: 6px; }

.activity-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--fs-sm);
  transition: all var(--transition);
}
.activity-option:hover   { background: var(--bg-surface-2); }
.activity-option.correct { background: #e6f4ea; border-color: var(--clr-success); color: #1e4620; }
.activity-option.wrong   { background: #fce8e6; border-color: var(--clr-danger); color: #721c24; }

#activity-feedback {
  font-size: var(--fs-sm);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}
#activity-feedback.ok  { background: #e6f4ea; color: #1e4620; }
#activity-feedback.err { background: #fce8e6; color: #721c24; }

.activity-nav {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  padding-top: 4px;
}

.activity-btn {
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  font-size: var(--fs-sm);
  color: var(--txt-secondary);
  transition: all var(--transition);
}
.activity-btn:hover:not(:disabled) { background: var(--bg-surface-2); }
.activity-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.activity-btn.primary { background: var(--clr-primary); color: #fff; border-color: var(--clr-primary); }
.activity-btn.primary:hover { background: var(--clr-primary-dark); }

.progress-bar {
  width: 120px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--clr-primary);
  border-radius: 3px;
  transition: width 0.4s ease;
}
#activity-step-info { font-size: var(--fs-xs); color: var(--txt-secondary); }

/* ──────────────────────────────────────────────────────────────
   10. TAULA PERIÒDICA (element grid)
   ────────────────────────────────────────────────────────────── */
#periodic-table-wrap {
  padding: 10px;
  background: var(--bg-sim);
  min-height: 100%;
  overflow: auto;
}

.pt-property-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px;
  background: rgba(255,255,255,.05);
  border-radius: var(--radius);
  margin-bottom: 10px;
}

.pt-prop-btn {
  padding: 3px 12px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,.2);
  background: transparent;
  color: #ccc;
  font-size: var(--fs-xs);
  cursor: pointer;
  transition: all var(--transition);
}
.pt-prop-btn:hover  { background: rgba(255,255,255,.1); color: #fff; }
.pt-prop-btn.active { background: var(--clr-primary); color: #fff; border-color: var(--clr-primary); }

/* Grid de la taula periòdica (18 columnes) */
.pt-grid {
  display: grid;
  grid-template-columns: repeat(18, 44px);
  grid-template-rows: repeat(10, 44px); /* 7 períodes + 2 files lantà/actínid + 1 de separació */
  gap: 2px;
  min-width: fit-content;
}

/* Cel·la d'element */
.pt-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
  position: relative;
  border: 1px solid rgba(0,0,0,.2);
  overflow: hidden;
  user-select: none;
}
.pt-cell:hover {
  transform: scale(1.25);
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  filter: brightness(1.15);
}
.pt-cell.selected {
  box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--clr-accent);
  z-index: 11;
}

.pt-cell .cell-number { font-size: 0.55rem; line-height: 1; color: rgba(0,0,0,.6); }
.pt-cell .cell-symbol { font-size: 0.9rem; font-weight: 700; color: rgba(0,0,0,.85); line-height: 1.1; }
.pt-cell .cell-mass   { font-size: 0.45rem; color: rgba(0,0,0,.55); }

/* Color per categoria */
.cat-alkali-metal     { background: var(--clr-alkali);    }
.cat-alkaline-earth   { background: var(--clr-alkaline);  }
.cat-transition-metal { background: var(--clr-transition);}
.cat-post-transition  { background: var(--clr-post);      }
.cat-metalloid        { background: var(--clr-metalloid); }
.cat-nonmetal         { background: var(--clr-nonmetal);  }
.cat-halogen          { background: var(--clr-halogen);   }
.cat-noble-gas        { background: var(--clr-noble);     }
.cat-lanthanide       { background: var(--clr-lanthanide);}
.cat-actinide         { background: var(--clr-actinide);  }
.cat-unknown          { background: var(--clr-unknown);   }

/* Etiquetes de fila/columna */
.pt-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  color: rgba(255,255,255,.4);
  font-weight: 600;
}

/* Llegenda de categories */
.pt-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  margin-top: 8px;
}
.pt-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xs);
  color: #ccc;
}
.pt-legend-dot {
  width: 12px; height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,.3);
}

/* Color de tendència (heatmap) */
.pt-cell.trend-low    { background: #1565c0 !important; }
.pt-cell.trend-mid    { background: #f9a825 !important; }
.pt-cell.trend-high   { background: #b71c1c !important; }
.pt-cell.trend-none   { background: #424242 !important; }

/* ──────────────────────────────────────────────────────────────
   11. TARGETA D'ELEMENT (panell dret)
   ────────────────────────────────────────────────────────────── */
.element-card-big {
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-primary-dark));
  color: #fff;
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  margin-bottom: 10px;
}
.ec-number { font-size: var(--fs-sm); opacity: .8; }
.ec-symbol { font-size: var(--fs-2xl); font-weight: 900; }
.ec-name   { font-size: var(--fs-base); font-weight: 600; }
.ec-mass   { font-size: var(--fs-sm); opacity: .8; margin-top: 2px; }

.prop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}
.prop-item {
  background: var(--bg-surface-2);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
}
.prop-item-label { font-size: var(--fs-xs); color: var(--txt-secondary); }
.prop-item-value {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--txt-primary);
  font-family: var(--font-mono);
}

.config-box {
  background: var(--bg-surface-2);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  word-break: break-all;
  line-height: 1.6;
}

/* ──────────────────────────────────────────────────────────────
   12. MODEL DE BOHR (canvas)
   ────────────────────────────────────────────────────────────── */
#bohr-info {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background: rgba(0,0,0,.7);
  color: #fff;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: var(--fs-sm);
  pointer-events: none;
  max-width: 260px;
}
#bohr-info .bi-title { font-weight: 700; font-size: var(--fs-base); margin-bottom: 4px; }

/* ──────────────────────────────────────────────────────────────
   13. BOTONS I CONTROLS GENÈRICS
   ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-primary   { background: var(--clr-primary);   color: #fff; }
.btn-success   { background: var(--clr-success);   color: #fff; }
.btn-danger    { background: var(--clr-danger);    color: #fff; }
.btn-secondary { background: var(--bg-surface-2);  color: var(--txt-primary); border: 1px solid var(--border); }
.btn:hover { opacity: 0.88; }

/* Checkbox estilitzat */
.styled-checkbox { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: var(--fs-sm); }
.styled-checkbox input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--clr-primary); }

/* Etiqueta-valor */
.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  font-size: var(--fs-sm);
  border-bottom: 1px dashed #eee;
}
.kv-key   { color: var(--txt-secondary); }
.kv-val   { font-family: var(--font-mono); font-weight: 700; color: var(--clr-primary); }

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

.modal-content {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(480px, 95vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-content.large { width: min(700px, 95vw); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-2);
  flex-shrink: 0;
}
.modal-header h2 { font-size: var(--fs-lg); }

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.2rem;
  color: var(--txt-secondary);
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  transition: background var(--transition);
}
.modal-close:hover { background: #f0f0f0; color: var(--txt-primary); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
}
.modal-body h3 { font-size: var(--fs-base); margin: 14px 0 6px; }
.modal-body p  { font-size: var(--fs-sm); color: var(--txt-secondary); margin-bottom: 8px; }
.modal-body ul { padding-left: 18px; font-size: var(--fs-sm); line-height: 1.8; }
.modal-body code { background: var(--bg-surface-2); padding: 2px 6px; border-radius: 3px; font-family: var(--font-mono); font-size: var(--fs-xs); }

/* Pestanyes eines */
.tools-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.tool-tab {
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-surface-2);
  font-size: var(--fs-xs);
  color: var(--txt-secondary);
  transition: all var(--transition);
}
.tool-tab:hover  { background: var(--clr-primary-light); color: var(--clr-primary); }
.tool-tab.active { background: var(--clr-primary); color: #fff; border-color: var(--clr-primary); font-weight: 600; }

/* Eines: inputs */
.tool-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.tool-form-full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: var(--fs-xs); font-weight: 600; color: var(--txt-secondary); }
.form-group input, .form-group select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  background: var(--bg-surface);
}
.tool-result {
  margin-top: 12px;
  padding: 12px;
  background: var(--clr-primary-light);
  border-radius: var(--radius);
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--clr-primary-dark);
  text-align: center;
}
.tool-formula {
  font-size: var(--fs-xs);
  color: var(--txt-secondary);
  font-family: var(--font-mono);
  text-align: center;
  margin-top: 4px;
}

/* Taula d'ajuda */
.help-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.help-table th, .help-table td { padding: 5px 10px; border: 1px solid var(--border); }
.help-table th { background: var(--bg-surface-2); font-weight: 700; }

/* ──────────────────────────────────────────────────────────────
   15. TOOLTIP I NOTIFICACIÓ
   ────────────────────────────────────────────────────────────── */
.tooltip {
  position: fixed;
  z-index: 2000;
  background: #1a1a2e;
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  pointer-events: none;
  box-shadow: var(--shadow-md);
  max-width: 200px;
  line-height: 1.5;
}
.tooltip::before {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #1a1a2e;
  border-bottom: 0;
}

.notification {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--txt-primary);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  z-index: 3000;
  animation: slideIn 0.3s ease;
}
.notification.success { background: var(--clr-success); }
.notification.error   { background: var(--clr-danger); }
.notification.warning { background: var(--clr-warning); color: #333; }

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

/* ──────────────────────────────────────────────────────────────
   16. MODE FOSC (dark theme)
   ────────────────────────────────────────────────────────────── */
body.dark-theme {
  --bg-body:      #0d1117;
  --bg-surface:   #161b22;
  --bg-surface-2: #21262d;
  --bg-sim:       #010409;
  --txt-primary:  #e6edf3;
  --txt-secondary:#8b949e;
  --border:       #30363d;
}
body.dark-theme .pt-cell .cell-number,
body.dark-theme .pt-cell .cell-symbol,
body.dark-theme .pt-cell .cell-mass { color: rgba(255,255,255,.85); }

body.dark-theme input[type=text],
body.dark-theme input[type=number],
body.dark-theme select {
  background: var(--bg-surface-2);
  color: var(--txt-primary);
  border-color: var(--border);
}

/* ──────────────────────────────────────────────────────────────
   17. RESPONSIVE (tablet)
   ────────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  #main-content {
    grid-template-columns: 1fr 240px;
  }
  .pt-grid {
    grid-template-columns: repeat(18, 38px);
    grid-template-rows: repeat(10, 38px);
  }
  .pt-cell .cell-symbol { font-size: 0.75rem; }
}

/* ──────────────────────────────────────────────────────────────
   18. MODE EXPANDIT I PANTALLA COMPLETA
   ────────────────────────────────────────────────────────────── */

/* Variable: amplada del panell de controls flotant */
:root { --float-ctrl-w: 300px; }

/* Botons d'expansió a la barra de la simulació */
.sim-expand-btns {
  display: flex;
  gap: 4px;
  margin-left: 4px;
  flex-shrink: 0;
}
/* El sim-header té fons clar → necessitem estil propi visible */
.sim-expand-btn {
  background: var(--bg-surface)   !important;
  color:      var(--txt-primary)  !important;
  border:     1px solid var(--border) !important;
  padding:    4px 10px            !important;
  font-size:  1.05rem             !important;
  font-weight: 600                !important;
  line-height: 1.2;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition), transform 0.1s;
  box-shadow: var(--shadow-sm);
}
.sim-expand-btn:hover {
  background: var(--clr-primary-light) !important;
  color:      var(--clr-primary)       !important;
  border-color: var(--clr-primary)     !important;
}
.sim-expand-btn:active { transform: scale(0.92); }
.sim-expand-btn.active {
  background:   var(--clr-primary) !important;
  color:        #fff               !important;
  border-color: var(--clr-primary) !important;
}

/* ═══════════════════════════════════════════════════════════════
   MODE EXPANDIT
   Simulació fixa ocupant tota la pantalla sota el header.
   Controls: panell flotant a la dreta (pot col·lapsar-se amb ◀).
   ═══════════════════════════════════════════════════════════════ */
body.sim-expanded #simulation-area,
body.sim-fullscreen #simulation-area {
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: var(--float-ctrl-w);   /* deixa espai per als controls */
  bottom: 0;
  z-index: 500;
  border-radius: 0;
  box-shadow: none;
  animation: sim-enter 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  transition: right 0.28s ease;
}

/* Panell de controls flotant a la dreta en mode expandit */
body.sim-expanded #controls-panel,
body.sim-fullscreen #controls-panel {
  position: fixed;
  top: var(--header-h);
  right: 0;
  bottom: 0;
  width: var(--float-ctrl-w);
  z-index: 501;
  border-radius: 0;
  box-shadow: -4px 0 20px rgba(0,0,0,.18);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  animation: ctrl-enter 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  transition: width 0.28s ease, right 0.28s ease;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
}

@keyframes ctrl-enter {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Quan el panell de controls està col·lapsat en mode expandit */
body.sim-expanded.controls-collapsed #controls-panel,
body.sim-fullscreen.controls-collapsed #controls-panel {
  width: 38px;
  padding: 8px 4px;
  overflow: hidden !important;
}
body.sim-expanded.controls-collapsed #simulation-area,
body.sim-fullscreen.controls-collapsed #simulation-area {
  right: 38px;
}
body.sim-expanded.controls-collapsed #controls-panel .panel-title,
body.sim-fullscreen.controls-collapsed #controls-panel .panel-title {
  padding: 6px 4px;
  justify-content: center;
  border-bottom: none;
}
body.sim-expanded.controls-collapsed #controls-panel #controls-container,
body.sim-fullscreen.controls-collapsed #controls-panel #controls-container,
body.sim-expanded.controls-collapsed #controls-panel #element-info,
body.sim-fullscreen.controls-collapsed #controls-panel #element-info,
body.sim-expanded.controls-collapsed .panel-title span,
body.sim-fullscreen.controls-collapsed .panel-title span {
  display: none !important;
}

/* Pantalla completa: amaga el header de l'app */
body.sim-fullscreen #app-header { display: none; }
body.sim-fullscreen #simulation-area,
body.sim-fullscreen #controls-panel { top: 0; }

@keyframes sim-enter {
  from { opacity: 0.55; transform: scale(0.975); }
  to   { opacity: 1;    transform: scale(1); }
}

/* Indicador ESC flotant dins el canvas */
#sim-expand-indicator {
  display: none;
  position: absolute;
  bottom: 10px;
  left: 12px;
  z-index: 10;
  background: rgba(0,0,0,.50);
  color: rgba(255,255,255,.65);
  font-size: 0.62rem;
  font-family: var(--font-mono);
  padding: 3px 8px;
  border-radius: 20px;
  pointer-events: none;
  letter-spacing: 0.05em;
}
body.sim-expanded  #sim-expand-indicator,
body.sim-fullscreen #sim-expand-indicator { display: block; }

@media (max-width: 800px) {
  :root { --sidebar-w: 50px; }
  .nav-text { display: none; }
  .nav-section-title { display: none; }
  .nav-btn { justify-content: center; padding: 10px; }
  .brand-sub { display: none; }
  #main-content {
    grid-template-columns: 1fr;
    grid-template-rows: 300px 200px 200px 160px;
    grid-template-areas: "simulation" "controls" "data" "activity";
  }
  #graph-section { display: none; }
}

/* ──────────────────────────────────────────────────────────────
   19. PANEL D'INFORMACIÓ DE LABORATORI (doble clic)
   ────────────────────────────────────────────────────────────── */
.lab-info-panel {
  position: fixed;
  width: 290px;
  max-height: 500px;
  overflow-y: auto;
  background: #1a2030;
  border: 1px solid rgba(80,150,220,0.40);
  border-radius: 10px;
  box-shadow: 0 10px 36px rgba(0,0,0,0.65), 0 0 0 1px rgba(80,150,220,0.10);
  z-index: 2500;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: #c8d8e8;
  user-select: none;
  animation: lipFadeIn 0.15s ease;
}
.lab-info-panel.hidden { display: none !important; }

@keyframes lipFadeIn {
  from { opacity: 0; transform: scale(0.94) translateY(-4px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

.lip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px 8px;
  background: rgba(10,20,40,0.70);
  border-bottom: 1px solid rgba(80,150,220,0.25);
  border-radius: 10px 10px 0 0;
  cursor: move;
  flex-shrink: 0;
}
.lip-title {
  font-weight: 700;
  font-size: 12.5px;
  color: #9cc8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lip-close {
  background: none;
  border: none;
  color: #607080;
  font-size: 15px;
  cursor: pointer;
  padding: 0 3px;
  line-height: 1;
  flex-shrink: 0;
  margin-left: 8px;
  transition: color 0.15s;
}
.lip-close:hover { color: #ef5350; }

.lip-body { padding: 4px 2px 8px; }

.lip-table {
  width: 100%;
  border-collapse: collapse;
}
.lip-table td {
  padding: 2px 10px;
  vertical-align: top;
  line-height: 1.5;
}
.lip-lbl {
  color: #7890a8;
  width: 44%;
  font-size: 10.5px;
}
.lip-val {
  color: #d4e4f4;
  font-weight: 500;
  word-break: break-word;
}
.lip-unit {
  color: #4a6070;
  font-size: 9.5px;
  font-style: italic;
  margin-left: 2px;
}
.lip-section td {
  padding: 6px 8px 2px;
  font-size: 9px;
  font-weight: 800;
  color: #4fc3f7;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-top: 1px solid rgba(80,150,220,0.18);
}
.lip-table tr:first-child .lip-section td,
.lip-section:first-child td { border-top: none; }

/* ──────────────────────────────────────────────────────────────
   20. GRÀFICA EN VISTA PRINCIPAL (graph-primary)
   ────────────────────────────────────────────────────────────── */

/*
 * Estratègia: ocultem NOMÉS el canvas i la capçalera de simulació.
 * El #sim-sub-nav (menú de seccions) queda visible al fons de la cel·la,
 * per sobre de la gràfica gràcies al z-index.
 */

/* Col·lapsa la capçalera (títol + botons play) — no s'usa en mode gràfica */
#main-content.graph-primary #sim-header {
  height: 0 !important;
  overflow: hidden;
  visibility: hidden;
}

/* Amaga el canvas/overlay però manté l'espai flex perquè el sub-nav baixe */
#main-content.graph-primary #sim-container {
  visibility: hidden;
  pointer-events: none;
}

/* Sub-nav: per sobre de la gràfica (z-index > 5) i sempre accessible */
#main-content.graph-primary #sim-sub-nav {
  position: relative;
  z-index: 10;
  border-top: 1px solid var(--border);
}

/* La gràfica ocupa la cel·la de simulació (col 1) deixant els controls accessibles */
#main-content.graph-primary #graph-section {
  grid-area: simulation;
  position: relative;
  z-index: 5;
  margin-bottom: 44px;
}

/* La taula de dades s'expandeix a tota l'amplada quan la gràfica puja */
#main-content.graph-primary #data-section {
  grid-column: 1 / -1;
}

/* Indicador de dades noves: punt verd parpellant al títol */
#graph-section.has-data .section-header h3::after {
  content: ' ●';
  color: #66bb6a;
  font-size: 8px;
  vertical-align: super;
  animation: graphPulse 1.4s ease-in-out 3;
}
@keyframes graphPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.2; }
}

/* Botons ampliar / col·lapsar / reset zoom */
#btn-graph-expand {
  font-size: 14px;
  padding: 2px 7px;
}
/* Cursor grab quan es pot fer pan */
#graph-canvas { cursor: grab; }
#graph-canvas:active { cursor: grabbing; }
/* Reset zoom s'il·lumina quan hi ha zoom actiu */
#btn-reset-zoom.active {
  background: var(--clr-accent, #ff9800);
  color: #000 !important;
  border-color: var(--clr-accent, #ff9800) !important;
}
.graph-collapse-btn {
  background: var(--clr-primary);
  color: #fff !important;
  border-color: var(--clr-primary) !important;
  font-weight: 600;
}
.graph-collapse-btn:hover {
  background: #1a56c0 !important;
}

/* ──────────────────────────────────────────────────────────────
   21. LABORATORI VIRTUAL – Sidebar, Context Menu, Etiquetes
   ────────────────────────────────────────────────────────────── */

/* ── Sidebar ──────────────────────────────────────────────────── */
#lab-sidebar {
  position: absolute;
  top: 0; left: 0;
  width: 210px;
  height: 100%;
  background: rgba(12, 18, 32, 0.97);
  border-right: 1px solid rgba(80, 120, 200, 0.25);
  display: flex;
  flex-direction: column;
  z-index: 20;
  font-size: 11px;
  color: rgba(190, 210, 255, 0.85);
  user-select: none;
  overflow: hidden;
}
#lab-sidebar.lab-sidebar-hidden { display: none; }

/* ── Capçalera del laboratori ─────────────────────────────────── */
.lab-sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px 12px;
  background: rgba(20, 30, 55, 0.80);
  border-bottom: 1px solid rgba(80, 120, 200, 0.25);
  flex-shrink: 0;
}
.lab-sidebar-header-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: #7eb8f7;
  opacity: 0.9;
}
.lab-sidebar-header-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}
.lab-sidebar-header-title {
  font-size: 12px;
  font-weight: 700;
  color: #c8e0ff;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lab-sidebar-header-sub {
  font-size: 9px;
  color: rgba(120, 160, 220, 0.65);
  font-style: italic;
  white-space: nowrap;
}

.lab-sidebar-tabs {
  display: flex;
  border-bottom: 1px solid rgba(80, 120, 200, 0.2);
  flex-shrink: 0;
}
.lab-sidebar-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 11px 4px;
  min-height: 44px;
  background: none;
  border: none;
  color: rgba(150, 180, 255, 0.55);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.lab-sidebar-tab.active   { color: #7eb8f7; border-bottom-color: #7eb8f7; }
.lab-sidebar-tab:hover    { color: #b0d8ff; }

.lab-sidebar-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(80, 120, 200, 0.35) transparent;
}

.lab-tab-panel.lab-tab-hidden { display: none; }

.lab-sidebar-section {
  padding: 9px 12px 5px;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: rgba(100, 150, 220, 0.70);
  border-bottom: 1px solid rgba(80, 120, 200, 0.12);
}
.lab-sidebar-note {
  padding: 4px 12px;
  font-size: 9px;
  color: rgba(150, 180, 255, 0.42);
  font-style: italic;
}

.lab-sidebar-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 5px 10px;
  background: none;
  border: none;
  color: rgba(200, 220, 255, 0.8);
  font-size: 10px;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
  line-height: 1.3;
}
.lab-sidebar-btn:hover    { background: rgba(80, 120, 200, 0.15); color: #fff; }
.lab-btn-icon             { font-size: 14px; flex-shrink: 0; }
.lab-desc                 { font-size: 8.5px; color: rgba(150, 180, 255, 0.45); font-style: normal; }

/* Experiment buttons */
.lab-exp-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: none;
  border-bottom: 1px solid rgba(80, 120, 200, 0.1);
  color: rgba(200, 220, 255, 0.85);
  font-size: 10px;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
  line-height: 1.3;
}
.lab-exp-btn:hover       { background: rgba(80, 120, 200, 0.15); }
.lab-exp-btn.active      { background: rgba(100, 160, 255, 0.12); color: #7eb8f7; border-left: 2px solid #7eb8f7; }
.lab-exp-btn.active strong { color: #a0d0ff; }
.exp-icon                { font-size: 20px; }
.exp-desc                { font-size: 8.5px; opacity: 0.55; }

/* Graella d'instruments – chips compactes */
.lab-inst-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
  padding: 8px;
}
.lab-inst-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 4px 8px;
  min-height: 62px;
  background: rgba(18, 28, 52, 0.75);
  border: 1px solid rgba(80, 120, 200, 0.22);
  border-radius: 8px;
  color: rgba(200, 220, 255, 0.85);
  font-family: var(--font-main);
  font-size: 9px;
  cursor: pointer;
  text-align: center;
  line-height: 1.25;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.lab-inst-chip:hover {
  background: rgba(60, 100, 200, 0.28);
  border-color: rgba(120, 170, 255, 0.55);
  color: #d0e8ff;
}
.lab-inst-chip:active { transform: scale(0.94); }
.lab-inst-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: #7eb8f7;
  flex-shrink: 0;
}
.lab-inst-icon svg { width: 100%; height: 100%; }
.lab-inst-name {
  display: block;
  font-size: 8.5px;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 88px;
}
.lab-inst-desc {
  display: block;
  font-size: 7.5px;
  color: rgba(100, 150, 220, 0.55);
  white-space: nowrap;
}

/* Botó Afegir al recipient del sidebar */
.lsb-add-btn {
  width: 100%;
  padding: 10px;
  min-height: 44px;
  background: rgba(40, 80, 180, 0.45);
  border: 1px solid rgba(100, 150, 255, 0.40);
  color: #a0c8ff;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  letter-spacing: 0.3px;
  margin-top: 4px;
}
.lsb-add-btn:hover {
  background: rgba(60, 110, 220, 0.70);
  border-color: rgba(130, 170, 255, 0.65);
  color: #fff;
}

/* Substance form */
.lab-subst-form {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.lab-subst-form label {
  font-size: 9px;
  color: rgba(150, 180, 255, 0.55);
  margin-top: 2px;
}
.lab-subst-form select,
.lab-subst-form input[type="number"] {
  width: 100%;
  background: rgba(18, 28, 52, 0.85);
  border: 1px solid rgba(80, 120, 200, 0.3);
  color: #ccdeff;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 10px;
  outline: none;
}
.lab-subst-form select:focus,
.lab-subst-form input:focus { border-color: rgba(120, 170, 255, 0.5); }
.lab-subst-form button {
  margin-top: 4px;
  padding: 6px;
  background: rgba(50, 90, 180, 0.45);
  border: 1px solid rgba(100, 150, 255, 0.35);
  color: #9ac8ff;
  border-radius: 4px;
  font-size: 10px;
  cursor: pointer;
  transition: background 0.12s;
}
.lab-subst-form button:hover { background: rgba(70, 110, 220, 0.6); color: #fff; }

/* ── Menú contextual ──────────────────────────────────────────── */
#lab-context-menu {
  position: fixed;
  z-index: 9999;
  background: rgba(12, 18, 35, 0.97);
  border: 1px solid rgba(80, 120, 200, 0.4);
  border-radius: 7px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.65);
  padding: 4px 0;
  min-width: 185px;
  font-size: 11px;
  display: none;
}
#lab-context-menu.visible { display: block; }
.lab-ctx-title {
  padding: 6px 12px 5px;
  font-size: 10px;
  font-weight: 700;
  color: rgba(140, 175, 255, 0.65);
  border-bottom: 1px solid rgba(80, 120, 200, 0.18);
}
.lab-ctx-sub { font-weight: 400; color: rgba(140, 175, 255, 0.45); }
.lab-ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  color: rgba(210, 228, 255, 0.85);
  cursor: pointer;
  transition: background 0.1s;
}
.lab-ctx-item:hover        { background: rgba(80, 120, 200, 0.2); color: #fff; }
.lab-ctx-item.danger       { color: rgba(255, 110, 90, 0.85); }
.lab-ctx-item.danger:hover { background: rgba(180, 50, 50, 0.2); color: #ff9090; }
.lab-ctx-sep               { height: 1px; background: rgba(80, 120, 200, 0.13); margin: 2px 0; }

/* ── Etiquetes flotants ───────────────────────────────────────── */
#lab-labels-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 15;
  overflow: hidden;
}
#lab-labels-overlay.hidden { display: none; }

.lab-float-label {
  position: absolute;
  background: rgba(8, 14, 28, 0.85);
  border: 1px solid rgba(80, 140, 220, 0.3);
  border-radius: 5px;
  padding: 3px 7px;
  font-size: 9px;
  line-height: 1.5;
  color: rgba(200, 220, 255, 0.85);
  white-space: nowrap;
  transform: translate(-50%, -100%) translateY(-8px);
  pointer-events: none;
  will-change: transform;
}
.lfl-name { font-weight: 700; color: #a8d4ff; display: block; }
.lfl-vol  { color: rgba(170, 195, 255, 0.65); }
.lfl-ph   { color: #a5d6a7; }
.lfl-temp { color: #ffcc80; }
.lfl-rxn  { color: #ce93d8; font-size: 8px; }

/* ──────────────────────────────────────────────────────────────
   20. PANELLS COL·LAPSABLES
   ────────────────────────────────────────────────────────────── */

/* Transició del layout principal (sidebar) */
#app-layout {
  transition: grid-template-columns 0.28s ease;
}

/* ── Sidebar: mode icones (1r clic) ─────────────────────────── */
body.sidebar-collapsed #app-layout {
  grid-template-columns: 50px 1fr;
}
body.sidebar-collapsed #sidebar {
  overflow: hidden;
  padding: 10px 0;
}
/* Amaga text i separadors, centra icones */
body.sidebar-collapsed .nav-text,
body.sidebar-collapsed .nav-section-title,
body.sidebar-collapsed .nav-divider {
  display: none;
}
body.sidebar-collapsed .nav-btn {
  justify-content: center;
  padding: 10px 0;
  border-left-color: transparent;
}
body.sidebar-collapsed .nav-btn.active {
  border-left-color: var(--clr-accent);
}

/* ── Sidebar: completament amagat (2n clic) ──────────────────── */
body.sidebar-hidden #app-layout {
  grid-template-columns: 0 1fr;
}
body.sidebar-hidden #sidebar {
  overflow: hidden;
  padding: 0;
  pointer-events: none;
}

/* ── Botó-pestanya: apareix quan el sidebar és ocult ─────────── */
#sidebar-tab {
  display: none;
  position: fixed;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  z-index: 200;
  background: var(--bg-sidebar);
  border: 1px solid rgba(255,255,255,.12);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 14px 7px;
  cursor: pointer;
  color: #9aa0ac;
  box-shadow: 3px 0 12px rgba(0,0,0,.35);
  transition: background 0.18s ease, color 0.18s ease, padding 0.18s ease;
}
#sidebar-tab:hover {
  background: var(--bg-sidebar-hover);
  color: #fff;
  padding: 14px 10px;
}
#sidebar-tab svg {
  display: block;
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.18s ease;
}
body.sidebar-hidden #sidebar-tab {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Contingut de les seccions col·lapsat ── */
body.data-collapsed     #data-section  #data-table-container { display: none; }
body.graph-collapsed    #graph-section #graph-container      { display: none; }
body.activity-collapsed #activity-section #activity-content  { display: none; }

/* Quan data o graph es col·lapsen, la secció no s'estira per
   omplir la fila del grid: ocupa sols l'alçada de la capçalera */
body.data-collapsed  #data-section  { align-self: start; }
body.graph-collapsed #graph-section { align-self: start; }

/* Quan tots dos estan col·lapsats: reduïm la fila del grid */
body.data-collapsed.graph-collapsed #main-content {
  grid-template-rows: 1fr 40px 160px;
}
body.activity-collapsed #main-content {
  grid-template-rows: 1fr 200px 40px;
}
body.data-collapsed.graph-collapsed.activity-collapsed #main-content {
  grid-template-rows: 1fr 40px 40px;
}

/* ── Botó de col·lapsar secció ── */
.btn-collapse-section {
  min-width: 36px;
}
/* SVG girat quan el panell és col·lapsat */
body.data-collapsed   #btn-collapse-data svg,
body.graph-collapsed  #btn-collapse-graph svg {
  transform: rotate(-90deg);
}

/* Icona de l'activitat (gestionada per activityPanel.js) */
#activity-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
}
#activity-toggle-icon svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  transition: transform 0.25s cubic-bezier(.4,0,.2,1);
}
body.activity-collapsed #activity-toggle-icon svg {
  transform: rotate(-90deg);
}

/* ──────────────────────────────────────────────────────────────
   18b. ACORDIÓ SIDEBAR
   ────────────────────────────────────────────────────────────── */
.acc-group {
  margin-bottom: 2px;
}

.acc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 14px 6px;
  background: transparent;
  border: none;
  color: #9aa0ac;
  font-family: var(--font-main);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  user-select: none;
  transition: color var(--transition), background var(--transition);
  border-left: 2px solid transparent;
}
.acc-header:hover {
  color: #c5cae9;
  background: rgba(255,255,255,.04);
}

.acc-title { flex: 1; text-align: left; }

.acc-arrow {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  transition: transform 0.25s cubic-bezier(.4,0,.2,1);
  opacity: 0.6;
}
.acc-group.collapsed .acc-arrow {
  transform: rotate(-90deg);
}

.acc-body {
  overflow: hidden;
  max-height: 600px;
  transition: max-height 0.3s cubic-bezier(.4,0,.2,1),
              opacity     0.25s ease;
  opacity: 1;
}
.acc-group.collapsed .acc-body {
  max-height: 0;
  opacity: 0;
}

/* Indica quin grup conté el mòdul actiu */
.acc-group:has(.nav-btn.active) .acc-header {
  color: #c5cae9;
  border-left-color: var(--clr-accent);
}

/* Mode col·lapsat de sidebar: oculta les capçaleres d'acordió */
body.sidebar-collapsed .acc-header { display: none; }
body.sidebar-collapsed .acc-body   { max-height: none; opacity: 1; }

/* ──────────────────────────────────────────────────────────────
   18c. FOCUS VISIBLE (accessibilitat teclat)
   ────────────────────────────────────────────────────────────── */
:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--clr-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Elements sobre fons fosc: focus blanc */
#app-header :focus-visible,
#sidebar    :focus-visible {
  outline-color: rgba(255,255,255,.8);
}

/* Botons de nav: focus amb vora interior */
.nav-btn:focus-visible {
  outline: 2px solid var(--clr-accent);
  outline-offset: -2px;
}

/* Botons de simulació */
.sim-btn:focus-visible,
.sim-expand-btn:focus-visible {
  outline: 2px solid var(--clr-primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(26,115,232,.18);
}

/* ──────────────────────────────────────────────────────────────
   18c. ICONES SVG (nav i header)
   ────────────────────────────────────────────────────────────── */
.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.85;
  transition: opacity var(--transition);
}
.nav-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.nav-btn:hover .nav-icon,
.nav-btn.active .nav-icon { opacity: 1; }

.header-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ──────────────────────────────────────────────────────────────
   18d. TOUCH TARGETS MÒBIL (mínim 44×44px)
   ────────────────────────────────────────────────────────────── */
/* Regles globals per a ús mixt PC + tàctil */
.panel-toggle-btn { min-width: 44px; min-height: 44px; }
.sim-expand-btn   { min-width: 44px; min-height: 44px; }

@media (max-width: 768px) {
  .header-btn      { min-height: 44px; padding: 8px 14px; font-size: var(--fs-sm); }
  .nav-btn         { min-height: 44px; padding: 12px 16px; }
  .small-btn       { min-height: 40px; padding: 8px 12px; }
  .sim-btn         { min-height: 44px; padding: 10px 16px; }
  .modal-close     { min-height: 44px; min-width: 44px; }
  .panel-toggle-btn{ min-width: 48px; min-height: 48px; }
  .wlc-mod-btn     { min-height: 48px; font-size: .85rem; }
}

/* ──────────────────────────────────────────────────────────────
   19. VARIABLES D'ACCENT (welcome screen + tokens globals)
   ────────────────────────────────────────────────────────────── */
:root {
  --acc-blue:  #3b82f6;
  --acc-amber: #f59e0b;
  --acc-green: #10b981;
}

/* ──────────────────────────────────────────────────────────────
   20. PANTALLA DE BENVINGUDA (SimWelcome)
   ────────────────────────────────────────────────────────────── */
.wlc-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 36px 24px 40px;
  min-height: 100%;
  overflow-y: auto;
  background: var(--bg-sim, #0d1117);
  color: var(--txt-on-dark, #e8eaed);
}

/* Hero */
.wlc-hero { text-align: center; }

.wlc-hero-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(59,130,246,.15);
  border: 1.5px solid rgba(59,130,246,.35);
  color: #60a5fa;
  margin-bottom: 16px;
}
.wlc-hero-icon svg { width: 34px; height: 34px; }

.wlc-title {
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 700;
  letter-spacing: .02em;
  color: #e8eaed;
  margin-bottom: 8px;
}

.wlc-sub {
  font-size: .85rem;
  color: rgba(232,234,237,.55);
  letter-spacing: .03em;
}

/* Grups */
.wlc-groups {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 680px;
}

.wlc-group {
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius-lg, 12px);
  overflow: hidden;
  transition: border-color .2s;
}
.wlc-group:hover {
  border-color: color-mix(in srgb, var(--grp-color) 40%, transparent);
}

.wlc-group-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 14px 18px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--txt-on-dark, #e8eaed);
  font-family: var(--font-main);
  font-size: .9rem;
  font-weight: 600;
  text-align: left;
  min-height: 48px;
  transition: background .2s;
}
.wlc-group-btn:hover { background: rgba(255,255,255,.06); }
.wlc-group-btn:focus-visible { outline: 2px solid var(--grp-color); outline-offset: -2px; }

.wlc-group-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--grp-color) 15%, transparent);
  color: var(--grp-color);
  flex-shrink: 0;
}
.wlc-group-icon svg { width: 18px; height: 18px; }

.wlc-group-label { flex: 1; }

.wlc-group-arrow {
  width: 16px;
  height: 16px;
  color: rgba(232,234,237,.4);
  flex-shrink: 0;
  transition: transform .2s;
}
.wlc-group-btn:hover .wlc-group-arrow { color: var(--grp-color); transform: translateX(3px); }

/* Mòduls dins del grup */
.wlc-mods {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 18px 16px;
}

.wlc-mod-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  min-height: 44px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 22px;
  cursor: pointer;
  color: rgba(232,234,237,.85);
  font-family: var(--font-main);
  font-size: .8rem;
  font-weight: 500;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
  white-space: nowrap;
}
.wlc-mod-btn:hover {
  background: color-mix(in srgb, var(--grp-color, #3b82f6) 20%, rgba(255,255,255,.08));
  border-color: color-mix(in srgb, var(--grp-color, #3b82f6) 60%, transparent);
  color: #fff;
  transform: translateY(-1px);
}
.wlc-mod-btn:active { transform: translateY(0); }
.wlc-mod-btn:focus-visible { outline: 2px solid var(--grp-color, #3b82f6); outline-offset: 2px; }

/* Icona de seccio als headers de panels */
.panel-section-icon {
  width: 15px;
  height: 15px;
  vertical-align: -3px;
  margin-right: 5px;
  opacity: .75;
  stroke: currentColor;
}

/* ──────────────────────────────────────────────────────────────
   18e. PREFERS-REDUCED-MOTION
   ────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

