/* CSS Reset & Base */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --wa-green: #008069;
    --wa-green-dark: #006656;
    --wa-bg: #efeae2;
    --wa-bg-pattern: #d4cdc4;
    --wa-sent: #d9fdd3;
    --wa-received: #ffffff;
    --wa-text: #111b21;
    --wa-text-muted: rgba(17, 27, 33, 0.45);
    --wa-check: #53bdeb;
    --wa-shadow: rgba(0, 0, 0, 0.13);
    
    --font-main: 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
    
    --phone-width: 375px;
    --phone-max-height: 85vh;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-main);
    background: linear-gradient(135deg, #667781 0%, #4a5568 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    color: var(--wa-text);
}

/* Skip link for accessibility */
.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--wa-green);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 0 0 8px 8px;
    text-decoration: none;
    font-weight: 500;
    z-index: 1000;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
}

/* Screen reader only utility */
.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;
}

/* Site header */
.site-header {
    text-align: center;
    margin-bottom: 1rem;
    color: white;
}

.site-title {
    font-size: 1.75rem;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.site-tagline {
    font-size: 0.9rem;
    opacity: 0.9;
    font-style: italic;
}

/* Main container */
.main-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    max-width: var(--phone-width);
}

/* Phone frame */
.phone-frame {
    width: 100%;
    max-width: var(--phone-width);
    background: var(--wa-bg);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 
        0 25px 80px rgba(0,0,0,0.4),
        0 0 0 1px rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    max-height: var(--phone-max-height);
    position: relative;
}

/* Status bar */
.status-bar {
    background: var(--wa-green);
    padding: 6px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: white;
    font-weight: 500;
}

.status-icons {
    display: flex;
    gap: 4px;
}

/* Chat header */
.chat-header {
    background: var(--wa-green);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.menu-button {
    background: none;
    border: none;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.menu-button:hover,
.menu-button:focus {
    background: rgba(255,255,255,0.1);
}

.menu-button:focus {
    outline: 2px solid white;
    outline-offset: 2px;
}

.avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #dfe5e7, #c8d1d3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--wa-green);
    font-weight: 600;
    font-size: 1rem;
    flex-shrink: 0;
}

.contact-info {
    flex: 1;
    min-width: 0;
}

.contact-name {
    color: white;
    font-size: 1rem;
    font-weight: 500;
    display: block;
}

.contact-status {
    color: rgba(255,255,255,0.8);
    font-size: 0.75rem;
    display: block;
}

.header-actions {
    display: flex;
    gap: 16px;
    color: white;
    font-size: 1.1rem;
}

/* Episode menu */
.episode-menu {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    z-index: 100;
    display: flex;
    flex-direction: column;
    animation: slideIn 0.2s ease;
}

.episode-menu[hidden] {
    display: none;
}

@keyframes slideIn {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

.menu-header {
    background: var(--wa-green);
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.menu-header h2 {
    font-size: 1.1rem;
    font-weight: 500;
}

.menu-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.menu-close:hover,
.menu-close:focus {
    background: rgba(255,255,255,0.1);
}

.menu-close:focus {
    outline: 2px solid white;
    outline-offset: 2px;
}

.episode-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

.episode-list-item {
    border-bottom: 1px solid #e9edef;
}

.episode-list-item a {
    display: flex;
    padding: 12px 16px;
    text-decoration: none;
    color: var(--wa-text);
    gap: 12px;
    align-items: center;
    transition: background 0.15s ease;
}

.episode-list-item a:hover,
.episode-list-item a:focus {
    background: #f0f2f5;
}

.episode-list-item a:focus {
    outline: 2px solid var(--wa-green);
    outline-offset: -2px;
}

.episode-list-item.active a {
    background: #d9fdd3;
}

.episode-list-avatar {
    width: 48px;
    height: 48px;
    background: var(--wa-green);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.episode-list-info {
    flex: 1;
    min-width: 0;
}

.episode-list-title {
    font-weight: 500;
    font-size: 0.95rem;
    margin-bottom: 2px;
}

.episode-list-preview {
    font-size: 0.85rem;
    color: var(--wa-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.episode-list-meta {
    font-size: 0.75rem;
    color: var(--wa-text-muted);
    text-align: right;
}

/* Chat area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    background: var(--wa-bg);
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4cdc4' fill-opacity='0.4'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    min-height: 400px;
}

.chat-area:focus {
    outline: none;
}

/* Episode content */
.episode {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.episode-header {
    text-align: center;
    padding: 8px 16px;
    margin-bottom: 8px;
}

.episode-title {
    display: inline-block;
    background: rgba(255,255,255,0.9);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    color: var(--wa-text-muted);
    box-shadow: 0 1px 0.5px var(--wa-shadow);
}

.episode-title strong {
    color: var(--wa-text);
}

/* Messages */
.message-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.message {
    display: flex;
    margin-bottom: 1px;
}

.message.sent {
    justify-content: flex-end;
}

.message.received {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 85%;
    padding: 6px 12px 6px 12px;
    border-radius: 8px;
    font-size: 0.9rem;
    line-height: 1.4;
    box-shadow: 0 1px 0.5px var(--wa-shadow);
    position: relative;
}

.message.sent .message-bubble {
    background: var(--wa-sent);
    border-top-right-radius: 2px;
}

.message.received .message-bubble {
    background: var(--wa-received);
    border-top-left-radius: 2px;
}

.message-text {
    margin: 0;
}

.message-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 3px;
    margin-top: 2px;
}

.message-time {
    font-size: 0.68rem;
    color: var(--wa-text-muted);
}

.message-checks {
    color: var(--wa-check);
    font-size: 0.85rem;
    letter-spacing: -3px;
}

/* Message gap for visual grouping */
.message-gap {
    height: 8px;
}

/* Navigation controls */
.nav-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: white;
    border-top: 1px solid #e9edef;
}

.nav-button {
    background: var(--wa-green);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.1s ease;
}

.nav-button:hover:not(:disabled) {
    background: var(--wa-green-dark);
}

.nav-button:active:not(:disabled) {
    transform: scale(0.95);
}

.nav-button:focus {
    outline: 2px solid var(--wa-green);
    outline-offset: 2px;
}

.nav-button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.episode-indicator {
    font-size: 0.9rem;
    color: var(--wa-text-muted);
    font-weight: 500;
}

/* Footer */
.site-footer {
    text-align: center;
    color: rgba(255,255,255,0.8);
    font-size: 0.8rem;
    margin-top: 1rem;
    padding: 1rem;
}

.site-footer a {
    color: white;
}

.redirect-note {
    margin-top: 0.5rem;
    font-size: 0.7rem;
    opacity: 0.7;
    font-style: italic;
}

/* Mobile adjustments */
@media (max-width: 400px) {
    body {
        padding: 0;
    }
    
    .site-header {
        padding: 1rem;
        margin-bottom: 0;
    }
    
    .phone-frame {
        border-radius: 0;
        max-height: none;
        min-height: calc(100vh - 120px);
    }
    
    .site-footer {
        padding: 0.75rem;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .message.received .message-bubble {
        border: 2px solid var(--wa-text);
    }
    
    .message.sent .message-bubble {
        border: 2px solid var(--wa-green-dark);
    }
}
