/* Root variables for theming */
:root {
    /* Light theme - soft, calming colors */
    --bg-primary: #fafafa;
    --bg-secondary: #ffffff;
    --text-primary: #424242;
    --text-secondary: #616161;
    --border: #e0e0e0;
    --focus: #1976D2;
    --focus-ring: 0 0 0 3px rgba(33, 150, 243, 0.3);
    
    /* Node type colors (slightly muted for comfort) */
    --trauma-color: #c62828;
    --trigger-color: #ef6c00;
    --response-color: #f9a825;
    --symptom-color: #6a1b9a;
    --emotion-color: #1565c0;
    --belief-color: #4e342e;
    --coping-color: #2e7d32;
    --support-color: #00695c;
    
    /* Spacing for readability */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    
    /* Transitions - gentle and predictable */
    --transition: all 0.3s ease;
}

/* Dark theme - easy on eyes */
[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --border: #404040;
}

/* Soft theme - low contrast for sensitivity */
[data-theme="soft"] {
    --bg-primary: #f5f2ed;
    --bg-secondary: #fffdf8;
    --text-primary: #5a524a;
    --text-secondary: #6b6054;
    --border: #d4cfc7;
    --focus: #3f6b73;
}

/* Reset and base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

*:focus {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
    box-shadow: var(--focus-ring);
}

/* Remove focus for mouse users, keep for keyboard */
*:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

/* Respect reduced-motion preferences (trauma-informed: no jarring motion) */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Typography - readable and calming */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 
                 'Roboto', 'Oxygen', 'Ubuntu', sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
}

/* Font size adjustments */
[data-font-size="small"] { font-size: 14px; }
[data-font-size="medium"] { font-size: 16px; }
[data-font-size="large"] { font-size: 18px; }
[data-font-size="xlarge"] { font-size: 20px; }

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: var(--spacing-sm);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

/* Buttons - clear and predictable */
.btn {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
}

.btn:hover:not(:disabled) {
    background: var(--border);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--focus);
    color: white;
    border-color: var(--focus);
}

.btn-primary:hover:not(:disabled) {
    background: #1565C0;
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
}

.btn-danger {
    background: var(--bg-secondary);
    color: #c62828;
    border-color: #e0a3a3;
}

.btn-danger:hover:not(:disabled) {
    background: #ffebee;
}

.settings-note {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: var(--spacing-xs) 0 var(--spacing-sm);
}

/* Forms */
.form-group {
    margin-bottom: var(--spacing-md);
}

.form-group label {
    display: block;
    margin-bottom: var(--spacing-xs);
    font-weight: 500;
}

input[type="text"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: var(--spacing-sm);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: var(--transition);
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--focus);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

/* Crisis resources bar */
.crisis-bar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: var(--spacing-sm);
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--spacing-md);
}

.crisis-bar a {
    color: white;
    font-weight: bold;
    text-decoration: underline;
}

/* Login screen */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
}

.login-box {
    background: var(--bg-secondary);
    padding: var(--spacing-xl);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    max-width: 400px;
    width: 100%;
}

.tagline {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-lg);
    text-align: center;
}

.login-box h1 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 0 0 var(--spacing-xs);
    font-size: 1.9rem;
}

.brand-mark {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
}

.privacy-notice {
    margin-top: var(--spacing-lg);
    padding: var(--spacing-md);
    background: var(--bg-primary);
    border-radius: 4px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
}

.setup-prompt {
    color: var(--text-secondary);
    text-align: center;
    margin: var(--spacing-md) 0;
    padding: var(--spacing-md);
    background: #e3f2fd;
    border-radius: 4px;
    border-left: 4px solid var(--focus);
}

/* Soft-start interstitial */
.soft-start {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    padding: var(--spacing-xl);
}

