* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: #2d3748;
    color: white;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
}

.sidebar .header {
    padding: 30px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    text-align: center;
}

.sidebar .header h1 {
    font-size: 24px;
    margin-bottom: 5px;
}

.sidebar .header .subtitle {
    font-size: 12px;
    opacity: 0.9;
}

/* Camera buttons */
.camera-buttons {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.camera-btn {
    width: 100%;
    padding: 15px;
    margin-bottom: 10px;
    background: #4a5568;
    border: 2px solid transparent;
    border-radius: 8px;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.camera-btn:hover {
    background: #5a6578;
    transform: translateY(-2px);
}

.camera-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: #fff;
}

.camera-btn .status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #718096;
}

.camera-btn.active .status-indicator {
    background: #48bb78;
    box-shadow: 0 0 10px #48bb78;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Status panel */
.status-panel {
    padding: 20px;
    background: #1a202c;
}

.status-panel h3 {
    font-size: 16px;
    margin-bottom: 15px;
    color: #a0aec0;
}

.status-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 14px;
}

.status-label {
    color: #a0aec0;
}

.status-value {
    color: #fff;
    font-weight: bold;
}

/* Footer */
.footer {
    padding: 15px 20px;
    background: #1a202c;
    text-align: center;
    font-size: 12px;
    color: #718096;
}

/* Footer logos section */
.footer-logos {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #2d3748;
}

.footer-logos .supported-by {
    font-size: 10px;
    color: #a0aec0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.footer-logo {
    display: block;
    width: 100%;
    max-width: 270px;
    height: auto;
    max-height: 95px;
    margin: 12px auto;
    padding: 14px 20px;
    background: #f7fafc;
    border-radius: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    object-fit: contain;
}

.footer-logo:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    background: #ffffff;
}

/* Footer info section */
.footer-info .copyright {
    margin-bottom: 3px;
}

.footer-info .version {
    margin-top: 3px;
    color: #4a5568;
}

/* Main content area */
.main-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
}

/* Video views */
.video-view {
    width: 100%;
    height: 100%;
    display: none;
}

.video-view.active {
    display: flex;
}

/* Single camera view */
.video-view.single {
    align-items: center;
    justify-content: center;
}

.video-view.single .video-wrapper {
    max-width: 90%;
    max-height: 90%;
}

/* Grid view (2x2) */
.video-view.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 20px;
}

/* Video wrapper */
.video-wrapper {
    position: relative;
    background: #000;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.video-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Video overlay */
.video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.overlay-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 15px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
    display: flex;
    justify-content: space-between;
}

.camera-label {
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: bold;
    color: white;
}

.fps-counter {
    background: rgba(0, 0, 0, 0.5);
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 12px;
    color: white;
}

/* Detection info */
.detection-info {
    position: absolute;
    bottom: 15px;
    left: 15px;
    right: 15px;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px;
    border-radius: 8px;
    color: white;
    font-size: 12px;
    max-height: 100px;
    overflow-y: auto;
}

.detection-item {
    margin-bottom: 5px;
}

.detection-item.fall {
    color: #fc8181;
    font-weight: bold;
}

.detection-item.risky {
    color: #f6e05e;
}

.detection-item.stand {
    color: #68d391;
}

.detection-item.normal {
    color: #68d391;
}

.detection-item.sit {
    color: #63b3ed;  /* sitting is safe — blue, distinct from green Stand/Normal */
}

/* Loading spinner */
.loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: white;
}

.loading-spinner.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Welcome screen */
.welcome-view {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: white;
}

.welcome-content h1 {
    font-size: 48px;
    margin-bottom: 20px;
}

.welcome-content p {
    font-size: 18px;
    opacity: 0.9;
    margin-bottom: 40px;
}

.welcome-icon {
    font-size: 100px;
    opacity: 0.5;
    animation: float 3s ease-in-out infinite;
}

.welcome-icon svg {
    stroke: currentColor;
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-20px); }
}

/* Responsive */
@media (max-width: 1200px) {
    .sidebar {
        width: 250px;
    }
}

