:root {
  --bg: #fff7f0;
  --surface: #ffffff;
  --text: #27211c;
  --muted: #756c64;
  --accent: #c64e12;
  --border: #eadfd5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; }

.topbar nav { display: flex; gap: 1.25rem; flex: 1; }
.topbar nav a { color: var(--text); text-decoration: none; }
.topbar nav a:hover { color: var(--accent); }

.user-info { display: flex; align-items: center; gap: 1rem; color: var(--muted); }
.logout-form { display: inline; margin: 0; }
.logout { color: var(--muted); text-decoration: none; background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }

.container { max-width: 900px; margin: 2rem auto; padding: 0 1rem; }

.login-box {
  max-width: 340px;
  margin: 4rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
  text-align: center;
}
.subtitle { color: var(--muted); margin-top: -0.5rem; }

form label { display: block; text-align: left; margin: 0.75rem 0 0.25rem; font-size: 0.9rem; color: var(--muted); }
input, select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}
button {
  margin-top: 1rem;
  padding: 0.5rem 1.25rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
}
button:hover { opacity: 0.9; }

.error { color: #b91c1c; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.tile {
  display: block;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
}
.tile.active:hover { border-color: var(--accent); }
.tile.disabled { opacity: 0.45; cursor: default; }
.tile-title { font-weight: 600; }
.tile-desc { color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; }

.upload-form { display: flex; gap: 0.75rem; align-items: center; margin: 1rem 0; }
.upload-form button { margin-top: 0; }

.filelist { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.filelist th, .filelist td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); }
.filelist .empty { color: var(--muted); text-align: center; }
.actions { display: flex; gap: 0.75rem; align-items: center; }
.actions form { margin: 0; }
.tria { width: 46px; text-align: center !important; }
.tria input { min-height: 20px; width: 20px; }
.seleccio-barra { align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; display: flex; flex-wrap: wrap; gap: .65rem; margin: 1rem 0 0; padding: .7rem .85rem; }
.seleccio-barra strong { color: var(--muted); margin-right: auto; }
.seleccio-barra button { margin: 0; }
.seleccio-barra .danger { background: var(--danger); }
.link-btn {
  background: none; border: none; color: #b91c1c; padding: 0; margin: 0;
  cursor: pointer; text-decoration: underline; font-size: 0.9rem;
}

