/* 공통 레이아웃 */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f4f6f8;
    min-height: 100vh;
    color: #1a1a2e;
}

header {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 0.875rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

header h1 { font-size: 1.125rem; }

.brand-link {
    color: inherit;
    text-decoration: none;
}

.brand-link:hover { color: #4f46e5; }

.user-info {
    font-size: 0.8125rem;
    color: #6b7280;
    margin-right: 0.75rem;
}

.actions { display: flex; align-items: center; gap: 0.5rem; }

button {
    padding: 0.5rem 0.875rem;
    border: none;
    border-radius: 8px;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
}

button:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-outline {
    background: #fff;
    color: #374151;
    border: 1px solid #d1d5db;
}

.btn-outline:hover:not(:disabled) { background: #f9fafb; }

.btn-primary { background: #4f46e5; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #4338ca; }

.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-sm { padding: 0.375rem 0.625rem; font-size: 0.75rem; }

.page {
    max-width: 800px;
    margin: 0 auto;
    padding: 1.25rem;
}

.page-room {
    max-width: 960px;
    height: calc(100vh - 53px);
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* 목록 화면 */
.list-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.list-toolbar h2 { font-size: 1.25rem; }

.list-actions { display: flex; gap: 0.5rem; }

.room-list {
    list-style: none;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

.room-list-full { min-height: 200px; }

.room-item {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
    transition: background 0.15s;
}

.room-item:last-child { border-bottom: none; }
.room-item:hover { background: #f9fafb; }

.room-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.room-item-name {
    flex: 1;
    font-weight: 600;
    font-size: 0.9375rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-item-meta {
    font-size: 0.75rem;
    color: #6b7280;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 0;
}

.room-item-last-message {
    margin-top: 0.375rem;
    font-size: 0.8125rem;
    color: #6b7280;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge {
    display: inline-block;
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-size: 0.6875rem;
    font-weight: 600;
    background: #e5e7eb;
    color: #374151;
}

.badge-direct { background: #dbeafe; color: #1d4ed8; }
.badge-group { background: #dcfce7; color: #15803d; }
.badge-owner { background: #fef3c7; color: #b45309; }

.empty-state {
    padding: 3rem 1rem;
    text-align: center;
    color: #9ca3af;
    font-size: 0.875rem;
    line-height: 1.6;
}

/* 상세 화면 */
.chat-panel-full {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    min-height: 0;
    border-left: 1px solid #e5e7eb;
    border-right: 1px solid #e5e7eb;
}

.chat-header {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-shrink: 0;
}

.chat-header-info h2 { font-size: 1rem; margin-bottom: 0.125rem; }

.chat-header-info p {
    font-size: 0.75rem;
    color: #6b7280;
}

.chat-header-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.connection-status {
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.25rem;
}

.status-connected { background: #22c55e; }
.status-disconnected { background: #ef4444; }

.participants {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 0.25rem;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    background: #f9fafb;
}

.message {
    max-width: 75%;
    padding: 0.625rem 0.875rem;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.45;
}

.message-other {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e5e7eb;
}

.message-mine {
    align-self: flex-end;
    background: #4f46e5;
    color: #fff;
}

.message-meta {
    font-size: 0.6875rem;
    opacity: 0.75;
    margin-bottom: 0.25rem;
}

.message-body {
    white-space: pre-wrap;
    word-break: break-word;
}

.message-system {
    align-self: center;
    background: #e5e7eb;
    color: #6b7280;
    font-size: 0.75rem;
    max-width: 100%;
}

.message-placeholder {
    align-self: center;
    color: #9ca3af;
    font-size: 0.8125rem;
    margin-top: 2rem;
}

.chat-input-area {
    padding: 0.875rem 1.25rem;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.chat-input-area input {
    flex: 1;
    padding: 0.625rem 0.875rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.875rem;
}

.chat-input-area input:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.chat-input-area input:disabled { background: #f3f4f6; }

/* 모달 */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-overlay.visible { display: flex; }

.modal {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-width: 420px;
    padding: 1.5rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.modal h3 {
    font-size: 1.125rem;
    margin-bottom: 1.25rem;
}

.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.375rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.875rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #4f46e5;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1.25rem;
}

.modal-join { max-width: 480px; }

.browse-toggle-btn {
    width: 100%;
    margin-top: 0.5rem;
}

.browse-room-panel {
    display: none;
    margin-bottom: 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #f9fafb;
    overflow: hidden;
}

.browse-room-panel.visible {
    display: block;
}

.browse-room-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
}

.browse-room-panel-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #374151;
}

.browse-room-list-wrap {
    max-height: min(280px, 45vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.browse-room-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.browse-room-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
}

.browse-room-item:last-child { border-bottom: none; }

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

.browse-room-name {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.browse-room-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: #6b7280;
}

.browse-room-select-btn {
    flex-shrink: 0;
    white-space: nowrap;
}

.error-banner {
    display: none;
    background: #fef2f2;
    color: #b91c1c;
    padding: 0.625rem 1rem;
    font-size: 0.8125rem;
    border-bottom: 1px solid #fecaca;
}

.error-banner.visible { display: block; }

@media (max-width: 768px) {
    .page { padding: 1rem; }
    .chat-header { flex-direction: column; }
    .chat-header-actions { width: 100%; }
}

/* 영상통화 */
[hidden] { display: none !important; }

.call-panel {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid #e5e7eb;
    background: #eef2ff;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    flex-shrink: 0;
}

.call-status { font-size: 0.875rem; color: #3730a3; }

.call-actions { display: flex; gap: 0.5rem; }

/* 통화 중 레이아웃: 왼쪽 영상, 오른쪽 채팅 */
.page-room.in-call {
    max-width: 1440px;
    flex-direction: row;
}

.page-room.in-call .chat-panel-full {
    flex: 0 0 440px;
}

.call-stage {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: #111827;
}

.call-videos {
    flex: 1;
    min-height: 0;
    position: relative;
}

#remoteVideo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

#localVideo {
    position: absolute;
    right: 1rem;
    bottom: 1rem;
    width: 22%;
    min-width: 120px;
    border: 2px solid #fff;
    border-radius: 6px;
    background: #000;
}

.call-stage-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: #1f2937;
    color: #e5e7eb;
    font-size: 0.875rem;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .page-room.in-call { flex-direction: column; }
    .page-room.in-call .chat-panel-full { flex: 1 1 auto; min-height: 0; }
    .call-stage { flex: 0 0 45vh; }
}

/* 시스템 메시지 (통화 기록 등) */
.message-system {
    align-self: center;
    max-width: 90%;
    padding: 0.375rem 0.75rem;
    border-radius: 999px;
    background: #e5e7eb;
    color: #4b5563;
    font-size: 0.75rem;
}

.message-system-time {
    margin-left: 0.375rem;
    color: #9ca3af;
}

/* WebRTC 연결 정보 */
.chat-header-info { flex: 1; min-width: 0; }
.rtc-monitor { margin-top: 0.5rem; font-size: 0.75rem; }
.rtc-monitor summary { cursor: pointer; color: #4f46e5; }
.rtc-info {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.125rem 0.5rem;
    margin: 0.375rem 0;
}
.rtc-info dt { color: #6b7280; }
.rtc-info dd { margin: 0; font-family: ui-monospace, monospace; word-break: break-all; }
.rtc-log {
    max-height: 10rem;
    overflow-y: auto;
    margin: 0;
    padding: 0.375rem 0.5rem;
    list-style: none;
    background: #f9fafb;
    border-radius: 4px;
    font-family: ui-monospace, monospace;
}
.rtc-log-send { color: #1d4ed8; }
.rtc-log-recv { color: #047857; }
.rtc-log-note { color: #6b7280; }

