/* ============================================================ */
/* HomeOS Platform .NET 8 - Main Global Styles                 */
/* MVVM Single Page Application Architecture                    */
/* ============================================================ */

/* ==================== CSS Variables ==================== */
:root {
    /* HomeOS Brand Colors */
    --homeos-orange: #F1592A;
    --homeos-blue: #25AAE1;
    --homeos-dark-blue: #1a8ab8;
    --homeos-navy: #115E90;

    /* Light Theme */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --bg-sidebar: #2d3748;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --border-color: #dee2e6;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-lg: rgba(0, 0, 0, 0.15);

    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --navbar-height: 60px;
    --footer-height: 36px;

    /* Transitions */
    --transition-speed: 0.3s;
}

[data-theme="dark"] {
    /* Dark Theme */
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --bg-tertiary: #4a5568;
    --bg-sidebar: #1a202c;
    --text-primary: #e2e8f0;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    --border-color: #4a5568;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-lg: rgba(0, 0, 0, 0.5);
}

/* ==================== Global Reset ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100vh;
    max-height: 100vh;
    width: 100vw;
    max-width: 100vw;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
}

/* ==================== Main Container ==================== */
.homeos-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* ==================== Sidebar ==================== */
.homeos-sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    color: white;
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    transition: width var(--transition-speed) ease, transform var(--transition-speed) ease;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.homeos-sidebar::-webkit-scrollbar {
    width: 6px;
}

.homeos-sidebar::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-logo {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    margin-right: 12px;
}

.brand-text h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: white;
}

.brand-text p {
    font-size: 0.75rem;
    opacity: 0.7;
    margin: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background-color: rgba(0, 0, 0, 0.1);
}

.user-avatar {
    font-size: 2.5rem;
    margin-right: 12px;
    color: var(--homeos-blue);
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.user-role {
    font-size: 0.8rem;
    opacity: 0.7;
}

/* Sidebar Menu */
.sidebar-menu {
    flex: 1;
    padding: 10px 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-menu::-webkit-scrollbar {
    width: 6px;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.menu-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.menu-item {
    margin-bottom: 2px;
}

.menu-link {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
}

.menu-link:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: white;
}

.menu-link.active {
    background-color: rgba(37, 170, 225, 0.2);
    color: white;
    border-left: 3px solid var(--homeos-blue);
}

/* Dark mode active state */
.dark .menu-link.active {
    background-color: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border-left: 3px solid #3b82f6;
}

.dark .menu-link:hover {
    background-color: rgba(255, 255, 255, 0.08);
    color: #e5e7eb;
}

.menu-link i {
    width: 20px;
    margin-right: 12px;
    text-align: center;
}

.menu-link span {
    flex: 1;
}

.menu-arrow {
    margin-left: auto;
    font-size: 0.75rem;
    transition: transform 0.2s ease;
}

.menu-parent.open .menu-arrow {
    transform: rotate(180deg);
}

/* Submenu */
.menu-submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background-color: rgba(0, 0, 0, 0.1);
}

.menu-parent.open .menu-submenu {
    max-height: 500px;
}

.menu-submenu a {
    display: flex;
    align-items: center;
    padding: 10px 20px 10px 52px;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.menu-submenu a:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: white;
}

.menu-submenu a.active {
    color: var(--homeos-blue);
    background-color: rgba(37, 170, 225, 0.1);
}

.menu-submenu i {
    width: 16px;
    margin-right: 10px;
    font-size: 0.85rem;
}

/* Sidebar Footer */
/* Sidebar Footer - Fixed at Bottom */
.sidebar-footer {
    padding: 10px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-sidebar-action {
    width: 100%;
    padding: 12px 20px;
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    font-weight: normal;
    text-align: left;
}

.btn-sidebar-action i {
    width: 20px;
    font-size: 14px;
    opacity: 0.8;
}

.btn-sidebar-action:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
}

.btn-sidebar-action:hover i {
    opacity: 1;
}

/* ==================== Main Content Area ==================== */
.homeos-main {
    flex: 1;
    min-width: 0;        /* CRITICAL: break min-width:auto propagation in flex layout */
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--transition-speed) ease;
}

