/* vv3B Base CSS - Mobile-First Design */

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

html {
    font-size: 16px;
    line-height: 1.5;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Focus styles for accessibility */
*:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Selection */
::selection {
    background-color: var(--accent-alpha-20);
    color: var(--text-primary);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 0.5rem;
}

h1 {
    font-size: 1.5rem;
}

h2 {
    font-size: 1.25rem;
}

h3 {
    font-size: 1.125rem;
}

p {
    margin-bottom: 1rem;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    text-align: center;
    max-width: 300px;
    padding: 2rem;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-secondary);
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-content h2 {
    color: var(--accent);
    font-size: 2rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.loading-content p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* App Container */
.app-container {
    height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
    background: var(--bg-primary);
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 100;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.app-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    margin: 0;
}

/* Menu Toggle */
.menu-toggle {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 24px;
    height: 24px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.menu-toggle span {
    display: block;
    height: 2px;
    width: 100%;
    background: var(--text-primary);
    border-radius: 1px;
    transition: all 0.3s ease;
}

.menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* Connection Status */
.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
}

.status-indicator.connected,
.status-indicator.online {
    background: #10b981;
    animation: pulse-green 2s infinite;
}

.status-indicator.disconnected,
.status-indicator.offline {
    background: #ef4444;
}

.status-indicator.connecting {
    background: #f59e0b;
    animation: pulse-yellow 1s infinite;
}

.status-indicator.error {
    background: #ef4444;
    animation: pulse-yellow 1s infinite;
}

@keyframes pulse-green {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes pulse-yellow {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Icon Button */
.icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-button:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.icon-button:active {
    transform: scale(0.95);
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 1fr;
    height: 100%;
    overflow: hidden;
}

/* Side Panel (Mobile) */
.side-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 200;
    display: flex;
    flex-direction: column;
}

.side-panel.open {
    transform: translateX(0);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.panel-header h2,
.panel-header h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

/* Chat Area */
.chat-area {
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: 100%;
    background: var(--bg-primary);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
}

.chat-header h2 {
    font-size: 1.125rem;
    margin: 0;
}

.room-info {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Messages */
.messages-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    min-height: 0; /* Critical for flex containers */
    display: flex;
    flex-direction: column;
}

.messages-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Prevent flex from expanding beyond container */
}

/* Welcome Message */
.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-secondary);
    max-width: 400px;
    margin: 0 auto;
}

.welcome-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.welcome-message h3 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.welcome-message p {
    font-size: 0.875rem;
    line-height: 1.6;
    margin-bottom: 0.5rem;
}

/* Message Composer */
.composer-container {
    padding: 1rem;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
}

.message-composer {
    width: 100%;
}

.composer-input-container {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.composer-input {
    width: 100%;
    min-height: 44px;
    max-height: 120px;
    padding: 12px 60px 12px 16px;
    background: none;
    border: none;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-primary);
    resize: none;
    outline: none;
}

.composer-input::placeholder {
    color: var(--text-secondary);
}

.composer-actions {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
}

.composer-actions .icon-button {
    width: 32px;
    height: 32px;
}

.send-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--accent);
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

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

/* Peer Panel (Hidden on mobile) */
.peer-panel {
    display: none;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 1rem;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-large {
    max-width: 600px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 1.5rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
}

.modal-close:hover {
    color: var(--text-primary);
    background: var(--bg-primary);
}

.modal-body {
    padding: 0 1.5rem 1.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.form-input,
.form-select {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    color: var(--text-primary);
    transition: border-color 0.2s ease;
}

.form-input:focus,
.form-select:focus {
    border-color: var(--accent);
}

.form-input::placeholder {
    color: var(--text-secondary);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 2rem;
}

.button {
    flex: 1;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.button-primary {
    background: var(--accent);
    color: white;
}

.button-primary:hover {
    background: var(--accent-hover);
}

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

.button-secondary:hover {
    background: var(--bg-secondary);
}

.button:active {
    transform: scale(0.98);
}

/* Accessibility */
@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 */
@media (prefers-contrast: high) {
    .border {
        border-width: 2px;
    }
    
    .icon-button:focus {
        outline: 3px solid var(--accent);
    }
}

/* Print styles */
@media print {
    .side-panel,
    .peer-panel,
    .composer-container,
    .modal-overlay {
        display: none !important;
    }
}