/* ============================================================
   STYLES.CSS - Estils base de LliureX Terminal Learning
   ============================================================
   Organitzacio:
   1. Variables CSS (colors, mides, ombres)
   2. Reset i base
   3. Utilitats (sr-only, hidden)
   4. Capçalera (app-header)
   5. Disposicio (app-wrapper, main-layout, sidebar, main-content)
   6. Navegacio (nav-list, nav-item)
   7. Barra de progres
   8. Arbre del sistema de fitxers (sidebar)
   9. Seccio de temari (accordion)
  10. Targetes de comandes (commands-grid)
  11. Cercador
  12. Pantalla de carrega
  13. Responsiu
   ============================================================ */

/* ------------------------------------------------------------
   1. VARIABLES CSS
   Canvia aqui els colors per personalitzar el tema
   ------------------------------------------------------------ */
:root {
  /* Paleta principal */
  --color-bg:         #f0f4f8;   /* fons general */
  --color-surface:    #ffffff;   /* targetes, sidebar */
  --color-border:     #dde3ea;   /* vores */

  /* Verd LliureX / terminal */
  --color-accent:     #2d7d46;   /* verd principal */
  --color-accent-light: #e8f5ed; /* verd clar (hover, fons) */
  --color-accent-dark:  #1e5c32; /* verd fosc (actiu) */

  /* Text */
  --color-text:       #1a2332;
  --color-text-muted: #6b7a8d;
  --color-text-light: #ffffff;

  /* Feedback */
  --color-success:    #2d7d46;
  --color-error:      #c0392b;
  --color-warning:    #e67e22;
  --color-info:       #2980b9;

  /* Mides */
  --sidebar-width:    240px;
  --header-height:    64px;
  --border-radius:    8px;
  --border-radius-lg: 12px;

  /* Ombres */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.10);
  --shadow-lg:  0 8px 24px rgba(0,0,0,0.14);

  /* Tipografia */
  --font-sans:  'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:  'Cascadia Code', 'Fira Code', 'Consolas', 'Courier New', monospace;

  /* Transicions */
  --transition: 200ms ease;
}


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

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

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

h1, h2, h3 {
  line-height: 1.3;
  font-weight: 700;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

ul {
  list-style: none;
}

button {
  font-family: var(--font-sans);
  cursor: pointer;
  border: none;
  background: none;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

code {
  font-family: var(--font-mono);
  background: var(--color-accent-light);
  color: var(--color-accent-dark);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}

kbd {
  font-family: var(--font-sans);
  font-size: 0.8em;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.1em 0.5em;
  box-shadow: var(--shadow-sm);
}


/* ------------------------------------------------------------
   3. UTILITATS
   ------------------------------------------------------------ */

/* Accessible: visible per a lectors de pantalla, invisible visualment */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}


/* ------------------------------------------------------------
   4. CAPCALERA
   ------------------------------------------------------------ */
.app-header {
  height: var(--header-height);
  background: var(--color-accent);
  color: var(--color-text-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.header-icon {
  font-size: 1.8rem;
}

.header-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: white;
}

.header-subtitle {
  font-size: 0.72rem;
  opacity: 0.85;
  margin-top: 0.1rem;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}


/* ------------------------------------------------------------
   5. DISPOSICIO GENERAL
   ------------------------------------------------------------ */
.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Contenidor horitzontal: sidebar + contingut */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar fixe a l'esquerra */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  flex-shrink: 0;
  height: calc(100vh - var(--header-height));
  position: sticky;
  top: var(--header-height);
}

/* Area de contingut principal */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  height: calc(100vh - var(--header-height));
}

/* Seccions de contingut (pestanyes) */
.tab-content {
  max-width: 900px;
  margin: 0 auto;
}

/* [hidden] CSS per assegurar ocultacio */
[hidden] {
  display: none !important;
}


