/**
 * ==========================================
 * Nursery CCTV System - Main Stylesheet
 * Font: Prompt (Offline)
 * ==========================================
 */

/* --- Font Face Declaration --- */
@font-face {
    font-family: 'Prompt';
    src: url('/font/Prompt-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
}

@font-face {
    font-family: 'Prompt';
    src: url('/font/Prompt-Medium.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
}

@font-face {
    font-family: 'Prompt';
    src: url('/font/Prompt-SemiBold.ttf') format('truetype');
    font-weight: 600;
    font-style: normal;
}

@font-face {
    font-family: 'Prompt';
    src: url('/font/Prompt-Bold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
}

/* --- Global Styles --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Prompt', Arial, sans-serif;
}

body {
    font-family: 'Prompt', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: #333;
}

input, select, textarea, button {
    font-family: 'Prompt', Arial, sans-serif;
}

table, th, td {
    font-family: 'Prompt', Arial, sans-serif;
}

/* --- Login Page Styles --- */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 420px;
}

.login-box {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 40px;
    animation: slideUp 0.5s ease-out;
}

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

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-header h1 {
    font-size: 28px;
    font-weight: 600;
    color: #667eea;
    margin-bottom: 8px;
}

.login-header p {
    font-size: 16px;
    color: #666;
}

/* --- Alert Styles --- */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}

.alert-error {
    background-color: #fee;
    color: #c33;
    border: 1px solid #fcc;
}

.alert-success {
    background-color: #efe;
    color: #3c3;
    border: 1px solid #cfc;
}

.alert-icon {
    font-size: 18px;
}

/* --- Form Styles --- */
.login-form {
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #555;
    margin-bottom: 8px;
}

.label-icon {
    font-size: 16px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    font-family: 'Prompt', Arial, sans-serif;
    transition: all 0.3s ease;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* --- Button Styles --- */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    font-family: 'Prompt', Arial, sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-block {
    width: 100%;
}

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

.btn-danger:hover {
    background-color: #c82333;
}

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

.btn-secondary:hover {
    background-color: #5a6268;
}

/* --- Login Footer --- */
.login-footer {
    text-align: center;
    margin-top: 20px;
}

.text-muted {
    color: #999;
    font-size: 13px;
    line-height: 1.6;
}

/* --- Main App Styles --- */
.app-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
}

.app-header {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.app-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-title h1 {
    font-size: 24px;
    font-weight: 600;
    color: #667eea;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-name {
    font-size: 16px;
    font-weight: 500;
    color: #333;
}

/* --- Video Container --- */
.video-section {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.video-header {
    margin-bottom: 15px;
}

.video-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: #333;
    display: flex;
    align-items: center;
    gap: 10px;
}

.video-container {
    width: 100%;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    aspect-ratio: 16/9;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

#player-div {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* ปรับปรุงการแสดงผลภาพ ให้คงสัดส่วนเดิมเสมอ */
#player-div canvas,
#player-div video,
#player-div img {
    max-width: 100% !important;
    max-height: 100% !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important; 
    outline: none;
    display: block;
}

/* --- Mute Button --- */
#mute-btn {
    position: absolute;
    bottom: 15px;
    right: 15px;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 15px;
    font-family: 'Prompt', Arial, sans-serif;
    cursor: pointer;
    z-index: 10;
    transition: all 0.3s;
    max-width: 60%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    backdrop-filter: blur(4px);
}

#mute-btn:hover {
    background-color: rgba(0, 0, 0, 0.9);
}

/* --- Fullscreen Button --- */
#fullscreen-btn {
    position: absolute;
    bottom: 15px;
    left: 15px;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 15px;
    font-family: 'Prompt', Arial, sans-serif;
    cursor: pointer;
    z-index: 10;
    transition: all 0.3s;
    white-space: nowrap;
    backdrop-filter: blur(4px);
}

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

/* --- Loading Spinner --- */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    color: white;
    font-size: 18px;
}

#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-right: 15px;
}

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

/* --- Camera Selector --- */
.camera-selector {
    margin-bottom: 25px;
    padding: 25px;
    background: linear-gradient(135deg, #f8f9ff 0%, #fff 100%);
    border-radius: 16px;
    border: 2px solid #e8ebff;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.08);
}

.camera-selector h3 {
    margin-bottom: 18px;
    font-size: 15px;
    color: #667eea;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.camera-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 15px;
    max-width: 100%;
}

@media (min-width: 1200px) {
    .camera-buttons {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 768px) and (max-width: 1199px) {
    .camera-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 767px) {
    .camera-buttons {
        grid-template-columns: 1fr;
    }
}

.camera-btn {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 18px 22px;
    background: white;
    border: 2px solid #e8ebff;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: 'Prompt', Arial, sans-serif;
    text-align: left;
    position: relative;
    overflow: hidden;
}

.camera-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
    transform: scaleY(0);
    transition: transform 0.3s ease;
}

.camera-btn:hover {
    border-color: #667eea;
    background: linear-gradient(135deg, #f8f9ff 0%, #fff 100%);
    transform: translateY(-3px) translateX(2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.15);
}

.camera-btn:hover::before {
    transform: scaleY(1);
}

.camera-btn.active {
    border-color: transparent;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
    transform: translateY(-2px);
}

.camera-btn.active::before {
    display: none;
}

.camera-btn-icon {
    font-size: 32px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
    transition: transform 0.3s ease;
}

.camera-btn:hover .camera-btn-icon {
    transform: scale(1.1) rotate(-5deg);
}

.camera-btn.active .camera-btn-icon {
    transform: scale(1.05);
    filter: drop-shadow(0 2px 8px rgba(255, 255, 255, 0.3));
}

.camera-btn-text {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
}

.camera-btn-text strong {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.3;
}

.camera-btn-text small {
    font-size: 13px;
    opacity: 0.7;
    font-weight: 400;
}

.camera-btn.active .camera-btn-text small {
    opacity: 0.95;
}

.camera-btn:active {
    transform: translateY(-1px);
}

/* --- Responsive Design (เพิ่มการรองรับหน้าจอมือถือสำหรับปุ่มวิดีโอ) --- */
@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .app-title h1 {
        font-size: 20px;
    }
    
    .user-info {
        width: 100%;
        justify-content: space-between;
    }
    
    .login-box {
        padding: 30px 20px;
    }
    
    .login-header h1 {
        font-size: 24px;
    }

    /* ปรับขนาดปุ่มบนวิดีโอเมื่ออยู่บนหน้าจอมือถือ */
    #mute-btn, #fullscreen-btn {
        bottom: 10px;
        font-size: 12px;
        padding: 8px 12px;
    }
    #mute-btn {
        right: 10px;
        max-width: 55%;
    }
    #fullscreen-btn {
        left: 10px;
        max-width: 35%;
    }
}

