/* ============================================================================
   FILE: /system/css/global.css
   PURPOSE: Global styles for Spatial Awareness Integration (SAI) system UI
   DESCRIPTION: Handles layout, blocks, devices, patients, controls, themes.
   ========================================================================= */

/* ============================================================================
   1. THEME VARIABLES & DARK MODE
   ========================================================================== */
:root {
    --main-blue: #007bff;
    --blue-hover: #0056b3;
    --main-bg: #f8f9fa;
    --text-color: #212529;
    --card-bg: #ffffff;
}

body.dark-mode {
    --main-bg: #121212;
    --text-color: #e0e0e0;
    --card-bg: #1e1e1e;
}

/* ============================================================================
   2. BASE STYLES
   ========================================================================== */
body {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    background-color: var(--main-bg);
    color: var(--text-color);
    direction: ltr;
}

body.rtl {
    direction: rtl;
}
/* ============================================================================
   3. SIDEBAR + TOPBAR LAYOUT (BLUE THEME)
   ========================================================================== */

/* Fixed sidebar with blue tone */
#sidebar {
    position: fixed;
    top: 44px; /* Reduced from 60px */
    left: 0;
    width: 250px;
    height: calc(100% - 44px); /* Reduced from 60px */
    background-color: var(--main-blue);
    color: white;
    overflow-y: auto;
    z-index: 1000;
}

/* Sidebar links and group toggles */
#sidebar a,
.submenu-toggle {
    display: block;
    padding: 10px 18px;
    color: white;
    text-decoration: none;
    font-size: 15px;
    background-color: var(--main-blue);
    transition: background 0.2s ease, color 0.2s ease;
    cursor: pointer;
}

#sidebar a:hover,
.submenu-toggle:hover {
    background-color: var(--blue-hover);
    font-weight: bold;
}

#sidebar a.active,
.submenu-toggle.active {
    background-color: #0056b3;
    font-weight: bold;
}

/* Indented submenu */
.submenu {
    padding-left: 15px;
    background-color: #0056b3;
    display: none;
}

.submenu a {
    font-size: 14px;
    padding: 8px 18px;
    color: #e0e0e0;
    text-decoration: none;
    transition: background 0.2s ease;
}

.submenu a:hover {
    background-color: #00408f;
    color: #fff;
}

.submenu a.active {
    background-color: #00356e;
    color: #fff;
}

/* TOPBAR */
#topbar {
    position: fixed;
    top: 0;
    left: 0;
    height: 44px; /* Reduced from 60px */
    width: 100%;
    background-color: #007bff;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    z-index: 1100;
    overflow: visible;
}

/* User section in topbar */
.topbar-user {
    display: flex;
    align-items: center;
    gap: 1rem;
    white-space: nowrap;
    position: relative;
}

/* Dropdown menu */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: 40px;
    background-color: #ffffff;
    min-width: 160px;
    box-shadow: 0px 2px 8px rgba(0,0,0,0.15);
    z-index: 9999;
    border-radius: 6px;
    overflow: hidden;
}

.dropdown-content a {
    color: #333;
    padding: 10px 14px;
    display: block;
    text-decoration: none;
    font-size: 14px;
}

.dropdown-content a:hover {
    background-color: #f2f2f2;
}

/* Collapsed and compact sidebar behavior */
body.collapsed #sidebar { width: 0; overflow: hidden; }
body.collapsed #topbar, body.collapsed #main { left: 0; margin-left: 0; }
body.compact-sidebar #sidebar { width: 80px; }
body.compact-sidebar #topbar, body.compact-sidebar #main { left: 80px; margin-left: 80px; }

body.collapsed #topbar {
    height: 36px !important; /* Ensure override when collapsed */
    font-size: 0.85rem;
}

body.collapsed #topbar span,
body.collapsed #topbar button,
body.collapsed #topbar div {
    transform: scale(0.85);
    transition: transform 0.3s ease;
}

/* Dark mode overrides */
body.dark-mode #sidebar {
    background-color: #1e2a3a;
}
body.dark-mode .submenu {
    background-color: #263545;
}
body.dark-mode .submenu-toggle,
body.dark-mode #sidebar a {
    background-color: #1e2a3a;
    color: #eee;
}
body.dark-mode .submenu a {
    color: #cfcfcf;
}
body.dark-mode .submenu a:hover,
body.dark-mode .submenu a.active {
    background-color: #2f3e50;
    color: #fff;
}

