/* ═══════════════════════════════════════════════════════════════════════
   Sistema de disseny — «Aurora Nocturne»
   Base fosca índigo, vidre esmerilat, accent violeta→cian i tocs corall.
   Tot amb piles de fonts del sistema (cap dependència de CDN).
═══════════════════════════════════════════════════════════════════════ */
:root {
    /* Superfícies */
    --bg:        #0A0D17;
    --bg-2:      #101424;
    --surface:   #141A2B;
    --surface-2: #1B2238;
    --card:      #141A2B;
    --glass:     rgba(22, 28, 46, .66);

    /* Línies */
    --line:      rgba(255,255,255,.08);
    --line-2:    rgba(255,255,255,.16);

    /* Tinta i text */
    --ink:       #EDEFF8;
    --ink-2:     #B7BDD4;
    --muted:     #79809A;

    /* Accent (violeta → cian) i secundari (corall) */
    --accent:     #7C5CFF;
    --accent-d:   #6A46F2;
    --accent-2:   #22D3EE;
    --accent-soft:rgba(124,92,255,.16);
    --coral:      #FF6B9A;
    --grad:       linear-gradient(135deg, #7C5CFF 0%, #22D3EE 100%);

    /* Estats */
    --success:    #34D399;
    --success-bg: rgba(52,211,153,.14);
    --danger:     #FB7185;
    --danger-bg:  rgba(251,113,133,.14);

    /* Ombres i resplendor */
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 10px 30px rgba(0,0,0,.45);
    --shadow-lg: 0 30px 70px rgba(0,0,0,.55);
    --glow:      0 0 0 4px rgba(124,92,255,.25);
    --glow-accent: 0 6px 24px rgba(124,92,255,.45);

    /* Radis */
    --radius:    18px;
    --radius-sm: 12px;
    --radius-xs: 10px;

    /* Tipografia (sans modern, sense serifs editorials) */
    --display: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --sans:    ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --serif:   var(--display);

    --maxw: 1080px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body, .app-body {
    margin: 0;
    font-family: var(--sans);
    background:
        radial-gradient(1100px 620px at 88% -8%, rgba(124,92,255,.22), transparent 60%),
        radial-gradient(900px 520px at -6% 4%, rgba(34,211,238,.14), transparent 55%),
        radial-gradient(700px 500px at 50% 110%, rgba(255,107,154,.12), transparent 60%),
        var(--bg);
    background-attachment: fixed;
    color: var(--ink);
    min-height: 100vh;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Gra subtil per trencar els degradats plans */
body::before {
    content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
    opacity: .04; mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.app-header, .app-main, .app-footer, .flash-wrap { position: relative; z-index: 1; }

::selection { background: rgba(124,92,255,.35); color: #fff; }

a { color: var(--accent-2); text-decoration: none; }
a:hover { color: #67e3f6; }

h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -.02em; color: var(--ink); }

/* ── Capçalera ─────────────────────────────────────────────────────────── */
.app-header {
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px clamp(16px, 5vw, 32px);
    background: rgba(10,13,23,.72);
    backdrop-filter: saturate(150%) blur(14px);
    -webkit-backdrop-filter: saturate(150%) blur(14px);
    border-bottom: 1px solid var(--line);
}
.brand {
    display: inline-flex; align-items: center; gap: 11px;
    color: var(--ink); font-weight: 800; font-size: 17px; letter-spacing: -.02em;
}
.brand:hover { color: var(--ink); }
.brand .brand-mark {
    width: 34px; height: 34px; border-radius: 11px;
    display: grid; place-items: center;
    background: var(--grad); color: #fff;
    box-shadow: var(--glow-accent);
}
.brand .brand-mark svg { width: 19px; height: 19px; }
.brand span[style] { background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent !important; }

.app-nav { display: flex; align-items: center; gap: 16px; }
.who {
    color: var(--ink-2); font-size: 14px; font-weight: 500;
    display: inline-flex; align-items: center; gap: 8px;
}
.who::before {
    content: ""; width: 26px; height: 26px; border-radius: 50%;
    background: var(--grad);
    display: inline-block; flex-shrink: 0;
}
.inline { display: inline; margin: 0; }

/* ── Botons ────────────────────────────────────────────────────────────── */
.btn-primary, .btn-sm, .btn-ghost {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    font-family: var(--sans); font-weight: 600; cursor: pointer;
    border-radius: var(--radius-xs); text-decoration: none;
    transition: transform .12s ease, background .18s ease, box-shadow .18s ease, border-color .18s ease, color .18s ease, filter .18s ease;
    white-space: nowrap; line-height: 1;
}
.btn-primary {
    background: var(--grad); color: #fff; border: 1px solid transparent;
    padding: 11px 18px; font-size: 15px;
    box-shadow: var(--glow-accent);
}
.btn-primary:hover { color: #fff; transform: translateY(-1px); filter: brightness(1.08); box-shadow: 0 10px 30px rgba(124,92,255,.55); }
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
    background: var(--glass); color: var(--ink); border: 1px solid var(--line-2);
    padding: 10px 16px; font-size: 15px; box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
}
.btn-ghost:hover { border-color: var(--accent); color: #fff; transform: translateY(-1px); }

.btn-link {
    background: none; border: none; color: var(--muted); cursor: pointer;
    display: inline-flex; align-items: center; gap: 5px; font-size: 14px;
    font-family: var(--sans); font-weight: 500; padding: 0; transition: color .15s;
}
.btn-link:hover { color: var(--ink); }

.btn-sm {
    background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line-2);
    padding: 8px 12px; font-size: 13px; box-shadow: var(--shadow-sm);
}
.btn-sm:hover { border-color: var(--accent); color: #fff; transform: translateY(-1px); }
.btn-sm.danger { color: var(--danger); }
.btn-sm.danger:hover { border-color: var(--danger); background: var(--danger-bg); color: #fff; }
.btn-sm .icon, .btn-primary .icon, .btn-link .icon { width: 17px; height: 17px; flex-shrink: 0; }

.icon { display: inline-block; vertical-align: middle; stroke: currentColor; fill: none;
    stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ── Contenidor principal ──────────────────────────────────────────────── */
.app-main {
    max-width: var(--maxw); margin: 0 auto;
    padding: clamp(28px, 6vw, 56px) clamp(16px, 5vw, 32px) 80px;
    animation: rise .5s cubic-bezier(.2,.7,.3,1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ── Flaixos / toasts ──────────────────────────────────────────────────── */
.flash-wrap {
    position: fixed; top: 72px; left: 50%; transform: translateX(-50%);
    z-index: 60; width: min(440px, calc(100vw - 32px));
    display: flex; flex-direction: column; gap: 8px;
}
.flash {
    padding: 12px 16px; border-radius: var(--radius-sm);
    background: var(--glass); border: 1px solid var(--line-2);
    box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500; color: var(--ink);
    display: flex; align-items: center; gap: 10px; backdrop-filter: blur(12px);
    animation: toastIn .4s cubic-bezier(.2,.8,.2,1) both;
}
.flash::before { content: ""; width: 6px; align-self: stretch; border-radius: 6px; background: var(--muted); flex-shrink: 0; }
.flash.success::before { background: var(--success); }
.flash.error::before, .flash.danger::before { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px) scale(.98); } to { opacity: 1; transform: none; } }

/* ── Targetes d'autenticació ───────────────────────────────────────────── */
.auth-wrap { min-height: calc(100vh - 64px); display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
    width: 100%; max-width: 420px;
    background: var(--glass); border: 1px solid var(--line-2);
    border-radius: var(--radius); padding: clamp(28px, 5vw, 40px);
    box-shadow: var(--shadow-md); backdrop-filter: blur(16px);
    animation: rise .5s cubic-bezier(.2,.7,.3,1) both;
}
.auth-eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
    background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; margin: 0 0 10px; }
.auth-card h1 { margin: 0 0 6px; font-size: clamp(26px, 5vw, 32px); }
.auth-card .sub { color: var(--muted); margin: 0 0 24px; font-size: 15px; }

.auth-card label, .settings-form label {
    display: block; margin-bottom: 16px; font-size: 13px; font-weight: 600;
    color: var(--ink-2); letter-spacing: .01em;
}
.auth-card input, .settings-form input, .settings-form textarea, .settings-form select {
    width: 100%; margin-top: 7px; padding: 12px 14px; border-radius: var(--radius-xs);
    border: 1px solid var(--line-2); background: rgba(10,13,23,.55); color: var(--ink);
    font-size: 15px; font-family: var(--sans); transition: border-color .15s, box-shadow .15s, background .15s;
}
.auth-card input:focus, .settings-form input:focus, .settings-form textarea:focus, .settings-form select:focus {
    outline: none; border-color: var(--accent); background: rgba(10,13,23,.8);
    box-shadow: var(--glow);
}
.auth-card input::placeholder, .settings-form input::placeholder, .settings-form textarea::placeholder { color: #5C6480; }
.auth-card .btn-primary { width: 100%; margin-top: 8px; padding: 13px; font-size: 15px; }
.auth-alt { margin-top: 22px; font-size: 14px; color: var(--muted); text-align: center; }
.auth-alt a { font-weight: 600; }

.field-error { color: var(--danger); display: block; margin-top: 6px; font-weight: 500; font-size: 13px; }
.form-error {
    color: #fff; background: var(--danger-bg); border: 1px solid rgba(251,113,133,.4);
    padding: 10px 14px; border-radius: var(--radius-xs); margin-bottom: 18px; font-size: 14px; font-weight: 500;
}
.hint { color: var(--muted); font-size: 12.5px; display: block; margin-top: 5px; font-weight: 400; }

/* ── Dashboard ─────────────────────────────────────────────────────────── */
.dash-head {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 20px; flex-wrap: wrap; margin-bottom: 34px;
}
.dash-head .eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
    background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; margin: 0 0 8px; }
.dash-head h1 { margin: 0; font-size: clamp(30px, 6vw, 46px); line-height: 1.04; }
.dash-head .lead { color: var(--ink-2); margin: 10px 0 0; font-size: 16px; max-width: 46ch; }

.new-project { position: relative; }
.new-project > summary { list-style: none; cursor: pointer; }
.new-project > summary::-webkit-details-marker { display: none; }
.new-project[open] > summary { opacity: .55; }
.new-project-form {
    display: flex; gap: 8px; margin-top: 12px; padding: 14px;
    background: var(--glass); border: 1px solid var(--line-2); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md); backdrop-filter: blur(14px);
    position: absolute; right: 0; z-index: 20; min-width: 320px;
    animation: rise .25s ease both;
}
.new-project-form input {
    flex: 1; padding: 11px 14px; border-radius: var(--radius-xs); border: 1px solid var(--line-2);
    background: rgba(10,13,23,.55); color: var(--ink); font-size: 15px; font-family: var(--sans);
}
.new-project-form input:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow); }

.project-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px;
}
.project-card {
    position: relative; overflow: hidden;
    background: var(--glass); border: 1px solid var(--line-2); border-radius: var(--radius);
    padding: 22px 22px 18px; display: flex; flex-direction: column; justify-content: space-between;
    box-shadow: var(--shadow-sm); backdrop-filter: blur(12px);
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
    animation: rise .5s cubic-bezier(.2,.7,.3,1) both;
}
.project-card::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
    background: var(--grad); opacity: 0; transition: opacity .2s;
}
.project-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: rgba(124,92,255,.5); }
.project-card:hover::before { opacity: 1; }
.project-card h2 { margin: 0 0 4px; font-size: 21px; line-height: 1.2; }
.project-card .muted { color: var(--muted); margin: 2px 0; font-size: 14px; }
.project-card .small { font-size: 12.5px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--accent-2);
    display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.project-card-actions { display: flex; gap: 7px; margin-top: 20px; flex-wrap: wrap; align-items: center; }
.project-card-actions .spacer { flex: 1; }

.role-badge {
    font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
    padding: 3px 8px; border-radius: 999px; color: var(--accent);
    background: var(--accent-soft); border: 1px solid rgba(124,92,255,.4);
}
.role-badge.public { color: var(--accent-2); background: rgba(34,211,238,.14); border-color: rgba(34,211,238,.4); }

.empty-state {
    text-align: center; color: var(--muted); padding: 72px 24px;
    border: 1.5px dashed var(--line-2); border-radius: var(--radius);
    background: rgba(20,26,43,.4);
}
.empty-state .empty-mark {
    width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 18px;
    display: grid; place-items: center; background: var(--accent-soft); color: var(--accent);
}
.empty-state .empty-mark svg { width: 30px; height: 30px; }
.empty-state h2 { font-size: 22px; color: var(--ink); margin: 0 0 6px; }
.empty-state p { margin: 0 0 20px; }

/* ── Configuració ──────────────────────────────────────────────────────── */
.settings-head { display: flex; align-items: center; gap: 18px; margin-bottom: 12px; flex-wrap: wrap; }
.settings-head .back { width: 100%; margin-bottom: 4px; }
.settings-head h1 { margin: 0; font-size: clamp(26px, 5vw, 36px); flex: 1; }
.settings-sub { color: var(--ink-2); margin: 0 0 30px; font-size: 16px; }

.settings-form { display: grid; gap: 18px; }
.settings-form fieldset, .settings-form-panel {
    border: 1px solid var(--line-2); border-radius: var(--radius);
    padding: 8px 24px 22px; margin: 0; background: var(--glass); box-shadow: var(--shadow-sm);
    backdrop-filter: blur(12px);
}
.settings-form legend, .settings-form-panel legend {
    font-family: var(--display); color: var(--ink); font-weight: 700; font-size: 18px;
    padding: 0 10px; margin-left: -4px;
}
.settings-form legend .num, .settings-form-panel legend .num {
    color: var(--accent-2); margin-right: 8px; font-size: 14px; font-weight: 800; }
.thumb {
    display: block; width: 84px; height: 84px; object-fit: cover; border-radius: var(--radius-xs);
    margin: 8px 0; border: 1px solid var(--line-2); box-shadow: var(--shadow-sm);
}
.settings-form input[type="file"] { padding: 10px 12px; background: rgba(10,13,23,.55); cursor: pointer; font-size: 14px; }
.settings-form input[type="file"]::file-selector-button {
    border: 1px solid var(--line-2); background: var(--surface-2); color: var(--ink);
    padding: 8px 14px; border-radius: var(--radius-xs); font-family: var(--sans);
    font-size: 13px; font-weight: 600; cursor: pointer; margin-right: 12px;
    transition: background .15s, border-color .15s;
}
.settings-form input[type="file"]::file-selector-button:hover { border-color: var(--accent); background: var(--accent-soft); }
.settings-actions { display: flex; gap: 10px; align-items: center; position: sticky; bottom: 16px; }
.settings-actions .btn-primary { box-shadow: var(--glow-accent); }
.check-row { display: flex; align-items: center; gap: 10px; }
.check-row input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--accent); transform: scale(1.2); }

