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

:root {
    --sage: #3C7A5E;
    --sage-deep: #2C5F4D;
    --sage-light: #4A9471;
    --sage-bg: #E8F3ED;
    --sage-border: #B8D8C8;
    --cream: #FFFBF5;
    --cream-dark: #F5EDE3;
    --text: #2D2A26;
    --text-secondary: #5C574F;
    --warm-gray: #8A8578;
    --white: #FFFFFF;
    --border: #E5DDD3;
    --red: #C4524A;
    --red-bg: #FFF5F3;
    --yellow-bg: #FFFBEB;
    --yellow-border: #E8C88A;
    --radius: 16px;
    --shadow: 0 2px 12px rgba(60,122,94,0.08);
    --shadow-lg: 0 12px 40px rgba(60,122,94,0.12);
}

body {
    font-family: 'Poppins', sans-serif;
    background: linear-gradient(135deg, var(--cream) 0%, #E8F3ED 100%);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Header */
.header {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 8px rgba(60,122,94,0.06);
}
.header-logo {
    font-family: 'Crimson Pro', serif;
    font-size: 22px;
    font-weight: 600;
    color: var(--sage);
}
.header-logo span { font-family: 'Poppins', sans-serif; font-weight: 300; color: var(--warm-gray); margin-left: 8px; font-size: 13px; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.header-user { font-size: 13px; color: var(--text-secondary); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-family: 'Poppins', sans-serif;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-primary { background: var(--sage); color: var(--white); }
.btn-primary:hover { background: var(--sage-light); box-shadow: 0 4px 12px rgba(60,122,94,0.2); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--sage); color: var(--sage); background: var(--sage-bg); }
.btn-danger { background: transparent; border: 1px solid var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red-bg); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-full { width: 100%; justify-content: center; }
.btn-full-mt { width: 100%; justify-content: center; margin-top: 8px; }

/* Views */
.view { display: none; max-width: 1000px; margin: 0 auto; padding: 32px 24px; }
.view.active { display: block; }

/* 2-column card grid on wide screens */
.client-card-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 1200px) {
    .client-card-grid { grid-template-columns: 1fr 1fr; }
}

/* Login */
.login-container {
    max-width: 440px;
    margin: 80px auto;
    padding: 44px;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}
.login-container h1 {
    font-family: 'Crimson Pro', serif;
    font-size: 26px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 4px;
    color: var(--sage);
}
.login-container p { text-align: center; color: var(--text-secondary); font-size: 14px; margin-bottom: 28px; }

/* Logo wordmark */
.portal-wordmark {
    text-align: center;
    margin-bottom: 28px;
}
.portal-wordmark .wordmark-text {
    font-size: 32px;
    letter-spacing: -0.5px;
}
.portal-wordmark .wordmark-simply {
    font-family: 'Crimson Pro', serif;
    font-style: italic;
    font-weight: 400;
    color: var(--warm-gray);
}
.portal-wordmark .wordmark-here {
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
    color: var(--sage-deep);
}

/* Site nav (marketing-style) */
.site-nav {
    padding: 1rem 2rem;
    background: rgba(255,251,245,0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(60,122,90,0.08);
}
.site-nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.site-nav-logo {
    font-size: 1.5rem;
    text-decoration: none;
    line-height: 1;
}
.site-nav-logo .wordmark-simply {
    font-family: 'Crimson Pro', serif;
    font-style: italic;
    font-weight: 400;
    color: var(--warm-gray);
}
.site-nav-logo .wordmark-here {
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
    color: var(--sage-deep);
}
.site-nav-links {
    display: flex;
    align-items: center;
    gap: 2rem;
    list-style: none;
}
.site-nav-links a {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.3s;
}
.site-nav-links a:hover { color: var(--sage); }
.site-nav-links a.active {
    color: var(--sage);
    font-weight: 600;
}

/* Empty field placeholder */
.detail-empty {
    font-size: 14px;
    color: var(--warm-gray);
    font-style: italic;
}

/* Progress metric cards */
.progress-section { margin-top: 24px; }
.progress-section .section-title { border-bottom-color: var(--sage-border); }
.metric-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.metric-card {
    background: var(--cream);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid var(--border);
}
.metric-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--warm-gray);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.metric-value {
    font-family: 'Crimson Pro', serif;
    font-size: 28px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
}
.metric-value .metric-unit {
    font-size: 14px;
    font-weight: 400;
    color: var(--warm-gray);
    font-family: 'Poppins', sans-serif;
}
.metric-trend {
    font-size: 12px;
    margin-top: 2px;
}
.metric-trend.improving { color: var(--sage); }
.metric-trend.worsening { color: var(--red); }
.progress-empty {
    text-align: center;
    padding: 32px 20px;
    color: var(--warm-gray);
    font-size: 14px;
}

/* Forms */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text); }
.form-group input, .form-group textarea, .form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    transition: border-color 0.2s;
    background: var(--white);
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
    outline: none;
    border-color: var(--sage);
    box-shadow: 0 0 0 3px rgba(60,122,94,0.1);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 12px; color: var(--warm-gray); margin-top: 4px; }

