/* ============================================================
   KidsHustle Influencer Portal — shadcn/ui-inspired design system
   ============================================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Brand tokens */
    --kh-primary: #0066FF;
    --kh-primary-hover: #0052CC;
    --kh-surface: #FFFFFF;
    --kh-border: #E5E7EB;
    --kh-text: #111827;
    --kh-text-muted: #6B7280;
    --kh-success: #10B981;
    --kh-warning: #F59E0B;
    --kh-danger: #EF4444;

    /* Surfaces */
    --kh-bg: #F9FAFB;
    --kh-bg-subtle: #F3F4F6;
    --kh-border-hover: #D1D5DB;

    /* Shadows */
    --kh-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --kh-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --kh-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);

    /* Radius */
    --kh-radius: 8px;
    --kh-radius-lg: 12px;
    --kh-radius-full: 9999px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
    background: var(--kh-bg);
    color: var(--kh-text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---- Header ---- */
.portal-header {
    background: var(--kh-surface);
    border-bottom: 1px solid var(--kh-border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--kh-shadow-sm);
}

.portal-header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.portal-logo {
    height: 28px;
    width: auto;
    display: block;
}

.portal-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.portal-username {
    font-size: 0.8125rem;
    color: var(--kh-text-muted);
    font-weight: 500;
    margin-right: 0.25rem;
}

/* ---- Main content ---- */
.portal-main {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1.5rem;
    min-height: calc(100vh - 140px);
}

.page-header {
    margin-bottom: 2rem;
}

.page-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--kh-text);
    letter-spacing: -0.02em;
}

.page-header p {
    color: var(--kh-text-muted);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* ---- Login page ---- */
.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem 1rem;
    background: var(--kh-bg);
}

.login-logo {
    height: 36px;
    width: auto;
    margin-bottom: 2rem;
}

.login-card {
    background: var(--kh-surface);
    border: 1px solid var(--kh-border);
    border-radius: var(--kh-radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--kh-shadow-md);
}

.login-card h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--kh-text);
    margin-bottom: 0.25rem;
    letter-spacing: -0.02em;
}

.login-card p {
    font-size: 0.875rem;
    color: var(--kh-text-muted);
    margin-bottom: 1.5rem;
}

/* ---- KPI stat cards ---- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--kh-surface);
    border: 1px solid var(--kh-border);
    border-radius: var(--kh-radius-lg);
    padding: 1.25rem 1.5rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: var(--kh-shadow-sm);
}

.stat-card:hover {
    border-color: var(--kh-border-hover);
    box-shadow: var(--kh-shadow);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--kh-text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--kh-text);
    letter-spacing: -0.02em;
}

/* ---- Card / Section ---- */
.section {
    background: var(--kh-surface);
    border: 1px solid var(--kh-border);
    border-radius: var(--kh-radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--kh-shadow-sm);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--kh-text);
}

.section-subtitle {
    font-size: 0.8125rem;
    color: var(--kh-text-muted);
}

/* ---- Onboarding card ---- */
.onboarding-card {
    background: var(--kh-surface);
    border: 1px solid var(--kh-border);
    border-radius: var(--kh-radius-lg);
    padding: 2rem;
    max-width: 560px;
    margin: 0 auto;
    box-shadow: var(--kh-shadow);
}

.onboarding-card h3 {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    letter-spacing: -0.01em;
}

.onboarding-card p {
    font-size: 0.875rem;
    color: var(--kh-text-muted);
    margin-bottom: 1rem;
    line-height: 1.7;
}

/* Step indicator */
.step-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 2rem;
}

.step-indicator-item {
    display: flex;
    align-items: center;
    gap: 0;
}

.step-indicator-circle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 0.8125rem;
    font-weight: 700;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}

.step-indicator-circle.active {
    background: var(--kh-primary);
    color: #fff;
}

.step-indicator-circle.completed {
    background: var(--kh-success);
    color: #fff;
}

.step-indicator-circle.upcoming {
    background: var(--kh-bg-subtle);
    color: var(--kh-text-muted);
    border: 1px solid var(--kh-border);
}

.step-indicator-line {
    width: 48px;
    height: 2px;
    background: var(--kh-border);
    margin: 0 0.5rem;
}

.step-indicator-line.completed {
    background: var(--kh-success);
}

.step-indicator-label {
    display: block;
    font-size: 0.6875rem;
    color: var(--kh-text-muted);
    text-align: center;
    margin-top: 0.375rem;
    font-weight: 500;
}

.step-indicator-label.active {
    color: var(--kh-primary);
    font-weight: 600;
}