/* ── Editor de text enriquit (pantalla final) ──────────────────────────── */
.wysiwyg { border: 1px solid var(--line-2); border-radius: var(--radius-sm); overflow: hidden; background: rgba(10,13,23,.45); }
.wysiwyg-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; padding: 8px; border-bottom: 1px solid var(--line);
    background: var(--surface-2); }
.wysiwyg-toolbar button {
    min-width: 32px; height: 32px; padding: 0 8px; border-radius: 8px; cursor: pointer;
    background: transparent; color: var(--ink-2); border: 1px solid transparent;
    font-size: 14px; font-family: var(--sans); transition: background .12s, color .12s, border-color .12s;
}
.wysiwyg-toolbar button:hover { background: var(--accent-soft); color: #fff; border-color: rgba(124,92,255,.4); }
.wysiwyg-sep { width: 1px; height: 20px; background: var(--line-2); margin: 0 4px; }
.wysiwyg-color-wrap { display: inline-flex; align-items: center; gap: 3px; color: var(--ink-2); cursor: pointer; padding: 0 4px; }
.wysiwyg-color { width: 24px; height: 24px; padding: 0; border: none; background: none; cursor: pointer; }
.wysiwyg-area { min-height: 160px; padding: 16px 18px; color: var(--ink); font-size: 15px; line-height: 1.6; outline: none; }
.wysiwyg-area:focus { box-shadow: inset 0 0 0 2px rgba(124,92,255,.35); }
.wysiwyg-area h1 { font-size: 26px; margin: .2em 0 .3em; }
.wysiwyg-area h2 { font-size: 20px; margin: .2em 0 .3em; }
.wysiwyg-area a { color: var(--accent-2); }

/* ── Col·laboradors i enllaç públic ────────────────────────────────────── */
.share-panels { display: grid; gap: 18px; margin-top: 22px; }
.member-add-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 4px; }
.member-add-row input { flex: 1; min-width: 160px; margin: 0; padding: 10px 13px; border-radius: var(--radius-xs);
    border: 1px solid var(--line-2); background: rgba(10,13,23,.55); color: var(--ink); font-size: 14px; }