.icon-preview {
    margin-left: 6px;
    font-size: 1.2em;
}


/* ============================================================================
   4. MAIN CONTENT LAYOUT
   ========================================================================== */
/* ============================================================================
   Layout: Page Structure and Sidebar Behavior
   ========================================================================= */

/* Main layout wrapper for the page content area */
#main {
    margin-left: 230px;
    padding: 44px 20px 20px; /* Top padding reduced from 60px */
    transition: margin-left 0.3s ease;
}

/* Inner content container inside #main */
#main-content {
    margin-left: 180px;
    padding: 1rem;
    padding-top: 0; /* Remove extra top padding */
    min-height: calc(100vh - 44px); /* Reduced from 60px */
    background: var(--main-bg);
    box-sizing: border-box;
    max-width: 1200px;
    margin: 0 auto;
    margin-top: 44px; /* This keeps content below the fixed topbar */
}

/* When sidebar is collapsed, #main shifts left */
body.collapsed #main {
    margin-left: 0;                 /* Removes space left for sidebar */
    width: 100%;                    /* Allows it to expand fully */
}

/* When sidebar is collapsed, #main-content expands to fill full width */
body.collapsed #main-content {
    margin-left: 0 !important;      /* Prevent leftover space from sidebar */
    padding-left: 1rem;             /* Optional: maintain minimal side padding */
    padding-right: 1rem;
    width: 100%;                    /* Full width inside #main */
    transition: all 0.3s ease;      /* Smooth transition for resizing on collapse */
}

/* Flex layout utility wrapper (used for rows of components or sidebars + content) */
.flex-wrapper {
    display: flex;                  /* Horizontal flex container */
    align-items: flex-start;        /* Aligns items to top */
    gap: 20px;                      /* Space between flex children */
    margin-top: 20px;               /* Adds spacing above the flex container */
}


/* ============================================================================
   5. DEVICE / BLOCK / PATIENT ELEMENTS
   ========================================================================== */
.block-box, .patient-box, .device {
    user-select: none;
    touch-action: none;
    pointer-events: auto;
}

.block, .patient, .device {
    box-sizing: border-box !important;
}

.block, .block-name {
    pointer-events: auto;
    user-select: text; /* allow text selection */
}

/* Shared Block Properties */
.block-box {
    position: absolute !important;
    padding: 5px;
    border: 2px solid #ccc;
    border-radius: 4px;
    background: #f9f9f9;
    width: 120px;
    min-height: 100px;
    max-height: 400px;              /* Allow more vertical space */
    resize: both;
    overflow: hidden;               /* Prevent double scrollbars */
    box-shadow: 1px 1px 3px rgba(0,0,0,0.1);

    display: flex;
    flex-direction: column;         /* Align contents top-to-bottom */
    justify-content: flex-start;
    align-items: stretch;
    box-sizing: border-box;
    cursor: move;
}


.block-header {
    background: #f1f1f1;
    color: #000;
    padding: 5px;
    text-align: left;
    font-weight: bold;
    border-bottom: 1px solid #ccc;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    cursor: grab;
}
.block-header:hover { background-color: #e0e0e0; }

/* Resize Grip */
.block-box::after, .patient-box::after {
    content: "";
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 12px;
    height: 12px;
    background: url('data:image/svg+xml;utf8,<svg width="12" height="12" xmlns="http://www.w3.org/2000/svg"><path d="M0,12 L12,0" stroke="%23999" stroke-width="2"/></svg>') no-repeat center center;
    background-size: contain;
    cursor: se-resize;
}

.patient-box {
    position: absolute;
    background: #28a745;
    border: 2px solid #31708f;
    border-radius: 50%;
    color: white;
    font-weight: bold;
    text-align: center;
    padding: 5px;
    min-width: 50px;
    min-height: 50px;
    max-width: 300px;
    max-height: 300px;
    resize: both;
    overflow: auto;
    cursor: move;
}

/* Device Style (Palette and in Block) */
.device, .device-palette {
    width: 90px;
    height: 40px;
    background: #ffc107;
    color: #000;
    font-size: 12px;
    line-height: 40px;
    padding: 0 6px;
    border: 1px dashed #aaa;
    border-radius: 4px;
    text-align: center;
    margin: 4px 0;
    font-weight: bold;
    cursor: grab;
    position: relative;
}

.block-box .device {
    position: absolute;
    font-size: 12px;
    padding: 2px 4px;
}

/* Deleted Block Visual Cue */
.block-box.deleted {
    background-color: #aaa;
    pointer-events: none;
    cursor: not-allowed;
}

.deleted-device {
    opacity: 0.5;
    border: 3px dashed red;
}
/* ============================================================================
   Deleted Block Appearance
   ============================================================================ */
.deleted-block {
    opacity: 0.6;
    background-color: #bfc9d4 !important;
    border: 2px dashed #6c757d !important;
    pointer-events: none;
    position: absolute;
}

/* ============================================================================
   Param Modal: Two-Column Layout
   ============================================================================ */
.param-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-top: 1rem;
}