/* ==================== Top Navbar ==================== */
.homeos-navbar {
    height: var(--navbar-height);
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px var(--shadow);
    position: sticky;
    top: 0;
    z-index: 999;
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-menu-toggle {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.2s ease;
}

.btn-menu-toggle:hover {
    background-color: var(--bg-secondary);
}

.navbar-breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
}

#currentModuleName {
    font-weight: 600;
    color: var(--text-primary);
}

.breadcrumb-separator {
    color: var(--text-muted);
}

#currentViewName {
    color: var(--text-secondary);
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-navbar-action {
    background: none;
    border: 1px solid var(--border-color);
    width: 40px;
    height: 40px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.btn-navbar-action:hover {
    background-color: var(--bg-secondary);
    border-color: var(--homeos-blue);
    color: var(--homeos-blue);
    transform: rotate(180deg);
}

.btn-user-menu {
    background: none;
    border: none;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-user-menu:hover {
    color: var(--homeos-blue);
    background-color: var(--bg-secondary);
    border-radius: 8px;
}

.btn-user-menu i.fa-user-circle {
    font-size: 1.5rem;
}

/* Avatar tròn với initials — hiển thị thay cho icon fa-user-circle */
.user-menu-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--homeos-blue) 0%, var(--homeos-dark-blue) 100%);
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    text-transform: uppercase;
}
.user-menu-name {
    font-size: 14px;
    font-weight: 500;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* User Dropdown Menu */
.user-dropdown-menu {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px var(--shadow-lg);
    min-width: 280px;
    margin-top: 0.5rem;
}

.user-dropdown-menu .dropdown-header {
    padding: 0;
    background-color: transparent;
}

.user-dropdown-menu .user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: linear-gradient(135deg, var(--homeos-blue) 0%, var(--homeos-dark-blue) 100%);
    color: white;
    border-radius: 8px 8px 0 0;
}

.user-dropdown-menu .user-avatar {
    font-size: 2.5rem;
    color: rgba(255, 255, 255, 0.9);
}

.user-dropdown-menu .user-details {
    flex: 1;
    min-width: 0;
}

