/* =====================================================
   VARIABLES I RESET
   ===================================================== */
:root {
  --bg:          #f1f5f9;
  --surface:     #ffffff;
  --surface-2:   #f8fafc;
  --border:      #e2e8f0;
  --primary:     #3b82f6;
  --primary-dark:#2563eb;
  --success:     #22c55e;
  --error:       #ef4444;
  --warning:     #f59e0b;
  --text:        #1e293b;
  --text-muted:  #4b5563; /* C-05: contrast WCAG AA ≥4.5:1 sobre blanc */
  --text-light:  #6b7280;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.12);
  --font-ui:     'Inter', system-ui, sans-serif;
  --font-mono:   'JetBrains Mono', 'Fira Code', monospace;
  --transition:  .18s ease;
}

/* =====================================================
   TEMA FOSC
   ===================================================== */
[data-theme="dark"] {
  --bg:          #0f172a;
  --surface:     #1e293b;
  --surface-2:   #162032;
  --border:      #334155;
  --primary:     #60a5fa;
  --primary-dark:#3b82f6;
  --success:     #34d399;
  --error:       #f87171;
  --warning:     #fbbf24;
  --text:        #f1f5f9;
  --text-muted:  #94a3b8;
  --text-light:  #64748b; /* C-05: #475569 era massa fosc sobre --bg fosc */
  --shadow:      0 1px 3px rgba(0,0,0,.35), 0 4px 12px rgba(0,0,0,.25);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.5);
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

/* Accessibilitat: focus visible */
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}
:focus:not(:focus-visible) { outline: none; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

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

input {
  font-family: var(--font-ui);
}

.hidden { display: none !important; }

/* =====================================================
   LAYOUT GENÈRIC
   ===================================================== */
.view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.view-center {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

/* =====================================================
   PANTALLA DE PERFILS
   ===================================================== */
.profiles-view {
  padding: 3rem 1.5rem 4rem;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.profiles-logo {
  text-align: center;
  margin-bottom: 2.5rem;
}

.profiles-logo .logo-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: .5rem;
  line-height: 1;
}

.profiles-logo h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.5px;
}

.profiles-logo p {
  color: var(--text-muted);
  margin-top: .25rem;
  font-size: .95rem;
}

/* Grid de targetes */
.profiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

/* Targeta de perfil */
.profile-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  position: relative;
  user-select: none;
}

.profile-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.profile-card:active {
  transform: translateY(0);
}

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.profile-name {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  word-break: break-word;
}

.profile-meta {
  font-size: .75rem;
  color: var(--text-muted);
  text-align: center;
}

/* Botó esborrar */
.profile-delete {
  position: absolute;
  top: .5rem;
  right: .5rem;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  font-size: .8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition);
}

.profile-card:hover .profile-delete {
  opacity: 1;
}

.profile-delete:hover,
.profile-delete:focus-visible {
  background: var(--error);
  color: #fff;
}

/* C-03: mostrar botó esborrar quan la targeta té el focus (navegació per teclat) */
.profile-card:focus-within .profile-delete {
  opacity: 1;
}

/* C-03: en dispositius tàctils, mostrar sempre el botó esborrar */
@media (hover: none) {
  .profile-delete {
    opacity: 1;
  }
}

/* Targeta "nou perfil" */
.profile-card-new {
  background: var(--surface-2);
  border: 2px dashed var(--border);
  color: var(--text-muted);
}

.profile-card-new:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--surface);
}

.profile-card-new .new-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px dashed currentColor;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
}

/* =====================================================
   MODAL
   ===================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  backdrop-filter: blur(2px);
  animation: fadeIn .15s ease;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  width: 100%;
  max-width: 420px;
  animation: slideUp .2s ease;
}

.modal-box h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: var(--text);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* =====================================================
   FORMULARI (modal i config)
   ===================================================== */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .4rem;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.form-input {
  width: 100%;
  padding: .65rem .9rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition);
  outline: none;
}

.form-input:focus {
  border-color: var(--primary);
}

/* Selector de color */
.color-picker {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform var(--transition), border-color var(--transition);
}

.color-swatch:hover {
  transform: scale(1.12);
}

.color-swatch.selected {
  border-color: var(--text);
}

/* =====================================================
   BOTONS
   ===================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .65rem 1.4rem;
  min-height: 44px; /* I-03: objectiu tàctil mínim WCAG 2.5.5 */
  border-radius: var(--radius-sm);
  font-size: .95rem;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
  cursor: pointer;
  border: none;
  user-select: none;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--border); color: var(--text); }

.btn-danger {
  background: #fee2e2;
  color: var(--error);
}
.btn-danger:hover { background: var(--error); color: #fff; }

.btn-row {
  display: flex;
  gap: .75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* =====================================================
   MISSATGE D'ESTAT / TOAST
   ===================================================== */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: #fff;
  padding: .65rem 1.25rem;
  border-radius: 2rem;
  font-size: .9rem;
  font-weight: 500;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 200;
  white-space: normal;          /* I-06: permet salts de línia en mòbil */
  max-width: calc(100vw - 3rem);/* I-06: evitar desbordament en pantalles petites */
  text-align: center;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* =====================================================
   BARRA DE NAVEGACIÓ (dashboard i views internes)
   ===================================================== */
.navbar {
  width: 100%;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: .75rem 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.navbar-brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
}

.navbar-spacer { flex: 1; }

.navbar-profile {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  padding: .3rem .6rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.navbar-profile:hover { background: var(--bg); }

.navbar-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  color: #fff;
}

/* =====================================================
   RESPONSIVE I ORBYS (4K)
   ===================================================== */
@media (max-width: 600px) {
  .profiles-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .profiles-logo h1 { font-size: 1.5rem; }
}

/* =====================================================
   IMPRESSIÓ — DIPLOMA
   ===================================================== */
@media print {
  body { background: #fff !important; color: #000 !important; }

  .no-print,
  .navbar,
  .btn,
  #modal-overlay,
  #toast-global        { display: none !important; }

  .diploma-page {
    max-width: 100% !important;
    margin: 0 !important;
    border: 3px solid #3b82f6 !important;
    border-radius: 8px !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    page-break-inside: avoid;
  }

  @page {
    size: A4 landscape;
    margin: 15mm;
  }
}

/* =====================================================
   ACCESSIBILITAT
   ===================================================== */

/* Classe per a contingut visible només per a lectors de pantalla */
.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;
}

/* Enllaç "Salta al contingut" per a navegació per teclat */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  z-index: 9999;
  background: var(--primary);
  color: #fff;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
  transition: top .15s;
}
.skip-link:focus {
  top: 1rem;
}

@media (min-width: 2400px) {
  /* ORBYS 4K — tota la UI escala via font-size base */
  html { font-size: 24px; }

  /* Navbar més alta */
  .navbar { padding: 1rem 2rem; }
  .navbar-avatar { width: 40px; height: 40px; font-size: 1rem; }

  /* Perfils */
  .profile-avatar { width: 80px; height: 80px; font-size: 2rem; }
  .profile-card { padding: 2rem 1.5rem; }
  .color-swatch { width: 48px; height: 48px; }

  /* Modal */
  .modal-box { max-width: 560px; }

  /* Focus visible més gran per tàctil */
  :focus-visible { outline-width: 4px; outline-offset: 4px; }
}