/* Chips for focus areas */
.chip-container { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--text-secondary);
    user-select: none;
}
.chip.selected { background: var(--sage-bg); border-color: var(--sage); color: var(--sage); font-weight: 500; }
.chip:hover { border-color: var(--sage-light); }

/* Coping strategies tag input */
.tag-input-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    min-height: 44px;
    cursor: text;
    transition: border-color 0.2s;
}
.tag-input-wrapper:focus-within { border-color: var(--sage); box-shadow: 0 0 0 3px rgba(60,122,94,0.1); }
.tag-input-wrapper input { border: none; outline: none; flex: 1; min-width: 120px; font-family: inherit; font-size: 14px; padding: 2px 4px; }
.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--sage-bg);
    border: 1px solid var(--sage-border);
    border-radius: 16px;
    font-size: 13px;
    color: var(--sage);
}
.tag-remove { cursor: pointer; font-size: 16px; line-height: 1; margin-left: 2px; }

/* Cards */
.card {
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 20px;
    margin-bottom: 12px;
    transition: box-shadow 0.2s;
    cursor: pointer;
}
.card:hover { box-shadow: var(--shadow); }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-name { font-family: 'Crimson Pro', serif; font-size: 18px; font-weight: 600; color: var(--text); }
.card-meta { font-size: 12px; color: var(--warm-gray); }
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}
.badge-linked { background: var(--sage-bg); color: var(--sage); }
.badge-pending { background: var(--yellow-bg); color: #92400E; border: 1px solid var(--yellow-border); }

.focus-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.focus-tag {
    padding: 3px 10px;
    background: var(--cream-dark);
    border-radius: 12px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* Page header */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.page-header h2 { font-family: 'Crimson Pro', serif; font-size: 26px; font-weight: 600; color: var(--text); }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--warm-gray);
}
.empty-state h3 { font-family: 'Crimson Pro', serif; font-size: 20px; color: var(--text); margin-bottom: 8px; }

/* Success / invite code display */
.success-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    padding: 44px;
    text-align: center;
    max-width: 480px;
    margin: 40px auto;
}
.success-card h2 { font-family: 'Crimson Pro', serif; color: var(--sage); margin-bottom: 12px; font-size: 24px; }
.invite-code-display {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--sage);
    background: var(--sage-bg);
    border: 2px dashed var(--sage-border);
    padding: 20px;
    border-radius: var(--radius);
    margin: 24px 0;
    font-family: 'Courier New', monospace;
    cursor: pointer;
    position: relative;
}
.invite-code-display:hover::after {
    content: 'Click to copy';
    position: absolute;
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: var(--warm-gray);
    font-family: 'Poppins', sans-serif;
    letter-spacing: 0;
    font-weight: 400;
}
.success-instructions {
    text-align: left;
    background: var(--cream);
    border-radius: 12px;
    padding: 16px;
    margin: 20px 0;
    font-size: 14px;
    line-height: 1.8;
}
.success-instructions li { margin-left: 20px; color: var(--text-secondary); }

/* Alert */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
}
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid #F5CDC9; }
.alert-success { background: var(--sage-bg); color: var(--sage); border: 1px solid var(--sage-border); }
.alert-info { background: var(--sage-bg); border-color: var(--sage-border); color: var(--sage); }