@media (max-width: 768px) {
    /* phones: allow the page to scroll and stack everything in one column */
    body { overflow: auto; -webkit-text-size-adjust: 100%; }

    .container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    /* Dissolve the sidebar box so its children flow into the page column. That
       lets us slot the VIDEO right under the camera buttons (via `order`),
       instead of below the status panel + footer. */
    .sidebar { display: contents; }

    .sidebar .header { order: 1; padding: 14px 16px; }
    .camera-buttons  { order: 2; }
    .sensitivity-btn { order: 3; }
    .main-content    { order: 4; }   /* video sits right under the controls */
    .status-panel    { order: 5; }
    .footer          { order: 6; }

    .sidebar .header h1 { font-size: 20px; }
    .sidebar .header .subtitle { font-size: 11px; }

    /* camera buttons: compact 2-column grid on a dark control bar */
    .camera-buttons {
        background: #2d3748;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 12px 14px;
        flex: none;
        overflow: visible;
    }
    .camera-btn { width: 100%; margin-bottom: 0; padding: 11px 10px; font-size: 13px; }

    .sensitivity-btn { margin: 0; border-radius: 0; padding: 14px; }

    .main-content { padding: 12px; align-items: stretch; min-height: 45vh; }

    /* every active view becomes a single vertical column of 4:3 video boxes */
    .video-view { flex-direction: column; gap: 12px; width: 100%; height: auto; }
    .video-view.grid {
        display: flex;
        grid-template-columns: none;
        grid-template-rows: none;
    }
    .video-view.single .video-wrapper,
    .video-wrapper {
        width: 100%;
        max-width: 100%;
        max-height: none;
        aspect-ratio: 4 / 3;   /* gives the box real height so the image shows */
    }
    .video-wrapper img { height: 100%; }

    .welcome-view { height: auto; min-height: 40vh; }
    .welcome-content h1 { font-size: 26px; }
    .welcome-content p { font-size: 14px; margin-bottom: 20px; }
    .welcome-icon { font-size: 56px; }
    .welcome-icon svg { width: 60px; height: 60px; }

    /* compact status + footer */
    .status-panel { padding: 12px 16px; }
    .footer { padding: 10px 16px; }
    .footer-logos { margin-bottom: 8px; padding-bottom: 8px; }
    .footer-logo { max-height: 48px; max-width: 200px; padding: 8px 14px; margin: 6px auto; }

    /* modals fit the phone */
    .modal-content { padding: 24px 20px; max-width: 94vw; }
    .modal-title { font-size: 26px; }
    .modal-message { font-size: 17px; }
    .sensitivity-content { width: 94vw; max-height: 88vh; }
    .sensitivity-title { font-size: 20px; }
    .slider-group { grid-template-columns: 48px 1fr 40px; gap: 8px; }

    /* login: keep both logos side-by-side on narrow screens */
    .login-card { padding: 28px 22px; }
    .login-logo { max-height: 40px; max-width: 128px; }
}

/* Alert Indicator (Traffic Light) */
.alert-indicator {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 100;
    background: rgba(0, 0, 0, 0.6);
    padding: 10px;
    border-radius: 50px;
    backdrop-filter: blur(5px);
}

.alert-light-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.alert-light {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.5);
    transition: all 0.3s ease;
    opacity: 0.15;  /* Very dimmed by default */
}

.alert-light.active {
    opacity: 1;  /* Bright when active */
    border-color: rgba(255, 255, 255, 0.9);
}

.alert-light.green {
    background: #48bb78;
}

.alert-light.green.active {
    box-shadow: 0 0 25px #48bb78, 0 0 50px rgba(72, 187, 120, 0.5);
}

.alert-light.yellow {
    background: #f6e05e;
}

.alert-light.yellow.active {
    box-shadow: 0 0 25px #f6e05e, 0 0 50px rgba(246, 224, 94, 0.5);
}

.alert-light.red {
    background: #fc8181;
}

.alert-light.red.active {
    box-shadow: 0 0 30px #fc8181, 0 0 60px rgba(252, 129, 129, 0.6);
    animation: pulse-red 1s infinite;
}

