/* ============================================
   Talking Therapies Portal - Client Frontend
   ============================================ */

/* CSS Variables */
:root {
    --ttp-primary: #2e86ab;
    --ttp-primary-dark: #1d6a8a;
    --ttp-primary-light: #e8f4f8;
    --ttp-secondary: #5a6c7d;
    --ttp-accent: #14a76c;
    --ttp-danger: #e8505b;
    --ttp-warning: #f0a500;
    --ttp-bg: #f5f7fa;
    --ttp-white: #ffffff;
    --ttp-text: #2d3748;
    --ttp-text-light: #718096;
    --ttp-border: #e2e8f0;
    --ttp-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --ttp-shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
    --ttp-radius: 8px;
    --ttp-radius-lg: 12px;
    --ttp-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Reset for portal */
.ttp-portal-wrap,
.ttp-auth-wrap {
    font-family: var(--ttp-font);
    color: var(--ttp-text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    box-sizing: border-box;
}

.ttp-portal-wrap *, .ttp-auth-wrap * {
    box-sizing: border-box;
}

/* ===== AUTH PAGES (Login / Register) ===== */
.ttp-auth-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ttp-bg);
    padding: 200px 20px 40px 20px;
}

.ttp-auth-container {
    background: var(--ttp-white);
    border-radius: var(--ttp-radius-lg);
    box-shadow: var(--ttp-shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 460px;
}

.ttp-auth-register {
    max-width: 560px;
}

.ttp-auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.ttp-auth-header h1 {
    font-size: 24px;
    color: var(--ttp-primary);
    margin: 0 0 8px;
    font-weight: 700;
}

.ttp-auth-header p {
    color: var(--ttp-text-light);
    margin: 0;
    font-size: 15px;
}

.ttp-auth-footer {
    text-align: center;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--ttp-border);
}

.ttp-auth-footer p {
    margin: 6px 0;
    font-size: 14px;
}

.ttp-auth-footer a {
    color: var(--ttp-primary);
    text-decoration: none;
}

.ttp-auth-footer a:hover {
    text-decoration: underline;
}

/* ===== PORTAL CONTAINER ===== */
.ttp-hide-page-title {
    display: none !important;
}

.ttp-portal-wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 200px 10px 0 10px;
}

/* ===== PILL NAVIGATION ===== */
.ttp-pill-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 16px 0;
    margin-bottom: 20px;
    border-bottom: 2px solid #e2e8f0;
}

.ttp-pill {
    display: inline-block;
    padding: 10px 18px;
    background: #f0f4f8;
    color: #2d3748;
    border-radius: 20px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid #e2e8f0;
    transition: all 0.2s;
    white-space: nowrap;
}

.ttp-pill:hover {
    background: #2e86ab;
    color: #ffffff;
    border-color: #2e86ab;
}

.ttp-pill-logout {
    background: transparent;
    color: #e8505b;
    border-color: #e8505b;
}

.ttp-pill-logout:hover {
    background: #e8505b;
    color: #ffffff;
}

/* ===== MAIN CONTENT ===== */
.ttp-main {
    padding: 0 0 30px 0;
    min-height: 50vh;
}

/* ===== FOOTER ===== */
.ttp-footer {
    background: var(--ttp-white);
    border-top: 1px solid var(--ttp-border);
    padding: 24px 20px;
    text-align: center;
    font-size: 13px;
    color: var(--ttp-text-light);
}

.ttp-footer p {
    margin: 4px 0;
}

/* ===== DASHBOARD ===== */
.ttp-welcome {
    margin-bottom: 30px;
}

.ttp-welcome h2 {
    font-size: 28px;
    margin: 0 0 8px;
    color: var(--ttp-text);
}

.ttp-welcome p {
    color: var(--ttp-text-light);
    margin: 0;
    font-size: 16px;
}

.ttp-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.ttp-stat-card {
    background: var(--ttp-white);
    border-radius: var(--ttp-radius);
    padding: 24px;
    text-align: center;
    box-shadow: var(--ttp-shadow);
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.ttp-stat-card:hover {
    box-shadow: var(--ttp-shadow-lg);
    border-color: var(--ttp-primary-light);
    transform: translateY(-2px);
}

.ttp-stat-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.ttp-stat-number {
    font-size: 36px;
    font-weight: 700;
    color: var(--ttp-primary);
}

.ttp-stat-label {
    font-size: 14px;
    color: var(--ttp-text-light);
    margin-top: 4px;
}

.ttp-dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

/* ===== CARDS ===== */
.ttp-card {
    background: var(--ttp-white);
    border-radius: var(--ttp-radius);
    box-shadow: var(--ttp-shadow);
    padding: 24px;
}

.ttp-card-muted {
    background: var(--ttp-bg);
    box-shadow: none;
    border: 1px solid var(--ttp-border);
    margin-top: 20px;
}

.ttp-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.ttp-card-header h3 {
    margin: 0;
    font-size: 18px;
}

/* ===== LISTS ===== */
.ttp-list-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--ttp-border);
}

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

