/**
 * WebRTC Calls PoC - Responsive CSS
 * Mobile-first design with large, touch-friendly buttons.
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
    display: flex;
    flex-direction: column;
}

/* Visually hidden utility class for screen readers */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    clip: rect(0 0 0 0);
    overflow: hidden;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    flex: 1;
}

/* Desktop layout: 2-column grid */
@media (min-width: 1024px) {
    .container {
        max-width: 1100px;
    }

    .app-footer {
        max-width: 1100px;
    }
    
    main {
        grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.3fr);
        align-items: start;
        gap: 32px;
        grid-template-areas:
            "status  video"
            "controls video"
            "controls chat"
            "extra   chat";
    }
    
    .status-section,
    .controls-section,
    .extra-controls {
        width: 100%;
    }
    
    .video-section,
    .chat-section {
        width: 100%;
    }
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    text-align: center;
}

header h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 8px;
}

.subtitle {
    font-size: 14px;
    opacity: 0.9;
    margin-bottom: 12px;
}

/* Header status container */
.header-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    font-size: 14px;
}

.header-status-left,
.header-status-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.header-status-left span,
.header-status-right span {
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    white-space: nowrap;
}

main {
    padding: 30px 20px;
    display: grid;
    grid-template-columns: 1fr;
    grid-auto-rows: auto;
    gap: 24px;
    grid-template-areas:
        "status"
        "controls"
        "video"
        "chat"
        "extra";
}

.status-section {
    grid-area: status;
}

.controls-section {
    grid-area: controls;
}

.video-section {
    grid-area: video;
}

.chat-section {
    grid-area: chat;
}

.extra-controls {
    grid-area: extra;
}

h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 16px;
    color: #333;
}

/* Nickname section */
.nickname-section {
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px solid #667eea;
}

.nickname-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.nickname-form label {
    font-weight: 500;
    color: #333;
}

.nickname-form input[type="text"] {
    padding: 12px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s;
}

.nickname-form input[type="text"]:focus {
    outline: none;
    border-color: #667eea;
}

.remember-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
}

.remember-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.remember-checkbox label {
    cursor: pointer;
    font-weight: normal;
}

.assigned-slot-info {
    padding: 12px;
    background: #e7f3ff;
    border-radius: 8px;
    border: 2px solid #667eea;
    font-weight: 500;
    color: #0066cc;
}

.nickname-hint {
    color: #666;
    font-size: 0.9em;
    line-height: 1.5;
}

/* All occupied section */
.all-occupied-section {
    padding: 40px 20px;
    text-align: center;
}

.message-block {
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 8px;
    padding: 30px;
}

.message-block h2 {
    color: #856404;
    margin-bottom: 16px;
}

.message-block p {
    color: #856404;
    margin-bottom: 20px;
    font-size: 16px;
}

/* Status cards */
.status-card {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 8px;
}

.status-card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    color: #495057;
}

.status-text {
    font-size: 14px;
    font-weight: 500;
    color: #333;
}

/* Slot status styles */
.status-taken {
    background: #d4edda !important;
    border-color: #28a745 !important;
}

.status-own {
    background: #c3e6cb !important;
    border-color: #1e7e34 !important;
    border-width: 2px;
}