.param-columns h3 {
    font-size: 1rem;
    font-weight: bold;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ============================================================================
   Param Controls (Search + Toggles)
   ============================================================================ */
.param-controls-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    justify-content: space-between;
    margin-top: 1rem;
}

.param-controls-row #param-search {
    flex: 1;
    min-width: 200px;
}

.param-controls-row #toggle-show-deleted {
    margin-left: 0;
}

/* ============================================================================
   Param List: Used in Override Modal and Room Block Display
   ============================================================================ */
.param-list {
    list-style: none;
    padding: 0 4px 0 0;
    margin: 0;
    width: 100%;
    max-height: 300px;
    overflow-y: auto;

    /* Grid layout for param modal (NOT room blocks) */
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 2px 6px;
    align-items: center;
}

/* ============================================================================
   Param Item: Shared Between Modal and Block Render
   ============================================================================ */
.param-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 1px 3px;
    border-bottom: 1px solid #ddd;
    font-size: 12px;
    background: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.param-item.param-hidden {
    opacity: 0.5;
    font-style: italic;
}

.param-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
    font-size: 13px;
}

.param-value {
    text-align: right;
    font-weight: 400;
    font-size: 13px;
}

/* ============================================================================
   Param Inputs (Override Modal)
   ============================================================================ */
.param-item label {
    flex: 1;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.param-item label small {
    font-size: 0.85em;
    color: #666;
}

/* Smart scroll behavior for .param-list only in block-boxes */
.block-box .param-list {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 100%;
    padding-right: 6px;
    margin: 0;
}


.param-list:empty::after {
    content: ' ';
    display: block;
    height: 20px;
}

.param-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Alternate background for zebra striping */
.param-list li:nth-child(even) {
    background-color: #f9f9f9;
}

/* ============================================================================
   6. CONTROLS, TOOLBARS & ACTION BUTTONS
   ========================================================================== */
.controls, .device .controls, .block-box .controls, .patient-box .controls {
    position: absolute;
    top: 2px;
    right: 2px;
    display: none;
    flex-direction: row;
    gap: 3px;
    background: rgba(255, 255, 255, 0.9);
    font-size: 0.8em;
    padding: 2px;
    border-radius: 4px;
}

.device:hover .controls,
.block-box:hover .controls,
.patient-box:hover .controls {
    display: flex !important;
}

.controls span {
    padding: 1px 3px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 3px;
    color: #333;
    cursor: pointer;
}
.controls span:hover { background-color: #ddd; }

.settings-btn {
    background: transparent;
    border: none;
    font-size: 14px;
    cursor: pointer;
}

/* Floating Save/Exit Buttons */
.floating-controls {
    position: fixed;
    bottom: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 100;
}
.floating-controls button {
    padding: 8px 12px;
    background-color: #1976d2;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 1px 1px 4px rgba(0,0,0,0.2);
}
.floating-controls button:hover {
    background-color: #115293;
}

/* ============================================================================
   7. MODALS
   ========================================================================== */
/* Delete Confirmation Modal */
#delete-confirmation-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 10000;
}

#delete-confirmation-modal.show {
    display: flex;
}

#delete-dialog {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    width: 300px;
    text-align: center;
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
}

#delete-dialog h3 {
    margin-top: 0;
    color: #d9534f;
}

#delete-dialog p {
    margin: 10px 0 20px;
}

#delete-confirm, #delete-cancel {
    padding: 8px 16px;
    margin: 5px;
    font-size: 14px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

#delete-confirm {
    background-color: #d9534f;
    color: white;
}

#delete-cancel {
    background-color: #6c757d;
    color: white;
}

#settings-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
    opacity: 0;
}
#settings-modal.show { opacity: 1; }

#settings-backdrop {
    position: absolute;
    background: rgba(0,0,0,0.5);
    top: 0; left: 0; right: 0; bottom: 0;
}
#settings-dialog {
    background: white;
    padding: 20px;
    border-radius: 10px;
    width: 300px;
    position: relative;
    z-index: 10000;
}

