* {
    box-sizing: border-box;
}

:root {
    --bg: #0b1020;
    --panel: #131a2e;
    --panel-2: #1a2340;
    --line: #2a355d;
    --text: #e8ecff;
    --muted: #9aa7d1;
    --brand: #4f7cff;
    --brand-2: #6f5cff;
    --ok: #20c997;
    --warn: #f59f00;
    --err: #ff6b6b;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

body {
    margin: 0;
    font-family: "Inter", "Segoe UI", sans-serif;
    background: radial-gradient(circle at top right, #18234a 0%, var(--bg) 35%);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

html,
body {
    width: 100%;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

a {
    color: #a9beff;
    text-decoration: none;
}

.layout {
    display: grid;
    grid-template-columns: 250px 1fr;
    min-height: 100vh;
    transition: grid-template-columns 0.22s ease;
}

.sidebar {
    background: linear-gradient(180deg, #0f1630 0%, #0a1126 100%);
    border-right: 1px solid var(--line);
    padding: 18px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 50;
    transition: transform 0.22s ease, opacity 0.22s ease;
}

.brand {
    font-weight: 700;
    letter-spacing: 0.3px;
    font-size: 18px;
    margin-bottom: 20px;
}

.brand small {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
}

.nav-link {
    display: block;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 10px;
    margin-bottom: 8px;
    color: #c9d4ff;
}

.nav-link.active,
.nav-link:hover {
    border-color: #3a4a7d;
    background: #151f3e;
}

.sidebar-footer {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
}

.main {
    padding: 20px;
    min-width: 0;
    overflow-x: hidden;
}

.mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(11, 16, 32, 0.92);
    backdrop-filter: blur(6px);
    padding: 10px 0;
}

.menu-btn {
    width: auto;
    min-width: 44px;
    padding: 8px 12px;
}

body.sidebar-collapsed .layout {
    grid-template-columns: 1fr;
}

body.sidebar-collapsed .sidebar {
    transform: translateX(-108%);
    opacity: 0;
    pointer-events: none;
}

body.sidebar-collapsed .main {
    padding-left: 20px;
}

body.device-responsive .layout {
    grid-template-columns: 1fr;
}
html.force-responsive .layout {
    grid-template-columns: 1fr;
}

body.device-responsive .sidebar {
    display: block;
    position: fixed;
    left: -280px;
    top: 0;
    width: 260px;
    transition: left 0.25s ease;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.4);
    transform: none;
    opacity: 1;
    pointer-events: auto;
}
html.force-responsive .sidebar {
    display: block;
    position: fixed;
    left: -280px;
    top: 0;
    width: 260px;
    transition: left 0.25s ease;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.4);
    transform: none;
    opacity: 1;
    pointer-events: auto;
}

body.device-responsive.sidebar-open .sidebar {
    left: 0;
}
html.force-responsive body.sidebar-open .sidebar {
    left: 0;
}

body.device-responsive .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(3, 6, 17, 0.72);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 40;
}
html.force-responsive .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(3, 6, 17, 0.72);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 40;
}

body.device-responsive.sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
}
html.force-responsive body.sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
}

body.device-responsive .mobile-header {
    display: flex;
}
html.force-responsive .mobile-header {
    display: flex;
}

body.device-responsive .main {
    padding: 14px;
    overflow-x: hidden;
    overflow-y: auto;
}
html.force-responsive .main {
    padding: 14px;
    overflow-x: hidden;
    overflow-y: auto;
}

body.device-responsive .grid-4,
body.device-responsive .grid-3,
body.device-responsive .grid-2 {
    grid-template-columns: 1fr;
}
html.force-responsive .grid-4,
html.force-responsive .grid-3,
html.force-responsive .grid-2 {
    grid-template-columns: 1fr;
}

body.device-responsive .table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
html.force-responsive .table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

body.device-responsive table {
    min-width: 0;
    width: 100%;
    table-layout: fixed;
}
html.force-responsive table {
    min-width: 0;
    width: 100%;
    table-layout: fixed;
}

body.device-responsive .tv-monitor-table {
    min-width: 0;
    width: 100%;
}
html.force-responsive .tv-monitor-table {
    min-width: 0;
    width: 100%;
}

body.device-responsive th,
body.device-responsive td,
html.force-responsive th,
html.force-responsive td {
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
}

body.device-responsive #room-grid.room-grid {
    width: 100% !important;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)) !important;
    grid-auto-rows: minmax(110px, 1fr) !important;
}
html.force-responsive #room-grid.room-grid {
    width: 100% !important;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)) !important;
    grid-auto-rows: minmax(110px, 1fr) !important;
}