/* Loading */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--white);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
.spinner-dark { border-color: var(--sage); border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Utility classes */
.hidden { display: none; }
.text-center { text-align: center; }
.loading-center { text-align: center; padding: 40px; }
.edit-form-padded { padding: 20px; }
.section-card { background: var(--white); border-radius: var(--radius); border: 1px solid var(--border); padding: 24px; margin-bottom: 16px; }
.section-title { font-family: 'Crimson Pro', serif; font-size: 18px; font-weight: 600; color: var(--sage); margin-bottom: 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.detail-label { font-size: 13px; font-weight: 500; color: var(--warm-gray); margin-bottom: 4px; }
.detail-value { font-size: 14px; }
.detail-edited { color: var(--warm-gray); font-size: 12px; font-style: italic; }
.detail-removed { color: var(--red); font-size: 12px; font-style: italic; }
.detail-footer { display: flex; gap: 16px; font-size: 12px; color: var(--warm-gray); border-top: 1px solid var(--border); padding-top: 16px; }
.detail-grid { display: grid; gap: 20px; }
.action-row { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }
.action-row-header { display: flex; gap: 8px; }
.copy-feedback { font-size: 13px; color: var(--sage); min-height: 20px; }
.register-link { text-align: center; margin-top: 20px; font-size: 14px; color: var(--text-secondary); }
.register-link a { color: var(--sage); text-decoration: none; font-weight: 600; }
.twofa-step { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--border); }
.twofa-title { font-family: 'Crimson Pro', serif; font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.twofa-subtitle { font-size: 14px; color: var(--text-secondary); margin-bottom: 16px; }
.twofa-code-input { text-align: center; font-size: 24px; letter-spacing: 8px; font-weight: 600; }
.resend-link { text-align: center; margin-top: 12px; }
.resend-link a { color: var(--sage); font-size: 14px; text-decoration: none; }
.empty-btn-mt { margin-top: 16px; }
.mb-12 { margin-bottom: 12px; }

/* Responsive */
@media (max-width: 768px) {
    .site-nav-links { display: none; }
    .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .metric-value { font-size: 22px; }
}
@media (max-width: 640px) {
    .header {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 8px;
    }
    .header-logo { font-size: 18px; }
    .header-logo span { font-size: 11px; margin-left: 6px; }
    .header-actions {
        gap: 6px;
        flex-wrap: wrap;
    }
    .header-actions .btn-sm {
        padding: 5px 10px;
        font-size: 12px;
    }
    .header-user { font-size: 12px; }
    .view { padding: 20px 16px; }
    .login-container {
        margin: 32px 12px;
        padding: 28px 20px;
    }
    .portal-wordmark .wordmark-text { font-size: 26px; }
    .login-container h1 { font-size: 22px; }
    .page-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
    .page-header h2 { font-size: 22px; }
    .action-row-header {
        flex-wrap: wrap;
        gap: 6px;
    }
    .action-row {
        flex-direction: column;
        gap: 8px;
    }
    .action-row .btn {
        width: 100%;
        justify-content: center;
    }
    .section-card { padding: 18px 16px; }
    .section-title { font-size: 16px; }
    .card { padding: 16px; }
    .card-name { font-size: 16px; }
    .success-card {
        padding: 28px 20px;
        margin: 24px auto;
    }
    .success-card h2 { font-size: 20px; }
    .invite-code-display {
        font-size: 20px;
        padding: 16px;
        letter-spacing: 1px;
    }
    .invite-code-display:hover::after { display: none; }
    .success-instructions { padding: 14px; font-size: 13px; }
    .twofa-title { font-size: 16px; }
    .twofa-code-input { font-size: 20px; letter-spacing: 6px; }
    .empty-state { padding: 40px 16px; }
    .empty-state h3 { font-size: 18px; }
    .chip { padding: 5px 12px; font-size: 12px; }
    .detail-footer {
        flex-direction: column;
        gap: 8px;
    }
}

@media (max-width: 390px) {
    .header-actions .btn-sm { padding: 4px 8px; font-size: 11px; }
    .login-container {
        margin: 24px 8px;
        padding: 24px 16px;
    }
    .portal-wordmark .wordmark-text { font-size: 24px; }
    .login-container h1 { font-size: 20px; }
    .view { padding: 16px 12px; }
    .invite-code-display { font-size: 18px; padding: 14px; }
}

/* Magic link box (success view) */
.magic-link-box {
    background: var(--sage-pale, #E8F3ED);
    border: 2px dashed var(--sage);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    margin: 1rem 0 0.5rem;
    text-align: center;
}
.magic-link-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.magic-link-url {
    font-size: 13px;
    font-weight: 500;
    color: var(--sage-deep);
    word-break: break-all;
    margin-bottom: 8px;
}
.invite-code-fallback {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 1rem;
}
.invite-code-inline {
    font-weight: 600;
    color: var(--sage-deep);
    letter-spacing: 0.03em;
}

/* Header button group */
.header-btn-group { display: flex; gap: 8px; align-items: center; }

/* Modal overlay */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
}
.modal-overlay.hidden { display: none; }
.modal-card {
    background: #fff;
    border-radius: 16px;
    padding: 2rem;
    max-width: 520px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}
.modal-card h3 { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.modal-card > p { font-size: 13px; color: var(--text-muted); margin-bottom: 1rem; }

/* Bulk code options */
.bulk-options { display: flex; gap: 8px; }
.bulk-opt {
    padding: 8px 18px;
    border-radius: 8px;
    border: 1px solid #ddd;
    background: #fff;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}
.bulk-opt:hover { border-color: var(--sage); color: var(--sage); }
.bulk-opt.active { background: var(--sage); color: #fff; border-color: var(--sage); }

/* Bulk links list */
.bulk-links-list {
    max-height: 300px;
    overflow-y: auto;
    margin: 1rem 0;
    border: 1px solid #eee;
    border-radius: 8px;
}
.bulk-link-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 12px;
    border-bottom: 1px solid #f5f5f5;
}
.bulk-link-row:last-child { border-bottom: none; }
.bulk-link-url { color: var(--sage-deep); word-break: break-all; flex: 1; }
.bulk-link-code { color: var(--text-muted); font-weight: 500; margin-left: 8px; white-space: nowrap; }

.mt-12 { margin-top: 12px; }

/* Tier registration links */
.tier-links { margin-top: 1.5rem; border-top: 1px solid #eee; padding-top: 1rem; }
.tier-links-label { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; text-align: center; }
.tier-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; margin-bottom: 6px;
    border: 1px solid #e8e8e8; border-radius: 10px;
    text-decoration: none; color: var(--text-dark);
    font-size: 13px; font-weight: 400;
    transition: border-color 0.15s, background 0.15s;
}
.tier-link:hover { border-color: var(--sage); background: var(--sage-pale, #E8F3ED); }
.tier-icon { font-size: 18px; width: 28px; text-align: center; }

/* Disable interactive elements */
.disabled { pointer-events: none; opacity: 0.5; }

/* Trial banner */
.trial-banner {
    background: var(--yellow-bg);
    border: 1px solid var(--yellow-border);
    border-radius: 8px;
    padding: 12px 20px;
    margin: 0 2rem 16px;
    font-size: 13px;
    color: #7A6A2E;
    text-align: center;
    line-height: 1.5;
}
.trial-banner a { color: var(--sage); font-weight: 500; text-decoration: none; }
.trial-banner a:hover { text-decoration: underline; }
.trial-banner-expired {
    background: var(--red-bg);
    border-color: #F5CDC9;
    color: var(--red);
}

/* Portal tabs */
.portal-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin: 0 2rem 20px;
}
.portal-tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--warm-gray);
    cursor: pointer;
    border: none;
    background: none;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    font-family: inherit;
}
.portal-tab:hover { color: var(--text); }
.portal-tab.active { color: var(--sage); border-bottom-color: var(--sage); }

/* Practice dashboard */
.practice-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
.practice-stat {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
}
.practice-stat-number {
    font-size: 28px;
    font-weight: 600;
    color: var(--sage);
    line-height: 1;
    margin-bottom: 4px;
}
.practice-stat-label {
    font-size: 12px;
    color: var(--warm-gray);
    font-weight: 400;
}
.practice-provider-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.practice-provider-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px;
}
.practice-provider-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.practice-provider-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}
.practice-provider-meta {
    font-size: 12px;
    color: var(--warm-gray);
}
.practice-provider-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

@media (max-width: 600px) {
    .practice-stats { grid-template-columns: 1fr; }
    .portal-tabs { margin: 0 1rem 16px; overflow-x: auto; }
    .trial-banner { margin: 0 1rem 12px; }
}