.step-indicator-col {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.onboarding-steps {
    list-style: none;
    margin-bottom: 1.5rem;
}

.onboarding-steps li {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.625rem 0;
    font-size: 0.875rem;
    color: var(--kh-text-muted);
    border-bottom: 1px solid var(--kh-border);
}

.onboarding-steps li:last-child {
    border-bottom: none;
}

.step-num {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--kh-primary);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 1px;
}

/* ---- Status pills / badges ---- */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.75rem;
    border-radius: var(--kh-radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    letter-spacing: 0.01em;
}

.status-pill.pending {
    background: #FEF3C7;
    color: #92400E;
    border: 1px solid #FDE68A;
}

.status-pill.complete {
    background: #D1FAE5;
    color: #065F46;
    border: 1px solid #A7F3D0;
}

.status-pill.active {
    background: #DBEAFE;
    color: #1E40AF;
    border: 1px solid #BFDBFE;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* Code pill badge */
.code-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    background: var(--kh-bg-subtle);
    border: 1px solid var(--kh-border);
    border-radius: var(--kh-radius);
    font-family: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, Monaco, Consolas, monospace;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--kh-text);
    letter-spacing: 0.02em;
}

/* ---- Buttons ---- */
.btn {
    padding: 0.5rem 1rem;
    border-radius: var(--kh-radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    cursor: pointer;
    border: 1px solid transparent;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
    font-family: inherit;
    text-decoration: none;
    line-height: 1.4;
}

.btn-primary {
    background: var(--kh-primary);
    color: #fff;
    border-color: var(--kh-primary);
    box-shadow: var(--kh-shadow-sm);
}

.btn-primary:hover {
    background: var(--kh-primary-hover);
    border-color: var(--kh-primary-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--kh-surface);
    color: var(--kh-text);
    border-color: var(--kh-border);
    box-shadow: var(--kh-shadow-sm);
}

.btn-secondary:hover {
    background: var(--kh-bg-subtle);
    border-color: var(--kh-border-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--kh-text-muted);
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--kh-bg-subtle);
    color: var(--kh-text);
}

.btn-sm {
    padding: 0.3125rem 0.625rem;
    font-size: 0.75rem;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    padding: 0.375rem;
    width: 32px;
    height: 32px;
}

/* ---- Forms ---- */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
    color: var(--kh-text);
    font-size: 0.8125rem;
}

.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--kh-border);
    border-radius: var(--kh-radius);
    font-size: 0.875rem;
    font-family: inherit;
    background: var(--kh-surface);
    color: var(--kh-text);
    transition: border-color 0.15s, box-shadow 0.15s;
    box-shadow: var(--kh-shadow-sm);
}

.form-control::placeholder {
    color: var(--kh-text-muted);
    opacity: 0.6;
}

.form-control:focus {
    outline: none;
    border-color: var(--kh-primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.1);
}

/* ---- Banners ---- */
.error-banner {
    background: #FEF2F2;
    color: var(--kh-danger);
    padding: 0.75rem 1rem;
    border-radius: var(--kh-radius);
    margin-bottom: 1rem;
    border: 1px solid #FECACA;
    font-size: 0.8125rem;
    display: none;
    font-weight: 500;
}

.warning-banner {
    background: #FFFBEB;
    color: #92400E;
    padding: 0.75rem 1rem;
    border-radius: var(--kh-radius);
    margin-bottom: 1.5rem;
    border: 1px solid #FDE68A;
    font-size: 0.8125rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

/* ---- Per-code cards ---- */
.code-card {
    display: grid;
    grid-template-columns: minmax(120px, 1.2fr) repeat(4, 1fr) minmax(140px, auto);
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--kh-border);
    transition: background 0.15s;
}

.code-card:last-child {
    border-bottom: none;
}

.code-card:hover {
    background: var(--kh-bg);
}

.code-card-header {
    display: grid;
    grid-template-columns: minmax(120px, 1.2fr) repeat(4, 1fr) minmax(140px, auto);
    gap: 1rem;
    padding: 0 1.25rem 0.75rem;
    border-bottom: 1px solid var(--kh-border);
}

.code-card-header span {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--kh-text-muted);
}

.code-card-value {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--kh-text);
}

.code-card-label {
    font-size: 0.6875rem;
    color: var(--kh-text-muted);
    display: none;
}

.copy-btn {
    background: var(--kh-bg-subtle);
    border: 1px solid var(--kh-border);
    border-radius: var(--kh-radius);
    padding: 0.3125rem 0.5rem;
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--kh-text-muted);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}