/* Modal-specific overrides */
.modal-actions { display: flex; justify-content: space-between; margin-top: 15px; }
.modal-content input { width: 90%; padding: 8px; margin: 10px 0; }
.modal-content button { margin: 5px; padding: 8px 12px; }

.modal-header.bg-warning { background-color: #ffe08a; color: #333; }
.modal-footer .btn-primary { background-color: #0056b3; border: none; }

/* ============================================================================
   8. ROOM CANVAS / DEVICE SIDEBAR / GRID
   ========================================================================== */
#room-canvas {
    position: relative;
    resize: both;
    overflow: auto;
    min-width: 400px;
    min-height: 300px;
    background-color: #f9f9f9;
    background-image:
            linear-gradient(#ddd 1px, transparent 1px),
            linear-gradient(90deg, #ddd 1px, transparent 1px);
    background-size: 40px 40px;
    border: 5px solid #333;
    border-radius: 8px;
    box-sizing: border-box;
}

#device-sidebar {
    width: 250px;
    min-width: 180px;
    max-width: 500px;
    padding: 10px;
    background: #fff3cd;
    border: 2px solid #f0ad4e;
    border-left: 1px solid #ccc;
    border-radius: 4px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
#device-filter {
    width: 100% !important;
    margin-bottom: 8px;
}

/* ============================================================================
   9. TABLES
   ========================================================================== */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}
table th, table td {
    border: 1px solid #ccc;
    padding: 8px 12px;
    text-align: left;
}
table th {
    background-color: #f2f2f2;
}

.record-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 2rem;
}
.record-table th, .record-table td {
    border: 1px solid #ccc;
    padding: 8px;
}
.record-table th {
    background: #f2f2f2;
    text-align: left;
}

/* ============================================================================
   10. DARK MODE OVERRIDES
   ========================================================================== */
body.dark-mode #sidebar,
body.dark-mode #topbar,
body.dark-mode .submenu {
    background-color: var(--card-bg);
    color: var(--text-color);
}

body.dark-mode #saving-indicator {
    background: #4caf50;
    color: #ffffff;
}
body:not(.dark-mode) #saving-indicator {
    background: #28a745;
    color: #ffffff;
}

/* Dark mode overrides for record-table and data-table */
body.dark-mode .record-table,
body.dark-mode .data-table {
    background-color: var(--card-bg);
    color: var(--text-color);
}

body.dark-mode .record-table th,
body.dark-mode .data-table th {
    background-color: #2a2a2a;
    color: #f1f1f1;
}

body.dark-mode .record-table td,
body.dark-mode .data-table td {
    background-color: #1c1c1c;
    border-color: #444;
}

body.dark-mode .record-table tr:hover td,
body.dark-mode .data-table tr:hover td {
    background-color: #2d2d2d;
}

/* ============================================================================
   11. UTILITY CLASSES
   ========================================================================== */
.bordered-box {
    border: 1px solid #ccc;
    background: white;
    padding: 8px;
    border-radius: 6px;
}
.chip {
    display: inline-block;
    padding: 2px 6px;
    margin: 2px;
    background: #e1eaff;
    border-radius: 10px;
    font-size: 0.8em;
}

/* ============================================================================
   12. RESPONSIVE ADJUSTMENTS
   ========================================================================== */
@media (max-width: 768px) {
    #topbar { left: 0 !important; height: 48px !important; } /* Adjusted for mobile */
    #main { margin-left: 0 !important; padding: 54px 10px 10px; } /* Top padding reduced */
    #sidebar { width: 100vw; top: 48px; height: calc(100% - 48px); }
    body.collapsed #sidebar { width: 60px; }
}

/* ============================================================================
   13. SAVING INDICATOR STYLES
   ========================================================================== */
#saving-indicator {
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.4s ease;
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 9999;
    background-color: #28a745;
    color: white;
    padding: 6px 12px;
    border-radius: 8px;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    display: none;
}

#saving-indicator.visible {
    opacity: 1;
    transform: translateY(0);
}

#saving-indicator.fade-out {
    opacity: 0;
    transform: translateY(-20px);
}

/* ============================================================================
   14. PATIENT STYLES
   ========================================================================== */

td.editable {
    background-color: #fffdf5;
    cursor: text;
}
td.editable:focus {
    background-color: #ffffcc;
    outline: 2px dashed #999;
}
td.error {
    background-color: #ffe5e5;
}
.deleted {
    background-color: #f5f5f5;
    color: #888;
}