.ttp-list-item-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.ttp-list-item-title {
    color: var(--ttp-text);
    text-decoration: none;
    font-weight: 600;
    font-size: 15px;
}

.ttp-list-item-title:hover {
    color: var(--ttp-primary);
}

.ttp-list-item-meta {
    font-size: 13px;
    color: var(--ttp-text-light);
    margin-top: 2px;
}

.ttp-unread {
    background: var(--ttp-primary-light);
    border-radius: 6px;
    padding-left: 12px !important;
    padding-right: 12px !important;
}

/* ===== MESSAGES ===== */
.ttp-messages-list {
    background: var(--ttp-white);
    border-radius: var(--ttp-radius);
    box-shadow: var(--ttp-shadow);
    overflow: hidden;
}

.ttp-message-preview {
    display: flex;
    gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--ttp-border);
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}

.ttp-message-preview:hover {
    background: var(--ttp-bg);
}

.ttp-message-preview.ttp-unread {
    background: var(--ttp-primary-light);
    border-radius: 0;
}

.ttp-message-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--ttp-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    flex-shrink: 0;
}

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

.ttp-message-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.ttp-message-from {
    font-weight: 600;
    font-size: 15px;
}

.ttp-message-date {
    font-size: 12px;
    color: var(--ttp-text-light);
}

.ttp-message-subject {
    font-size: 14px;
    color: var(--ttp-text);
    margin-bottom: 2px;
}

.ttp-message-excerpt {
    font-size: 13px;
    color: var(--ttp-text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Message Thread */
.ttp-thread-messages {
    max-height: 60vh;
    overflow-y: auto;
    padding: 20px 0;
}

.ttp-msg {
    display: flex;
    margin-bottom: 16px;
}

.ttp-msg-sent {
    justify-content: flex-end;
}

.ttp-msg-received {
    justify-content: flex-start;
}

.ttp-msg-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 16px;
    position: relative;
}

.ttp-msg-sent .ttp-msg-bubble {
    background: var(--ttp-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.ttp-msg-received .ttp-msg-bubble {
    background: var(--ttp-bg);
    color: var(--ttp-text);
    border-bottom-left-radius: 4px;
}

.ttp-msg-system .ttp-msg-bubble {
    background: var(--ttp-primary-light);
    color: var(--ttp-primary-dark);
    max-width: 85%;
    text-align: center;
}

.ttp-msg-sender {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    opacity: 0.85;
}

.ttp-msg-body {
    font-size: 15px;
    line-height: 1.5;
}

.ttp-msg-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 6px;
}

.ttp-reply-form {
    background: var(--ttp-white);
    border-top: 1px solid var(--ttp-border);
    padding: 20px;
    border-radius: 0 0 var(--ttp-radius) var(--ttp-radius);
}

/* ===== JOURNAL ===== */
.ttp-journal-card {
    background: var(--ttp-white);
    border-radius: var(--ttp-radius);
    box-shadow: var(--ttp-shadow);
    padding: 20px;
    margin-bottom: 16px;
    transition: box-shadow 0.2s;
}

.ttp-journal-card:hover {
    box-shadow: var(--ttp-shadow-lg);
}

.ttp-journal-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 8px;
}

.ttp-journal-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--ttp-text);
    text-decoration: none;
}

.ttp-journal-title:hover {
    color: var(--ttp-primary);
}

.ttp-journal-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.ttp-journal-preview {
    color: var(--ttp-text-light);
    font-size: 14px;
    margin: 8px 0;
}

.ttp-journal-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--ttp-text-light);
}

.ttp-journal-actions {
    display: flex;
    gap: 12px;
}

/* ===== DOCUMENTS ===== */
.ttp-doc-category {
    margin-bottom: 30px;
}

.ttp-doc-category h3 {
    font-size: 18px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--ttp-primary-light);
    color: var(--ttp-primary);
}

