/* =========================================
   RESET / GLOBAL
========================================= */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: #f5f5f5;
}

/* =========================================
   AUTH STATES (controlled by body class)
   body.guest  -> show login only
   body.authed -> show app only
========================================= */

#loginOverlay {
    display: none;   /* default */
}

#mainApp {
    display: none;   /* default */
}

body.guest #loginOverlay {
    display: flex;
}

body.guest #mainApp {
    display: none;
}

body.authed #loginOverlay {
    display: none;
}

body.authed #mainApp {
    display: flex;
}

/* =========================================
   LOGIN OVERLAY
========================================= */

#loginOverlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.85);
    align-items: center;
    justify-content: center;
}

#loginBox {
    background: #ffffff;
    padding: 30px;
    border-radius: 10px;
    width: 320px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    text-align: center;
}

#loginBox h2 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 22px;
    color: #333333;
}

#loginBox form {
    margin: 0;
}

#loginBox input {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    font-size: 16px;
    border-radius: 4px;
    border: 1px solid #cccccc;
}

#loginBox button {
    padding: 10px;
    background-color: #3f51b5;
    color: #ffffff;
    border: none;
    cursor: pointer;
    font-size: 16px;
    width: 100%;
    border-radius: 4px;
    font-weight: 600;
}

#loginBox button:hover {
    background-color: #2c3e90;
}

#loginBox .apply-btn {
    background-color: #e53935 !important;
    margin-top: 10px;
}

#loginError {
    color: red;
    margin-top: 10px;
    font-size: 14px;
}

/* =========================================
   MAIN APP WRAPPER
========================================= */

#mainApp {
    flex: 1;
    flex-direction: column;
    min-height: 0;
}

/* =========================================
   HEADER
========================================= */

header {
    background-color: #1f3554; /* darker blue for nicer look */
    color: #ffffff;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.header-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    flex: 1;
}

.info-box {
    background-color: rgba(255, 255, 255, 0.1);
    padding: 8px 14px;
    border-radius: 6px;
    font-weight: bold;
    font-size: 15px;
    white-space: nowrap;
}

.visualizer-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #ffffff;
    font-size: 18px;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    padding: 0;
}

.visualizer-btn:hover {
    background-color: rgba(255, 255, 255, 0.25);
}

header > div:last-child {
    display: flex;
    align-items: center;
    gap: 16px;
    white-space: nowrap;
}

header i.fas.fa-bell {
    cursor: pointer;
}

/* Header buttons */

.switch-client-btn,
.logout-btn {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

.switch-client-btn:hover,
.logout-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.switch-client-btn {
    border: 1px solid rgba(255, 255, 255, 0.4);
}

/* =========================================
   LAYOUT: SIDEBAR + MAIN
========================================= */

.container {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* Sidebar */

.sidebar {
    width: 200px;
    background-color: #2c3e50;
    color: #ffffff;
    padding-top: 20px;
    transition: width 0.3s ease;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar ul li {
    padding: 15px 20px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    font-size: 14px;
}

.sidebar ul li:hover {
    background-color: #34495e;
}

.sidebar ul li i {
    margin-right: 10px;
    min-width: 20px;
    text-align: center;
}

.sidebar.collapsed {
    width: 50px;
}

.sidebar.collapsed ul li span {
    display: none;
}

/* Sidebar toggle */

.toggle-btn {
    position: absolute;
    top: 70px;
    left: 200px;
    width: 20px;
    height: 40px;
    background-color: #3f51b5;
    color: #ffffff;
    border-radius: 0 5px 5px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: left 0.3s ease;
    z-index: 10;
}

.sidebar.collapsed + .toggle-btn {
    left: 50px;
}

/* =========================================
   MAIN CONTENT / CARD
========================================= */

.main {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    min-width: 0;
}

.card {
    background-color: #ffffff;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    max-width: 100%;
    height: 85vh;
}

.card iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* =========================================
   FULLSCREEN VISUALIZER
========================================= */

.fullscreen-overlay {
    position: fixed;
    inset: 0;
    background: #000000;
    z-index: 9999;
    display: none;
}

.fullscreen-overlay iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

.fullscreen-overlay .close-btn {
    position: absolute;
    top: 20px;
    right: 30px;
    font-size: 30px;
    color: #ffffff;
    cursor: pointer;
    z-index: 10000;
}

/* =========================================
   FOOTER
========================================= */

footer {
    background-color: #f0f0f0;
    padding: 10px;
    text-align: center;
    font-size: 13px;
    color: #666666;
}

/* =========================================
   EXTERNAL LINK POPUP
========================================= */

.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.popup-box {
    background: #ffffff;
    padding: 20px 24px;
    border-radius: 12px;
    width: 90%;
    max-width: 360px;
    text-align: center;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

.popup-box h3 {
    margin: 0 0 8px;
}

.popup-box p {
    margin: 0;
    font-size: 14px;
    color: #555555;
}

.popup-buttons {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.popup-buttons button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    background: #2196f3;
    color: #ffffff;
    transition: 0.2s;
    font-weight: 500;
}

.popup-buttons button:last-child {
    background: #999999;
}

.popup-buttons button:hover {
    opacity: 0.85;
}

/* =========================================
   RESPONSIVE
========================================= */

@media (max-width: 768px) {
    header {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-center {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .toggle-btn {
        top: 110px;
    }
}
