:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #0f172a;
    --primary-hover: #1e293b;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --radius: 18px;
    --radius-sm: 12px;
    --wrap: 1180px;
}

/* =========================
   BASE
   ========================= */

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    font-family: Inter, Segoe UI, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

body {
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    max-width: 100%;
    display: block;
}

.wrap {
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 0 24px;
}

/* =========================
   TOPBAR
   ========================= */

.topbar {
    background: linear-gradient(180deg, #081224 0%, #0b1730 100%);
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.topbar-inner {
    min-height: 78px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    white-space: nowrap;
}

.news-list { display: grid; gap: 12px; }
.news-list-item { display: grid; gap: 4px; padding: 16px; border: 1px solid #d7dee9; border-radius: 8px; color: inherit; text-decoration: none; }
.news-list-item:hover { background: #f4f8fc; border-color: #92afd0; }
.news-list-item span, .news-list-item small { color: #526274; }
.news-detail-header { margin-bottom: 16px; }
.news-content-frame { width: 100%; min-height: 800px; border: 0; background: #f5f5f5; }

    .brand-logo {
        display: inline-flex;
        align-items: center;
        width: 240px;
        flex: 0 0 auto;
    }

    .brand-logo img {
        width: 100%;
        height: auto;
        max-height: 52px;
        object-fit: contain;
    }

    .brand span {
        color: rgba(255, 255, 255, 0.65);
        font-size: 1rem;
    }

.topnav {
    display: flex;
    align-items: center;
    gap: 24px;
}

.topnav-link {
    color: rgba(255, 255, 255, 0.92);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.98rem;
    transition: opacity 0.2s ease, background 0.2s ease;
}

    .topnav-link:hover {
        opacity: 0.8;
    }

.topnav-link--cta {
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
}

    .topnav-link--cta:hover {
        background: rgba(255, 255, 255, 0.12);
        opacity: 1;
    }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.topnav-user {
    color: rgba(255, 255, 255, 0.82);
    font-size: 0.95rem;
    white-space: nowrap;
}

.topnav-user-link {
    font-weight: 700;
    text-decoration: none;
}

    .topnav-user-link:hover {
        color: #fff;
        text-decoration: underline;
        text-underline-offset: 4px;
    }

.topnav-form {
    margin: 0;
}

.topnav-button {
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    padding: 10px 14px;
    border-radius: 10px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

    .topnav-button:hover {
        background: rgba(255, 255, 255, 0.12);
        border-color: rgba(255, 255, 255, 0.24);
    }

/* =========================
   CONTENT
   ========================= */

.content {
    padding: 44px 24px 56px;
}

.page-header {
    margin-bottom: 28px;
}

.page-title {
    margin: 0 0 8px;
    font-size: 2.25rem;
    line-height: 1.1;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.page-subtitle {
    margin: 0;
    color: var(--muted);
    font-size: 1.02rem;
}

.section-divider {
    height: 1px;
    background: var(--border);
    margin: 34px 0;
}

/* =========================
   GENERIC CARD / GRID
   ========================= */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 26px 24px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 22px;
}

/* =========================
   DASHBOARD
   ========================= */

.alerts-card {
    margin-bottom: 22px;
    padding: 24px;
    background: #fffaf0;
    border: 1px solid #f5d58a;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.alerts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.alerts-header h2 { margin: 0 0 6px; font-size: 1.2rem; }
.alerts-header p { margin: 0; color: #74520a; }
.alerts-list { display: grid; gap: 10px; margin-top: 18px; }
.alert-item { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 13px 14px; background: #fff; border: 1px solid #f5dfaa; border-radius: 12px; }
.alert-item span { display: block; color: var(--muted); font-size: .9rem; }
.alert-item-action { display: flex; align-items: center; gap: 14px; white-space: nowrap; }
.alert-item-action a { color: #075985; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 22px;
}

.dashboard-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 26px 24px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

    .dashboard-card:hover {
        transform: translateY(-3px);
        box-shadow: 0 14px 34px rgba(15, 23, 42, 0.1);
    }

    .dashboard-card h2,
    .dashboard-card h3 {
        margin: 0 0 10px;
        font-size: 1.1rem;
        font-weight: 700;
    }

    .dashboard-card p {
        margin: 0 0 14px;
        color: var(--muted);
    }

    .dashboard-card .btn-primary,
    .dashboard-card .btn-secondary,
    .dashboard-card .btn-disabled {
        margin-top: 10px;
    }

/* =========================
   PORTAL
   ========================= */

.hero {
    margin-bottom: 22px;
}

    .hero h1 {
        margin: 0 0 8px;
        font-size: 2rem;
        font-weight: 800;
    }

    .hero p {
        margin: 0;
        color: var(--muted);
    }

.card h2 {
    margin: 0 0 14px;
    font-size: 1.15rem;
}

.card p {
    margin: 0 0 10px;
    color: var(--text);
}

    .card p strong {
        color: var(--text);
    }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1;
}

.badge-ok {
    background: #dcfce7;
    color: #166534;
}

.badge-off {
    background: #fee2e2;
    color: #991b1b;
}

/* =========================
   BUTTONS
   ========================= */

.btn-primary,
.btn-secondary,
.btn-disabled {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 18px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-weight: 700;
    font-size: 0.96rem;
    line-height: 1.2;
    vertical-align: middle;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border: 1px solid var(--primary);
    transition: all 0.2s ease;
    cursor: pointer;
}

    .btn-primary:hover {
        background: var(--primary-hover);
        border-color: var(--primary-hover);
        transform: translateY(-1px);
    }

.btn-secondary {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    transition: all 0.2s ease;
    cursor: pointer;
}

    .btn-secondary:hover {
        background: var(--surface-soft);
        transform: translateY(-1px);
    }

.btn-disabled {
    border: 1px solid var(--border);
    background: #f8fafc;
    color: #94a3b8;
    cursor: not-allowed;
}

.btn-primary + .btn-secondary,
.btn-secondary + .btn-primary,
.btn-primary + .btn-primary,
.btn-secondary + .btn-secondary {
    margin-left: 10px;
}

/* =========================
   STATS
   ========================= */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 22px;
}

.stat-card {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    background: var(--surface);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--muted);
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
}

/* =========================
   AUTH / LOGIN
   ========================= */

.auth-shell {
    display: flex;
    justify-content: center;
    padding: 60px 20px;
}

.auth-card {
    width: 100%;
    max-width: 500px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 36px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
}

.auth-card-header {
    margin-bottom: 22px;
}

.auth-title {
    font-size: 2rem;
    font-weight: 800;
    margin: 0 0 8px;
    line-height: 1.1;
}

.auth-subtitle {
    color: var(--muted);
    margin: 0;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-label {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
}

.auth-input {
    width: 100%;
    padding: 13px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    font: inherit;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

    .auth-input:focus {
        border-color: #94a3b8;
        box-shadow: 0 0 0 4px rgba(148, 163, 184, 0.15);
    }

.auth-submit {
    width: 100%;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    padding: 13px 16px;
    border-radius: 12px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

    .auth-submit:hover {
        background: var(--primary-hover);
        border-color: var(--primary-hover);
    }

    .auth-submit:active {
        transform: translateY(1px);
    }

.auth-forgot-password {
    align-self: flex-end;
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
}

.auth-forgot-password--back {
    align-self: center;
}

    .auth-forgot-password:hover,
    .auth-forgot-password:focus-visible {
        color: var(--primary-hover);
        text-decoration: underline;
    }

.auth-alert {
    margin-bottom: 18px;
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #991b1b;
    border-radius: 14px;
    padding: 12px 14px;
    font-size: 0.95rem;
}

    .auth-alert ul {
        margin: 0;
        padding-left: 18px;
    }

.auth-validation {
    font-size: 0.88rem;
    color: #b91c1c;
}

/* =========================
   RESPONSIVE
   ========================= */

@media (max-width: 980px) {
    .brand-logo {
        width: 210px;
    }

    .topbar-inner {
        min-height: auto;
        padding: 16px 0;
        flex-wrap: wrap;
        justify-content: center;
    }

    .topnav,
    .topbar-right {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .dashboard-grid,
    .stats-grid,
    .grid {
        grid-template-columns: 1fr;
    }

    .alerts-header,
    .alert-item,
    .alert-item-action {
        align-items: flex-start;
        flex-direction: column;
    }

    .page-title {
        font-size: 1.9rem;
    }
}

@media (max-width: 640px) {
    .wrap {
        padding: 0 16px;
    }

    .content {
        padding: 32px 16px 44px;
    }

    .brand {
        flex-wrap: wrap;
        justify-content: center;
        text-align: center;
        gap: 10px;
    }

    .brand-logo {
        width: 170px;
    }

    .brand span {
        font-size: 0.9rem;
    }

    .topnav {
        gap: 16px;
    }

    .topnav-user {
        white-space: normal;
        text-align: center;
    }

    .dashboard-card,
    .card {
        padding: 22px 18px;
    }

    .auth-shell {
        padding: 20px 0 28px;
    }

    .auth-card {
        padding: 24px 18px;
        border-radius: 18px;
    }

    .auth-title {
        font-size: 1.75rem;
    }
}
/* =========================
   TABLES
   ========================= */

.table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
}

    .table th {
        text-align: left;
        font-size: 0.85rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--muted);
        background: #f8fafc;
        padding: 12px 14px;
        border-bottom: 1px solid var(--border);
    }

    .table td {
        padding: 14px;
        border-bottom: 1px solid var(--border);
        font-size: 0.95rem;
    }

    .table tr:last-child td {
        border-bottom: none;
    }

    .table tr:hover {
        background: #f8fafc;
    }
/* =========================
   FACTURAS
   ========================= */

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

    .page-header h1 {
        margin: 0 0 6px;
        font-size: 2rem;
        font-weight: 800;
    }

.muted {
    color: var(--muted);
}

.auth-alert--success {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}

    .auth-alert:empty {
        display: none;
    }

/* =========================
   CLIENTES DISTRIBUIDOR
   ========================= */

.clientes-lista {
    display: grid;
    gap: 16px;
}

.cliente-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 24px;
    padding: 24px 26px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.cliente-card h4 {
    margin: 0 0 18px;
    font-size: 1.1rem;
}

.cliente-codigo {
    margin: 0 0 10px;
}

.cliente-contacto {
    color: var(--muted);
    line-height: 1.6;
}

.cliente-licencias-btn {
    white-space: nowrap;
    align-self: center;
}

@media (max-width: 640px) {
    .cliente-card {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    .cliente-licencias-btn {
        justify-self: start;
    }
}

.documents-switch {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    margin: 16px 0 18px;
    background: #e9ecef;
    border: 1px solid #d7d9dc;
    border-radius: 8px;
}

    .documents-switch a {
        min-width: 130px;
        padding: 9px 14px;
        border-radius: 6px;
        color: #334155;
        font-weight: 800;
        text-align: center;
        text-decoration: none;
    }

    .documents-switch a.active {
        background: #083c6d;
        color: #fff;
        box-shadow: 0 2px 8px rgba(8, 60, 109, 0.22);
    }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 18px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-weight: 700;
    font-size: 0.96rem;
    line-height: 1.2;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-sm {
    min-height: 36px;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 0.88rem;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

    .btn-primary:hover {
        background: var(--primary-hover);
        border-color: var(--primary-hover);
        transform: translateY(-1px);
    }

.btn-secondary {
    background: #fff;
    color: var(--text);
    border-color: var(--border);
}

    .btn-secondary:hover {
        background: var(--surface-soft);
        transform: translateY(-1px);
    }

.btn.disabled,
.btn[disabled],
a.disabled {
    pointer-events: none;
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.filters-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    margin-bottom: 20px;
}

.filters-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
}

    .filters-grid label {
        display: block;
        margin-bottom: 8px;
        font-size: 0.92rem;
        font-weight: 700;
        color: var(--text);
    }

.form-control {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: 12px;
    padding: 11px 12px;
    font: inherit;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

    .form-control:focus {
        border-color: #94a3b8;
        box-shadow: 0 0 0 4px rgba(148, 163, 184, 0.15);
    }

.filters-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 18px;
}

.summary-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin: 18px 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.empty-state {
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 28px 22px;
    text-align: center;
    color: var(--muted);
}

.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

    .data-table thead th {
        background: #f8fafc;
        color: var(--muted);
        font-size: 0.83rem;
        font-weight: 800;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        padding: 14px 16px;
        border-bottom: 1px solid var(--border);
    }

    .data-table tbody td {
        padding: 16px;
        border-bottom: 1px solid var(--border);
        vertical-align: middle;
    }

    .data-table tbody tr:last-child td {
        border-bottom: none;
    }

    .data-table tbody tr:hover {
        background: #fafcff;
    }

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

.support-form { display: grid; gap: 18px; }
.support-form .filters-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.support-textarea { resize: vertical; }
.support-link { color: #083c6d; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
.support-status { display: inline-flex; padding: 4px 9px; border-radius: 999px; background: #e0efff; color: #075985; font-weight: 700; font-size: .85rem; }
.support-thread { display: grid; gap: 14px; margin: 24px 0; }
.support-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.support-file-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.support-drop-zone { display: flex; min-height: 128px; flex-direction: column; align-items: center; justify-content: center; gap: 5px; border: 2px dashed #94a3b8; border-radius: var(--radius-sm); background: var(--surface-soft); color: var(--text); cursor: pointer; text-align: center; padding: 20px; transition: border-color .2s, background .2s; }
.support-drop-zone:hover, .support-drop-zone.is-dragging { border-color: #083c6d; background: #eaf3ff; }
.support-drop-zone span, .support-drop-zone small, .support-selected-files { color: var(--muted); }
.support-selected-files { margin-top: 8px; font-size: .9rem; word-break: break-word; }
.support-message { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 18px; }
.support-message strong { display: block; }
.support-message span { color: var(--muted); font-size: .86rem; }
.support-message p { white-space: pre-wrap; margin: 12px 0 0; }

.document-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.budget-accepted {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 8px 12px;
    border-radius: 10px;
    background: #dcfce7;
    color: #166534;
    font-size: .88rem;
    font-weight: 800;
}

.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 18px;
}

@media (max-width: 980px) {
    .filters-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .summary-bar,
    .pagination-bar,
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 640px) {
    .filters-grid {
        grid-template-columns: 1fr;
    }

    .filters-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .support-form .filters-grid { grid-template-columns: 1fr; }

    .documents-switch {
        display: flex;
    }

        .documents-switch a {
            flex: 1;
            min-width: 0;
        }

    .pagination-bar {
        align-items: stretch;
    }

    .document-actions {
        flex-direction: column;
    }

    .data-table {
        font-size: 0.93rem;
    }

        .data-table thead th,
        .data-table tbody td {
            padding: 12px 10px;
        }
}