.ttp-doc-item {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--ttp-white);
    border-radius: var(--ttp-radius);
    padding: 16px;
    margin-bottom: 8px;
    box-shadow: var(--ttp-shadow);
}

.ttp-doc-icon {
    font-size: 28px;
    flex-shrink: 0;
}

.ttp-doc-info {
    flex: 1;
}

.ttp-doc-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--ttp-text);
}

.ttp-doc-meta {
    font-size: 13px;
    color: var(--ttp-text-light);
    margin-top: 2px;
}

/* ===== TAGS ===== */
.ttp-tag {
    display: inline-block;
    font-size: 12px;
    padding: 2px 10px;
    border-radius: 12px;
    font-weight: 500;
}

.ttp-tag-shared {
    background: #e8f5e9;
    color: #2e7d32;
}

.ttp-tag-private {
    background: var(--ttp-bg);
    color: var(--ttp-text-light);
}

.ttp-tag-mood {
    background: var(--ttp-primary-light);
    color: var(--ttp-primary-dark);
}

/* ===== FORMS ===== */
.ttp-form-group {
    margin-bottom: 20px;
}

.ttp-form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--ttp-text);
    margin-bottom: 6px;
}

.ttp-form-group small {
    font-weight: 400;
    color: var(--ttp-text-light);
}

.ttp-form-row {
    display: flex;
    gap: 16px;
}

.ttp-form-half {
    flex: 1;
}

.ttp-input,
.ttp-select,
.ttp-textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--ttp-border);
    border-radius: 6px;
    font-size: 15px;
    font-family: var(--ttp-font);
    color: var(--ttp-text);
    background: var(--ttp-white);
    transition: border-color 0.2s;
}

.ttp-input:focus,
.ttp-select:focus,
.ttp-textarea:focus {
    outline: none;
    border-color: var(--ttp-primary);
    box-shadow: 0 0 0 3px rgba(46, 134, 171, 0.1);
}

.ttp-textarea {
    resize: vertical;
    min-height: 100px;
}

.ttp-form-checkbox label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-weight: 400;
    cursor: pointer;
}

.ttp-form-checkbox input[type="checkbox"] {
    margin-top: 3px;
    flex-shrink: 0;
}

.ttp-help-text {
    font-size: 13px;
    color: var(--ttp-text-light);
    margin-top: 4px;
    display: block;
}

.ttp-range {
    width: 100%;
    cursor: pointer;
}

.ttp-form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.ttp-divider {
    border: none;
    border-top: 1px solid var(--ttp-border);
    margin: 24px 0;
}

/* ===== BUTTONS ===== */
.ttp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--ttp-font);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    line-height: 1.4;
}

.ttp-btn-primary {
    background: var(--ttp-primary);
    color: white;
}

.ttp-btn-primary:hover {
    background: var(--ttp-primary-dark);
}

.ttp-btn-secondary {
    background: var(--ttp-bg);
    color: var(--ttp-text);
    border: 1px solid var(--ttp-border);
}

.ttp-btn-secondary:hover {
    background: var(--ttp-border);
}

.ttp-btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

.ttp-btn-full {
    width: 100%;
}

/* ===== ALERTS ===== */
.ttp-alert {
    padding: 14px 18px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 14px;
}

.ttp-alert ul {
    margin: 4px 0 0 16px;
    padding: 0;
}

.ttp-alert-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.ttp-alert-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

/* ===== PAGE HEADERS ===== */
.ttp-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.ttp-page-header h2 {
    margin: 0;
    font-size: 24px;
}

.ttp-back-link {
    color: var(--ttp-primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
}

.ttp-back-link:hover {
    text-decoration: underline;
}

/* ===== LINKS ===== */
.ttp-link {
    color: var(--ttp-primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--ttp-font);
}

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

.ttp-link-danger {
    color: var(--ttp-danger);
}

/* ===== EMPTY STATES ===== */
.ttp-empty-state {
    text-align: center;
    color: var(--ttp-text-light);
    padding: 20px;
    font-size: 14px;
}

.ttp-empty-state a {
    color: var(--ttp-primary);
}

.ttp-empty-state-large {
    text-align: center;
    padding: 60px 20px;
    background: var(--ttp-white);
    border-radius: var(--ttp-radius);
    box-shadow: var(--ttp-shadow);
}

.ttp-empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.ttp-empty-state-large h3 {
    margin: 0 0 8px;
    font-size: 20px;
}

.ttp-empty-state-large p {
    color: var(--ttp-text-light);
    margin: 0 0 20px;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

/* ===== CRISIS CARD ===== */
.ttp-crisis-card {
    background: #fffbeb;
    border: 1px solid #fde68a;
    margin-top: 20px;
}

.ttp-crisis-card h3 {
    color: #92400e;
    margin-top: 0;
}

.ttp-crisis-card p {
    color: #78350f;
}

.ttp-crisis-contacts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.ttp-crisis-item {
    font-size: 14px;
    color: #78350f;
}

/* ===== ENTRY PAGE ===== */
.ttp-entry-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--ttp-border);
    font-size: 14px;
    color: var(--ttp-text-light);
}