.user-form { max-width: 320px; margin-top: 1rem; }
.ok { color: #137855; }

/* ---------- Arxius: espais, permisos i navegació (fase 5) ---------- */

.subtitol { color: #756c64; margin-top: -.4em; }

.espais { display: grid; gap: 12px; margin: 16px 0 24px; }

.espai {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; min-height: 44px;
    border: 1px solid #eadfd5; border-radius: 12px;
    background: #fff; color: inherit; text-decoration: none;
}
.espai:hover { border-color: #f36b21; }
.espai__icona {
    flex: none; width: 32px; height: 32px;
    display: grid; place-items: center;
    border-radius: 8px; background: #fff1e8;
}
.espai__icona svg { width: 18px; height: 18px; fill: #c64e12; }
.espai__text { display: flex; flex-direction: column; }
.espai__text small { color: #756c64; }
.espai__text i { color: #756c64; font-style: normal; font-weight: 400; }

.molles { font-size: 14px; color: #756c64; margin-bottom: 8px; }
.molles a { color: #756c64; }
.molles a:last-child { color: #27211c; font-weight: 600; }
.molles span { margin: 0 4px; }

.accions-espai { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.accions-espai .upload-form { display: flex; gap: 8px; align-items: center; }

.espai-admin {
    border: 1px solid #eadfd5; border-radius: 12px;
    padding: 16px; margin: 16px 0; background: #fff;
}
.espai-admin h2 { margin-top: 0; }
.espai-admin h2 small { color: #756c64; font-weight: 400; font-size: 14px; }

.user-form--fila { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.user-form--fila select { min-height: 44px; }

.avis-groc {
    padding: 12px 16px; border-radius: 12px;
    background: #fff8e6; border: 1px solid #8e6311; color: #5a3f0a;
}

/* Documentació renderitzada des del Markdown del pla */
.document { max-width: 46rem; }
.document h1, .document h2, .document h3 { margin-top: 1.6em; }
.document h2 { border-bottom: 1px solid #eadfd5; padding-bottom: .2em; }
.document code {
    background: #fff1e8; padding: .1em .35em; border-radius: 4px;
    font-size: .92em;
}
.document pre {
    background: #27211c; color: #fff7f0; padding: 12px 16px;
    border-radius: 12px; overflow-x: auto;
}
.document pre code { background: none; color: inherit; padding: 0; }
.document table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; }
.document th, .document td { border: 1px solid #eadfd5; padding: 6px 10px; text-align: left; }
.document th { background: #fff1e8; }
.document blockquote {
    border-left: 3px solid #f36b21; margin-left: 0; padding-left: 16px; color: #756c64;
}

/* ── Identitat compartida amb el tauler 2026 ───────────────── */
:root,
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f2ee; --surface: #fffdfc; --surface-alt: #fbf7f2;
  --text: #151618; --muted: #6c6b68; --accent: #d85a12;
  --accent-strong: #b8470a; --accent-soft: #fff0e6; --border: #e7ddd3;
  --green: #367b2b; --danger: #b83a25;
  --shadow: 0 7px 20px rgba(27,20,14,.07);
  --shadow-large: 0 18px 40px rgba(27,20,14,.11);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0a09; --surface: #12100e; --surface-alt: #191613;
  --text: #f6f0e8; --muted: #b9afa4; --accent: #f17026;
  --accent-strong: #e15d13; --accent-soft: rgba(216,90,18,.15);
  --border: rgba(216,90,18,.22); --green: #78bd60; --danger: #ee7664;
  --shadow: 0 10px 24px rgba(0,0,0,.30); --shadow-large: 0 22px 48px rgba(0,0,0,.45);
}
html { min-width: 0; background: var(--bg); }
body { min-width: 0; overflow-x: hidden; line-height: 1.55; transition: background .2s ease, color .2s ease; }
a { color: var(--accent-strong); text-underline-offset: 3px; }
[data-theme="dark"] a { color: var(--accent); }
.topbar {
  min-height: 68px; position: sticky; top: 0; z-index: 30;
  padding: .7rem clamp(1rem, 3vw, 2.25rem); gap: clamp(1rem, 3vw, 2.5rem);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-color: var(--border); box-shadow: 0 4px 18px rgba(0,0,0,.04);
  backdrop-filter: blur(14px);
}
/* Correu és una pantalla llarga: la capçalera queda dins del flux perquè
   no tapi camps ni títols quan es recorre el formulari. */
.pagina-correu .topbar { position: relative; }
.brand { display: inline-flex; align-items: center; gap: .6rem; color: var(--text); text-decoration: none; font-weight: 800; }
.brand img { border-radius: 50%; }
.brand img.marca-logo-complet {
  width: clamp(126px, 14vw, 158px);
  height: auto;
  max-height: 40px;
  object-fit: contain;
  border-radius: 8px;
  background: #090a0b;
  padding: 4px 8px;
}
.brand i { color: var(--accent); font-style: normal; }
.topbar nav a { min-height: 42px; display: inline-flex; align-items: center; padding: 0 .75rem; border-radius: 11px; font-weight: 650; }
.topbar nav a:hover { color: var(--accent); background: var(--accent-soft); }
.theme-toggle {
  width: 40px; height: 40px; margin: 0; padding: 0; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-alt); color: var(--text);
}
.theme-toggle:hover { opacity: 1; border-color: var(--accent); }
.logout { min-height: 38px; margin: 0; padding: 0 .8rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-alt); color: var(--muted); }
.container { width: min(1120px, 100%); max-width: none; margin: 0 auto; padding: clamp(1.5rem, 4vw, 3rem) clamp(1rem, 4vw, 2.25rem); }
.container > h1 { margin: 0; font-size: clamp(1.8rem, 4vw, 2.55rem); letter-spacing: -.04em; }
.container > h1::after { content: ""; display: block; width: 42px; height: 3px; margin-top: .6rem; border-radius: 4px; background: var(--accent); }
.subtitol { color: var(--muted); max-width: 760px; }
.login-box, .espai, .espai-admin, .tile {
  background: linear-gradient(145deg, var(--surface), var(--surface-alt));
  border-color: var(--border); box-shadow: var(--shadow); border-radius: 18px;
}
.login-box { margin-top: min(12vh, 6rem); border-top: 3px solid var(--accent); padding: 2.25rem; box-shadow: var(--shadow-large); }
.login-box h1 { letter-spacing: -.035em; }
.espais { grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); }
.espai { min-width: 0; padding: 16px 18px; transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
.espai:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow-large); }
.espai__icona { background: var(--accent-soft); }
.espai__icona svg { fill: var(--accent-strong); }
.espai__text { min-width: 0; }
.espai__text small, .espai__text i, .molles, .molles a, .subtitol { color: var(--muted); }
.espai-admin { padding: clamp(1rem, 3vw, 1.5rem); }
.espai-admin h2 small { color: var(--muted); }
input, select, textarea {
  min-height: 44px; background: var(--surface); color: var(--text);
  border-color: var(--border); border-radius: 10px; padding: .65rem .75rem;
}
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
button { min-height: 44px; background: var(--accent-strong); border-radius: 10px; font-weight: 700; }
.filelist { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; border-collapse: separate; border-spacing: 0; overflow: hidden; }
.filelist th { background: var(--surface-alt); color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.filelist th, .filelist td { border-color: var(--border); padding: .75rem; overflow-wrap: anywhere; }
.filelist tbody tr:hover { background: var(--accent-soft); }
.avis-groc { background: color-mix(in srgb, #e89a23 12%, var(--surface)); border-color: #a86f12; color: var(--text); }
.error { color: var(--danger); }
.ok { color: var(--green); }
.document { max-width: 52rem; }
.document h2 { border-color: var(--border); }
.document code { background: var(--accent-soft); }
.document pre { background: #17130f; color: #f6f0e8; box-shadow: var(--shadow); }
.document th, .document td { border-color: var(--border); }
.document th { background: var(--accent-soft); }
.document blockquote { border-color: var(--accent); color: var(--muted); }

@media (max-width: 720px) {
  .topbar { min-height: auto; flex-wrap: wrap; gap: .5rem 1rem; }
  .brand span { display: none; }
  .topbar nav { order: 3; width: 100%; gap: .25rem; overflow-x: auto; }
  .topbar nav a { white-space: nowrap; }
  .user-info { margin-left: auto; gap: .5rem; }
  .user-info > span { display: none; }
  .container { padding-top: 1.5rem; }
  .upload-form, .user-form--fila { align-items: stretch; flex-direction: column; }
  .actions { flex-wrap: wrap; }
  .filelist { display: block; overflow-x: auto; white-space: nowrap; }
}
@media (prefers-reduced-motion: reduce) {
  body, .espai { transition: none; }
  .espai:hover { transform: none; }
}
