/* ============================================================
   Cobra · full d'estils propi (sense build ni frameworks)
   Mobile-first amb variables CSS.
   ============================================================ */

:root {
    --color-bg: #0f172a;
    --color-surface: #ffffff;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-border: #e2e8f0;
    --color-danger: #dc2626;
    --color-danger-bg: #fef2f2;
    --color-danger-border: #fecaca;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 10px 30px rgba(2, 8, 23, 0.25);
    --space: 1rem;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --max-width: 420px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    color: var(--color-text);
    background: linear-gradient(160deg, #1e293b 0%, #0f172a 100%);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}

/* ---------- Layout d'autenticació ---------- */

.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.card {
    background: var(--color-surface);
    width: 100%;
    max-width: var(--max-width);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem 1.75rem;
}

.brand {
    text-align: center;
    margin-bottom: 1.75rem;
}

.brand h1 {
    margin: 0;
    font-size: 1.75rem;
    letter-spacing: 0.5px;
    color: var(--color-text);
}

.brand p {
    margin: 0.35rem 0 0;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* ---------- Formularis ---------- */

.field {
    margin-bottom: 1.1rem;
}

.field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
    color: var(--color-text);
}

.field input[type="email"],
.field input[type="password"],
.field input[type="text"] {
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    color: var(--color-text);
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.field .field-error {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.8rem;
    color: var(--color-danger);
}

.check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.check input {
    width: 1rem;
    height: 1rem;
}

.btn {
    display: inline-block;
    width: 100%;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.8rem 1rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: var(--color-primary);
    cursor: pointer;
    transition: background 0.15s;
}

.btn:hover {
    background: var(--color-primary-hover);
}

.btn--ghost {
    width: auto;
    background: transparent;
    color: var(--color-primary);
    border: 1px solid var(--color-border);
    padding: 0.5rem 0.9rem;
    font-size: 0.9rem;
}

.btn--ghost:hover {
    background: #f8fafc;
}

/* ---------- Alertes ---------- */

.alert {
    border-radius: var(--radius-sm);
    padding: 0.75rem 0.9rem;
    font-size: 0.88rem;
    margin-bottom: 1.25rem;
}

.alert--danger {
    background: var(--color-danger-bg);
    border: 1px solid var(--color-danger-border);
    color: var(--color-danger);
}

/* ---------- Dashboard ---------- */

.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0.9rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.topbar .topbar-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--color-text);
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem;
}

.panel {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(2, 8, 23, 0.12);
    padding: 1.75rem;
}

.panel h2 {
    margin-top: 0;
    color: var(--color-text);
}

.panel p {
    color: var(--color-text-muted);
}

.logout-form {
    margin: 0;
}

/* ---------- App shell (àrea autenticada) ---------- */

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: #f1f5f9;
}