.status.completed {
    background-color: #28a745;
    color: white;
    padding: 3px 6px;
    border-radius: 4px;
}
.status.in-progress {
    background-color: #ffc107;
    color: black;
    padding: 3px 6px;
    border-radius: 4px;
}
.status.not-started {
    background-color: #6c757d;
    color: white;
    padding: 3px 6px;
    border-radius: 4px;
}

.filter-form {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    margin-bottom: 1em;
}
.filter-form label {
    display: flex;
    align-items: center;
    gap: 5px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 15px;
    margin-bottom: 2em;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}
.data-table th,
.data-table td {
    border: 1px solid #ccc;
    padding: 8px;
    text-align: left;
}
.data-table th {
    background-color: #f8f8f8;
    font-weight: bold;
}
.data-table td[contenteditable="true"] {
    background-color: #fffdf5;
    cursor: text;
}
.data-table td[contenteditable="true"]:focus {
    background-color: #ffffcc;
    outline: 2px dashed #999;
}

/* Filter and Add Row Controls */
.controls-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 1rem;
}
.controls-row input[type="text"],
.controls-row select {
    padding: 6px;
    font-size: 14px;
}

/* Button Base */
button {
    background-color: var(--main-blue);
    color: white;
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
button:hover {
    background-color: var(--blue-hover);
}

/* ============================================================================
   15. AUTH PAGES
   ========================================================================= */

.auth-container {
    max-width: 400px;
    margin: 60px auto;
    padding: 2rem;
    background: var(--card-bg);
    border: 1px solid #ccc;
    border-radius: 8px;
}

.auth-container input {
    width: 100%;
    padding: 10px;
    margin: 6px 0;
}


.form-container {
    max-width: 500px;
    margin: 3rem auto;
    padding: 2rem;
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.form-vertical .form-group {
    margin-bottom: 1rem;
}
.form-vertical label {
    display: block;
    margin-bottom: 0.25rem;
}
.form-vertical input {
    width: 100%;
    padding: 0.5rem;
    border-radius: 4px;
    border: 1px solid #ccc;
}


/* ============================================================================
   16. ROOM LAYOUT PAGE STYLES (/api/rooms/room_layout.php)
   ========================================================================== */

.layout-wrapper {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: 300px;
    transition: width 0.3s ease;
    background: #f8f9fa;
    border-right: 1px solid #ccc;
    padding: 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    position: relative;
}

.sidebar.collapsed {
    width: 0;
    padding: 0;
    overflow: hidden;
    border-right: none;
}

.sidebar-toggle {
    position: absolute;
    top: 10px;
    right: -15px;
    width: 30px;
    height: 30px;
    background: #007bff;
    color: #fff;
    border: none;
    border-radius: 0 5px 5px 0;
    cursor: pointer;
    z-index: 10;
}

#device-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-start;
}
.device-palette {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100px;
    max-width: 140px;
    padding: 4px;
    background: #fff;
    border: 1px solid #007bff;
    border-radius: 4px;
    cursor: grab;
    resize: horizontal;
    overflow: hidden;
    box-sizing: border-box;
    font-size: 13px;
    line-height: 1.2;
    gap: 4px;
}

.device-palette i {
    font-size: 16px;
    margin-top: 2px;
}

.palette-label {
    text-align: center;
    white-space: normal;
    font-weight: normal;
}

.room-area {
    flex: 1;
    overflow: hidden;
    position: relative;
    padding: 10px;
}

#room {
    background: #eaeaea;
    border: 2px solid #007bff;
    position: relative;
    resize: both;
    overflow: hidden;
}



.block {
    position: absolute;
    background: #d1ecf1;
    border: 2px solid #17a2b8;
    padding: 4px;
    box-sizing: border-box;
    border-radius: 4px;
    font-size: 13px;
    font-weight: bold;
    cursor: move;
    overflow: hidden;
}
.block .block-name {
    display: block;
    padding: 2px;
    font-size: 13px;
    margin-bottom: 4px;
}

.block-name[contenteditable="true"] {
    outline: 1px dashed #007bff;
    padding: 2px 4px;
    border-radius: 4px;
    min-height: 18px;
    cursor: text;
    background-color: rgba(0, 123, 255, 0.05);
}

.block-name[contenteditable="true"]:focus {
    outline: 2px solid #007bff;
    background-color: white;
}

