/**
 * Capital Razors — Base Styles
 * ============================
 * Global resets, typography, and layout shell styles.
 * Uses design tokens from cr-design-tokens.css.
 *
 * Sprint: Sprint-0000200-CR-Foundation-Auth
 * BLI: BLI-0002006
 */

/* ─── Reset & Base ─── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--cr-font-body);
    background-color: var(--cr-bg-primary);
    color: var(--cr-text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

/* ─── Typography ─── */
h1, h2, h3, h4 {
    font-family: var(--cr-font-heading);
    font-weight: var(--cr-weight-semibold);
    line-height: 1.25;
    color: var(--cr-text-primary);
}

h1 { font-size: var(--cr-text-3xl); }
h2 { font-size: var(--cr-text-2xl); }
h3 { font-size: var(--cr-text-xl); }
h4 { font-size: var(--cr-text-lg); }

p {
    font-size: var(--cr-text-base);
    color: var(--cr-text-secondary);
    line-height: 1.6;
}

a {
    color: var(--cr-gold);
    text-decoration: none;
    transition: color var(--cr-transition-fast);
}

a:hover {
    color: var(--cr-gold-light);
}

/* ─── App Shell ─── */
.cr-app {
    display: flex;
    min-height: 100vh;
}

/* ─── Sidebar ─── */
.cr-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--cr-sidebar-width);
    background: var(--cr-bg-sidebar);
    border-right: 1px solid var(--cr-border);
    display: flex;
    flex-direction: column;
    z-index: var(--cr-z-sidebar);
    transition: transform var(--cr-transition-base);
}

.cr-sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--cr-space-3);
    padding: var(--cr-space-5) var(--cr-space-5);
    border-bottom: 1px solid var(--cr-border);
    text-decoration: none;
}

.cr-sidebar__logo {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--cr-gold), var(--cr-gold-dark));
    border-radius: var(--cr-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--cr-font-heading);
    font-weight: var(--cr-weight-bold);
    font-size: var(--cr-text-lg);
    color: var(--cr-text-inverse);
    flex-shrink: 0;
}

.cr-sidebar__title {
    font-family: var(--cr-font-heading);
    font-weight: var(--cr-weight-bold);
    font-size: var(--cr-text-lg);
    color: var(--cr-gold);
    line-height: 1.2;
}

.cr-sidebar__subtitle {
    font-family: var(--cr-font-body);
    font-size: var(--cr-text-xs);
    color: var(--cr-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* Navigation */
.cr-sidebar__nav {
    flex: 1;
    padding: var(--cr-space-4) 0;
    overflow-y: auto;
}

.cr-sidebar__section-label {
    padding: var(--cr-space-2) var(--cr-space-5);
    font-size: var(--cr-text-xs);
    font-weight: var(--cr-weight-semibold);
    color: var(--cr-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-top: var(--cr-space-4);
}

.cr-sidebar__section-label:first-child {
    margin-top: 0;
}

.cr-sidebar__link {
    display: flex;
    align-items: center;
    gap: var(--cr-space-3);
    padding: var(--cr-space-2) var(--cr-space-5);
    margin: 1px var(--cr-space-2);
    font-size: var(--cr-text-sm);
    font-weight: var(--cr-weight-medium);
    color: var(--cr-text-secondary);
    border-radius: var(--cr-radius-md);
    transition: all var(--cr-transition-fast);
    text-decoration: none;
}

.cr-sidebar__link:hover {
    background: var(--cr-bg-card);
    color: var(--cr-text-primary);
}

.cr-sidebar__link--active {
    background: var(--cr-gold-dim);
    color: var(--cr-gold);
}

.cr-sidebar__link--active:hover {
    background: var(--cr-gold-dim);
    color: var(--cr-gold-light);
}

.cr-sidebar__icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.7;
}

.cr-sidebar__link--active .cr-sidebar__icon {
    opacity: 1;
}

/* Sidebar footer */
.cr-sidebar__footer {
    padding: var(--cr-space-4) var(--cr-space-5);
    border-top: 1px solid var(--cr-border);
}

.cr-sidebar__user {
    display: flex;
    align-items: center;
    gap: var(--cr-space-3);
}

.cr-sidebar__avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--cr-radius-full);
    background: var(--cr-gold-dim);
    border: 1px solid var(--cr-border-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--cr-text-xs);
    font-weight: var(--cr-weight-bold);
    color: var(--cr-gold);
    flex-shrink: 0;
}