.app-nav {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.app-nav__bar {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: space-between;
}

.app-nav__brand {
    font-weight: 800;
    font-size: 1.15rem;
    color: var(--color-primary);
    text-decoration: none;
    letter-spacing: 0.5px;
}

.app-nav__links {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    align-items: center;
}

.app-nav__links a {
    color: var(--color-text);
    text-decoration: none;
    padding: 0.4rem 0.7rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
}

.app-nav__links a:hover {
    background: #f1f5f9;
}

.app-nav__links a.is-active {
    background: var(--color-primary);
    color: #fff;
}

.app-main {
    flex: 1;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.page-head h1 {
    margin: 0;
    font-size: 1.5rem;
}

.page-head .subtitle {
    color: var(--color-text-muted);
    margin: 0.2rem 0 0;
    font-size: 0.9rem;
}

/* ---------- Grids i targetes de mètriques ---------- */

.grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

.grid--2 { grid-template-columns: 1fr; }
.grid--3 { grid-template-columns: 1fr; }
.grid--4 { grid-template-columns: repeat(2, 1fr); }

.stat {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: 0 2px 8px rgba(2, 8, 23, 0.06);
}

.stat__label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    margin: 0 0 0.35rem;
}

.stat__value {
    font-size: 1.55rem;
    font-weight: 700;
    margin: 0;
}

.stat__hint {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin: 0.3rem 0 0;
}

/* ---------- Aging bars ---------- */

.aging {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.aging__row {
    display: grid;
    grid-template-columns: 90px 1fr auto;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
}

.aging__track {
    background: #e2e8f0;
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}

.aging__fill {
    height: 100%;
    border-radius: 999px;
}

.aging__fill--0 { background: #22c55e; }
.aging__fill--1 { background: #eab308; }
.aging__fill--2 { background: #f97316; }
.aging__fill--3 { background: #dc2626; }

/* ---------- Taules ---------- */

.table-wrap {
    overflow-x: auto;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(2, 8, 23, 0.06);
}

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

table.data th,
table.data td {
    padding: 0.7rem 0.9rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

table.data th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-muted);
    background: #f8fafc;
}

table.data tr:last-child td { border-bottom: none; }

.tag {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
}

.tag--green { background: #dcfce7; color: #166534; }
.tag--yellow { background: #fef9c3; color: #854d0e; }
.tag--orange { background: #ffedd5; color: #9a3412; }
.tag--red { background: #fee2e2; color: #991b1b; }
.tag--blue { background: #dbeafe; color: #1e40af; }
.tag--gray { background: #e2e8f0; color: #334155; }

/* ---------- Formularis a l'app ---------- */

.form-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(2, 8, 23, 0.06);
    padding: 1.5rem;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.btn--sm { width: auto; padding: 0.45rem 0.9rem; font-size: 0.85rem; }
.btn--inline { width: auto; }

.flash {
    background: #dcfce7;
    border: 1px solid #86efac;
    color: #166534;
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.muted { color: var(--color-text-muted); }
.right { text-align: right; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- Commutador d'idioma ---------- */

.lang-switcher {
    position: relative;
    display: inline-block;
}

.lang-switcher__toggle {
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.6rem;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--color-text);
}

.lang-switcher__menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    min-width: 140px;
    z-index: 40;
    overflow: hidden;
}

.lang-switcher__menu.is-open { display: block; }

.lang-switcher__menu a {
    display: block;
    padding: 0.5rem 0.8rem;
    font-size: 0.85rem;
    color: var(--color-text);
    text-decoration: none;
}

.lang-switcher__menu a:hover { background: #f1f5f9; }
.lang-switcher__menu a.is-active { background: var(--color-primary); color: #fff; }

/* ---------- Modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 50;
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.modal textarea,
.modal input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font: inherit;
}

select {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: #fff;
}

.field textarea {
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font: inherit;
    resize: vertical;
}

/* ---------- Landing ---------- */

.hero {
    text-align: center;
    padding: 2rem 0 2.5rem;
}

.hero h1 {
    font-size: 2rem;
    line-height: 1.15;
    margin: 0 0 0.75rem;
    color: var(--color-text);
}

.hero p.lead {
    font-size: 1.05rem;
    color: var(--color-text-muted);
    max-width: 640px;
    margin: 0 auto 1.5rem;
}

.hero .cta-row {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.section-title {
    text-align: center;
    font-size: 1.4rem;
    margin: 2.5rem 0 1.25rem;
}

.pricing {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

.plan {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.plan--featured {
    border-color: var(--color-primary);
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.15);
}

.plan h3 { margin: 0 0 0.25rem; font-size: 1.15rem; }
.plan .price { font-size: 2rem; font-weight: 800; margin: 0.25rem 0; }
.plan .price small { font-size: 0.9rem; font-weight: 500; color: var(--color-text-muted); }
.plan ul { list-style: none; padding: 0; margin: 1rem 0 1.25rem; font-size: 0.9rem; }
.plan ul li { padding: 0.3rem 0; border-bottom: 1px solid var(--color-border); }
.plan ul li::before { content: "✓ "; color: var(--color-primary); font-weight: 700; }

.hero-cta-btn {
    display: inline-block;
    background: var(--color-primary);
    color: #fff;
    text-decoration: none;
    padding: 0.8rem 1.5rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
}
.hero-cta-btn:hover { background: var(--color-primary-hover); }
.hero-cta-btn--ghost { background: transparent; color: var(--color-primary); border: 1px solid var(--color-border); }

/* ---------- Responsive ---------- */

@media (min-width: 640px) {
    .hero h1 { font-size: 2.6rem; }
    .pricing { grid-template-columns: repeat(3, 1fr); }
    .card { padding: 2.5rem 2.25rem; }
    .grid--2 { grid-template-columns: repeat(2, 1fr); }
    .grid--3 { grid-template-columns: repeat(3, 1fr); }
    .grid--4 { grid-template-columns: repeat(4, 1fr); }
    .form-grid { grid-template-columns: repeat(2, 1fr); }
}