body.device-responsive .room-status-btn {
    min-height: 110px;
}
html.force-responsive .room-status-btn {
    min-height: 110px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.topbar h1 {
    margin: 0;
    font-size: 22px;
}

.badge {
    display: inline-block;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    border: 1px solid var(--line);
    background: #111936;
    color: var(--muted);
}

.badge.ok {
    color: #9bf4dd;
    border-color: #2f8f75;
    background: rgba(32, 201, 151, 0.1);
}

.badge.err {
    color: #ffc4c4;
    border-color: #8c3f55;
    background: rgba(255, 107, 107, 0.1);
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.card {
    background: linear-gradient(180deg, var(--panel) 0%, #111933 100%);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.card h2 {
    margin-top: 0;
}

.chart-card {
    min-height: 240px;
}

.chart-card canvas {
    width: 100% !important;
    height: 180px !important;
    max-height: 180px;
}

.label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.value {
    font-size: 30px;
    margin-top: 8px;
    font-weight: 700;
}

table {
    width: 100%;
    min-width: 0;
    table-layout: auto;
    border-collapse: collapse;
    margin-top: 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    background: var(--panel);
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

th,
td {
    border-bottom: 1px solid #243057;
    padding: 10px;
    text-align: left;
    vertical-align: top;
    white-space: normal;
    overflow-wrap: anywhere;
}

th {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

input,
select,
textarea,
button {
    width: 100%;
    background: #101836;
    color: var(--text);
    border: 1px solid #31406e;
    border-radius: 10px;
    padding: 10px 11px;
    outline: none;
}

textarea {
    resize: vertical;
    min-height: 40px;
}

button {
    cursor: pointer;
    background: linear-gradient(180deg, var(--brand) 0%, var(--brand-2) 100%);
    border: none;
    font-weight: 600;
}

button.secondary {
    background: #1a2548;
    border: 1px solid #31406e;
}

.inline-form {
    display: inline-block;
}

.inline-form button {
    width: auto;
}

.action-btn {
    width: auto;
    padding: 8px 12px;
}

.room-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
    grid-auto-rows: minmax(120px, 1fr);
    gap: 12px;
    width: 100%;
}

.checkinout-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.room-tile-form {
    margin: 0;
    min-width: 0;
}

.room-status-btn {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 8px;
    text-align: left;
    min-height: 120px;
    aspect-ratio: 1 / 1;
    border: 1px solid transparent;
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
    width: 100%;
    height: 100%;
    padding: 12px;
}

.room-title {
    font-size: 15px;
    line-height: 1.2;
    word-break: break-word;
}

.room-state {
    font-size: 12px;
    opacity: 0.98;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.room-status-btn.not-checked-in {
    background: linear-gradient(180deg, #2ed8a3 0%, #15966f 100%) !important;
    border-color: #46e5b7;
    color: #052b20;
}

.room-status-btn.checked-in {
    background: linear-gradient(180deg, #ffbe4d 0%, #e48c00 100%) !important;
    border-color: #ffd287;
    color: #362100;
}

.room-status-btn:hover {
    filter: brightness(1.04);
    transform: translateY(-1px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.22);
}

.room-grid > .alert {
    grid-column: 1 / -1;
}

@media (min-width: 900px) {
    .room-grid {
        grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
    }
}

@media (min-width: 1200px) {
    .room-grid {
        grid-template-columns: repeat(auto-fill, minmax(142px, 1fr));
    }
}

@media (max-width: 700px) {
    .room-grid {
        grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
        grid-auto-rows: minmax(110px, 1fr);
        gap: 10px;
    }
}

.tv-monitor-table {
    min-width: 980px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 19, 0.72);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 98;
}

.modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-box {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.98);
    width: min(560px, calc(100vw - 24px));
    background: linear-gradient(180deg, var(--panel) 0%, #0e1730 100%);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 14px;
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.modal-box.open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.modal-head h3 {
    margin: 0;
    font-size: 18px;
}

.alerts {
    margin: 8px 0 14px;
}

.alert {
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 8px;
    font-size: 14px;
}

.alert.ok {
    background: rgba(32, 201, 151, 0.14);
    border: 1px solid #2f8f75;
    color: #9bf4dd;
}

.alert.err {
    background: rgba(255, 107, 107, 0.12);
    border: 1px solid #8c3f55;
    color: #ffc4c4;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 16px;
}

.login-card {
    width: min(92vw, 620px);
    padding: clamp(16px, 2.2vw, 24px);
}

.login-title {
    margin-top: 0;
    margin-bottom: 8px;
    font-size: clamp(24px, 2.8vw, 34px);
    line-height: 1.15;
}

.login-subtitle {
    color: var(--muted);
    margin-top: 0;
    margin-bottom: 14px;
    font-size: clamp(14px, 1.5vw, 18px);
}

.login-card label {
    display: block;
    margin-bottom: 6px;
    font-size: clamp(14px, 1.3vw, 16px);
}

.login-card input,
.login-card button {
    font-size: clamp(15px, 1.4vw, 18px);
    padding: clamp(11px, 1.2vw, 14px) clamp(12px, 1.2vw, 14px);
}

.mobile-nav {
    display: none;
}

.sidebar-overlay {
    display: none;
}

@media (max-width: 1024px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: block;
        position: fixed;
        left: -280px;
        top: 0;
        width: 260px;
        transition: left 0.25s ease;
        box-shadow: 8px 0 30px rgba(0, 0, 0, 0.4);
    }

    body.sidebar-open .sidebar {
        left: 0;
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(3, 6, 17, 0.72);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
        z-index: 40;
    }

    body.sidebar-open .sidebar-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    .mobile-nav {
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
        margin-bottom: 10px;
    }

    .grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grid-3,
    .grid-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .topbar {
        flex-wrap: wrap;
        align-items: flex-start;
    }
}

@media (max-width: 768px) {
    .main {
        padding: 14px;
    }

    .card {
        padding: 12px;
        border-radius: 12px;
    }

    .value {
        font-size: 24px;
    }

    .grid-4,
    .grid-3,
    .grid-2 {
        grid-template-columns: 1fr;
    }

    table {
        display: table;
    }

    thead {
        display: table-header-group;
    }

    tbody {
        display: table-row-group;
    }

    tr {
        display: table-row;
        border-bottom: 0;
        padding: 0;
    }

    th,
    td {
        display: table-cell;
        border-bottom: 1px solid #243057;
        padding: 10px;
        position: static;
        min-height: 0;
    }

    td::before {
        content: none;
    }

    .inline-form {
        display: block;
        margin-bottom: 6px;
    }

    .inline-form button,
    .inline-form .secondary {
        width: 100%;
    }

    .login-card {
        width: min(96vw, 540px);
    }
}

@media (orientation: landscape) and (max-height: 520px) {
    .mobile-header {
        position: static;
    }

    .topbar h1 {
        font-size: 19px;
    }

    .card {
        padding: 10px;
    }
}

/* ==========================================================
   STRICT MOBILE/TABLET RESPONSIVE TEMPLATE
   Applied only when runtime detects mobile/webview device.
   ========================================================== */
html.force-responsive,
html.force-responsive body,
body.device-responsive {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
}

html.force-responsive .layout,
body.device-responsive .layout {
    display: block !important;
    grid-template-columns: 1fr !important;
    min-height: 100vh !important;
}

html.force-responsive .sidebar,
body.device-responsive .sidebar {
    position: fixed !important;
    left: -280px !important;
    top: 0 !important;
    width: 260px !important;
    height: 100vh !important;
    z-index: 90 !important;
    overflow-y: auto !important;
    transform: none !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

html.force-responsive body.sidebar-open .sidebar,
body.device-responsive.sidebar-open .sidebar {
    left: 0 !important;
}

html.force-responsive .sidebar-overlay,
body.device-responsive .sidebar-overlay {
    display: block !important;
    position: fixed !important;
    inset: 0 !important;
    z-index: 80 !important;
    background: rgba(3, 6, 17, 0.72) !important;
    opacity: 0 !important;
    pointer-events: none !important;
    transition: opacity 0.2s ease !important;
}

html.force-responsive body.sidebar-open .sidebar-overlay,
body.device-responsive.sidebar-open .sidebar-overlay {
    opacity: 1 !important;
    pointer-events: auto !important;
}

html.force-responsive .main,
body.device-responsive .main {
    width: 100% !important;
    max-width: 100% !important;
    padding: 14px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
}

html.force-responsive .mobile-header,
body.device-responsive .mobile-header {
    display: flex !important;
}

html.force-responsive .menu-btn,
body.device-responsive .menu-btn {
    width: auto !important;
    min-width: 44px !important;
}

html.force-responsive .mobile-nav,
body.device-responsive .mobile-nav {
    display: flex !important;
    flex-wrap: wrap !important;
}

html.force-responsive .grid-4,
html.force-responsive .grid-3,
html.force-responsive .grid-2,
body.device-responsive .grid-4,
body.device-responsive .grid-3,
body.device-responsive .grid-2 {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
}

html.force-responsive .card,
body.device-responsive .card {
    width: 100% !important;
    max-width: 100% !important;
    padding: 12px !important;
    border-radius: 12px !important;
}

html.force-responsive .table-wrap,
body.device-responsive .table-wrap {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
}

html.force-responsive table,
body.device-responsive table {
    width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed !important;
}

html.force-responsive th,
html.force-responsive td,
body.device-responsive th,
body.device-responsive td {
    white-space: normal !important;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
}

html.force-responsive #room-grid.room-grid,
body.device-responsive #room-grid.room-grid {
    width: 100% !important;
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)) !important;
    grid-auto-rows: minmax(108px, 1fr) !important;
    gap: 10px !important;
}

html.force-responsive .room-status-btn,
body.device-responsive .room-status-btn {
    width: 100% !important;
    min-height: 108px !important;
    aspect-ratio: 1 / 1 !important;
    font-size: 14px !important;
}

html.force-responsive .tv-monitor-table,
body.device-responsive .tv-monitor-table {
    width: 100% !important;
    min-width: 0 !important;
}

/* WebView desktop-fit compensation (when viewport scale < 1) */
body.viewport-scale-fix {
    zoom: var(--viewport-fix-scale, 1);
}

/* Fallback for environments where zoom is unavailable/ignored */
@supports not (zoom: 1) {
body.viewport-scale-fix .layout {
    transform: scale(var(--viewport-fix-scale, 1));
    transform-origin: top left;
    width: calc(100% / var(--viewport-fix-scale, 1));
}
}

.badge.warn {
    color: #c9b88a;
    border-color: #5c5238;
    background: rgba(120, 100, 62, 0.1);
}