.user-dropdown-menu .user-name {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-dropdown-menu .user-role {
    font-size: 0.75rem;
    opacity: 0.9;
    margin-bottom: 0.25rem;
}

.user-dropdown-menu .user-email {
    font-size: 0.75rem;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-dropdown-menu .dropdown-item {
    padding: 0.75rem 1.25rem;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.user-dropdown-menu .dropdown-item:hover {
    background-color: var(--bg-secondary);
    color: var(--homeos-blue);
}

.user-dropdown-menu .dropdown-item i {
    width: 20px;
    text-align: center;
}

.user-dropdown-menu .dropdown-divider {
    border-top-color: var(--border-color);
    margin: 0.5rem 0;
}

/* ==================== Content Area ==================== */
.homeos-content {
    flex: 1;
    padding: 5px;
    background-color: var(--bg-secondary);
    height: calc(100vh - var(--navbar-height) - var(--footer-height));
    max-height: calc(100vh - var(--navbar-height) - var(--footer-height));
    max-width: 100%;
    min-width: 0;        /* Prevent flex child from overflowing parent */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.content-view {
    background-color: var(--bg-primary);
    border-radius: 8px;
    padding: 5px;
    box-shadow: 0 2px 8px var(--shadow);
    flex: 1;
    max-width: 100%;
    min-width: 0;        /* Prevent flex child from overflowing parent */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Loading Screen */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

/* ==================== Footer ==================== */
.homeos-footer {
    height: var(--footer-height);
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    line-height: 1.2;
}

.footer-left {
    color: var(--text-secondary);
}

.footer-left strong {
    color: var(--text-primary);
}

.footer-right {
    display: flex;
    align-items: center;
}

.footer-right a {
    color: var(--homeos-blue);
    text-decoration: none;
}

.footer-right a:hover {
    text-decoration: underline;
}

/* ==================== Sidebar Collapsed State (Desktop) ==================== */
/* Collapsed sidebar - only icons visible */
.homeos-sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* When collapsed, hide text elements */
.homeos-sidebar.collapsed .brand-text,
.homeos-sidebar.collapsed .user-info,
.homeos-sidebar.collapsed .menu-link span,
.homeos-sidebar.collapsed .btn-sidebar-action span,
.homeos-sidebar.collapsed .menu-arrow {
    display: none;
}

/* Center icons when collapsed */
.homeos-sidebar.collapsed .menu-link {
    justify-content: center;
    padding: 12px 0;
}

.homeos-sidebar.collapsed .menu-link i {
    margin-right: 0;
}

.homeos-sidebar.collapsed .btn-sidebar-action {
    justify-content: center;
    padding: 12px 0;
}

.homeos-sidebar.collapsed .btn-sidebar-action i {
    margin-right: 0;
}

/* Adjust main content when sidebar collapsed */
.homeos-main.sidebar-collapsed {
    margin-left: var(--sidebar-collapsed-width);
}

/* Hover expand - show full menu on hover */
.homeos-sidebar.collapsed:hover {
    width: var(--sidebar-width);
    box-shadow: 4px 0 12px var(--shadow-lg);
}

/* Show text on hover */
.homeos-sidebar.collapsed:hover .brand-text,
.homeos-sidebar.collapsed:hover .user-info,
.homeos-sidebar.collapsed:hover .menu-link span,
.homeos-sidebar.collapsed:hover .btn-sidebar-action span,
.homeos-sidebar.collapsed:hover .menu-arrow {
    display: block;
}

.homeos-sidebar.collapsed:hover .menu-link {
    justify-content: flex-start;
    padding: 12px 20px;
}

.homeos-sidebar.collapsed:hover .menu-link i {
    margin-right: 12px;
}

.homeos-sidebar.collapsed:hover .btn-sidebar-action {
    justify-content: flex-start;
    padding: 12px 20px;
    gap: 12px;
}

/* Hide submenu when collapsed (unless hovering) */
.homeos-sidebar.collapsed .menu-submenu {
    display: none;
}

.homeos-sidebar.collapsed:hover .menu-submenu {
    display: block;
}

/* ==================== Mobile Sidebar Backdrop ==================== */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 998; /* Below sidebar (999) but above content */
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

/* ==================== Responsive Design ==================== */
@media (max-width: 768px) {
    /* CRITICAL: Mobile — release body lock để cho phép scroll native theo touch.
       Desktop: html/body overflow:hidden + height:100vh (module tự tạo scroll container).
       Mobile: nhiều browser chrome ẩn/hiện làm 100vh sai; khoá body khiến .homeos-content
       overflow:auto bị chặn (touch không scroll được qua container cố định). */
    html, body {
        height: auto;
        min-height: 100vh;
        max-height: none;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .homeos-container {
        height: auto;
        min-height: 100vh;
    }

    .homeos-sidebar {
        transform: translateX(-100%);
        z-index: 1001; /* Above navbar (999) + content backdrop */
        /* Sử dụng 100dvh (dynamic viewport) để tránh bị cắt bởi browser chrome */
        height: 100vh;
        height: 100dvh;
        /* Khoảng trống phía dưới để menu cuối (IoT Gateway) không bị che bởi
           Android navigation bar / iOS home indicator / footer status bar */
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .homeos-sidebar.show {
        transform: translateX(0);
    }

    /* Đảm bảo sidebar-menu scroll được và có chỗ cho safe area */
    .sidebar-menu {
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
    }

    .homeos-main {
        margin-left: 0;
    }

    .homeos-content {
        padding: 5px;
        /* Mobile: footer chuyển flex-direction:column với padding-bottom safe-area
           → height động vượt --footer-height. Cho phép content-area scroll thay vì
           cắt cứng để dashboard/module dài có thể cuộn được */
        height: auto;
        min-height: calc(100vh - var(--navbar-height));
        max-height: none;
        overflow-y: auto;
        overflow-x: hidden;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .content-view {
        padding: 5px;
        /* Cho phép content-view co theo nội dung trên mobile */
        flex: 0 0 auto;
        min-height: 0;
        /* CRITICAL: override desktop rule `overflow: hidden` ở line ~567.
           Desktop: parent .homeos-content co cứng height=100vh-navbar-footer + overflow:hidden, child .content-view cũng overflow:hidden (inner modules tự tạo scroll container riêng).
           Mobile: parent .homeos-content đã đổi sang height:auto + overflow-y:auto (scroll theo body). Child .content-view phải để overflow visible, KHÔNG hidden, nếu không nội dung module bị cắt cứng và không scroll được. */
        overflow: visible;
    }

    /* Module roots thường khai báo `height: calc(100vh - 60px); overflow: hidden` (pattern tạo scroll container riêng cho desktop — vd .tsk-root, .dash-root, .ast-container, .db-studio, .iot-root...).
       Trên mobile, pattern này phá scroll — content bị cắt cứng theo viewport-navbar, inner scroll không trigger được trên touch.
       Override globally: mọi direct child của .content-view đều bỏ height fixed + bỏ overflow hidden trên mobile → scroll theo body/content-area outer. */
    .content-view > * {
        height: auto !important;
        max-height: none !important;
        min-height: 0;
        overflow: visible !important;
    }

    .homeos-navbar {
        padding: 0 10px;
    }

    /* Mobile: compact navbar — bỏ text tên user, chỉ còn avatar */
    .user-menu-name {
        display: none;
    }
    .btn-user-menu {
        padding: 0.25rem;
        gap: 0;
    }
    .user-menu-avatar {
        width: 32px;
        height: 32px;
        font-size: 11px;
    }
    .navbar-right {
        gap: 6px;
    }
    .btn-navbar-action {
        width: 36px;
        height: 36px;
    }
    .btn-navbar-action:hover {
        transform: none;
    }

    .homeos-footer {
        padding: 0 15px;
        flex-direction: column;
        height: auto;
        padding-top: 10px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    /* Safe area bottom cho toàn bộ body (tránh Android nav bar / iOS home bar che) */
    .homeos-content {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
}

/* ==================== Animations ==================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.slide-in-left {
    animation: slideInLeft 0.3s ease;
}

/* ==================== Form Elements (Theme Support) ==================== */
/* Note: File Manager uses Tailwind classes and will inherit Tailwind's CSS Variables below */

/* Form labels */
.form-label,
label {
    display: inline-block;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-weight: 500;
}

/* Form groups */
.form-group {
    margin-bottom: 1rem;
}

/* Checkbox and Radio - Removed width:auto to allow Tailwind w-* classes to work */
/* input[type="checkbox"],
input[type="radio"] {
    width: auto;
    margin-right: 0.5rem;
} */

/* ==================== Utility Classes ==================== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mt-5 { margin-top: 3rem; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }
.mb-5 { margin-bottom: 3rem; }

.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.p-3 { padding: 1.5rem; }
.p-4 { padding: 2rem; }
.p-5 { padding: 3rem; }

.d-none { display: none; }
.d-block { display: block; }
.d-flex { display: flex; }
.d-inline { display: inline; }
.d-inline-block { display: inline-block; }

/* ==================== Login State (Sidebar Hidden) ==================== */
/* When sidebar is hidden (display: none), main content should take full width */
.homeos-sidebar[style*="display: none"] ~ .homeos-main,
.homeos-sidebar[style*="display:none"] ~ .homeos-main {
    margin-left: 0;
}

/* Alternative approach using class-based hiding */
.homeos-container.login-mode .homeos-sidebar {
    display: none;
}

.homeos-container.login-mode .homeos-main {
    margin-left: 0;
}

/* ==================== Animation Keyframes ==================== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInFromLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.fade-in {
    animation: fadeIn 0.5s ease-out;
}

.slide-in {
    animation: slideIn 0.5s ease-out;
}

.slide-in-left {
    animation: slideInFromLeft 0.5s ease-out;
}

/* ==================== Full-height module support ==================== */
/* For modules like File Manager that need full viewport height without padding */
#file-manager-panel {
    /* Let File Manager use its own Tailwind classes without interference */
    height: 100%;
}

/* Remove content-view padding when File Manager is active and make it full height */
.content-view:has(#file-manager-panel) {
    padding: 0 !important;
    background-color: transparent !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    min-height: calc(100vh - var(--navbar-height) - var(--footer-height) - 60px) !important;
}

/* Remove content-view padding when Form Designer is active */
.content-view:has(.form-designer-container) {
    padding: 0 !important;
    background-color: transparent !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    height: calc(100vh - var(--navbar-height) - var(--footer-height) - 10px) !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
}

.form-designer-container {
    height: 100%;
    max-height: 100%;
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Hide scrollbars in Form Designer but keep scroll functionality */
.form-designer-container ::-webkit-scrollbar {
    width: 0px;
    height: 0px;
}

.form-designer-container ::-webkit-scrollbar-track {
    background: transparent;
}

.form-designer-container ::-webkit-scrollbar-thumb {
    background: transparent;
}

.form-designer-container * {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

/* ==================== Tailwind Dark Mode Fallback ==================== */
/* Ensure File Manager respects theme even if Tailwind dark: classes don't apply immediately */
[data-theme="dark"] #file-manager-panel .bg-white {
    background-color: var(--bg-secondary) !important;
}

[data-theme="dark"] #file-manager-panel .bg-gray-50 {
    background-color: var(--bg-primary) !important;
}

[data-theme="dark"] #file-manager-panel .text-gray-900 {
    color: var(--text-primary) !important;
}

[data-theme="dark"] #file-manager-panel .text-gray-700 {
    color: var(--text-secondary) !important;
}

[data-theme="dark"] #file-manager-panel .border-gray-200 {
    border-color: var(--border-color) !important;
}

/* ==================== SweetAlert2 Dark Theme ==================== */
.swal-dark-theme {
    background-color: #2d3748 !important;
    color: #e2e8f0 !important;
}

.swal-dark-theme .swal2-title {
    color: #e2e8f0 !important;
}

.swal-dark-theme .swal2-html-container {
    color: #e2e8f0 !important;
}

.swal-dark-theme .swal2-input {
    background-color: #1a202c !important;
    border-color: #4a5568 !important;
    color: #e2e8f0 !important;
}

.swal-dark-theme .swal2-validation-message {
    background-color: #742a2a !important;
    color: #feb2b2 !important;
}

.swal-dark-theme .bg-gray-50 {
    background-color: #4a5568 !important;
}

.swal-dark-theme .bg-gray-100 {
    background-color: #4a5568 !important;
}

.swal-dark-theme .text-gray-600 {
    color: #a0aec0 !important;
}

.swal-dark-theme .text-gray-700 {
    color: #a0aec0 !important;
}

.swal-dark-theme .text-gray-900 {
    color: #e2e8f0 !important;
}

/* ==================== File Manager Group Hover Actions ==================== */
.file-item-row:hover .file-actions {
    display: flex !important;
}

.file-item-row .file-actions {
    display: none;
}

@media (hover: hover) {
    .file-item-row .file-actions {
        display: none;
    }
    .file-item-row:hover .file-actions {
        display: flex !important;
    }
}

/* On touch devices, always show actions */
@media (hover: none) {
    .file-item-row .file-actions {
        display: flex !important;
    }
}

/* ==================== Toast Notification Theme (SweetAlert2) ==================== */
.homeos-toast-popup {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border: 2px solid var(--border-color) !important;
    border-radius: 8px !important;
    box-shadow: 0 8px 24px var(--shadow-lg) !important;
    font-size: 14px !important;
    padding: 12px 16px !important;
}

.homeos-toast-title {
    color: var(--text-primary) !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    margin: 0 !important;
    padding: 0 !important;
}

.homeos-toast-icon {
    width: 28px !important;
    height: 28px !important;
    margin: 0 8px 0 0 !important;
}

.homeos-toast-progress {
    background: linear-gradient(135deg, #667eea, #764ba2) !important;
    height: 3px !important;
}

/* Success Toast - Green theme */
.swal2-toast.swal2-icon-success .homeos-toast-popup {
    border-left: 4px solid #10b981 !important;
}

.swal2-toast.swal2-icon-success .swal2-icon {
    border-color: #10b981 !important;
    color: #10b981 !important;
}

/* Error Toast - Red theme */
.swal2-toast.swal2-icon-error .homeos-toast-popup {
    border-left: 4px solid #ef4444 !important;
}

.swal2-toast.swal2-icon-error .swal2-icon {
    border-color: #ef4444 !important;
    color: #ef4444 !important;
}

/* Warning Toast - Amber theme */
.swal2-toast.swal2-icon-warning .homeos-toast-popup {
    border-left: 4px solid #f59e0b !important;
}

.swal2-toast.swal2-icon-warning .swal2-icon {
    border-color: #f59e0b !important;
    color: #f59e0b !important;
}

/* Info Toast - Blue theme */
.swal2-toast.swal2-icon-info .homeos-toast-popup {
    border-left: 4px solid #3b82f6 !important;
}

.swal2-toast.swal2-icon-info .swal2-icon {
    border-color: #3b82f6 !important;
    color: #3b82f6 !important;
}

/* Dark mode adjustments for toast */
[data-theme="dark"] .homeos-toast-popup {
    background: var(--bg-secondary) !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6) !important;
}

/* Small size following Rule 16: TailwindCSS, controls always SMALL */
.homeos-toast-popup .swal2-icon {
    width: 28px !important;
    height: 28px !important;
    font-size: 16px !important;
}

.homeos-toast-popup .swal2-icon-content {
    font-size: 16px !important;
}

/* ==================== SweetAlert2 Modal/Dialog - Follow System Theme ==================== */
/* Applied globally for all SweetAlert2 dialogs (not toast) */

/* Light mode (default) */
.swal2-popup:not(.swal2-toast) {
    background: var(--bg-primary) !important;
    border: 1px solid var(--border-color) !important;
}

.swal2-popup:not(.swal2-toast) .swal2-title {
    color: var(--text-primary) !important;
    font-size: 1.25rem !important;
}

.swal2-popup:not(.swal2-toast) .swal2-html-container {
    color: var(--text-secondary) !important;
    font-size: 0.875rem !important;
}

.swal2-popup:not(.swal2-toast) .swal2-confirm {
    background: var(--homeos-blue) !important;
    border: none !important;
    padding: 8px 20px !important;
    font-size: 0.875rem !important;
}

.swal2-popup:not(.swal2-toast) .swal2-cancel {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
    padding: 8px 20px !important;
    font-size: 0.875rem !important;
}

.swal2-popup:not(.swal2-toast) .swal2-actions {
    gap: 8px !important;
}

/* Dark mode for SweetAlert2 modal/dialog */
[data-theme="dark"] .swal2-popup:not(.swal2-toast) {
    background: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .swal2-popup:not(.swal2-toast) .swal2-title {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .swal2-popup:not(.swal2-toast) .swal2-html-container {
    color: var(--text-secondary) !important;
}

[data-theme="dark"] .swal2-popup:not(.swal2-toast) .swal2-cancel {
    background: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

/* Icon colors for dark mode */
[data-theme="dark"] .swal2-icon.swal2-success [class^='swal2-success-line'] {
    background-color: #10b981 !important;
}

[data-theme="dark"] .swal2-icon.swal2-success .swal2-success-ring {
    border-color: rgba(16, 185, 129, 0.3) !important;
}

[data-theme="dark"] .swal2-icon.swal2-error [class^='swal2-x-mark-line'] {
    background-color: #ef4444 !important;
}

[data-theme="dark"] .swal2-icon.swal2-warning {
    border-color: #f59e0b !important;
    color: #f59e0b !important;
}

[data-theme="dark"] .swal2-icon.swal2-info {
    border-color: #3b82f6 !important;
    color: #3b82f6 !important;
}

/* Backdrop for dark mode */
[data-theme="dark"] .swal2-container {
    background: rgba(0, 0, 0, 0.6) !important;
}