.status-free {
    background: #f8f9fa;
    border-color: #dee2e6;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    display: inline-block;
    text-align: center;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

.btn:active:not(:disabled) {
    transform: translateY(0);
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #5568d3;
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #218838;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #c82333;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #5a6268;
}

/* Emergency Stop Button */
.btn-emergency-stop {
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    display: inline-block;
    transition: transform 0.1s ease, filter 0.1s ease;
    outline: none;
}

.btn-emergency-stop:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.btn-emergency-stop:active {
    transform: scale(0.95);
    filter: brightness(0.9);
}

.emergency-stop-image {
    width: 120px;  /* Фиксированный разумный размер */
    max-width: 100%;  /* Не больше контейнера */
    height: auto;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

/* Адаптивный размер для очень маленьких экранов */
@media (max-width: 480px) {
    .emergency-stop-image {
        width: 100px;
    }
}

/* Responsive adjustments for emergency stop button on mobile */
@media (max-width: 600px) {
    .emergency-stop-image {
        width: 150px;
    }
}

/* Extra controls section */
.extra-controls {
    grid-area: extra;
    padding-top: 0;
    margin-top: -8px;
    border-top: 2px solid #e9ecef;
}

.extra-controls h2 {
    margin-bottom: 12px;
}

.file-transfers {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 12px;
    margin-top: 16px;
    max-height: 300px;
    overflow-y: auto;
}

.file-transfer-entry {
    padding: 12px;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 14px;
}

.file-transfer-entry:last-child {
    border-bottom: none;
}

.file-transfer-entry a {
    color: #667eea;
    text-decoration: none;
}

.file-transfer-entry a:hover {
    text-decoration: underline;
}

.file-transfer-sending {
    color: #667eea;
}

.file-transfer-sent {
    color: #28a745;
}

.file-transfer-receiving {
    color: #ffc107;
}

.file-transfer-received {
    color: #28a745;
}

.file-transfer-error {
    color: #dc3545;
}

.file-transfer-download {
    background-color: #f8f9fa;
}

.file-label {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.file-name-display {
    font-size: 14px;
    color: #495057;
    font-style: italic;
    display: none;
}

/* Responsive adjustments for new sections */
@media (max-width: 600px) {
    .video-row {
        flex-direction: column;
    }
    
    .chat-input-row {
        flex-direction: column;
    }
    
    .extra-row {
        flex-direction: column;
    }
    
    .file-transfer-entry {
        padding: 10px;
        font-size: 13px;
    }
    
    .file-transfer-entry .btn {
        font-size: 13px;
        padding: 6px 10px;
        min-width: 80px;
    }
}

/* Video section */
.video-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.video-container {
    flex: 1;
    min-width: 250px;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.video-container figcaption {
    padding: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
}

.video-wrapper {
    position: relative;
    width: 100%;
    padding-top: 56.25%; /* 16:9 aspect ratio */
    background: #000;
}

.video-wrapper video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.btn-fullscreen {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 8px;
    cursor: pointer;
    font-size: 18px;
    z-index: 10;
    transition: background 0.2s;
}

.btn-fullscreen:hover {
    background: rgba(0, 0, 0, 0.9);
}

/* Chat section */
.chat-messages {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 16px;
    min-height: 200px;
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 16px;
}

.chat-message {
    margin-bottom: 12px;
    padding: 8px 12px;
    background: white;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.chat-message-sender {
    font-weight: 600;
    color: #667eea;
    margin-bottom: 4px;
}

.chat-message-text {
    color: #333;
    word-wrap: break-word;
}

.chat-input-row {
    display: flex;
    gap: 8px;
}

.chat-input-row input {
    flex: 1;
    padding: 12px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-size: 16px;
}

.chat-input-row input:focus {
    outline: none;
    border-color: #667eea;
}

/* Controls section */
.call-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.call-buttons .btn {
    flex: 1;
    min-width: 120px;
}

.hint-text {
    color: #666;
    font-size: 0.9em;
    margin-top: 8px;
}

/* Settings section */
.settings-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.settings-hint {
    text-align: center;
    max-width: 400px;
}

/* Footer */
.app-footer {
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    text-align: center;
    margin-top: 20px;
    margin-left: auto;
    margin-right: auto;
    max-width: 800px;
    width: 100%;
    border-radius: 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.app-footer span {
    display: inline-block;
    margin: 0 10px;
    color: #666;
    font-size: 0.9em;
}

/* File input */
.file-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: border-color 0.2s;
}

.file-label:hover {
    border-color: #667eea;
}

.file-label input[type="file"] {
    display: none;
}

.extra-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* Landing page (main domain) */
.landing-main {
    max-width: 500px;
    margin: 50px auto;
    padding: 40px 20px 20px;
    text-align: center;
}

.landing-booth-img {
    max-width: 220px;
    width: 100%;
    height: auto;
    display: block;
    margin: 0 auto 20px;
    user-select: none;
}

.landing-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 16px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 16px;
    display: block;
}

.landing-input:focus {
    outline: none;
    border-color: #667eea;
}

#landing-login-btn {
    margin-top: 0;
    margin-bottom: 0;
}

.landing-error {
    color: #d32f2f;
    margin-top: 12px;
    font-size: 14px;
}

@media (max-width: 600px) {
    .landing-main {
        max-width: 300px;
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: white;
    margin: 15% auto;
    padding: 30px;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
}

.modal-content h2 {
    margin-top: 0;
    color: #333;
}

.modal-content p {
    margin: 15px 0;
    color: #666;
    line-height: 1.6;
}

/* ========== Htpasswd Generator Styles ========== */
.htpasswd-generator {
    margin-top: 20px;
    padding: 20px;
    border: 2px solid #667eea;
    border-radius: 12px;
    background: linear-gradient(135deg, #f8f9ff 0%, #f0f4ff 100%);
}

.htpasswd-generator h3 {
    margin: 0 0 15px 0;
    color: #667eea;
    font-size: 1.1em;
}

.htpasswd-form .form-group {
    margin-bottom: 15px;
}

.htpasswd-form label {
    display: block;
    margin-bottom: 5px;
    color: #555;
    font-weight: 500;
}

.htpasswd-form input[type="text"],
.htpasswd-form input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1em;
    transition: border-color 0.2s;
}

.htpasswd-form input[type="text"]:focus,
.htpasswd-form input[type="password"]:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.password-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.password-input-wrapper input {
    flex: 1;
}

.btn-toggle-password {
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 1.1em;
    transition: background-color 0.2s, border-color 0.2s;
}

.btn-toggle-password:hover {
    background-color: #f0f4ff;
    border-color: #667eea;
}

.htpasswd-generator .btn {
    width: 100%;
    margin-top: 10px;
}