/* ------------------------------------------------------------
   6. NAVEGACIO LATERAL
   ------------------------------------------------------------ */
.nav-list {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text);
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  text-align: left;
}

.nav-item:hover {
  background: var(--color-accent-light);
  color: var(--color-accent-dark);
}

.nav-item.active {
  background: var(--color-accent-light);
  color: var(--color-accent);
  font-weight: 700;
  border-left: 3px solid var(--color-accent);
}

.nav-icon {
  font-size: 1.1rem;
  width: 1.4rem;
  text-align: center;
}


/* ------------------------------------------------------------
   7. BARRA DE PROGRES
   ------------------------------------------------------------ */
.sidebar-section {
  padding: 1rem;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: 0.6rem;
}

.progress-track {
  height: 8px;
  background: var(--color-border);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 0.4rem;
}

.progress-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 99px;
  width: 0%;
  transition: width 400ms ease;
}

.progress-label {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}


/* ------------------------------------------------------------
   8. ARBRE DEL SISTEMA DE FITXERS (sidebar)
   ------------------------------------------------------------ */
.fs-tree {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--color-text);
  line-height: 1.7;
}

/* Cada node de l'arbre - generat per app.js */
.fs-node {
  display: block;
  padding: 0.05rem 0;
}

.fs-dir {
  color: var(--color-accent);
  font-weight: 600;
}

.fs-file {
  color: var(--color-text-muted);
}

.fs-indent {
  display: inline-block;
  width: 1.2em;
}


/* ------------------------------------------------------------
   9. TEMARI - ACCORDION
   Generat per accordion.js a partir de temari.json
   ------------------------------------------------------------ */

/* Capçalera de seccio */
.accordion-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  margin-bottom: 0.75rem;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.accordion-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-surface);
  border: none;
  cursor: pointer;
  transition: background var(--transition);
  text-align: left;
  gap: 0.5rem;
}

.accordion-header:hover {
  background: var(--color-accent-light);
}

.accordion-header[aria-expanded="true"] {
  background: var(--color-accent-light);
  color: var(--color-accent-dark);
  border-bottom: 1px solid var(--color-border);
}

.accordion-title {
  flex: 1;
}

.accordion-icon {
  font-size: 0.8rem;
  transition: transform var(--transition);
  color: var(--color-text-muted);
}

.accordion-header[aria-expanded="true"] .accordion-icon {
  transform: rotate(180deg);
}

/* Contingut del panel */
.accordion-content {
  padding: 1.25rem;
}

.accordion-text {
  color: var(--color-text);
  margin-bottom: 1rem;
  line-height: 1.7;
}

/* Titol "Exemples:" dins del panel */
.examples-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
}

/* Bloc d'exemple de comanda (estil terminal petit) */
.terminal-block {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #1a2332;
  color: #a8d8a8;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  margin-bottom: 0.4rem;
  position: relative;
}

.terminal-block-prompt {
  color: #4ecdc4;
  font-weight: 700;
  flex-shrink: 0;
}

.terminal-block-command {
  flex: 1;
  color: #a8d8a8;
}

/* Boto de copiar dins del bloc d'exemple */
.copy-btn {
  background: rgba(255,255,255,0.1);
  color: #ccc;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  padding: 0.1rem 0.5rem;
  font-size: 0.72rem;
  cursor: pointer;
  transition: background var(--transition);
  flex-shrink: 0;
}

.copy-btn:hover {
  background: rgba(255,255,255,0.2);
  color: white;
}

.copy-btn.copied {
  background: var(--color-success);
  color: white;
  border-color: var(--color-success);
}

/* Numero de la seccio (01, 02...) */
.accordion-number {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-accent);
  background: var(--color-accent-light);
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  flex-shrink: 0;
}

/* Contenidor dels exemples */
.examples-container {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
}

/* Boto per provar a la terminal */
.try-terminal-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding: 0.45rem 0.9rem;
  background: #1a2332;
  color: #4ecdc4;
  border: 1px solid #4ecdc4;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 200ms ease;
}