.copy-btn:hover {
    background: var(--kh-border);
    color: var(--kh-text);
}

.copy-btn.copied {
    background: #D1FAE5;
    color: #065F46;
    border-color: #A7F3D0;
}

/* ---- Chart section ---- */
.chart-container {
    position: relative;
    height: 280px;
    width: 100%;
}

/* ---- Recent attributions timeline ---- */
.timeline-list {
    list-style: none;
}

.timeline-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--kh-border);
    font-size: 0.8125rem;
}

.timeline-item:last-child {
    border-bottom: none;
}

.timeline-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--kh-primary);
    flex-shrink: 0;
    margin-top: 0.375rem;
}

.timeline-dot.paid {
    background: var(--kh-success);
}

.timeline-dot.pending {
    background: var(--kh-warning);
}

.timeline-content {
    flex: 1;
    min-width: 0;
}

.timeline-text {
    color: var(--kh-text);
    line-height: 1.5;
}

.timeline-text strong {
    font-weight: 600;
}

.timeline-meta {
    color: var(--kh-text-muted);
    font-size: 0.75rem;
    margin-top: 0.125rem;
}

/* ---- Table (legacy compat) ---- */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table th {
    text-align: left;
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--kh-border);
    font-weight: 600;
    color: var(--kh-text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--kh-border);
    color: var(--kh-text);
    vertical-align: middle;
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover td {
    background: var(--kh-bg);
}

.alert-warning {
    background: #FFFBEB;
    border: 1px solid var(--kh-warning);
    border-radius: var(--kh-radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: #92400E;
}

.no-results {
    text-align: center;
    padding: 3rem;
    color: var(--kh-text-muted);
    font-size: 0.875rem;
}

.loading {
    text-align: center;
    padding: 3rem;
    color: var(--kh-text-muted);
    font-size: 0.875rem;
}

/* ---- Help sidebar ---- */
.help-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 200;
    backdrop-filter: blur(2px);
}

.help-overlay.open {
    display: block;
}

.help-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 340px;
    height: 100vh;
    background: var(--kh-surface);
    border-left: 1px solid var(--kh-border);
    z-index: 300;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
}

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

.help-sidebar-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--kh-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.help-sidebar-header h3 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--kh-text);
}

.help-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--kh-text-muted);
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    font-family: inherit;
    border-radius: var(--kh-radius);
    transition: background 0.15s;
}

.help-close:hover {
    background: var(--kh-bg-subtle);
    color: var(--kh-text);
}

.help-sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 1rem;
}

.help-section {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--kh-border);
}

.help-section:last-child {
    border-bottom: none;
}

.help-section h4 {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--kh-text);
    margin-bottom: 0.5rem;
}

.help-section p,
.help-section li {
    font-size: 0.8125rem;
    color: var(--kh-text-muted);
    line-height: 1.65;
}

.help-section ul {
    padding-left: 1.25rem;
    margin-top: 0.25rem;
}

.help-section li {
    margin-bottom: 0.25rem;
}

.help-sidebar-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--kh-border);
    flex-shrink: 0;
    font-size: 0.8125rem;
    color: var(--kh-text-muted);
}

.support-link {
    color: var(--kh-primary);
    font-weight: 500;
    font-size: 0.8125rem;
    text-decoration: none;
}

.support-link:hover {
    text-decoration: underline;
}

/* ---- Footer ---- */
.portal-footer {
    text-align: center;
    padding: 2rem 1.5rem;
    color: var(--kh-text-muted);
    font-size: 0.75rem;
    border-top: 1px solid var(--kh-border);
    margin-top: 3rem;
    background: var(--kh-surface);
}

/* ---- Dashboard grid layout ---- */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.dashboard-grid-full {
    grid-column: 1 / -1;
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .portal-main {
        padding: 0 1rem;
        margin: 1.25rem auto;
    }

    .portal-header-inner {
        padding: 0 1rem;
    }

    .portal-username {
        display: none;
    }

    .stat-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .stat-card {
        padding: 1rem 1.25rem;
    }

    .stat-value {
        font-size: 1.375rem;
    }

    .help-sidebar {
        width: 100%;
    }

    .code-card-header {
        display: none;
    }

    .code-card {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 1rem 1.25rem;
    }

    .code-card > div {
        display: flex;
        align-items: center;
        gap: 0.375rem;
    }

    .code-card-label {
        display: inline;
        margin-right: 0.25rem;
    }

    .chart-container {
        height: 220px;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

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

    .login-card {
        padding: 1.5rem;
    }

    .step-indicator-line {
        width: 24px;
    }
}