.block-name[contenteditable="true"]:hover {
    background-color: rgba(0, 123, 255, 0.15);
    cursor: text;
}


.block .block-controls {
    position: absolute;
    top: 2px;
    right: 4px;
}

.device {
    background: #fff3cd;
    border: 1px solid #856404;
    padding: 2px 5px;
    margin: 2px;
    font-size: 12px !important;  /* ✅ prevent inflation on nested divs */
    position: absolute;
    overflow: hidden;
    resize: none;
    line-height: normal; /* ✅ ensures consistent sizing */

}

.patient {
    background: #ffc107;
    border: 2px solid #ff8800;
    border-radius: 6px;
    text-align: center;
    font-weight: bold;
    position: absolute;
    overflow: hidden;
    font-size: 14px;   /* ✅ slightly larger for readability */
    padding: 4px;
}

#toast {
    opacity: 0;
    transition: opacity 0.3s ease;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #007bff;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    z-index: 9999;
}
#toast.visible {
    opacity: 1;
}


.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #28a745;
    color: #fff;
    padding: 10px;
    display: none;
    border-radius: 4px;
    z-index: 9999;
}

.toast-confirm {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: #fff3cd;
    color: #856404;
    padding: 12px 16px;
    border: 1px solid #ffeeba;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    z-index: 9999; !important;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.toast-confirm button {
    font-size: 12px;
    padding: 4px 8px;
}

.inline-confirm {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
    padding: 8px 12px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    font-size: 14px;
    width: 100%;
    justify-content: center;
}



/* ============================================================================
   MATRIX TABLE: Sticky headers + scroll
   ========================================================================== */
.scroll-x {
    overflow-x: auto;
    max-width: 100%;
}

.data-table.matrix {
    border-collapse: collapse;
    min-width: 1000px;
    font-size: 14px;
    width: 100%;
}

.data-table.matrix th,
.data-table.matrix td {
    border: 1px solid #ccc;
    padding: 6px 10px;
    text-align: left;
    background-color: #fff;
}

.data-table.matrix thead th {
    position: sticky;
    top: 0;
    background-color: #007bff;
    color: #fff;
    z-index: 2;
}

.data-table.matrix .group-header {
    background-color: #e9ecef;
    font-weight: bold;
    text-align: left;
}

#topbar-clock {
    margin-left: 10px;
    font-weight: bold;
    font-family: monospace;
    font-size: 0.9rem;
}

.history-bubble {
    position: absolute;
    z-index: 9999;
    background: #fff;
    border: 1px solid #ccc;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    border-radius: 6px;
    max-height: 300px;
    max-width: 600px;
    overflow: auto;
    padding: 10px;
}

.bubble-wrapper {
    max-height: 300px;
    overflow-y: auto;
    padding: 0;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
}

.history-table th,
.history-table td {
    padding: 4px 8px;
    text-align: center;
    border: 1px solid #ccc;
}

.history-table thead th {
    background: #f4f4f4;
    font-weight: bold;
}


.bubble-wrapper div:first-child {
    font-family: monospace;
    margin-bottom: 5px;
}


.param-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 110px;
    display: inline-block;
    vertical-align: middle;
    font-weight: bold;
    text-align: right;
    padding-right: 6px;
}

.param-name, .param-value {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.param-value {
    text-align: left;
}

.param-field-wrap {
    width: 48%;
    display: inline-block;
    margin: 0 1% 1rem 1%;
    vertical-align: top;
}
.param-field-wrap input,
.param-field-wrap select,
.param-field-wrap textarea {
    width: 100%;
}

.comment-box {
    margin-top: 6px;
}
.comment-box textarea {
    width: 100%;
    min-height: 60px;
    padding: 6px;
}
.add-comment-link {
    display: inline-block;
    font-size: 0.85em;
    color: #007bff;
    cursor: pointer;
    margin-top: 4px;
}
.add-comment-link:hover {
    text-decoration: underline;
}


/* ============================================================================
   IV Gtts Block Styles
   ========================================================================== */

#iv-gtts-block {
    border: 1px solid #ccc;
    padding: 10px;
    margin-top: 10px;
}
#iv-gtts-block ul {
    list-style: none;
    padding-left: 0;
}
#iv-gtts-block li {
    margin-bottom: 4px;
    font-weight: bold;
}

/* Make the flowsheet tab scrollable in room.php */
#flowsheet-container {
  overflow: auto;
  max-height: 60vh; /* Adjust as needed for your layout */
}