.ttp-entry-content {
    font-size: 16px;
    line-height: 1.8;
    white-space: pre-wrap;
}

.ttp-entry-actions {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--ttp-border);
}

/* ===== LOADING SPINNER ===== */
.ttp-loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--ttp-border);
    border-top-color: var(--ttp-primary);
    border-radius: 50%;
    animation: ttp-spin 0.6s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

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

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .ttp-pill-nav {
        gap: 6px;
    }

    .ttp-pill {
        padding: 6px 12px;
        font-size: 13px;
    }

    .ttp-stats-grid {
        grid-template-columns: 1fr;
    }

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

    .ttp-form-row {
        flex-direction: column;
    }

    .ttp-crisis-contacts {
        grid-template-columns: 1fr;
    }

    .ttp-msg-bubble {
        max-width: 85%;
    }

    .ttp-auth-container {
        padding: 24px;
    }
}

@media (max-width: 480px) {
    .ttp-main {
        padding: 16px;
    }

    .ttp-welcome h2 {
        font-size: 22px;
    }

    .ttp-stat-number {
        font-size: 28px;
    }
}

/* ===== DOCUMENT FILTERS (Phase 2) ===== */
.ttp-doc-filters {
    margin-bottom: 24px;
}

.ttp-search-form {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.ttp-search-input {
    max-width: 400px;
}

.ttp-cat-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ttp-cat-tab {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    text-decoration: none;
    color: var(--ttp-secondary);
    background: var(--ttp-bg);
    border: 1px solid var(--ttp-border);
    transition: all 0.2s;
}

.ttp-cat-tab:hover,
.ttp-cat-tab.active {
    background: var(--ttp-primary);
    color: white;
    border-color: var(--ttp-primary);
}

/* ===== APPOINTMENTS (Phase 3) ===== */
.ttp-appointments-page .ttp-doc-item {
    border-left: 3px solid var(--ttp-primary);
}

@media (max-width: 768px) {
    .ttp-search-form {
        flex-direction: column;
    }
    .ttp-search-input {
        max-width: 100%;
    }
    .ttp-cat-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 8px;
    }
    .ttp-cat-tab {
        white-space: nowrap;
    }
}

/* ===== PROGRESS BARS (Phase 4) ===== */
.ttp-progress-bar {
    background: var(--ttp-border);
    border-radius: 6px;
    height: 12px;
    overflow: hidden;
    margin-top: 8px;
}

.ttp-progress-fill {
    background: var(--ttp-primary);
    height: 100%;
    border-radius: 6px;
    transition: width 0.5s ease;
}

/* ===== SESSION SUMMARIES (Phase 4) ===== */
.ttp-session-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--ttp-border);
}

.ttp-session-section h3 {
    font-size: 16px;
    color: var(--ttp-primary);
    margin: 0 0 8px;
}

.ttp-session-content {
    font-size: 15px;
    line-height: 1.8;
    color: var(--ttp-text);
}

.ttp-homework-section {
    background: var(--ttp-primary-light);
    margin-left: -24px;
    margin-right: -24px;
    padding: 16px 24px;
    border-top: none;
    border-radius: 0;
}

/* ===== MOOD DISTRIBUTION (Phase 4) ===== */
.ttp-mood-dist {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ttp-mood-dist-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ttp-mood-dist-label {
    width: 140px;
    font-size: 14px;
    font-weight: 500;
    flex-shrink: 0;
}

.ttp-mood-dist-item .ttp-progress-bar {
    flex: 1;
    margin-top: 0;
}

.ttp-mood-dist-count {
    font-size: 13px;
    color: var(--ttp-text-light);
    width: 70px;
    text-align: right;
    flex-shrink: 0;
}

/* ===== STATS GRID UPDATE (Phase 4) ===== */
.ttp-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}
