:root {
    --brand-950: #17304a;
    --brand-900: #2e4e6e;
    --brand-800: #3e6081;
    --brand-100: #e9f0f6;
    --brand-50: #f4f7fa;
    --accent-600: #167a72;
    --accent-100: #dff4f0;
    --ink-900: #17212b;
    --ink-700: #405261;
    --ink-500: #6f7f8c;
    --line: #dce4ea;
    --surface: #ffffff;
    --background: #f3f6f8;
    --danger: #b42318;
    --danger-bg: #fff1f0;
    --success: #167a53;
    --success-bg: #e9f8f0;
    --warning: #9a6700;
    --warning-bg: #fff7df;
    --shadow-sm: 0 1px 3px rgba(23, 48, 74, 0.08);
    --shadow-lg: 0 24px 64px rgba(18, 40, 60, 0.16);
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
        "Segoe UI", sans-serif;
    color: var(--ink-900);
    background: var(--background);
    font-synthesis: none;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    min-height: 100%;
    background: var(--background);
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    background: var(--background);
    color: var(--ink-900);
    line-height: 1.5;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: wait;
    opacity: 0.72;
}

img {
    display: block;
    max-width: 100%;
}

[hidden] {
    display: none !important;
}

.skip-link {
    position: fixed;
    z-index: 100;
    top: 12px;
    left: 12px;
    padding: 10px 14px;
    transform: translateY(-180%);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--brand-950);
    box-shadow: var(--shadow-lg);
}

.skip-link:focus {
    transform: translateY(0);
}

.login-shell {
    display: grid;
    min-height: 100vh;
    grid-template-columns: minmax(360px, 0.95fr) minmax(440px, 1.05fr);
}

.brand-panel {
    position: relative;
    display: flex;
    min-height: 100%;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    padding: clamp(36px, 6vw, 76px);
    background:
        radial-gradient(circle at 78% 22%, rgba(255, 255, 255, 0.13), transparent 26%),
        linear-gradient(145deg, var(--brand-950), var(--brand-900));
    color: #ffffff;
}

.brand-panel::after {
    position: absolute;
    right: -120px;
    bottom: -150px;
    width: 390px;
    height: 390px;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 50%;
    box-shadow:
        0 0 0 56px rgba(255, 255, 255, 0.035),
        0 0 0 112px rgba(255, 255, 255, 0.025);
    content: "";
}

.brand-logo {
    width: 190px;
    height: auto;
    object-fit: contain;
}

.brand-logo--login {
    position: relative;
    z-index: 1;
    width: min(72%, 420px);
    padding: 20px;
    border-radius: var(--radius-md);
    background: #ffffff;
}

.brand-copy {
    position: relative;
    z-index: 1;
    max-width: 590px;
}

.brand-copy h1 {
    max-width: 560px;
    margin: 12px 0 20px;
    font-size: clamp(2.25rem, 5vw, 4.75rem);
    font-weight: 720;
    letter-spacing: -0.045em;
    line-height: 0.98;
}

.brand-copy > p:last-child {
    max-width: 520px;
    margin: 0;
    color: rgba(255, 255, 255, 0.76);
    font-size: clamp(1rem, 1.7vw, 1.2rem);
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--brand-800);
    font-size: 0.73rem;
    font-weight: 750;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.eyebrow--light {
    color: rgba(255, 255, 255, 0.68);
}

.login-main {
    display: grid;
    min-height: 100%;
    place-items: center;
    padding: clamp(24px, 6vw, 84px);
    background: var(--surface);
}

.login-card {
    width: min(100%, 460px);
}

.login-card h2 {
    margin: 0;
    color: var(--brand-950);
    font-size: clamp(2rem, 4vw, 2.75rem);
    letter-spacing: -0.035em;
    line-height: 1.1;
}

.muted {
    color: var(--ink-500);
}

.login-card > .muted {
    margin: 12px 0 30px;
}

.mobile-brand {
    display: none;
}

.auth-form {
    display: grid;
    gap: 20px;
}

.field {
    display: grid;
    gap: 7px;
}

.field label {
    color: var(--ink-700);
    font-size: 0.9rem;
    font-weight: 670;
}