@keyframes pulse-red {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.08);
    }
}

/* Fall Alert Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    color: white;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: modal-appear 0.3s ease;
    max-width: 500px;
}

@keyframes modal-appear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-title {
    font-size: 36px;
    margin-bottom: 20px;
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.modal-message {
    font-size: 20px;
    margin-bottom: 15px;
}

.modal-camera-info {
    font-size: 16px;
    margin-bottom: 30px;
    opacity: 0.9;
}

.confirm-btn {
    background: white;
    color: #667eea;
    border: none;
    padding: 15px 40px;
    font-size: 18px;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.confirm-btn:hover {
    background: #f0f0f0;
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(255, 255, 255, 0.3);
}

.confirm-btn:active {
    transform: scale(0.95);
}

/* ===================== Sensitivity tuner ===================== */
.sensitivity-btn {
    margin: 5px 15px 10px 15px;
    padding: 12px;
    background: #38a169;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s ease;
}

.sensitivity-btn:hover {
    background: #2f855a;
}

.sensitivity-content {
    text-align: left;
    max-width: 640px;
    width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.sensitivity-title {
    font-size: 24px;
    margin-bottom: 12px;
    text-align: center;
}

.sensitivity-hint {
    font-size: 13px;
    line-height: 1.5;
    opacity: 0.95;
    margin-bottom: 16px;
    background: rgba(0, 0, 0, 0.18);
    padding: 10px 12px;
    border-radius: 8px;
}

.sensitivity-list {
    overflow-y: auto;
    flex: 1;
    padding-right: 6px;
}

.sensitivity-row {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 12px;
}

.sensitivity-cam {
    font-size: 15px;
    font-weight: bold;
    margin-bottom: 10px;
}

.slider-group {
    display: grid;
    grid-template-columns: 60px 1fr 48px;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.slider-group label {
    font-size: 13px;
    font-weight: bold;
}

.slider-group.fall label { color: #fed7d7; }
.slider-group.risky label { color: #fefcbf; }
.slider-group.stand label { color: #c6f6d5; }
.slider-group.sit label { color: #bee3f8; }

.weight-slider {
    width: 100%;
    cursor: pointer;
    accent-color: #fff;
}

.slider-val {
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    text-align: right;
    opacity: 0.95;
}

.sensitivity-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 16px;
    gap: 12px;
}

.sensitivity-status {
    font-size: 14px;
    min-height: 18px;
    opacity: 0.95;
}

/* ===================== Login page ===================== */
.login-body {
    min-height: 100vh;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    font-family: 'Segoe UI', 'Microsoft JhengHei', sans-serif;
}

.login-card {
    background: #ffffff;
    width: 360px;
    max-width: 90vw;
    padding: 36px 32px 28px;
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    text-align: center;
}

.login-logos {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.login-logo {
    max-height: 52px;
    max-width: 170px;
    object-fit: contain;
}

.login-title {
    font-size: 22px;
    color: #2d3748;
    margin: 0 0 6px;
}

.login-subtitle {
    font-size: 14px;
    color: #718096;
    margin: 0 0 18px;
}

.login-error {
    background: #fff5f5;
    color: #c53030;
    border: 1px solid #feb2b2;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 14px;
}

.login-form {
    display: flex;
    flex-direction: column;
    text-align: left;
}

.login-form label {
    font-size: 13px;
    font-weight: bold;
    color: #4a5568;
    margin: 8px 0 4px;
}

.login-form input {
    padding: 10px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    font-size: 15px;
    outline: none;
}

.login-form input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.18);
}

.login-btn {
    margin-top: 18px;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: opacity 0.2s ease, transform 0.1s ease;
}

.login-btn:hover { opacity: 0.92; }
.login-btn:active { transform: scale(0.98); }

.login-footer {
    margin: 18px 0 0;
    font-size: 11px;
    color: #a0aec0;
}

/* Logout link in the sidebar footer */
.logout-link {
    color: #a0aec0;
    font-size: 12px;
    text-decoration: none;
}

.logout-link:hover {
    color: #ffffff;
    text-decoration: underline;
}