.member-add-row select { width: auto; margin: 0; padding: 10px 13px; border-radius: var(--radius-xs);
    border: 1px solid var(--line-2); background: rgba(10,13,23,.55); color: var(--ink); }
.member-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.member-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px;
    background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-xs); }
.member-name { font-weight: 600; color: var(--ink); }
.member-role { font-size: 12px; color: var(--muted); margin-left: auto; text-transform: uppercase; letter-spacing: .05em; }
.member-row .btn-sm.danger { padding: 6px 8px; }
.share-box { display: flex; gap: 8px; margin-top: 14px; align-items: center; }
.share-box input { flex: 1; margin: 0; padding: 10px 13px; border-radius: var(--radius-xs);
    border: 1px solid var(--line-2); background: rgba(10,13,23,.55); color: var(--accent-2); font-size: 13px; font-family: ui-monospace, monospace; }

/* ── Peu ───────────────────────────────────────────────────────────────── */
.app-footer {
    border-top: 1px solid var(--line); margin-top: 40px;
    padding: 26px clamp(16px, 5vw, 32px);
    color: var(--muted); font-size: 13px;
    display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    max-width: var(--maxw); margin-left: auto; margin-right: auto;
}
.app-footer a { color: var(--ink-2); font-weight: 500; }

/* ── Responsiu ─────────────────────────────────────────────────────────── */
@media (max-width: 560px) {
    .dash-head { align-items: stretch; }
    .new-project-form { position: static; min-width: 0; }
    .project-card-actions { gap: 6px; }
    .flash-wrap { top: 64px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