.field input {
    width: 100%;
    min-height: 50px;
    padding: 12px 14px;
    border: 1px solid #c9d4dd;
    border-radius: var(--radius-sm);
    outline: none;
    background: var(--surface);
    color: var(--ink-900);
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field input:focus {
    border-color: var(--brand-800);
    box-shadow: 0 0 0 3px rgba(62, 96, 129, 0.15);
}

.password-field {
    position: relative;
}

.password-field input {
    padding-right: 86px;
}

.password-toggle {
    position: absolute;
    top: 50%;
    right: 13px;
    transform: translateY(-50%);
}

.text-button {
    padding: 2px;
    border: 0;
    background: transparent;
    color: var(--brand-800);
    font-size: 0.84rem;
    font-weight: 730;
}

.text-button:hover {
    color: var(--brand-950);
    text-decoration: underline;
}

.button {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-weight: 720;
    transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.button:not(:disabled):active {
    transform: translateY(1px);
}

.button--primary {
    min-height: 52px;
    background: var(--brand-900);
    color: #ffffff;
}

.button--primary:hover {
    background: var(--brand-950);
}

.button--secondary {
    border-color: var(--line);
    background: var(--surface);
    color: var(--brand-900);
}

.button--secondary:hover {
    border-color: #b6c5d0;
    background: var(--brand-50);
}

.button--ghost {
    background: transparent;
    color: var(--ink-700);
}

.button--ghost:hover {
    background: var(--brand-50);
    color: var(--brand-950);
}

.form-error {
    margin: 0;
    padding: 11px 13px;
    border: 1px solid #f4c7c3;
    border-radius: var(--radius-sm);
    background: var(--danger-bg);
    color: var(--danger);
    font-size: 0.88rem;
}

.security-note {
    margin: 24px 0 0;
    color: var(--ink-500);
    font-size: 0.78rem;
    text-align: center;
}

.app-shell {
    min-height: 100vh;
}

.topbar {
    position: sticky;
    z-index: 20;
    top: 0;
    display: flex;
    min-height: 76px;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 10px clamp(20px, 5vw, 72px);
    border-bottom: 1px solid rgba(220, 228, 234, 0.9);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(14px);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 18px;
    color: var(--brand-950);
    font-weight: 730;
    text-decoration: none;
}

.topbar-brand img {
    width: 124px;
    height: 48px;
    object-fit: contain;
}

.topbar-brand span {
    padding-left: 18px;
    border-left: 1px solid var(--line);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-summary {
    display: grid;
    margin-right: 14px;
    text-align: right;
}

.user-summary strong {
    color: var(--brand-950);
    font-size: 0.9rem;
}

.user-summary span {
    color: var(--ink-500);
    font-size: 0.75rem;
}

.dashboard {
    width: min(100% - 36px, 1220px);
    margin: 0 auto;
    padding: 42px 0 54px;
}

.welcome-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 28px;
    margin-bottom: 24px;
}

.welcome-card h1 {
    margin: 0;
    color: var(--brand-950);
    font-size: clamp(1.8rem, 4vw, 2.65rem);
    letter-spacing: -0.04em;
}

.welcome-card .muted {
    margin: 8px 0 0;
}

.referral-code-card {
    display: grid;
    min-width: 230px;
    gap: 2px;
    justify-items: end;
    padding: 16px 18px;
    border: 1px solid #cad9e5;
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.referral-code-card > span {
    color: var(--ink-500);
    font-size: 0.74rem;
}

.referral-code-card strong {
    color: var(--brand-950);
    font-size: 1.2rem;
    letter-spacing: 0.06em;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 15px;
}

.metric-card,
.overview-card,
.content-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.metric-card {
    display: grid;
    min-height: 154px;
    align-content: space-between;
    padding: 20px;
}

.metric-card > span,
.metric-card small {
    color: var(--ink-500);
}

.metric-card > span {
    font-size: 0.8rem;
    font-weight: 670;
}

.metric-card strong {
    color: var(--brand-950);
    font-size: clamp(1.45rem, 2.6vw, 2rem);
    letter-spacing: -0.035em;
}

.metric-card small {
    font-size: 0.72rem;
}

.metric-card--featured {
    border-color: var(--brand-900);
    background: linear-gradient(145deg, var(--brand-950), var(--brand-900));
}

.metric-card--featured > span,
.metric-card--featured strong,
.metric-card--featured small {
    color: #ffffff;
}

.metric-card--featured small {
    color: rgba(255, 255, 255, 0.68);
}

.overview-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px;
    margin: 15px 0 24px;
}

.overview-card {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 18px 20px;
}

.overview-icon {
    display: grid;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    place-items: center;
    border-radius: 50%;
    background: var(--brand-100);
    color: var(--brand-900);
    font-weight: 800;
}

.overview-card > div {
    display: grid;
}

.overview-card strong {
    color: var(--brand-950);
    font-size: 1.45rem;
    line-height: 1.15;
}

.overview-card div span {
    color: var(--ink-500);
    font-size: 0.78rem;
}

.content-card {
    padding: 22px;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

.section-heading h2 {
    margin: 0;
    color: var(--brand-950);
    font-size: 1.2rem;
    letter-spacing: -0.02em;
}

.count-badge,
.status-badge {
    display: inline-flex;
    width: fit-content;
    align-items: center;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
}

.count-badge {
    padding: 6px 10px;
    background: var(--brand-50);
    color: var(--brand-800);
}

.status-badge {
    padding: 4px 8px;
    background: var(--brand-100);
    color: var(--brand-900);
}

.status-badge--success {
    background: var(--success-bg);
    color: var(--success);
}

.status-badge--warning {
    background: var(--warning-bg);
    color: var(--warning);
}

.status-badge--danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.table-scroll {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}

th,
td {
    padding: 13px 12px;
    border-top: 1px solid #e8edf1;
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--ink-500);
    font-size: 0.7rem;
    font-weight: 750;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

td {
    color: var(--ink-700);
}

td:first-child {
    color: var(--ink-900);
    font-weight: 660;
}

.two-column-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.activity-list {
    display: grid;
    margin: 0;
    padding: 0;
    list-style: none;
}

.activity-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 13px 0;
    border-top: 1px solid #e8edf1;
}

.activity-item:first-child {
    border-top: 0;
}

.activity-copy {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.activity-copy strong {
    overflow: hidden;
    color: var(--ink-900);
    font-size: 0.84rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.activity-copy span,
.activity-value small {
    color: var(--ink-500);
    font-size: 0.72rem;
}

.activity-value {
    display: grid;
    flex: 0 0 auto;
    justify-items: end;
    gap: 2px;
}

.activity-value strong {
    color: var(--brand-950);
    font-size: 0.9rem;
}

.empty-state {
    margin: 0;
    padding: 30px 16px;
    border-top: 1px solid #e8edf1;
    color: var(--ink-500);
    font-size: 0.84rem;
    text-align: center;
}

.alert {
    margin-bottom: 18px;
    padding: 12px 14px;
    border: 1px solid #f1cf8a;
    border-radius: var(--radius-sm);
    background: var(--warning-bg);
    color: #704d00;
    font-size: 0.86rem;
}

.alert--error {
    border-color: #f4c7c3;
    background: var(--danger-bg);
    color: var(--danger);
}

.toast {
    position: fixed;
    z-index: 80;
    right: 24px;
    bottom: 24px;
    max-width: min(360px, calc(100vw - 48px));
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--brand-950);
    color: #ffffff;
    box-shadow: var(--shadow-lg);
    font-size: 0.84rem;
}

.footer {
    display: flex;
    width: min(100% - 36px, 1220px);
    justify-content: space-between;
    gap: 24px;
    margin: 0 auto;
    padding: 0 0 28px;
    color: var(--ink-500);
    font-size: 0.72rem;
}

.section-heading-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.referral-new-button {
    min-height: 38px;
    padding: 8px 14px;
    font-size: 0.78rem;
}

.referral-form {
    margin: 2px 0 18px;
    padding: 18px;
    border: 1px solid #dbe4ea;
    border-radius: var(--radius-sm);
    background: #f8fafb;
}

.referral-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.referral-field {
    display: grid;
    gap: 7px;
}

.referral-field--wide {
    grid-column: 1 / -1;
}

.referral-field span {
    color: var(--ink-700);
    font-size: 0.75rem;
    font-weight: 700;
}

.referral-field input,
.referral-field select {
    width: 100%;
    min-height: 44px;
    padding: 9px 11px;
    border: 1px solid #cfd9e0;
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink-900);
    font: inherit;
}

.referral-field input:focus,
.referral-field select:focus {
    border-color: var(--brand-700);
    outline: 2px solid rgba(28, 75, 111, 0.12);
    outline-offset: 1px;
}

.referral-form-error {
    margin: 14px 0 0;
    color: var(--danger);
    font-size: 0.8rem;
}

.referral-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}


@media (max-width: 980px) {
    .login-shell {
        grid-template-columns: minmax(320px, 0.8fr) minmax(390px, 1.2fr);
    }

    .brand-panel {
        padding: 42px;
    }

    .brand-copy h1 {
        font-size: clamp(2.2rem, 5vw, 3.6rem);
    }

    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .topbar {
        position: static;
    }
}

@media (max-width: 760px) {
    .login-shell {
        display: block;
        background: var(--surface);
    }

    .brand-panel {
        display: none;
    }

    .login-main {
        min-height: 100vh;
        padding: 28px 22px;
    }

    .mobile-brand {
        display: block;
        margin-bottom: 44px;
    }

    .mobile-brand .brand-logo {
        width: 154px;
    }

    .topbar {
        align-items: flex-start;
        padding: 12px 18px;
    }

    .topbar-brand span,
    .user-summary,
    #refresh-button {
        display: none;
    }

    .topbar-brand img {
        width: 108px;
        height: 44px;
    }

    .dashboard {
        width: min(100% - 28px, 1220px);
        padding: 28px 0 40px;
    }

    .welcome-card {
        align-items: stretch;
        flex-direction: column;
    }

    .referral-code-card {
        min-width: 0;
        justify-items: start;
    }

    .metric-grid,
    .overview-grid,
    .two-column-grid {
        grid-template-columns: 1fr;
    }

    .footer {
        width: min(100% - 28px, 1220px);
    }
}

@media (max-width: 760px) {
    .section-heading-actions {
        align-items: flex-end;
        flex-direction: column;
    }

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

    .referral-field--wide {
        grid-column: auto;
    }

    .referral-form-actions {
        align-items: stretch;
        flex-direction: column-reverse;
    }

    .referral-form-actions .button {
        width: 100%;
    }
}


@media (max-width: 440px) {
    .metric-grid {
        grid-template-columns: 1fr;
    }

    .metric-card {
        min-height: 134px;
    }

    .topbar-actions {
        gap: 2px;
    }

    .button {
        padding-right: 12px;
        padding-left: 12px;
    }

    th,
    td {
        padding-right: 9px;
        padding-left: 9px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