.try-terminal-btn:hover {
  background: #4ecdc4;
  color: #1a2332;
}


/* ------------------------------------------------------------
  10. TARGETES DE COMANDES (commands-grid)
  Generat per app.js a partir de commands.json
   ------------------------------------------------------------ */

/* Seccio per categoria */
.commands-section {
  margin-bottom: 2rem;
}

.commands-category {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--color-accent-light);
}

/* Graella de targetes */
.commands-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.75rem;
}

.command-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
}

.command-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.cmd-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.cmd-name {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-accent);
  background: var(--color-accent-light);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

.cmd-description {
  font-size: 0.88rem;
  color: var(--color-text-muted);
  margin-bottom: 0.6rem;
  line-height: 1.5;
}

.cmd-syntax,
.cmd-example-block {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  margin-bottom: 0.3rem;
  flex-wrap: wrap;
}

.cmd-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.term-prompt-small {
  color: var(--color-accent);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
}

.cmd-example {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.83rem;
  background: #1a2332;
  color: #a8d8a8;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.copy-cmd-btn {
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-size: 0.72rem;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.copy-cmd-btn:hover {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}

/* Opcions de la targeta (mode professor) */
.cmd-options {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--color-border);
}

.cmd-options-list {
  list-style: disc;
  padding-left: 1.2rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 0.3rem;
}


/* ------------------------------------------------------------
  11. CERCADOR
   ------------------------------------------------------------ */
.search-wrapper {
  position: relative;
}

.search-input {
  width: 220px;
  padding: 0.45rem 0.85rem;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 99px;
  background: rgba(255,255,255,0.15);
  color: white;
  font-size: 0.85rem;
  transition: all var(--transition);
}

.search-input::placeholder {
  color: rgba(255,255,255,0.7);
}

.search-input:focus {
  outline: none;
  background: rgba(255,255,255,0.25);
  border-color: rgba(255,255,255,0.6);
  width: 280px;
}

/* Dropdown de resultats */
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  max-height: 320px;
  overflow-y: auto;
  display: none;
}

.search-results.visible {
  display: block;
}

.search-result-item {
  display: block;
  width: 100%;
  padding: 0.6rem 1rem;
  text-align: left;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover,
.search-result-item:focus {
  background: var(--color-accent-light);
  outline: none;
}

.search-result-type {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-accent);
  margin-right: 0.4rem;
}

.search-no-results {
  padding: 1rem;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.88rem;
}

/* Destacat del text coincident */
.search-highlight {
  background: #fff3c4;
  color: var(--color-text);
  border-radius: 2px;
  padding: 0 0.1em;
}


/* ------------------------------------------------------------
  12. PANTALLA DE CARREGA
   ------------------------------------------------------------ */
#loading {
  position: fixed;
  inset: 0;
  background: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 400ms ease;
}

#loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-box {
  text-align: center;
  color: white;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

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

.loading-text {
  font-size: 1rem;
  opacity: 0.9;
}


/* ------------------------------------------------------------
  13. RESPONSIU
  Adaptat per a projector (pantalla gran) i tablet
   ------------------------------------------------------------ */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 180px;
    --header-height: 56px;
  }

  .header-subtitle { display: none; }
  .search-input { width: 160px; }
  .search-input:focus { width: 200px; }
  .teacher-btn-text { display: none; }

  .main-content { padding: 1rem; }
}

@media (max-width: 600px) {
  .main-layout { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }

  .nav-list {
    display: flex;
    flex-direction: row;
    border-bottom: none;
    border-right: 1px solid var(--color-border);
  }

  .nav-item { padding: 0.5rem 0.75rem; }
  .nav-icon { display: none; }

  .sidebar-section { display: none; }

  .main-content {
    height: auto;
    overflow: visible;
  }
}