.cr-sidebar__user-name {
    font-size: var(--cr-text-sm);
    font-weight: var(--cr-weight-medium);
    color: var(--cr-text-primary);
    line-height: 1.2;
}

.cr-sidebar__user-role {
    font-size: var(--cr-text-xs);
    color: var(--cr-text-muted);
}

/* ─── Header ─── */
.cr-header {
    position: fixed;
    top: 0;
    left: var(--cr-sidebar-width);
    right: 0;
    height: var(--cr-header-height);
    background: var(--cr-bg-header);
    border-bottom: 1px solid var(--cr-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--cr-space-6);
    z-index: var(--cr-z-header);
}

.cr-header__left {
    display: flex;
    align-items: center;
    gap: var(--cr-space-4);
}

.cr-header__mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--cr-text-secondary);
    cursor: pointer;
    padding: var(--cr-space-2);
}

.cr-header__page-title {
    font-family: var(--cr-font-body);
    font-size: var(--cr-text-md);
    font-weight: var(--cr-weight-semibold);
    color: var(--cr-text-primary);
}

.cr-header__right {
    display: flex;
    align-items: center;
    gap: var(--cr-space-4);
}

/* ─── Main Content ─── */
.cr-main {
    flex: 1;
    margin-left: var(--cr-sidebar-width);
    margin-top: var(--cr-header-height);
    padding: var(--cr-space-6);
    min-height: calc(100vh - var(--cr-header-height));
}

.cr-main__content {
    max-width: var(--cr-content-max-width);
    margin: 0 auto;
}

/* ─── Cards ─── */
.cr-card {
    background: var(--cr-bg-card);
    border: 1px solid var(--cr-border);
    border-radius: var(--cr-radius-lg);
    padding: var(--cr-space-6);
    transition: border-color var(--cr-transition-fast);
}

.cr-card:hover {
    border-color: var(--cr-border-gold);
}

.cr-card--gold {
    border-color: var(--cr-border-gold);
    box-shadow: var(--cr-shadow-gold);
}

.cr-card__title {
    font-family: var(--cr-font-heading);
    font-size: var(--cr-text-xl);
    font-weight: var(--cr-weight-semibold);
    color: var(--cr-text-primary);
    margin-bottom: var(--cr-space-2);
}

.cr-card__subtitle {
    font-size: var(--cr-text-sm);
    color: var(--cr-text-muted);
}

/* ─── Buttons ─── */
.cr-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--cr-space-2);
    padding: var(--cr-space-2) var(--cr-space-5);
    font-family: var(--cr-font-body);
    font-size: var(--cr-text-sm);
    font-weight: var(--cr-weight-medium);
    border-radius: var(--cr-radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--cr-transition-fast);
    text-decoration: none;
    line-height: 1.5;
}

.cr-btn--primary {
    background: var(--cr-gold);
    color: var(--cr-text-inverse);
    border-color: var(--cr-gold);
}

.cr-btn--primary:hover {
    background: var(--cr-gold-light);
    border-color: var(--cr-gold-light);
    color: var(--cr-text-inverse);
}

.cr-btn--secondary {
    background: transparent;
    color: var(--cr-text-secondary);
    border-color: var(--cr-border);
}

.cr-btn--secondary:hover {
    border-color: var(--cr-border-gold);
    color: var(--cr-text-primary);
}

.cr-btn--ghost {
    background: transparent;
    color: var(--cr-gold);
    border: none;
    padding: var(--cr-space-2) var(--cr-space-3);
}

.cr-btn--ghost:hover {
    background: var(--cr-gold-dim);
}

/* ─── Family-First Mode Banner (BLI-0002036) ─── */
.cr-ffm-banner {
    margin-bottom: var(--cr-space-5);
}