.soft-start-card {
    max-width: 420px;
    text-align: center;
    background: var(--bg-secondary);
    padding: var(--spacing-xl);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.soft-start-card p {
    color: var(--text-secondary);
    margin: var(--spacing-md) 0 var(--spacing-lg);
}

.soft-start-actions {
    display: flex;
    gap: var(--spacing-sm);
    justify-content: center;
    flex-wrap: wrap;
}

.error-message {
    color: #d32f2f;
    background: #ffebee;
    padding: var(--spacing-md);
    border-radius: 4px;
    margin: var(--spacing-md) 0;
    text-align: center;
}

/* Account creation: password strength + no-recovery acknowledgement */
.password-strength {
    margin-bottom: var(--spacing-md);
}

.strength-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.strength-fill {
    height: 100%;
    width: 0;
    background: #e57373;
    transition: var(--transition);
}

.strength-fill.strength-2 { background: #ffb74d; }
.strength-fill.strength-3 { background: #aed581; }
.strength-fill.strength-4 { background: #66bb6a; }

.strength-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.strength-hint {
    margin: 4px 0 0;
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Show/hide password toggle (added to every password field by app.js). */
.password-wrap {
    position: relative;
    display: block;
}

.password-wrap input {
    width: 100%;
    padding-right: 42px;
}

.password-toggle {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
}

.password-toggle:hover { color: var(--text-primary); }
.password-toggle:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.auth-restore-hint {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: var(--spacing-lg);
}

.restore-link {
    color: var(--focus);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.restore-link:hover { color: var(--text-primary); }
.restore-link code { font-size: 0.85em; }

.btn-danger {
    background: #b3261e;
    color: #fff;
    border: none;
}

.btn-danger:hover { background: #9c2018; }
.btn-danger:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.ack-label {
    display: flex;
    gap: var(--spacing-sm);
    align-items: flex-start;
    font-size: 0.85rem;
    font-weight: normal;
    color: var(--text-secondary);
    cursor: pointer;
}

.ack-label input {
    width: auto;
    margin-top: 3px;
    flex-shrink: 0;
}

/* Vault auth panels (create · recovery sheet · unlock · recover) */
.auth-heading {
    text-align: center;
    margin-bottom: var(--spacing-sm);
}

.auth-sub {
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-align: center;
    margin-bottom: var(--spacing-lg);
}

.btn-link {
    display: block;
    width: 100%;
    margin-top: var(--spacing-md);
    background: none;
    border: none;
    color: var(--focus);
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.9rem;
}

.recovery-code {
    font-family: monospace;
    font-size: 1.1rem;
    letter-spacing: 1px;
    text-align: center;
    word-break: break-all;
    background: var(--bg-primary);
    border: 1px dashed var(--border);
    border-radius: 6px;
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    user-select: all;
}

.recovery-actions {
    display: flex;
    gap: var(--spacing-sm);
    justify-content: center;
    margin-bottom: var(--spacing-md);
}

#recovery-continue {
    margin-top: var(--spacing-md);
    width: 100%;
}

/* Main app header */
.app-header {
    background: var(--bg-secondary);
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.header-nav {
    display: flex;
    gap: var(--spacing-sm);
}

.save-indicator {
    padding: var(--spacing-xs) var(--spacing-sm);
    background: #2E7D32;
    color: white;
    border-radius: 4px;
    font-size: 0.85rem;
}

.save-indicator.saving {
    background: #FFC107;
    color: #212121;
}

.save-indicator.error {
    background: #c62828;
}

/* Main app content. min-height (not a fixed height) so the map keeps filling the viewport,
   but the page can grow and scroll when the accessible outline twin sits below it. */
.app-main {
    min-height: calc(100vh - 140px);
    display: flex;
    flex-direction: column;
}

.app-footer {
    background: var(--bg-secondary);
    padding: var(--spacing-sm);
    border-top: 1px solid var(--border);
    text-align: center;
}

.keyboard-hints {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

kbd {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 2px 4px;
    font-size: 0.8rem;
}

/* Mind map container */
.mindmap-container {
    flex: 1;
    background: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin: var(--spacing-md);
    position: relative;
    overflow: hidden;
    min-height: 400px;
}

.mindmap {
    width: 100%;
    height: 100%;
    min-height: 400px;
}

/* The graph is drawn to a canvas by Cytoscape; node/edge styling (pastel building-block
   nodes, first-class edges) lives in mindmap.js (the Cytoscape style array, theme-aware).
   The list-view twin below is the accessible, keyboard-first representation of the same map. */

/* ===== MAP OUTLINE (accessible list-view twin of the canvas) ===== */
.map-outline-region {
    margin: 0 var(--spacing-md) var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.map-outline-heading {
    margin: 0 0 var(--spacing-xs);
    font-size: 1rem;
    color: var(--text-primary);
}

.map-outline-note {
    margin: 0 0 var(--spacing-md);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.map-outline-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.map-outline-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.map-outline-node {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    width: 100%;
    text-align: left;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    /* Keep focus/scroll-into-view clear of the sticky top crisis bar and the fixed
       bottom safety bar (both z-index 1000), so a node never tucks under them. */
    scroll-margin-top: 4rem;
    scroll-margin-bottom: 4rem;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.map-outline-node:hover {
    border-color: var(--accent, #6f5f96);
}

.map-outline-node:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.map-outline-node.selected {
    border-color: var(--accent, #6f5f96);
    box-shadow: 0 0 0 2px rgba(111, 95, 150, 0.25);
}

.map-outline-chip {
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid rgba(74, 69, 64, 0.18);
}

.map-outline-title {
    flex: 1 1 auto;
    font-weight: 600;
}

.map-outline-type {
    flex: 0 0 auto;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.map-outline-connections {
    padding-left: calc(14px + var(--spacing-sm) + var(--spacing-md));
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.map-outline-empty {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ===== NODE DETAIL DRAWER (#108): a selected node's home ===== */
.node-detail {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(380px, 92vw);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    pointer-events: none;
}

.node-detail.open {
    transform: translateX(0);
    pointer-events: auto;
}

@media (prefers-reduced-motion: reduce) {
    .node-detail { transition: none; }
}

.node-detail-head {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border);
}

.detail-chip {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(74, 69, 64, 0.18);
}

.detail-type-name {
    flex: 1 1 auto;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.85rem;
}

.detail-close {
    flex: 0 0 auto;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 var(--spacing-xs);
    border-radius: 6px;
}

.detail-close:hover { color: var(--text-primary); }
.detail-close:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.node-detail-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.detail-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.detail-input {
    width: 100%;
    padding: var(--spacing-sm);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
}

.detail-input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.detail-story {
    resize: vertical;
    min-height: 120px;
    line-height: 1.5;
}

.detail-hint {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.keyword-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-xs);
}

.keyword-tags:empty { display: none; }

.keyword-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 6px 3px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.keyword-tag button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0 2px;
    border-radius: 50%;
}

.keyword-tag button:hover { color: var(--text-primary); }
.keyword-tag button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.detail-connections {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-connections li {
    font-size: 0.9rem;
    color: var(--text-primary);
    padding: 4px 0;
}

.detail-connections-empty {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.node-detail-foot {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    border-top: 1px solid var(--border);
}

.btn-text-danger {
    background: transparent;
    border: 1px solid transparent;
    color: #b3261e;
    cursor: pointer;
}

.btn-text-danger:hover {
    background: rgba(179, 38, 30, 0.08);
    border-color: rgba(179, 38, 30, 0.3);
}

.btn-text-danger:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ===== Discovery: a quiet "possible connections" affordance + its gentle list ===== */
.suggest-affordance {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: var(--spacing-md);
    padding: 4px 12px;
    background: rgba(155, 139, 189, 0.12);
    border: 1px solid rgba(155, 139, 189, 0.4);
    border-radius: 999px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease;
}

.suggest-affordance[hidden] { display: none; }
.suggest-affordance:hover { background: rgba(155, 139, 189, 0.2); border-color: rgba(155, 139, 189, 0.6); }
.suggest-affordance:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.suggest-spark { color: #9b8bbd; }

.suggest-intro {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0 0 var(--spacing-md);
}

.suggest-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.suggest-item {
    padding: var(--spacing-md);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-left: 4px solid #9b8bbd;
    border-radius: 10px;
}

.suggest-pair {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-weight: 600;
    color: var(--text-primary);
}

.suggest-chip {
    flex: 0 0 auto;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(74, 69, 64, 0.18);
}

.suggest-link-icon { color: var(--text-secondary); }

.suggest-reason {
    color: var(--text-secondary);
    font-size: 0.88rem;
    margin: 4px 0 var(--spacing-sm);
}

.suggest-actions {
    display: flex;
    gap: var(--spacing-sm);
}

.suggest-connect {
    background: #B2DFDB;
    color: #1f3b37;
    border: none;
    padding: 6px 14px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.suggest-connect:hover { filter: brightness(0.97); }
.suggest-connect:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.suggest-dismiss {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
}

.suggest-dismiss:hover { color: var(--text-primary); }
.suggest-dismiss:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.suggest-empty {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.noscript-note {
    max-width: 540px;
    margin: 15vh auto;
    padding: var(--spacing-lg);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    text-align: center;
    line-height: 1.6;
    color: var(--text-primary);
}

.mindmap-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-secondary);
}

.node-type-preview {
    display: flex;
    gap: var(--spacing-lg);
    margin-top: var(--spacing-lg);
    justify-content: center;
}

.node-type-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
}

.node-preview {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.node-preview.event { background: #C8E6C9; }
.node-preview.emotion { background: #BBDEFB; }
.node-preview.person { background: #F8BBD9; }
.node-preview.place { background: #D7CCC8; }
.node-preview.trigger { background: #FFE0B2; }
.node-preview.coping { background: #A5D6A7; }
.node-preview.insight { background: #E1BEE7; }
.node-preview.growth { background: #C8F7C5; }
.node-preview.support { background: var(--support-color); }

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 8px;
    max-width: 600px;
    max-height: 80vh;
    overflow: auto;
    width: 90%;
}

.modal-large {
    max-width: 800px;
}

.modal-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: var(--spacing-lg);
}

.modal-footer {
    padding: var(--spacing-lg);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: var(--border);
}

/* Node type selector */
.node-type-select {
    margin-bottom: var(--spacing-sm);
}

.type-description {
    padding: var(--spacing-md);
    background: var(--bg-primary);
    border-radius: 4px;
    border-left: 4px solid var(--focus);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.type-info {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.type-info small {
    opacity: 0.8;
    font-style: italic;
}

/* Export options */
.export-options {
    display: flex;
    gap: var(--spacing-md);
    margin-top: var(--spacing-lg);
}

/* Crisis resources in settings */
.crisis-resources ul {
    padding-left: var(--spacing-lg);
    margin-top: var(--spacing-sm);
}

.crisis-resources li {
    margin-bottom: var(--spacing-sm);
}

/* Notifications */
.notification {
    position: fixed;
    bottom: var(--spacing-xl);
    right: var(--spacing-xl);
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    z-index: 2000;
}

.notification.show {
    opacity: 1;
    transform: translateY(0);
}

.notification-success {
    border-color: #4CAF50;
    background: #E8F5E9;
    color: #2E7D32;
}

.notification-error {
    border-color: #F44336;
    background: #FFEBEE;
    color: #C62828;
}

/* The trigger pairing nudge: a gentle, opt-in invitation (not an auto-dismissing toast). */
.notification-nudge {
    border-color: var(--accent, #6f5f96);
    max-width: 320px;
}
.notification-nudge .nudge-text {
    margin: 0 0 var(--spacing-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.5;
}
.notification-nudge .nudge-actions {
    display: flex;
    gap: var(--spacing-sm);
}
.notification-nudge .nudge-actions button {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.4rem 0.9rem;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background 0.3s ease, border-color 0.3s ease;
}
.notification-nudge .nudge-add {
    background: #A5D6A7;
    border-color: #A5D6A7;
    color: #1f3b22;
}
.notification-nudge .nudge-add:hover {
    background: #94c997;
    border-color: #94c997;
}
.notification-nudge .nudge-dismiss {
    background: transparent;
    color: var(--text-secondary);
}
.notification-nudge .nudge-dismiss:hover {
    border-color: var(--text-secondary);
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .notification {
        transition: none;
    }
}

/* Responsive design */
@media (max-width: 768px) {
    /* Header stacks: logo row on top, the actions wrap full-width below (no more cramming). */
    .app-header {
        flex-direction: column;
        align-items: stretch;
        gap: var(--spacing-sm);
    }

    .header-left {
        justify-content: space-between;
    }

    .header-nav {
        flex-wrap: wrap;
        gap: var(--spacing-xs);
    }

    .header-nav .btn {
        flex: 1 1 auto;
        justify-content: center;
        min-height: 44px;
    }

    .toolbar-status {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--spacing-xs);
    }

    .suggest-affordance {
        margin-left: 0;
    }

    .btn-toolbar {
        min-height: 44px;
    }

    /* Modals fill the width but stay clear of the fixed bottom safety bar. */
    .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: calc(100dvh - 4rem);
        border-radius: 12px;
    }

    .node-type-preview {
        flex-direction: column;
        gap: var(--spacing-md);
    }
}

/* Phones: the node detail drawer becomes a bottom sheet (easier to reach + dismiss by thumb). */
@media (max-width: 640px) {
    .node-detail {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 85dvh;
        border-left: none;
        border-top: 1px solid var(--border);
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.16);
    }

    .node-detail.open {
        transform: translateY(0);
    }
}

/* Print styles for therapy sessions */
@media print {
    .no-print {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        color: black;
        background: white;
    }
    
    .mindmap-container {
        box-shadow: none;
        border: 1px solid #000;
    }
}

/* Loading states */
.loading {
    text-align: center;
    color: var(--text-secondary);
    padding: var(--spacing-xl);
}

.loading-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--focus);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: var(--spacing-sm);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Safety affordances (persistent) ===== */
/* Clear the fixed bottom safety bar (which can wrap to two rows on narrow screens), so the
   last of the page content is never tucked underneath it. */
body {
    padding-bottom: 4rem;
}

.safety-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-md);
    flex-wrap: wrap;
    padding: var(--spacing-xs) var(--spacing-md);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.safety-disclaimer {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.safety-actions {
    display: flex;
    gap: var(--spacing-sm);
}

.btn-safety {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: var(--spacing-xs) var(--spacing-md);
    font-size: 0.85rem;
}

.btn-safety:hover {
    background: var(--bg-primary);
}

/* ===== Grounding + crisis: warm, reassuring presentation (#107) ===== */
.grounding-intro,
.crisis-intro {
    color: var(--text-primary);
    line-height: 1.6;
}

.grounding-section {
    margin-bottom: var(--spacing-lg);
}

.grounding-section h3 {
    font-size: 1.05rem;
    color: var(--text-primary);
    margin: 0 0 var(--spacing-sm);
}

/* Breathing: a soft orb that swells with the breath, in step with the words. */
.grounding-breathe {
    background: linear-gradient(180deg, rgba(178, 223, 219, 0.18), rgba(200, 230, 201, 0.12));
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: var(--spacing-lg) var(--spacing-md) var(--spacing-md);
    text-align: center;
}

.breathing-orb-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 170px;
}

.breathing-orb {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: radial-gradient(circle at 50% 38%, #d6f0e6 0%, #b2dfdb 55%, #a5d6a7 100%);
    box-shadow: 0 0 0 10px rgba(178, 223, 219, 0.18), 0 8px 24px rgba(120, 160, 150, 0.25);
    transform: scale(0.7);
    transition: transform 4s ease-in-out, box-shadow 4s ease-in-out;
}

.breathing-orb.is-in {
    transform: scale(1);
    transition: transform 4s ease-in-out, box-shadow 4s ease-in-out;
}

.breathing-orb.is-hold {
    transform: scale(1);
    transition: transform 0.4s ease;
}

.breathing-orb.is-out {
    transform: scale(0.7);
    transition: transform 6s ease-in-out, box-shadow 6s ease-in-out;
}

.breathing-guide {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: var(--spacing-sm);
    letter-spacing: 0.02em;
    transition: opacity 0.45s ease;
}

.grounding-hint {
    color: var(--text-secondary);
    text-align: center;
    font-size: 0.9rem;
}

.grounding-hint-left {
    text-align: left;
    margin: 0 0 var(--spacing-sm);
}

/* 5-4-3-2-1 senses, as gentle pastel cards. */
.senses-list {
    list-style: none;
    margin: var(--spacing-sm) 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.sense-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.sense-num {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #3a3a3a;
}

.sense-text { color: var(--text-primary); }

.sense-see .sense-num { background: #BBDEFB; }
.sense-feel .sense-num { background: #FFCCBC; }
.sense-hear .sense-num { background: #D1C4E9; }
.sense-smell .sense-num { background: #C8E6C9; }
.sense-taste .sense-num { background: #F8BBD9; }

/* Crisis resources, as calm cards with a soft accent edge. */
.crisis-list {
    list-style: none;
    margin: var(--spacing-md) 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.crisis-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-left: 4px solid #B2DFDB;
    border-radius: 10px;
}

.crisis-key {
    font-weight: 700;
    color: var(--text-primary);
}

.crisis-link { color: var(--focus); text-decoration: none; }
.crisis-link:hover { text-decoration: underline; }

.crisis-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* The breathing guide is the one place we keep gentle motion under reduce-motion: the slow
   swell and the word fade ARE the exercise (functional, calm, non-vestibular), not decoration.
   !important is needed to win over the global reduce-motion reset above. */
@media (prefers-reduced-motion: reduce) {
    .breathing-orb { transition: transform 4s ease-in-out !important; }
    .breathing-orb.is-in { transition: transform 4s ease-in-out !important; }
    .breathing-orb.is-hold { transition: transform 0.4s ease !important; }
    .breathing-orb.is-out { transition: transform 6s ease-in-out !important; }
    .breathing-guide { transition: opacity 0.45s ease !important; }
}

/* ===== MIND MAP TOOLBAR ===== */
.mindmap-toolbar {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.mindmap-toolbar .toolbar-section {
    margin-bottom: var(--spacing-sm);
}

.mindmap-toolbar h3 {
    margin: 0 0 var(--spacing-xs) 0;
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 600;
}

.mindmap-toolbar .toolbar-help {
    margin: 0 0 var(--spacing-md) 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-style: italic;
}

.toolbar-buttons {
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
    margin-bottom: var(--spacing-sm);
}

.btn-toolbar {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: 4px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.btn-toolbar:hover:not(:disabled) {
    background: var(--focus);
    color: white;
    border-color: var(--focus);
}

.btn-toolbar.active {
    background: var(--focus);
    color: white;
    border-color: var(--focus);
}

.btn-toolbar:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--bg-secondary);
}

.toolbar-status {
    font-size: 0.875rem;
    color: var(--text-secondary);
    padding: var(--spacing-xs) 0;
    border-top: 1px solid var(--border);
    margin-top: var(--spacing-sm);
    padding-top: var(--spacing-sm);
}

#selection-status {
    font-weight: 500;
}

/* ===== MIND MAP HELP SYSTEM ===== */
.mindmap-help {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: var(--spacing-lg);
    margin-top: var(--spacing-lg);
    max-width: 500px;
}

.mindmap-help h3 {
    margin: 0 0 var(--spacing-md) 0;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.mindmap-help ul {
    margin: 0 0 var(--spacing-md) 0;
    padding-left: var(--spacing-lg);
}

.mindmap-help li {
    margin-bottom: var(--spacing-sm);
    line-height: 1.5;
}

.mindmap-help li strong {
    color: var(--focus);
}

.mindmap-help-note {
    background: rgba(33, 150, 243, 0.1);
    border-left: 4px solid var(--focus);
    padding: var(--spacing-md);
    margin: var(--spacing-md) 0 0 0;
    border-radius: 4px;
    font-size: 0.9rem;
    line-height: 1.4;
}

/* Improve node type selector styling */
.node-type-select {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: var(--spacing-sm);
    border-radius: 4px;
    font-size: 1rem;
    width: 100%;
}

.node-type-select option {
    padding: var(--spacing-sm);
}

/* Better visual hierarchy for form labels */
.form-group label {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-xs);
}