/* Haven - Trauma Support Companion */

:root {
    --bg-primary: #1a1625;
    --bg-secondary: #211d2e;
    --bg-tertiary: #2a2639;
    --accent: #c4b5fd;
    --accent-light: #e9d5ff;
    --accent-dark: #a78bfa;
    --accent-warm: #fcd5ce;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.75);
    --text-muted: rgba(255, 255, 255, 0.5);
    --safe-top: env(safe-area-inset-top, 20px);
    --safe-bottom: env(safe-area-inset-bottom, 20px);
    --font-main: 'Inter', sans-serif;
    --font-display: 'Lora', serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(var(--safe-top) + 10px) 15px 15px;
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(196, 181, 253, 0.1);
}

.back-btn, .menu-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.back-btn:hover, .menu-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.companion-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-small {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.companion-info h1 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 500;
}

.companion-info .status {
    font-size: 0.75rem;
    color: var(--accent-light);
    font-style: italic;
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 15px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Message Groups */
.message-group {
    display: flex;
    gap: 10px;
    max-width: 85%;
}

.message-group.companion {
    align-self: flex-start;
}

.message-group.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.message-group.user .message-avatar {
    background: linear-gradient(135deg, var(--accent-warm) 0%, #f9a8d4 100%);
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Individual Messages */
.message {
    padding: 14px 18px;
    border-radius: 20px;
    line-height: 1.7;
    font-size: 0.95rem;
    animation: messageIn 0.4s ease;
}

@keyframes messageIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-group.companion .message {
    background: var(--bg-tertiary);
    border-bottom-left-radius: 6px;
}

.message-group.companion .message:first-child {
    border-top-left-radius: 20px;
}

.message-group.companion .message:last-child {
    border-bottom-left-radius: 20px;
}

.message-group.user .message {
    background: linear-gradient(135deg, var(--accent-dark) 0%, var(--accent) 100%);
    color: #1a1625;
    border-bottom-right-radius: 6px;
}

.message-group.user .message:first-child {
    border-top-right-radius: 20px;
}

.message-group.user .message:last-child {
    border-bottom-right-radius: 20px;
}

.message p {
    margin: 0;
}

.message strong {
    color: var(--accent-light);
}

.message-group.user .message strong {
    color: #1a1625;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 14px 18px;
    background: var(--bg-tertiary);
    border-radius: 20px;
    width: fit-content;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    opacity: 0.5;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Quick Options */
.quick-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 0;
}

.quick-btn {
    padding: 12px 18px;
    background: var(--bg-tertiary);
    border: 1px solid rgba(196, 181, 253, 0.15);
    border-radius: 25px;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.quick-btn:hover {
    background: rgba(196, 181, 253, 0.2);
    border-color: var(--accent);
}

/* Input Area */
.input-area {
    padding: 15px 15px calc(var(--safe-bottom) + 15px);
    background: var(--bg-secondary);
    border-top: 1px solid rgba(196, 181, 253, 0.1);
}

.input-container {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: var(--bg-tertiary);
    border-radius: 30px;
}

.voice-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.voice-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.voice-btn.listening {
    background: var(--accent);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 1rem;
    outline: none;
}

#message-input::placeholder {
    color: var(--text-muted);
    font-style: italic;
}

.send-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    color: #1a1625;
    cursor: pointer;
    transition: all 0.3s ease;
}

.send-btn:disabled {
    background: var(--bg-secondary);
    color: var(--text-muted);
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    background: var(--accent-light);
    transform: scale(1.05);
}

.safety-note {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 10px;
}

.safety-note a {
    color: var(--accent-light);
    text-decoration: none;
    margin: 0 2px;
}

.safety-note a:hover {
    text-decoration: underline;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 24px;
    padding: 28px;
    max-width: 400px;
    width: 100%;
    border: 1px solid rgba(196, 181, 253, 0.1);
}

.modal-content h3 {
    font-family: var(--font-display);
    font-size: 1.4rem;
    margin-bottom: 15px;
    text-align: center;
    font-weight: 500;
}

.menu-option {
    width: 100%;
    padding: 14px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 12px;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 1rem;
    cursor: pointer;
    margin-bottom: 10px;
    transition: all 0.3s ease;
    text-align: left;
}

.menu-option:last-child {
    margin-bottom: 0;
}

.menu-option:hover {
    background: rgba(196, 181, 253, 0.2);
}

.menu-option.primary {
    background: var(--accent);
    color: #1a1625;
    text-align: center;
    font-weight: 500;
}

.menu-option.close {
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
}

/* Help Modal */
.help-content p {
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 15px;
}

.help-links {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.help-link {
    display: flex;
    flex-direction: column;
    padding: 14px;
    background: var(--bg-tertiary);
    border: 1px solid rgba(196, 181, 253, 0.1);
    border-radius: 12px;
    text-decoration: none;
    transition: all 0.3s ease;
}

.help-link:hover {
    background: rgba(196, 181, 253, 0.15);
    border-color: var(--accent);
}

.help-link strong {
    color: var(--accent-light);
    font-size: 1rem;
}

.help-link span {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Grounding Modal */
.grounding-content {
    text-align: center;
}

.grounding-content > p {
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.6;
}

.grounding-steps {
    margin: 20px 0;
}

.grounding-step {
    padding: 14px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    margin-bottom: 8px;
    font-size: 1rem;
}

.grounding-step strong {
    font-size: 1.4rem;
    color: var(--accent);
    margin-right: 10px;
}

.grounding-step span {
    color: var(--accent-light);
    font-weight: 500;
}

.grounding-reminder {
    color: var(--accent-light);
    font-family: var(--font-display);
    font-style: italic;
    margin: 20px 0;
    padding: 15px;
    background: rgba(196, 181, 253, 0.1);
    border-radius: 12px;
}

/* Breathing Modal */
.breathing-content {
    text-align: center;
}

.breathing-content > p {
    color: var(--text-secondary);
    margin-bottom: 25px;
}

.breath-circle {
    width: 180px;
    height: 180px;
    margin: 0 auto 25px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 4s ease-in-out;
}

.breath-circle.inhale {
    transform: scale(1.3);
}

.breath-circle.exhale {
    transform: scale(1);
}

.breath-circle span {
    color: #1a1625;
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 500;
}

.breath-controls {
    margin-bottom: 20px;
}

.breath-btn {
    padding: 12px 30px;
    background: var(--accent);
    border: none;
    border-radius: 25px;
    color: #1a1625;
    font-family: var(--font-main);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.breath-btn:hover {
    background: var(--accent-light);
}

/* Container Exercise */
.container-content {
    text-align: center;
}

.container-content > p {
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 20px;
}

.container-visual {
    margin: 30px 0;
}

.container-box {
    width: 120px;
    height: 120px;
    margin: 0 auto;
    background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-primary));
    border: 2px solid var(--accent);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    animation: containerFloat 3s ease-in-out infinite;
}

@keyframes containerFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.container-instruction {
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Tool Cards */
.tool-card {
    background: linear-gradient(135deg, rgba(196, 181, 253, 0.12) 0%, rgba(196, 181, 253, 0.05) 100%);
    border: 1px solid rgba(196, 181, 253, 0.15);
    border-radius: 16px;
    padding: 18px;
    margin-top: 12px;
}

.tool-card h4 {
    color: var(--accent-light);
    font-size: 1rem;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tool-card p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.7;
    margin: 0;
}

.tool-card ul {
    margin: 12px 0 0;
    padding-left: 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.8;
}

.tool-card li {
    margin-bottom: 6px;
}

/* Affirmation Card */
.affirmation-card {
    background: linear-gradient(135deg, rgba(196, 181, 253, 0.2) 0%, rgba(252, 213, 206, 0.15) 100%);
    border: 1px solid rgba(196, 181, 253, 0.25);
    border-radius: 16px;
    padding: 22px;
    text-align: center;
    margin-top: 12px;
}

.affirmation-card p {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 500;
    color: var(--accent-light);
    margin: 0;
    line-height: 1.6;
    font-style: italic;
}

