/* ===========================================================
   Customer Portal - design tokens & layout
   =========================================================== */

:root {
    --portal-ink: #0f172a;
    --portal-ink-soft: #475569;
    --portal-muted: #64748b;
    --portal-bg: #f4f6fb;
    --portal-card-bg: #ffffff;
    --portal-border: rgba(15, 23, 42, 0.08);
    --portal-primary: #2563eb;
    --portal-primary-dark: #1d4ed8;
    --portal-accent: #0ea5e9;
    --portal-success: #16a34a;
    --portal-danger: #dc2626;
    --portal-warning: #d97706;
    --portal-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 12px 28px -18px rgba(15, 23, 42, 0.35);
}

html, body {
    height: 100%;
    margin: 0;
    background: var(--portal-bg);
    color: var(--portal-ink);
    font-family: 'Noto Sans Arabic', Tahoma, 'Segoe UI', Arial, sans-serif;
}

/* Numeric/money figures read more naturally kept left-to-right even inside RTL flow
   (thousand separators and decimals don't reorder), while still sitting on the correct
   side of their row because the surrounding table cell/flex item is still RTL-positioned. */
.stat-tile-value, .barchart-value, .portal-table td[data-label], td, th,
.donut-hole-value, .pagination-size .form-select {
    font-variant-numeric: tabular-nums;
}

a { text-decoration: none; }

/* ===================== App shell / header ===================== */

.portal-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.portal-header {
    background: linear-gradient(100deg, #0f172a 0%, #1e3a8a 100%);
    box-shadow: 0 2px 14px rgba(15, 23, 42, 0.18);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.portal-header-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 64px;
    display: flex;
    align-items: center;
    gap: 2rem;
}

.portal-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}

.portal-brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--portal-accent), var(--portal-primary));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1rem;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

.portal-brand-text {
    color: white;
    font-weight: 700;
    font-size: 1.02rem;
    letter-spacing: 0.01em;
}

.portal-nav {
    display: flex;
    gap: 0.25rem;
    flex: 1;
}

.portal-nav-link {
    color: rgba(255, 255, 255, 0.72);
    padding: 0.45rem 0.9rem;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background .15s ease, color .15s ease;
}

.portal-nav-icon { font-size: 0.85rem; opacity: 0.85; }

.portal-nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: white;
}

.portal-nav-link.active {
    background: rgba(255, 255, 255, 0.14);
    color: white;
}

.portal-user {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    flex-shrink: 0;
}

.portal-user-info {
    text-align: right;
    line-height: 1.2;
}

.portal-user-company {
    color: white;
    font-size: 0.82rem;
    font-weight: 600;
}

.portal-user-place {
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.74rem;
}

.portal-logout {
    border-color: rgba(255, 255, 255, 0.35);
    color: white;
}

.portal-logout:hover {
    background: rgba(255, 255, 255, 0.12);
    color: white;
    border-color: rgba(255, 255, 255, 0.5);
}

/* ===================== Main content ===================== */

.portal-main {
    flex: 1;
    padding: 1.75rem 0 2.5rem;
}

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

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

.portal-footer {
    padding: 1rem 0 1.5rem;
    color: var(--portal-muted);
    font-size: 0.78rem;
    text-align: center;
}

/* ===================== Cards / tiles ===================== */

.portal-card {
    background: var(--portal-card-bg);
    border: 1px solid var(--portal-border);
    border-radius: 14px;
    box-shadow: var(--portal-shadow);
}

.stat-tile {
    position: relative;
    overflow: hidden;
    background: linear-gradient(160deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid var(--portal-border);
    border-radius: 14px;
    padding: 1.1rem 1.25rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 10px 24px -14px var(--accent, var(--portal-primary));
    transition: transform .15s ease, box-shadow .15s ease;
    height: 100%;
}

.stat-tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 16px 28px -14px var(--accent, var(--portal-primary));
}

.stat-tile::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--accent, var(--portal-primary));
}

.stat-tile-glow {
    position: absolute;
    top: -34px; right: -34px;
    width: 96px; height: 96px;
    border-radius: 50%;
    background: var(--accent, var(--portal-primary));
    opacity: 0.10;
    filter: blur(6px);
    pointer-events: none;
}

.stat-tile-label {
    position: relative;
    font-size: 0.78rem;
    color: var(--portal-ink-soft);
    margin-bottom: 0.3rem;
}

.stat-tile-value {
    position: relative;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--portal-ink);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.stat-tile-sub {
    position: relative;
    font-size: 0.72rem;
    color: var(--portal-muted);
    margin-top: 0.3rem;
}

/* ===================== Tables ===================== */

.portal-table {
    font-size: 0.88rem;
}

.portal-table thead th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--portal-muted);
    border-bottom-width: 1px;
    font-weight: 700;
}

.portal-table tbody tr:hover {
    background: #f0f6ff;
}

.badge-paid, .badge-due {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.74rem;
    font-weight: 700;
}

.badge-paid {
    background: rgba(22, 163, 74, 0.12);
    color: var(--portal-success);
}

.badge-due {
    background: rgba(220, 38, 38, 0.10);
    color: var(--portal-danger);
}

.small-link {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--portal-primary);
}

.small-link:hover { color: var(--portal-primary-dark); }

.summary-bar {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    padding: 0.75rem 1.1rem;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 10px;
    font-size: 0.88rem;
}

