:root {
    --brand-primary: #1a56db;
    --brand-primary-dark: #1e429f;
    --brand-primary-light: #e8f0fe;
    --brand-success: #057a55;
    --brand-danger: #c81e1e;
    --sidebar-bg: #0f172a;
    --sidebar-width: 250px;
    --topbar-height: 60px;
    --surface: #f8fafc;
    --card-bg: #ffffff;
    --card-shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --card-radius: 10px;
    --text-primary: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    color: var(--text-primary);
    background: var(--surface);
}

/* ── Portal layout ── */
.portal-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.portal-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform .25s ease;
    overflow-y: auto;
}

.portal-sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-width)));
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 1.4rem 1.2rem;
    color: #fff;
    font-weight: 700;
    font-size: .95rem;
    letter-spacing: .01em;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-logo-img {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: contain;
    flex-shrink: 0;
    background: #fff;
    padding: 2px;
}

.brand-logo-initials {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #3b82f6;
    color: #fff;
    font-weight: 800;
    font-size: .8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    letter-spacing: .02em;
}

.brand-name {
    font-size: .88rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav {
    flex: 1;
    padding: .75rem 0;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .65rem 1.2rem;
    color: #94a3b8;
    text-decoration: none;
    font-size: .875rem;
    border-radius: 0;
    transition: background .15s, color .15s;
}

.sidebar-nav .nav-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sidebar-nav .nav-link:hover {
    background: rgba(255,255,255,.07);
    color: #e2e8f0;
}

.sidebar-nav .nav-link.active {
    background: rgba(96,165,250,.15);
    color: #60a5fa;
    font-weight: 600;
}

.sidebar-divider {
    height: 1px;
    background: rgba(255,255,255,.08);
    margin: .5rem 1rem;
}

.sidebar-footer {
    padding: 1rem 1.2rem;
    border-top: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: .75rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: .6rem;
    flex: 1;
    min-width: 0;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--brand-primary);
    color: #fff;
    font-weight: 700;
    font-size: .8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-name {
    font-size: .8rem;
    color: #e2e8f0;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-label {
    font-size: .7rem;
    color: #64748b;
}

.btn-logout {
    background: none;
    border: none;
    padding: .3rem;
    color: #64748b;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    transition: color .15s;
}

.btn-logout svg { width: 18px; height: 18px; }
.btn-logout:hover { color: #f87171; }

/* ── Main area ── */
.portal-main {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
    transition: margin .25s ease;
}

.portal-topbar {
    height: var(--topbar-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.sidebar-toggle {
    background: none;
    border: none;
    padding: .3rem;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 6px;
    display: none;
}

.sidebar-toggle svg { width: 20px; height: 20px; }

.page-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.portal-content {
    flex: 1;
    padding: 1.5rem;
}

/* ── Cards ── */
.portal-card {
    background: var(--card-bg);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.portal-card-header {
    padding: .85rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: .875rem;
    color: var(--text-primary);
    background: #fafafa;
}

.portal-card-body {
    padding: 1.25rem;
}

.portal-card-footer {
    padding: .75rem 1.25rem;
    border-top: 1px solid var(--border);
    background: #fafafa;
}

/* ── Stat cards ── */
.stat-card {
    background: var(--card-bg);
    border-radius: var(--card-radius);
    border: 1px solid var(--border);
    box-shadow: var(--card-shadow);
    padding: 1.1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg { width: 22px; height: 22px; }

.stat-card--blue .stat-icon  { background: #dbeafe; color: #1d4ed8; }
.stat-card--green .stat-icon { background: #d1fae5; color: #065f46; }
.stat-card--indigo .stat-icon{ background: #e0e7ff; color: #4338ca; }
.stat-card--amber .stat-icon { background: #fef3c7; color: #92400e; }

.stat-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.stat-label {
    font-size: .75rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-sub {
    font-size: .8rem;
    color: var(--text-muted);
}

.stat-inline {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    flex-wrap: wrap;
}

.stat-value-amount {
    font-size: .95rem;
    font-weight: 600;
    color: var(--brand-primary);
}

/* ── Info list (dt/dd pairs) ── */
.info-list { margin: 0; }

.info-row {
    display: flex;
    padding: .5rem 0;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
}

.info-row:last-child { border-bottom: none; }

.info-row dt {
    width: 45%;
    flex-shrink: 0;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    padding-top: .1rem;
}

.info-row dd {
    margin: 0;
    font-size: .9rem;
    color: var(--text-primary);
    word-break: break-word;
}

/* ── Tables ── */
.portal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.portal-table thead tr {
    background: #f8fafc;
    border-bottom: 2px solid var(--border);
}

.portal-table th {
    padding: .7rem 1rem;
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    text-align: left;
    white-space: nowrap;
}

.portal-table td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    vertical-align: middle;
}

.portal-table tbody tr:last-child td { border-bottom: none; }
.portal-table tbody tr:hover { background: #f8fafc; }

/* ── Badges ── */
.badge-status {
    display: inline-block;
    padding: .2em .65em;
    border-radius: 99px;
    font-size: .72rem;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-status--enrolled, .badge-status--completed, .badge-status--cleared { background: #d1fae5; color: #065f46; }
.badge-status--open, .badge-status--pending, .badge-status--processing { background: #fef3c7; color: #92400e; }
.badge-status--paused { background: #e0e7ff; color: #4338ca; }
.badge-status--closed, .badge-status--failed, .badge-status--returned { background: #fee2e2; color: #991b1b; }

.doc-type-badge {
    display: inline-block;
    padding: .2em .6em;
    border-radius: 6px;
    font-size: .72rem;
    font-weight: 600;
    background: var(--brand-primary-light);
    color: var(--brand-primary);
    text-transform: capitalize;
}

/* ── Dashboard quick actions ── */
.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .75rem;
}

.quick-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-primary);
    font-size: .8rem;
    font-weight: 500;
    text-align: center;
    transition: background .15s, border-color .15s;
}

.quick-action-btn svg { width: 22px; height: 22px; color: var(--brand-primary); }
.quick-action-btn:hover { background: var(--brand-primary-light); border-color: var(--brand-primary); color: var(--brand-primary); }

/* ── Welcome banner ── */
.welcome-banner {
    background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-dark) 100%);
    border-radius: var(--card-radius);
    padding: 1.5rem 1.75rem;
    color: #fff;
}

.welcome-title { font-size: 1.4rem; font-weight: 700; margin: 0 0 .25rem; }
.welcome-sub { margin: 0; opacity: .85; font-size: .9rem; }

/* ── Liability cards ── */
.liability-name { font-weight: 600; font-size: .9rem; }
.liability-type { font-size: .75rem; color: var(--text-muted); margin-top: .15rem; }

/* ── Address block ── */
.address-block { font-size: .875rem; line-height: 1.6; }
.address-label { font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: .2rem; }

/* ── Document upload area ── */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
    transition: border-color .15s;
}

.upload-area:hover { border-color: var(--brand-primary); }
.upload-link { color: var(--brand-primary); cursor: pointer; text-decoration: underline; }

/* ── Buttons ── */
.btn-portal { font-weight: 600; letter-spacing: .01em; }

/* ── Auth layout ── */
.auth-body {
    background: var(--surface);
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 2rem 1rem;
}

@media (min-height: 600px) {
    .auth-body { align-items: center; }
}

.auth-wrapper {
    width: 100%;
    max-width: 440px;
}

.auth-card {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0,0,0,.1);
    padding: 2.5rem 2rem;
    border: 1px solid var(--border);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--brand-primary);
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 1.75rem;
}

.auth-brand-icon { width: 26px; height: 26px; }

.auth-title {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0 0 .4rem;
}

.auth-subtitle {
    color: var(--text-muted);
    font-size: .9rem;
    margin-bottom: 1.5rem;
}

.auth-link { color: var(--brand-primary); text-decoration: none; font-size: .875rem; }
.auth-link:hover { text-decoration: underline; }

.auth-alt-link {
    text-align: center;
    margin-top: 1.25rem;
    font-size: .875rem;
    color: var(--text-muted);
}

.auth-footer {
    text-align: center;
    margin-top: 1.25rem;
    font-size: .75rem;
    color: #9ca3af;
}

.confirm-icon { color: var(--brand-primary); }

/* ── Login step transitions ── */
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeSlideOut {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(-12px); }
}

.step-enter {
    animation: fadeSlideIn .3s cubic-bezier(.4, 0, .2, 1) forwards;
}

.step-exit {
    animation: fadeSlideOut .28s cubic-bezier(.4, 0, .2, 1) forwards;
    pointer-events: none;
}

/* ── Company welcome block (step 2) ── */
.welcome-step {
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.welcome-greeting {
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    margin: .85rem 0 .2rem;
    font-weight: 600;
}

.company-name {
    font-size: 1.45rem;
    font-weight: 800;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -.01em;
}

/* ── Pulse rings animation (step 2) ── */
.welcome-pulse-rings {
    position: relative;
    width: 80px;
    height: 80px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

.pulse-core {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--brand-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
    animation: coreBreath 2s ease-in-out infinite;
}

@keyframes coreBreath {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(26, 86, 219, .35); }
    50%       { transform: scale(1.06); box-shadow: 0 0 0 10px rgba(26, 86, 219, 0); }
}

.pulse-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--brand-primary);
    opacity: 0;
    animation: ringExpand 2.4s ease-out infinite;
}

.pulse-ring--1 { animation-delay: 0s; }
.pulse-ring--2 { animation-delay: .8s; }
.pulse-ring--3 { animation-delay: 1.6s; }

@keyframes ringExpand {
    0%   { transform: scale(1);    opacity: .7; }
    100% { transform: scale(2.4);  opacity: 0; }
}

/* ── Loading dots ── */
.loading-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.loading-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--brand-primary);
    opacity: .25;
    animation: dotPulse 1.2s ease-in-out infinite;
}

.loading-dots span:nth-child(2) { animation-delay: .2s; }
.loading-dots span:nth-child(3) { animation-delay: .4s; }

@keyframes dotPulse {
    0%, 80%, 100% { opacity: .2; transform: scale(.85); }
    40%            { opacity: 1;  transform: scale(1); }
}

/* ── Welcome full step ── */
.welcome-full {
    padding: 1rem 0 .5rem;
}

/* ── Welcome progress bar ── */
.welcome-progress-bar {
    width: 100%;
    height: 5px;
    background: var(--border);
    border-radius: 99px;
    overflow: hidden;
    margin: 0 0 .75rem;
}

.welcome-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--brand-primary), #60a5fa);
    border-radius: 99px;
}

/* ── Signing-into header (step 3) ── */
.signing-into-header {
    text-align: center;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.signing-into-label {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    font-weight: 600;
    color: var(--text-muted);
    margin: 0 0 .3rem;
}

.signing-into-name {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -.02em;
    margin: 0;
}

/* ── Username availability indicator (setup page) ── */
.input-with-status {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-status .form-control {
    padding-right: 2.5rem;
}

.username-status {
    position: absolute;
    right: .75rem;
    display: flex;
    align-items: center;
    pointer-events: none;
}

/* ── Back button ── */
.btn-text-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--text-muted);
    font-size: .8rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    transition: color .15s;
}

.btn-text-link:hover { color: var(--brand-primary); }

/* ── Impersonation banner ── */
.impersonation-banner {
    background: #7c3aed;
    color: #fff;
    padding: .55rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-size: .82rem;
    font-weight: 500;
    position: sticky;
    top: 0;
    z-index: 60;
}

.impersonation-banner-inner {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.impersonation-banner strong {
    font-weight: 700;
}

.impersonation-exit-btn {
    background: rgba(255,255,255,.15);
    border: 1px solid rgba(255,255,255,.3);
    color: #fff;
    border-radius: 6px;
    padding: .25rem .65rem;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    transition: background .15s;
    white-space: nowrap;
}

.impersonation-exit-btn:hover {
    background: rgba(255,255,255,.25);
}

/* ── Portal footer ── */
.portal-footer {
    padding: 1rem 1.5rem;
    font-size: .75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    text-align: center;
    background: var(--card-bg);
    margin-top: auto;
}

.portal-footer strong {
    color: var(--brand-primary);
    font-weight: 600;
}

/* ── Sidebar overlay (mobile) ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 99;
    opacity: 0;
    transition: opacity .25s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ── Responsive — tablet (≤ 992px) ── */
@media (max-width: 992px) {
    .portal-content {
        padding: 1.25rem;
    }
}

/* ── Responsive — mobile (≤ 768px) ── */
@media (max-width: 768px) {
    /* Sidebar hidden off-canvas by default */
    .portal-sidebar {
        transform: translateX(calc(-1 * var(--sidebar-width)));
        box-shadow: none;
        z-index: 200;
    }

    /* Toggle 'open' class to show on mobile */
    .portal-sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, .35);
    }

    .portal-main {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: flex;
    }

    /* Content padding reduced */
    .portal-content {
        padding: 1rem;
    }

    /* Topbar */
    .page-title {
        font-size: .95rem;
    }

    /* Stat cards — 2 per row on mobile */
    .stat-card {
        padding: .9rem 1rem;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    /* Info list — stack vertically on small screens */
    .info-row {
        flex-direction: column;
        gap: .15rem;
    }

    .info-row dt {
        width: 100%;
        font-size: .72rem;
    }

    .info-row dd {
        font-size: .875rem;
    }

    /* Quick actions single column */
    .quick-actions {
        grid-template-columns: 1fr 1fr;
    }

    /* Welcome banner */
    .welcome-title {
        font-size: 1.1rem;
    }

    /* Liability cards full width */
    .liability-card {
        margin-bottom: .5rem;
    }

    /* Tables — allow horizontal scroll */
    .portal-table th,
    .portal-table td {
        padding: .6rem .75rem;
        font-size: .8rem;
        white-space: nowrap;
    }

    /* Portal card header/body */
    .portal-card-header,
    .portal-card-footer {
        padding: .75rem 1rem;
    }

    .portal-card-body {
        padding: 1rem;
    }

    /* Impersonation banner */
    .impersonation-banner {
        padding: .5rem 1rem;
        font-size: .75rem;
        flex-wrap: wrap;
        gap: .5rem;
    }

    /* Footer */
    .portal-footer {
        padding: .75rem 1rem;
    }
}

/* ── Responsive — small phone (≤ 480px) ── */
@media (max-width: 480px) {
    .portal-content {
        padding: .75rem;
    }

    .quick-actions {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: .75rem;
    }

    /* Auth card full width on tiny screens */
    .auth-card {
        padding: 1.75rem 1.25rem;
    }

    .company-name {
        font-size: 1.2rem;
    }

    .signing-into-name {
        font-size: 1.2rem;
    }
}

/* ── Touch targets — ensure min 44px tap area ── */
@media (pointer: coarse) {
    .nav-link {
        padding: .8rem 1.2rem;
        min-height: 44px;
    }

    .btn {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 36px;
    }

    .portal-table td, .portal-table th {
        padding: .75rem;
    }
}