.cr-ffm-banner__inner {
    display: flex;
    align-items: center;
    gap: var(--cr-space-5);
    padding: var(--cr-space-4) var(--cr-space-5);
    background: linear-gradient(135deg, rgba(201, 168, 76, 0.12) 0%, rgba(201, 168, 76, 0.06) 100%);
    border: 1px solid var(--cr-border-gold);
    border-radius: var(--cr-radius-lg);
    position: relative;
}

.cr-ffm-banner__left {
    display: flex;
    align-items: center;
    gap: var(--cr-space-3);
    flex-shrink: 0;
}

.cr-ffm-banner__icon {
    width: 36px;
    height: 36px;
    border-radius: var(--cr-radius-full);
    background: var(--cr-gold-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cr-gold);
    flex-shrink: 0;
}

.cr-ffm-banner__title {
    font-family: var(--cr-font-heading);
    font-size: var(--cr-text-md);
    font-weight: var(--cr-weight-semibold);
    color: var(--cr-gold);
    line-height: 1.2;
}

.cr-ffm-banner__subtitle {
    font-size: var(--cr-text-xs);
    color: var(--cr-text-secondary);
    line-height: 1.4;
}

.cr-ffm-banner__progress-wrap {
    flex: 1;
    min-width: 0;
}

.cr-ffm-banner__amounts {
    display: flex;
    align-items: baseline;
    gap: var(--cr-space-1);
    font-size: var(--cr-text-sm);
    margin-bottom: var(--cr-space-1);
}

.cr-ffm-banner__bar {
    width: 100%;
    height: 6px;
    background: var(--cr-bg-card);
    border-radius: var(--cr-radius-full);
    overflow: hidden;
}

.cr-ffm-banner__bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--cr-gold-dark), var(--cr-gold), var(--cr-gold-light));
    border-radius: var(--cr-radius-full);
    transition: width var(--cr-transition-slow);
}

.cr-ffm-banner__remaining {
    font-size: var(--cr-text-xs);
    color: var(--cr-text-muted);
    margin-top: 2px;
}

.cr-ffm-banner__close {
    position: absolute;
    top: var(--cr-space-2);
    right: var(--cr-space-2);
    background: none;
    border: none;
    color: var(--cr-text-muted);
    cursor: pointer;
    padding: var(--cr-space-1);
    border-radius: var(--cr-radius-sm);
    transition: color var(--cr-transition-fast), background var(--cr-transition-fast);
    line-height: 0;
}

.cr-ffm-banner__close:hover {
    color: var(--cr-text-primary);
    background: rgba(255, 255, 255, 0.06);
}

/* Responsive: stack vertically on mobile */
@media (max-width: 639px) {
    .cr-ffm-banner__inner {
        flex-direction: column;
        align-items: stretch;
        gap: var(--cr-space-3);
        padding-right: var(--cr-space-8);
    }
}

/* ─── Loading State ─── */
.cr-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--cr-space-12);
}

.cr-loading__spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--cr-border);
    border-top-color: var(--cr-gold);
    border-radius: var(--cr-radius-full);
    animation: cr-spin 0.8s linear infinite;
}

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

/* ─── Mobile Overlay ─── */
.cr-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--cr-bg-overlay);
    z-index: calc(var(--cr-z-sidebar) - 1);
}

/* ─── Responsive: Tablet & Below ─── */
@media (max-width: 1023px) {
    .cr-sidebar {
        transform: translateX(-100%);
    }

    .cr-sidebar.cr-sidebar--open {
        transform: translateX(0);
    }

    .cr-sidebar-overlay.cr-sidebar-overlay--visible {
        display: block;
    }

    .cr-header {
        left: 0;
    }

    .cr-header__mobile-toggle {
        display: flex;
    }

    .cr-main {
        margin-left: 0;
    }
}

/* ─── Responsive: Mobile ─── */
@media (max-width: 639px) {
    .cr-main {
        padding: var(--cr-space-4);
    }

    .cr-header {
        padding: 0 var(--cr-space-4);
    }

    .cr-card {
        padding: var(--cr-space-4);
    }
}