/* --- Admin Panel Styles --- */
.admin-container {
    background: white;
    border-radius: 12px;
    padding: 30px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.admin-nav {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.admin-nav .btn {
    padding: 10px 20px;
    font-size: 14px;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

table th,
table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

table th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #555;
}

table tr:hover {
    background-color: #f8f9fa;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success {
    background-color: #d4edda;
    color: #155724;
}

.badge-danger {
    background-color: #f8d7da;
    color: #721c24;
}

.badge-warning {
    background-color: #fff3cd;
    color: #856404;
}

/* คลาสพิเศษสำหรับขยายเต็มจอบน iPhone (กรณีเป็น MJPEG) */
.video-container.pseudo-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    margin: 0 !important;
    border-radius: 0 !important;
    z-index: 9999 !important;
    background: #000 !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
}

/* --- Footer Styles --- */
.app-footer {
    background: rgba(255, 255, 255, 0.95);
    padding: 20px;
    text-align: center;
    margin-top: auto;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.app-footer p {
    margin: 0;
    color: #666;
    font-size: 14px;
}

/* Footer สำหรับหน้า Login - ตัวหนังสือสีขาว */
.login-page .app-footer {
    background: transparent;
    border-top: none;
    box-shadow: none;
    margin-top: 30px;
}

.login-page .app-footer p {
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.login-page .app-footer a {
    color: rgba(255, 255, 255, 0.9) !important;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Footer Link Hover Effect */
.app-footer a {
    transition: opacity 0.2s ease;
}

.app-footer a:hover {
    opacity: 0.7;
    text-decoration: underline;
}

/* Ensure body uses flexbox for footer positioning */
body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-container,
.login-page {
    flex: 1;
    display: flex;
    flex-direction: column;
}

@media (max-width: 768px) {
    .app-footer p {
        font-size: 12px;
    }
}

/* --- Settings Page Styles --- */
.card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    margin-bottom: 20px;
}

.card-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 30px;
    border-bottom: none;
}

.card-header h2,
.card-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.card-header p {
    margin: 5px 0 0 0;
    opacity: 0.9;
}

/* Settings Form Styles */
.form-group {
    margin-bottom: 25px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: #333;
    font-size: 14px;
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="email"],
.form-group input[type="number"],
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    font-family: 'Prompt', Arial, sans-serif;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group p {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
}

/* Admin Navigation */
.admin-nav {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    padding: 15px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.admin-nav a {
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s ease;
    background: #f5f5f5;
    color: #666;
}

.admin-nav a:hover {
    background: #e0e0e0;
    color: #333;
}

.admin-nav a.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

/* Content Wrapper */
.content-wrapper {
    flex: 1;
}

/* Alert Styles */
.alert {
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.alert-error {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.alert-icon {
    font-size: 20px;
}

/* Table Responsive Wrapper */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

table th,
table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
    white-space: nowrap;
}

table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #333;
}

table tr:hover {
    background: #f8f9fa;
}

/* Add Form Styles */
.add-form {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 30px;
}

.form-grid {
    display: grid;
    grid-template-columns: 2fr 2fr 1fr auto;
    gap: 15px;
    align-items: end;
}

.form-grid-3 {
    grid-template-columns: 1fr 1fr auto;
}

.form-grid-5 {
    grid-template-columns: 2fr 2fr 2fr 1fr auto;
}

.form-grid .form-group {
    margin-bottom: 0;
}

.form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-family: 'Prompt', Arial, sans-serif;
    font-size: 15px;
    transition: all 0.3s ease;
    box-sizing: border-box;
    background: white;
    cursor: pointer;
}

.form-group select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-submit {
    display: flex;
    align-items: flex-end;
}

.btn-block {
    width: 100%;
}

/* Responsive Design */
@media (max-width: 768px) {
    .card-header {
        padding: 15px 20px;
    }
    
    .admin-nav {
        flex-direction: column;
    }
    
    .admin-nav a {
        width: 100%;
        text-align: center;
    }
    
    /* Mobile Table Adjustments */
    table {
        font-size: 13px;
        min-width: 500px;
    }
    
    table th,
    table td {
        padding: 8px 10px;
    }
    
    .app-header {
        flex-direction: column;
        gap: 10px;
        padding: 15px;
    }
    
    .app-header .app-title h1 {
        font-size: 18px;
    }
    
    .user-info {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .user-info a {
        font-size: 13px;
        padding: 8px 12px;
    }
    
    .app-container {
        padding: 10px;
    }
    
    /* Mobile Form Grid */
    .form-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .form-grid .form-group {
        margin-bottom: 0;
    }
    
    .add-form {
        padding: 15px;
    }
}