/* ═══════════════════════════════════════════════════════════
   Auth & Cloud Sync Styles
   ═══════════════════════════════════════════════════════════ */

/* ── Auth Button in Header ── */
.auth-user-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary, #666);
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    flex-shrink: 0;
}

.auth-user-btn:hover {
    border-color: var(--apple-blue, #007AFF);
    color: var(--apple-blue, #007AFF);
    transform: scale(1.05);
}

.auth-user-btn.signed-in {
    border-color: var(--apple-blue, #007AFF);
    background: var(--apple-blue, #007AFF);
    color: #fff;
}

.auth-avatar {
    font-size: 16px;
    font-weight: 600;
    line-height: 1;
}

.auth-user-indicator {
    font-size: 0.75rem;
    color: var(--text-secondary, #666);
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Modal Overlay ── */
.auth-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: authFadeIn 0.25s ease;
}

@keyframes authFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ── Modal Box ── */
.auth-modal {
    background: var(--bg-card, #fff);
    border-radius: 20px;
    width: 100%;
    max-width: 400px;
    padding: 2.25rem 2rem;
    position: relative;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.18),
                0 0 0 1px rgba(0, 0, 0, 0.06);
    animation: authSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes authSlideUp {
    from { transform: translateY(24px) scale(0.97); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.auth-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-secondary, #666);
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.auth-close:hover {
    background: rgba(0, 0, 0, 0.10);
    color: var(--text, #333);
}

/* ── Modal Header ── */
.auth-modal-header {
    margin-bottom: 1.5rem;
    text-align: center;
}

.auth-modal-header h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text, #1d1d1f);
    margin: 0 0 0.3rem 0;
    letter-spacing: -0.02em;
}

.auth-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary, #666);
    margin: 0;
    line-height: 1.4;
}

/* ── App branding in auth modal ── */
.auth-brand {
    text-align: center;
    margin-bottom: 1.25rem;
}

.auth-brand-logo {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: linear-gradient(135deg, #007AFF, #5856D6);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.25);
}

.auth-brand-logo svg {
    color: #fff;
}

.auth-brand-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text, #1d1d1f);
    letter-spacing: -0.01em;
}

/* ── Form Fields ── */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.auth-field label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary, #666);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.auth-field input {
    padding: 0.75rem 1rem;
    border: 1.5px solid var(--border, #ddd);
    border-radius: 12px;
    font-size: 1rem;
    background: var(--bg-input, #f5f5f7);
    color: var(--text, #1d1d1f);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    outline: none;
    font-family: inherit;
}

.auth-field input:focus {
    border-color: var(--apple-blue, #007AFF);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
    background: var(--bg-card, #fff);
}

.auth-field input::placeholder {
    color: var(--text-secondary, #999);
    opacity: 0.7;
}

.auth-readonly {
    padding: 0.5rem 0;
    color: var(--text, #1d1d1f);
    font-size: 0.95rem;
    margin: 0;
}

/* ── Buttons ── */
.btn-auth {
    padding: 0.75rem 1.2rem;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    font-family: inherit;
}

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

.btn-auth-primary {
    background: linear-gradient(135deg, #007AFF, #0066d6);
    color: #fff;
    width: 100%;
    margin-top: 0.5rem;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.25);
}

.btn-auth-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #0066d6, #0055b3);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0, 122, 255, 0.35);
}

.btn-auth-primary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 122, 255, 0.2);
}

.btn-auth-secondary {
    background: var(--bg-input, #f5f5f7);
    color: var(--text, #1d1d1f);
    border: 1px solid var(--border, #ddd);
}

.btn-auth-secondary:hover:not(:disabled) {
    background: var(--border, #e5e5e5);
}

.btn-auth-danger {
    background: transparent;
    color: var(--danger, #ff3b30);
    border: 1px solid rgba(255, 59, 48, 0.3);
    font-size: 0.85rem;
}

.btn-auth-danger:hover:not(:disabled) {
    background: rgba(255, 59, 48, 0.08);
    border-color: rgba(255, 59, 48, 0.5);
}

.btn-auth-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    border-radius: 8px;
}

/* ── Error & Success Messages ── */
.auth-error {
    background: rgba(255, 59, 48, 0.08);
    color: #ff3b30;
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    font-size: 0.85rem;
    border: 1px solid rgba(255, 59, 48, 0.2);
}

.auth-success {
    background: rgba(52, 199, 89, 0.08);
    color: #34c759;
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    font-size: 0.85rem;
    border: 1px solid rgba(52, 199, 89, 0.2);
}

/* ── Auth Divider (legacy) ── */
.auth-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.25rem 0;
    color: var(--text-secondary, #999);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border, #eee);
}

/* ── Settings Accordion Sections ── */
.settings-section {
    border: 1px solid var(--border, #BEC5D4);
    border-radius: 12px;
    background: var(--bg-card, rgba(255,255,255,0.92));
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

.settings-section[open] {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.settings-section-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 0.85rem;
    cursor: pointer;
    user-select: none;
    list-style: none;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text, #1a1a1e);
    letter-spacing: 0.02em;
    transition: background 0.15s ease;
}

.settings-section-header::-webkit-details-marker {
    display: none;
}

.settings-section-header::marker {
    display: none;
    content: '';
}

.settings-section-header:hover {
    background: var(--bg-input, #EDF0F8);
}

.settings-section-header:active {
    background: var(--border, #BEC5D4);
}

.settings-section-icon {
    font-size: 1rem;
    line-height: 1;
    flex-shrink: 0;
}

.settings-section-title {
    flex: 1;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.72rem;
    color: var(--text-secondary, #556070);
}

.settings-section-badge {
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 6px;
    background: var(--apple-blue, #007AFF);
    color: #fff;
    font-weight: 600;
    line-height: 1.4;
}

.settings-section-badge:empty {
    display: none;
}

.settings-section-chevron {
    font-size: 1.1rem;
    font-weight: 300;
    color: var(--text-secondary, #556070);
    transition: transform 0.25s ease;
    line-height: 1;
}

.settings-section[open] > .settings-section-header .settings-section-chevron {
    transform: rotate(90deg);
}

.settings-section-body {
    padding: 0 0.85rem 0.85rem;
    animation: settingsSlideIn 0.2s ease;
}

/* ── Agency Glossary Textarea ── */

.glossary-textarea {
    width: 100%;
    min-height: 90px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1.5px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    line-height: 1.5;
    resize: vertical;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.glossary-textarea:focus {
    outline: none;
    border-color: var(--apple-blue);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.glossary-textarea::placeholder {
    color: var(--text-tertiary);
    font-size: 12px;
}

.glossary-hint {
    margin: 6px 0 0;
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.4;
}

@keyframes settingsSlideIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Refined select inside settings */
.settings-select {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    border: 1.5px solid var(--border, #BEC5D4);
    background: var(--bg-input, #EDF0F8);
    color: var(--text);
    font-size: 13px;
    appearance: auto;
    transition: border-color 0.2s ease;
}

.settings-select:focus {
    border-color: var(--apple-blue, #007AFF);
    outline: none;
}

/* AI Model Info Card (inside settings) */
.ai-model-info-card {
    margin: -0.15rem 0 0.4rem;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--bg-input, #EDF0F8);
    border: 1px solid var(--border, #BEC5D4);
    font-size: 12px;
    line-height: 1.5;
}

/* AI Cost Card */
.ai-cost-card {
    margin: -0.15rem 0 0.4rem;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--bg-input, #EDF0F8);
    border: 1px solid var(--border, #BEC5D4);
    font-size: 11px;
    line-height: 1.6;
}

/* ── Auth Links ── */
.auth-links {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border, #eee);
}

.auth-link {
    background: none;
    border: none;
    color: var(--apple-blue, #007AFF);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.auth-link:hover {
    background: rgba(0, 122, 255, 0.08);
    text-decoration: none;
}

/* ── Account View ── */
.auth-account-info {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    margin-bottom: 1.5rem;
}

.auth-account-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #007AFF, #5856D6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 auto 0.25rem;
}

.auth-sync-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-input, #f5f5f7);
    border-radius: 12px;
    font-size: 0.88rem;
    color: var(--text-secondary, #666);
    border: 1px solid var(--border, rgba(0,0,0,0.06));
}

.auth-sync-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.auth-sync-timestamp {
    font-size: 0.75rem;
    color: var(--text-secondary, #999);
    opacity: 0.8;
}

/* ── Invite Row ── */
.auth-invite-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-input, #f5f5f7);
    border-radius: 12px;
    border: 1px solid var(--border, rgba(0,0,0,0.06));
    cursor: pointer;
    transition: background 0.15s;
}

.auth-invite-row:hover {
    background: var(--border, rgba(0,0,0,0.08));
}

.auth-invite-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.auth-invite-text strong {
    font-size: 0.88rem;
    color: var(--text, #1a1a1e);
}

.auth-invite-text span {
    font-size: 0.75rem;
    color: var(--text-secondary, #666);
}

.auth-invite-arrow {
    font-size: 1.3rem;
    color: var(--text-secondary, #999);
    font-weight: 300;
}

.auth-account-actions {
    display: flex;
    gap: 0.6rem;
    flex-direction: column;
    margin-top: 0.25rem;
}

/* ── Sync Indicator Toast ── */
.sync-indicator {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 1.2rem;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 10001;
    animation: authSlideUp 0.3s ease;
    pointer-events: none;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.sync-success {
    background: rgba(52, 199, 89, 0.15);
    color: #34c759;
    border: 1px solid rgba(52, 199, 89, 0.3);
}

.sync-error {
    background: rgba(255, 59, 48, 0.15);
    color: #ff3b30;
    border: 1px solid rgba(255, 59, 48, 0.3);
}

.sync-warning {
    background: rgba(255, 159, 10, 0.15);
    color: #ff9f0a;
    border: 1px solid rgba(255, 159, 10, 0.3);
}

.sync-info {
    background: rgba(0, 122, 255, 0.15);
    color: var(--apple-blue, #007AFF);
    border: 1px solid rgba(0, 122, 255, 0.3);
}

/* ── Conflict Dialog ── */
.conflict-modal {
    max-width: 400px;
    padding: 1.5rem;
    text-align: center;
}

.conflict-modal-icon {
    font-size: 2rem;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.conflict-modal .auth-modal-header {
    margin-bottom: 1rem;
}

.conflict-modal .auth-modal-header h3 {
    font-size: 1.15rem;
    margin-bottom: 0.15rem;
}

.conflict-modal .auth-modal-body {
    text-align: left;
}

.conflict-item {
    padding: 0.85rem 1rem;
    background: var(--bg-input, #f5f5f7);
    border-radius: 12px;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border, rgba(0,0,0,0.06));
}

.conflict-item-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.conflict-icon {
    font-size: 1.15rem;
    line-height: 1;
    flex-shrink: 0;
}

.conflict-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text, #1d1d1f);
}

.conflict-item p {
    margin: 0 0 0.35rem 0;
    font-size: 0.8rem;
    color: var(--text-secondary, #666);
    line-height: 1.4;
}

.conflict-hint {
    font-style: italic;
    opacity: 0.7;
    font-size: 0.78rem;
}

.conflict-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.6rem;
}

.conflict-actions .btn-auth {
    flex: 1;
    font-size: 0.82rem;
    padding: 0.5rem 0.6rem;
    border-radius: 8px;
    position: relative;
}

.conflict-btn-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.conflict-timestamp {
    font-size: 0.7rem;
    opacity: 0.75;
    font-weight: 400;
}

.conflict-newest {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    color: #34C759;
    margin-top: 2px;
    letter-spacing: 0.02em;
}

.conflict-actions .btn-auth-primary .conflict-newest {
    color: #fff;
}

.conflict-actions .btn-auth-primary {
    margin-top: 0;
    width: auto;
}

body.dark-mode .conflict-item {
    background: #2C2C2E;
    border-color: #38383A;
}

/* ── Intake Session Dialog ── */
.intake-session-modal {
    max-width: 380px;
    padding: 1.75rem 1.5rem;
    text-align: center;
}

.intake-session-icon {
    font-size: 2.2rem;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.intake-session-modal .auth-modal-header {
    margin-bottom: 1rem;
}

.intake-session-modal .auth-modal-header h3 {
    font-size: 1.1rem;
}

.intake-session-preview {
    background: var(--bg-input, #f5f5f7);
    border: 1px solid var(--border, rgba(0,0,0,0.06));
    border-radius: 12px;
    padding: 0.85rem 1rem;
    margin-bottom: 1.25rem;
    text-align: left;
}

.intake-session-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text, #1d1d1f);
    margin-bottom: 0.2rem;
}

.intake-session-meta {
    font-size: 0.8rem;
    color: var(--text-secondary, #666);
}

.intake-session-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.intake-session-actions .btn-auth {
    width: 100%;
    padding: 0.65rem 1rem;
    font-size: 0.9rem;
    border-radius: 10px;
}

.intake-session-actions .btn-auth-primary {
    margin-top: 0;
}

.btn-auth-ghost {
    background: transparent;
    color: var(--text-secondary, #888);
    border: none;
    font-size: 0.82rem !important;
    padding: 0.5rem 1rem !important;
}

.btn-auth-ghost:hover {
    color: var(--text);
    background: rgba(0, 0, 0, 0.04);
}

body.dark-mode .intake-session-preview {
    background: #2C2C2E;
    border-color: #38383A;
}

body.dark-mode .intake-session-name {
    color: #FFFFFF;
}

body.dark-mode .btn-auth-ghost {
    color: #98989D;
}

body.dark-mode .btn-auth-ghost:hover {
    color: #FFFFFF;
    background: rgba(255, 255, 255, 0.06);
}

/* ── Dark Mode ── */
body.dark-mode .auth-modal {
    background: #1C1C1E;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6),
                0 0 0 1px rgba(255, 255, 255, 0.08);
}

body.dark-mode .auth-modal-header h3 {
    color: #FFFFFF;
}

body.dark-mode .auth-subtitle {
    color: #98989D;
}

body.dark-mode .auth-brand-name {
    color: #FFFFFF;
}

body.dark-mode .auth-field label {
    color: #98989D;
}

body.dark-mode .auth-field input {
    background: #2C2C2E;
    border-color: #38383A;
    color: #FFFFFF;
}

body.dark-mode .auth-field input:focus {
    border-color: #0A84FF;
    box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.15);
    background: #2C2C2E;
}

body.dark-mode .auth-field input::placeholder {
    color: #636366;
}

body.dark-mode .auth-close {
    background: rgba(255, 255, 255, 0.08);
    color: #98989D;
}

body.dark-mode .auth-close:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #FFFFFF;
}

body.dark-mode .btn-auth-secondary {
    background: #2C2C2E;
    color: #FFFFFF;
    border-color: #38383A;
}

body.dark-mode .btn-auth-secondary:hover:not(:disabled) {
    background: #3A3A3C;
}

body.dark-mode .btn-auth-danger {
    color: #FF453A;
    border-color: rgba(255, 69, 58, 0.3);
}

body.dark-mode .btn-auth-danger:hover:not(:disabled) {
    background: rgba(255, 69, 58, 0.1);
}

body.dark-mode .auth-links {
    border-top-color: #38383A;
}

body.dark-mode .auth-link:hover {
    background: rgba(10, 132, 255, 0.1);
}

body.dark-mode .auth-divider {
    color: #636366;
}

body.dark-mode .auth-divider::before,
body.dark-mode .auth-divider::after {
    background: #38383A;
}

body.dark-mode .auth-sync-status {
    background: #2C2C2E;
    border-color: #38383A;
    color: #98989D;
}

body.dark-mode .auth-invite-row {
    background: #2C2C2E;
    border-color: #38383A;
}

body.dark-mode .auth-invite-row:hover {
    background: #3A3A3C;
}

body.dark-mode .auth-invite-text strong {
    color: #FFFFFF;
}

body.dark-mode .auth-invite-text span {
    color: #98989D;
}

body.dark-mode .auth-readonly {
    color: #FFFFFF;
}

body.dark-mode .sync-indicator {
    backdrop-filter: blur(12px);
}

body.dark-mode .auth-error {
    background: rgba(255, 69, 58, 0.12);
    color: #FF453A;
    border-color: rgba(255, 69, 58, 0.25);
}

body.dark-mode .auth-success {
    background: rgba(50, 215, 75, 0.12);
    color: #32D74B;
    border-color: rgba(50, 215, 75, 0.25);
}

/* ── Responsive ── */
@media (max-width: 480px) {
    .auth-modal {
        padding: 1.75rem 1.5rem;
        border-radius: 16px;
        margin: 0.5rem;
    }

    .auth-modal-header h3 {
        font-size: 1.3rem;
    }

    .auth-brand-logo {
        width: 48px;
        height: 48px;
        border-radius: 14px;
    }

    .auth-user-indicator {
        display: none !important;
    }

    .conflict-actions {
        flex-direction: column;
    }
}