.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--portal-muted);
    background: var(--portal-card-bg);
    border: 1px dashed var(--portal-border);
    border-radius: 14px;
}

.server-error-card {
    max-width: 480px;
    margin: 3rem auto;
    padding: 2rem;
    text-align: center;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 12px;
}

.server-error-card h4 { color: #991b1b; margin-bottom: 0.75rem; }
.server-error-card p { color: #7f1d1d; margin-bottom: 0.5rem; }

/* ===================== Bar chart (dashboard) ===================== */

.barchart-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.barchart-label {
    width: 130px;
    flex-shrink: 0;
    font-size: 0.82rem;
    color: var(--portal-ink-soft);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.barchart-track {
    flex: 1;
    background: #e9edf5;
    border-radius: 6px;
    height: 12px;
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.06);
}

.barchart-fill {
    height: 100%;
    border-radius: 6px;
    min-width: 4px;
    background: linear-gradient(90deg, var(--portal-primary) 0%, var(--portal-accent) 100%);
    box-shadow: 0 0 8px rgba(37, 99, 235, 0.4);
    transition: width .4s ease;
}

.barchart-value {
    width: auto;
    min-width: 110px;
    flex-shrink: 0;
    text-align: right;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--portal-ink);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ===================== Loading / pagination ===================== */

.loading-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 1rem;
    color: var(--portal-muted);
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #e2e8f0;
    border-top-color: var(--portal-primary);
    border-radius: 50%;
    animation: loading-spin 0.7s linear infinite;
}

@keyframes loading-spin {
    to { transform: rotate(360deg); }
}

.pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0.5rem 0 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.pagination-size {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pagination-size .form-select { width: auto; }

.pagination-controls {
    display: flex;
    gap: 4px;
    align-items: center;
}

.nav-loading-bar {
    position: fixed;
    top: 0; left: 0;
    height: 3px; width: 100%;
    z-index: 3000;
    background: linear-gradient(90deg, var(--portal-primary) 0%, #93c5fd 50%, var(--portal-primary) 100%);
    background-size: 200% 100%;
    animation: nav-loading-sweep 1s linear infinite;
}

@keyframes nav-loading-sweep {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===================== Auth pages (login / error) ===================== */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 15% 20%, rgba(14, 165, 233, 0.25), transparent 45%),
        radial-gradient(circle at 85% 80%, rgba(37, 99, 235, 0.25), transparent 45%),
        linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    padding: 1.5rem;
}

.auth-page-inner {
    width: 100%;
    display: flex;
    justify-content: center;
}

.auth-card {
    background: var(--portal-card-bg);
    padding: 2.25rem 2rem;
    border-radius: 18px;
    box-shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.55);
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.auth-brand { margin-bottom: 0.75rem; }

.auth-brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--portal-accent), var(--portal-primary));
    color: white;
    font-weight: 800;
    font-size: 1.4rem;
    box-shadow: 0 8px 20px rgba(14, 165, 233, 0.4);
}

.auth-icon-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(220, 38, 38, 0.12);
    color: var(--portal-danger);
    font-weight: 800;
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
}

.auth-title {
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.auth-subtitle {
    color: var(--portal-muted);
    font-size: 0.86rem;
    margin-bottom: 1.5rem;
}

.auth-card .form-label {
    text-align: left;
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--portal-ink-soft);
}

.auth-footnote {
    color: var(--portal-muted);
    font-size: 0.76rem;
    margin: 1.25rem 0 0;
}

/* ===================== Buttons ===================== */

.btn-primary {
    background: linear-gradient(135deg, var(--portal-primary) 0%, var(--portal-primary-dark) 100%);
    border-color: var(--portal-primary-dark);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--portal-primary-dark) 0%, #1e40af 100%);
    border-color: #1e40af;
}

/* ===================== Blazor error UI ===================== */

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 4000;
    background: #991b1b;
    color: white;
    padding: 1rem 1.5rem;
    text-align: center;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.2);
}

#blazor-error-ui .reload {
    color: white;
    text-decoration: underline;
    margin-left: 0.75rem;
    font-weight: 600;
}

#blazor-error-ui .dismiss {
    position: absolute;
    right: 1rem; top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    font-size: 1.3rem;
}

/* ===================== Responsive ===================== */

@media (max-width: 900px) {
    .portal-header-inner {
        flex-wrap: wrap;
        height: auto;
        padding: 0.75rem 1.25rem;
        gap: 0.75rem;
    }
    .portal-nav {
        order: 3;
        width: 100%;
        justify-content: space-between;
        gap: 0.15rem;
    }
    .portal-nav-link {
        flex: 1;
        justify-content: center;
        padding: 0.4rem 0.4rem;
        font-size: 0.78rem;
    }
    .portal-nav-icon { display: none; }
    .portal-user-info { display: none; }
}

@media (max-width: 576px) {
    .portal-table thead { display: none; }
    .portal-table, .portal-table tbody, .portal-table tr, .portal-table td {
        display: block; width: 100%;
    }
    .portal-table tr {
        margin-bottom: 10px;
        border: 1px solid var(--portal-border);
        border-radius: 10px;
        padding: 8px;
    }
    .portal-table td {
        text-align: right;
        padding: 5px 8px;
        border: none;
    }
    .portal-table td::before {
        content: attr(data-label);
        float: left;
        font-weight: 600;
        color: var(--portal-muted);
    }
}
