/* =============================================================================
   pibiCo IoT Hub - Styles
   Shelly Cloud inspired design with white background
   ============================================================================= */

:root {
    /* pibiCo Brand Colors */
    --primary-color: #4682B4;           /* Steel Blue - main brand color */
    --primary-dark: #36648B;            /* Darker steel blue */
    --primary-light: #B0C4DE;           /* Light steel blue */
    --primary-pastel: #E8F0F7;          /* Very light blue pastel */

    /* Secondary - Light Gray family */
    --secondary-color: #D3D3D3;         /* Light gray */
    --secondary-light: #F0F0F0;         /* Very light gray */

    /* Status colors - pastel variants */
    --success-color: #7CB47C;           /* Pastel green */
    --success-light: #E8F5E8;           /* Very light green */
    --warning-color: #D4A76A;           /* Pastel orange/amber */
    --warning-light: #FFF5E6;           /* Very light amber */
    --danger-color: #CD6B6B;            /* Pastel red */
    --danger-light: #FFEBEB;            /* Very light red */

    /* Text colors */
    --text-color: #2C3E50;              /* Dark blue-gray */
    --text-secondary: #5D6D7E;          /* Medium gray-blue */
    --text-muted: #95A5A6;              /* Light gray */

    /* Background and surfaces */
    --bg-color: #F7F9FB;                /* Very light blue-gray */
    --card-bg: #FFFFFF;
    --border-color: #DCE4EC;            /* Light blue-gray border */

    /* Shadows and effects */
    --shadow: 0 2px 8px rgba(70, 130, 180, 0.1);
    --shadow-hover: 0 4px 16px rgba(70, 130, 180, 0.2);
    --radius: 8px;
    --radius-lg: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Figtree', 'Raleway', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
}

/* =============================================================================
   Typography
   ============================================================================= */

h1, h2, h3 {
    font-weight: 600;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }

/* =============================================================================
   Buttons
   ============================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    gap: 0.5rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-dark);
}

.btn-secondary {
    background-color: var(--border-color);
    color: var(--text-color);
}

.btn-secondary:hover:not(:disabled) {
    background-color: #D0D0D0;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

/* Icon button - Frappe style square */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: white;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.8rem;
}

.btn-icon:hover {
    background-color: var(--bg-color);
    color: var(--text-color);
    border-color: var(--text-muted);
}

.btn-icon.primary {
    color: var(--primary-color);
    border-color: var(--primary-light);
}

.btn-icon.primary:hover {
    background-color: var(--primary-pastel);
    border-color: var(--primary-color);
}

.btn-icon.danger {
    color: var(--danger-color);
    border-color: #F5D0D0;
}

.btn-icon.danger:hover {
    background-color: var(--danger-light);
    border-color: var(--danger-color);
}

/* =============================================================================
   Forms
   ============================================================================= */

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.checkbox-label input {
    width: auto;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.readonly-field {
    padding: 0.65rem 0.75rem;
    background-color: var(--bg-color);
    border-radius: var(--radius);
    font-family: monospace;
    font-size: 0.9rem;
}

/* =============================================================================
   Login Page
   ============================================================================= */

.login-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
}

.login-page .app-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
}

.login-page .footer-logo {
    filter: brightness(0) invert(1);
    opacity: 0.8;
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
}

.login-box {
    background: white;
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-hover);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo {
    width: 64px;
    height: 64px;
    margin-bottom: 1rem;
    object-fit: contain;
}

.login-header h1 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.login-form .btn {
    width: 100%;
    margin-top: 1rem;
    padding: 0.75rem;
}

.login-footer {
    margin-top: 2rem;
    text-align: center;
}

.login-footer .footer-logo {
    height: 32px;
    object-fit: contain;
    opacity: 0.7;
}

.error-message {
    background-color: var(--danger-light);
    color: var(--danger-color);
    padding: 0.75rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.hidden {
    display: none !important;
}

/* =============================================================================
   App Layout - New unified layout with sidebar
   ============================================================================= */

.app-layout {
    display: flex;
    min-height: 100vh;
    background-color: var(--bg-color);
}

/* Sidebar - Unified across all pages */
.sidebar {
    width: 220px;
    background-color: #F0F2F5;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 200;
    border-right: 1px solid var(--border-color);
    transition: width 0.3s ease, transform 0.3s ease;
}

.sidebar.collapsed {
    width: 56px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    gap: 10px;
}

.sidebar-toggle {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px 10px;
    border-radius: var(--radius);
    transition: all 0.2s;
    font-size: 1rem;
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background-color: white;
    color: var(--text-color);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.brand-logo {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    object-fit: contain;
}

.brand-text {
    font-family: 'Raleway', Arial, sans-serif;
    font-weight: 600;
    font-size: 1.1rem;
    white-space: nowrap;
    color: var(--primary-dark);
    transition: opacity 0.2s, width 0.2s;
}

.sidebar.collapsed .brand-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    padding: 8px;
    overflow-y: auto;
}

.sidebar .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius);
    margin-bottom: 4px;
    transition: all 0.15s;
    cursor: pointer;
    font-size: 0.95rem;
}

.sidebar .nav-item:hover {
    background-color: var(--primary-pastel);
    color: var(--primary-dark);
}

.sidebar .nav-item.active {
    background-color: var(--primary-pastel);
    color: var(--primary-dark);
    font-weight: 500;
}

.sidebar .nav-icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar .nav-label {
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.2s, width 0.2s;
}

.sidebar.collapsed .nav-label {
    opacity: 0;
    width: 0;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 8px;
    border-top: 1px solid var(--border-color);
}

.sidebar-footer .user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.sidebar-footer .user-info .nav-icon {
    font-size: 0.9rem;
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: 220px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

.sidebar.collapsed ~ .main-content {
    margin-left: 56px;
}

/* Top Bar */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: white;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-toggle-mobile {
    display: none;
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px 10px;
    border-radius: var(--radius);
    font-size: 1rem;
}

.page-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-color);
    margin: 0;
}

.topbar-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.topbar-filter {
    display: flex;
    align-items: center;
}

.topbar-filter .filter-select {
    min-width: 180px;
}

/* Content Area */
.content-area {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

/* =============================================================================
   Slide Panel (replaces modals)
   ============================================================================= */

.slide-panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 999;
}

.slide-panel-overlay.open {
    opacity: 1;
    visibility: visible;
}

.slide-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 63%;
    min-width: 320px;
    height: 100vh;
    background: white;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    transition: transform 0.3s ease-out;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.slide-panel.terminal-panel {
    width: 81%;
}

.slide-panel.open {
    transform: translateX(0);
}

.slide-panel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-color);
    flex-shrink: 0;
}

.slide-panel .panel-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-color);
    margin: 0;
}

.slide-panel .panel-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius);
    transition: all 0.2s;
}

.slide-panel .panel-close:hover {
    background: var(--border-color);
    color: var(--text-color);
}

.slide-panel .panel-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

/* Full-width panel body for VNC/terminal */
.slide-panel.terminal-panel .panel-body {
    padding: 10px;
    overflow: hidden;
}

.slide-panel .panel-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-color);
    flex-shrink: 0;
}

.slide-panel .panel-footer:empty {
    display: none;
}

/* Body class when panel is open */
body.panel-open {
    overflow: hidden;
}

/* Responsive - Sidebar and Slide Panel */
@media (max-width: 1024px) {
    .slide-panel {
        width: 50%;
    }
}

@media (max-width: 768px) {
    /* Sidebar becomes overlay on mobile */
    .sidebar {
        transform: translateX(-100%);
        width: 260px;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar.collapsed {
        width: 260px;
        transform: translateX(-100%);
    }

    .sidebar.collapsed.open {
        transform: translateX(0);
    }

    .sidebar.collapsed .nav-label,
    .sidebar.collapsed .brand-text {
        opacity: 1;
        width: auto;
    }

    .main-content {
        margin-left: 0;
    }

    .sidebar.collapsed ~ .main-content {
        margin-left: 0;
    }

    .sidebar-toggle-mobile {
        display: flex;
    }

    /* Slide panel full width on mobile */
    .slide-panel {
        width: 100%;
        max-width: none;
        min-width: 0;
    }

    .topbar {
        padding: 10px 16px;
    }

    .page-title {
        font-size: 1.1rem;
    }

    .content-area {
        padding: 16px;
    }
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 199;
}

.sidebar-overlay.open {
    display: block;
}

/* =============================================================================
   Legacy App Container (keeping for backward compatibility)
   ============================================================================= */

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-container .device-cards-container {
    flex: 1;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: white;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-left h1 {
    color: var(--primary-color);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info {
    font-weight: 500;
    color: var(--text-secondary);
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-admin {
    background-color: var(--primary-light);
    color: var(--primary-dark);
}

.badge-client {
    background-color: var(--warning-light);
    color: var(--warning-color);
    font-size: 0.75rem;
    padding: 0.3rem 0.75rem;
}

/* Client link in tables */
.client-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.client-link:hover {
    text-decoration: underline;
    color: var(--primary-dark);
}

/* =============================================================================
   Admin Layout with Sidebar (Claude-style)
   ============================================================================= */

.admin-layout {
    display: flex;
    min-height: 100vh;
    background-color: var(--bg-color);
}

/* Sidebar */
.sidebar {
    width: 200px;
    background-color: #F0F2F5;
    color: var(--primary-dark);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 200;
    border-right: 1px solid var(--border-color);
}

.sidebar.collapsed {
    width: 44px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
}

.logo-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    color: var(--primary-color);
}

.logo-img {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    object-fit: contain;
}

.logo-text {
    font-family: 'Raleway', Arial, sans-serif;
    font-weight: 600;
    font-size: 1.1rem;
    white-space: nowrap;
    transition: opacity 0.2s;
    color: var(--primary-dark);
}

.sidebar.collapsed .logo-text {
    opacity: 0;
    width: 0;
}


/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    padding: 6px;
    overflow-y: auto;
}

.sidebar .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    line-height: 1.2;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius);
    margin-bottom: 2px;
    transition: all 0.15s;
    cursor: pointer;
    font-size: 1rem;
}

.sidebar .nav-item:hover {
    background-color: var(--primary-pastel);
    color: var(--primary-dark);
}

.sidebar .nav-item.active {
    background-color: var(--primary-pastel);
    color: var(--primary-dark);
    font-weight: 500;
}

.sidebar .nav-icon {
    font-size: 0.9rem;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar .nav-label {
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.2s, width 0.2s;
}

.sidebar.collapsed .nav-label {
    opacity: 0;
    width: 0;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 6px;
    border-top: 1px solid var(--border-color);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    line-height: 1;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Admin Main Content */
.admin-main {
    flex: 1;
    margin-left: 200px;
    transition: margin-left 0.3s ease;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.sidebar.collapsed + .admin-main {
    margin-left: 44px;
}

/* Admin Top Bar */
.admin-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: white;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.admin-topbar .sidebar-toggle {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius);
    transition: all 0.2s;
    font-size: 0.9rem;
}

.admin-topbar .sidebar-toggle:hover {
    background-color: var(--bg-color);
    color: var(--text-color);
}

.admin-topbar h1 {
    font-size: 1.25rem;
    color: var(--text-color);
    margin: 0;
}

.topbar-actions {
    display: flex;
    gap: 0.75rem;
}

/* Admin Content Area */
.admin-content {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
}

.content-filters {
    margin-bottom: 1rem;
}

.filter-select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: white;
    font-size: 0.9rem;
    min-width: 200px;
}

/* Legacy nav-tab styles (keeping for compatibility) */
.app-nav {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: white;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
}

.nav-tab {
    padding: 0.5rem 1rem;
    border: none;
    background: none;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius);
    transition: all 0.2s;
    white-space: nowrap;
}

.nav-tab:hover {
    background-color: var(--bg-color);
}

.nav-tab.active {
    background-color: var(--primary-pastel);
    color: var(--primary-dark);
}

/* Responsive sidebar */
@media (max-width: 768px) {
    .sidebar {
        width: 44px;
    }

    .sidebar .nav-label,
    .sidebar .logo-text {
        display: none;
    }

    .admin-main {
        margin-left: 44px;
    }
}

/* =============================================================================
   Main Content
   ============================================================================= */

.app-content {
    flex: 1;
    padding: 1.5rem;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.section-header h2 {
    color: var(--text-color);
}

/* =============================================================================
   Data Tables
   ============================================================================= */

.data-table-container {
    background: white;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
}

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

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background-color: var(--bg-color);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.data-table tr:hover {
    background-color: #FAFAFA;
}

.data-table .loading {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

.data-table .actions {
    display: flex;
    gap: 0.35rem;
}

/* Frappe-style tags */
.tag {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    background-color: var(--bg-color);
    color: var(--text-secondary);
    text-transform: capitalize;
}

.tag.admin {
    background-color: var(--primary-pastel);
    color: var(--primary-dark);
}

.tag.sensor {
    background-color: var(--success-light);
    color: #3D8B3D;
}

.tag.gateway {
    background-color: var(--warning-light);
    color: #B8860B;
}

/* Status dot for tables */
.status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--text-muted);
}

.status-dot.online {
    background-color: var(--success-color);
    box-shadow: 0 0 6px var(--success-color);
}

.status-dot.offline {
    background-color: var(--danger-color);
}

/* Monospace text */
.mono {
    font-family: 'SF Mono', Consolas, 'Liberation Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* =============================================================================
   Dashboard Stats
   ============================================================================= */

.dashboard-stats {
    display: flex;
    gap: 1rem;
    padding: 1rem 1.5rem;
    flex-wrap: wrap;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    min-width: 160px;
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon.online { background-color: var(--success-light); }
.stat-icon.online::before { content: ''; width: 12px; height: 12px; border-radius: 50%; background-color: var(--success-color); }
.stat-icon.offline { background-color: var(--danger-light); }
.stat-icon.offline::before { content: ''; width: 12px; height: 12px; border-radius: 50%; background-color: var(--danger-color); }
.stat-icon.power { background-color: var(--primary-pastel); }
.stat-icon.power::before { content: '⚡'; font-size: 1.2rem; }

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* =============================================================================
   Device Cards Grid (Shelly-style)
   ============================================================================= */

.device-cards-container {
    padding: 0 1.5rem 1.5rem;
}

.cards-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.filter-buttons {
    display: flex;
    gap: 0.5rem;
}

.filter-btn {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 999px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn:hover {
    border-color: var(--primary-color);
}

.filter-btn.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.device-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

/* Device Card - Shelly Cloud style */
.device-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: all 0.2s;
    border-left: 4px solid var(--border-color);
}

.device-card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}

.device-card.online {
    border-left-color: var(--success-color);
}

.device-card.offline {
    border-left-color: var(--danger-color);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.device-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-color);
}

.device-type {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-indicator.online {
    background-color: var(--success-color);
    box-shadow: 0 0 8px var(--success-color);
}

.status-indicator.offline {
    background-color: var(--danger-color);
}

.card-body {
    padding: 1rem;
}

.reading-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.reading {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.reading-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.reading-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-color);
}

.reading-value.power-value {
    color: var(--primary-color);
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: var(--bg-color);
    border-top: 1px solid var(--border-color);
}

.device-hostname {
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* =============================================================================
   MQTT Status Cards
   ============================================================================= */

.status-cards {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.status-card {
    background: white;
    padding: 1.25rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    min-width: 200px;
}

.status-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.status-value {
    font-size: 1.25rem;
    font-weight: 600;
}

.status-value.connected {
    color: var(--success-color);
}

.status-value.disconnected {
    color: var(--danger-color);
}

/* =============================================================================
   Pending Device Cards
   ============================================================================= */

.pending-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.pending-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    border-left: 4px solid var(--warning-color);
}

.pending-card h4 {
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.pending-card .info-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-bottom: 0.35rem;
}

.pending-card .info-label {
    color: var(--text-muted);
}

.pending-card .actions {
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
}

.info-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

/* =============================================================================
   Modal
   ============================================================================= */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    color: var(--text-color);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-color);
}

.modal-content form {
    padding: 1.25rem;
}

/* =============================================================================
   Utilities
   ============================================================================= */

.loading-spinner {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-state,
.error-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

/* App Footer */
.app-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1.5rem;
    background: white;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: auto;
}

.footer-logo {
    height: 32px;
    object-fit: contain;
}

.error-state {
    color: var(--danger-color);
}

.refresh-icon {
    display: inline-block;
    transition: transform 0.3s;
}

.btn:active .refresh-icon {
    transform: rotate(180deg);
}

/* =============================================================================
   Responsive
   ============================================================================= */

@media (max-width: 768px) {
    .app-header {
        padding: 0.75rem 1rem;
    }

    .header-left h1 {
        font-size: 1.2rem;
    }

    .app-content {
        padding: 1rem;
    }

    .dashboard-stats {
        padding: 0.75rem 1rem;
    }

    .device-cards-container {
        padding: 0 1rem 1rem;
    }

    .device-cards-grid {
        grid-template-columns: 1fr;
    }

    .data-table-container {
        overflow-x: auto;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* =============================================================================
   Terminal Modal Styles
   ============================================================================= */

.modal-fullscreen {
    width: 95vw;
    max-width: 1400px;
    height: 85vh;
    max-height: 900px;
    display: flex;
    flex-direction: column;
}

.modal-fullscreen .modal-header {
    flex-shrink: 0;
    background: var(--primary-color);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: var(--radius) var(--radius) 0 0;
}

.modal-fullscreen .modal-header h3 {
    color: white;
    font-size: 1rem;
}

.modal-fullscreen .modal-close {
    color: white;
    opacity: 0.8;
}

.modal-fullscreen .modal-close:hover {
    opacity: 1;
}

.terminal-container {
    flex: 1;
    background: #1e1e1e;
    border-radius: 0 0 var(--radius) var(--radius);
    overflow: hidden;
}

.terminal-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #1e1e1e;
}

/* Terminal button in actions */
.btn-terminal {
    background: #2d3436;
    color: white;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    transition: background 0.2s;
}

.btn-terminal:hover {
    background: #000;
}

.btn-terminal:disabled {
    background: #95a5a6;
    cursor: not-allowed;
}

.btn-terminal i {
    font-size: 0.75rem;
}

/* =============================================================================
   MQTT Explorer Styles - Compact View
   ============================================================================= */

/* Base styles for MQTT Explorer */
.mqtt-explorer-page {
    font-family: 'Figtree', Arial, sans-serif;
}

/* Monospace elements */
.mqtt-explorer-page code,
.mqtt-explorer-page .mono,
.mqtt-explorer-page .topic-label,
.mqtt-explorer-page .message-topic,
.mqtt-explorer-page .message-preview,
.mqtt-explorer-page .payload-content,
.mqtt-explorer-page .detail-info-value,
.mqtt-explorer-page .publish-form input,
.mqtt-explorer-page .publish-form textarea {
    font-family: 'SF Mono', Consolas, 'Liberation Mono', monospace;
}

.mqtt-explorer-page .admin-main {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.mqtt-explorer-container {
    flex: 1;
    display: flex;
    gap: 1px;
    background-color: var(--border-color);
    overflow: hidden;
    min-height: 0;
}

/* Connection Badge */
.connection-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1;
}

.connection-badge.connected {
    background-color: var(--success-light);
    color: #2d7a2d;
}

.connection-badge.connected i {
    color: var(--success-color);
    animation: pulse 2s infinite;
}

.connection-badge.disconnected {
    background-color: var(--danger-light);
    color: var(--danger-color);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* MQTT Panels */
.mqtt-panel {
    display: flex;
    flex-direction: column;
    background-color: var(--card-bg);
    min-width: 0;
}

.topic-panel {
    flex: 0 0 260px;
    min-width: 180px;
    max-width: 400px;
    resize: horizontal;
    overflow: hidden;
    transition: flex-basis 0.2s ease, min-width 0.2s ease, max-width 0.2s ease;
}

.messages-panel {
    flex: 1;
    min-width: 280px;
    display: flex;
    flex-direction: column;
}

.detail-panel {
    flex: 0 0 380px;
    min-width: 300px;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    background-color: var(--border-color);
}

.detail-panel > div {
    background-color: var(--card-bg);
}

/* Panel Header */
.mqtt-panel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-color);
    gap: 8px;
}

.mqtt-panel .panel-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1;
    margin: 0;
}

.mqtt-panel .panel-header h3 i {
    color: var(--primary-color);
    font-size: 14px;
}

.topic-stats, .message-stats {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1;
}

/* Panel Toolbar */
.panel-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-bottom: 1px solid var(--border-color);
    background-color: #FAFBFC;
}

.search-input {
    flex: 1;
    padding: 5px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    background: white;
    line-height: 1;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.selected-topic {
    flex: 1;
    font-size: 14px;
    color: var(--text-secondary);
    overflow: hidden;
    line-height: 1;
}

.selected-topic .topic-label {
    color: var(--primary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.checkbox-inline {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    cursor: pointer;
    line-height: 1;
}

.checkbox-inline input {
    margin: 0;
    width: 12px;
    height: 12px;
}

/* Panel Content */
.mqtt-panel .panel-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.mqtt-panel .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 14px;
    gap: 6px;
    line-height: 1;
}

.mqtt-panel .empty-state i {
    font-size: 24px;
    opacity: 0.5;
}

/* Topic Tree */
.topic-tree-node {
    user-select: none;
}

.topic-tree-item {
    display: flex;
    align-items: center;
    padding: 2px 4px;
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: all 0.1s;
    line-height: 1;
}

.topic-tree-item:hover {
    background-color: var(--bg-color);
}

.topic-tree-item.selected {
    background-color: var(--primary-pastel);
    border-left-color: var(--primary-color);
}

.topic-tree-item.has-update {
    animation: highlight 0.5s ease;
}

@keyframes highlight {
    0% { background-color: var(--warning-light); }
    100% { background-color: transparent; }
}

.topic-toggle {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 9px;
    flex-shrink: 0;
}

.topic-toggle.expanded i {
    transform: rotate(90deg);
}

.topic-icon {
    width: 18px;
    text-align: center;
    color: var(--text-muted);
    font-size: 11px;
    flex-shrink: 0;
}

.topic-icon.folder {
    color: var(--warning-color);
}

.topic-icon.leaf {
    color: var(--primary-color);
}

.topic-name {
    flex: 1;
    font-size: 14px;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-left: 4px;
    line-height: 1;
}

.topic-badge {
    font-size: 10px;
    padding: 1px 6px;
    background-color: var(--primary-pastel);
    color: var(--primary-dark);
    border-radius: 999px;
    margin-left: 6px;
    line-height: 1;
}

.topic-children {
    margin-left: 0;
    display: none;
}

.topic-children.expanded {
    display: block;
}

/* Message List */
.message-list {
    padding: 4px;
    flex: 1;
    overflow-y: auto;
}

.message-item {
    display: flex;
    flex-direction: column;
    padding: 6px 8px;
    margin-bottom: 3px;
    background-color: #FAFBFC;
    border-radius: 4px;
    border-left: 2px solid var(--border-color);
    cursor: pointer;
    transition: all 0.1s;
}

.message-item:hover {
    background-color: var(--bg-color);
    border-left-color: var(--primary-light);
}

.message-item.selected {
    background-color: var(--primary-pastel);
    border-left-color: var(--primary-color);
}

.message-item.new {
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px;
}

.message-topic {
    font-size: 13px;
    color: var(--primary-color);
    font-weight: 500;
    word-break: break-all;
    flex: 1;
    line-height: 1;
}

.message-time {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    margin-left: 8px;
    line-height: 1;
    font-family: 'SF Mono', Consolas, monospace;
}

.message-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1;
}

.message-meta {
    display: flex;
    gap: 8px;
    margin-top: 3px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1;
}

.message-meta span {
    display: flex;
    align-items: center;
    gap: 3px;
}

/* Chart Container - below messages */
.chart-container {
    height: 0;
    overflow: hidden;
    background-color: var(--card-bg);
    border-top: 1px solid var(--border-color);
    transition: height 0.2s ease;
}

.chart-container.visible {
    height: 150px;
}

.chart-container .chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background-color: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
}

.chart-container .chart-header h4 {
    font-size: 12px;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chart-container .chart-header h4 i {
    color: var(--primary-color);
}

.chart-container .chart-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    font-size: 12px;
}

.chart-container .chart-close:hover {
    color: var(--text-color);
}

.chart-container .chart-body {
    height: calc(100% - 32px);
    padding: 8px;
    display: flex;
    align-items: flex-end;
    gap: 2px;
}

.chart-bar {
    flex: 1;
    background-color: var(--primary-light);
    border-radius: 2px 2px 0 0;
    min-height: 4px;
    max-width: 20px;
    transition: height 0.2s ease;
    position: relative;
}

.chart-bar:hover {
    background-color: var(--primary-color);
}

.chart-bar::after {
    content: attr(data-value);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 9px;
    color: var(--text-muted);
    white-space: nowrap;
    display: none;
}

.chart-bar:hover::after {
    display: block;
}

/* Publish Section */
.publish-section {
    flex-shrink: 0;
}

.publish-form {
    padding: 8px;
}

.publish-form .form-group {
    margin-bottom: 6px;
}

.publish-form label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 3px;
    display: block;
    line-height: 1;
}

.publish-form input,
.publish-form select,
.publish-form textarea {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    font-family: 'SF Mono', Consolas, monospace;
    line-height: 1.2;
}

.publish-form textarea {
    resize: vertical;
    min-height: 50px;
}

.form-row {
    display: flex;
    gap: 8px;
}

.form-group-sm {
    flex: 1;
}

.form-group-sm .checkbox-label {
    margin-top: 16px;
    font-size: 11px;
    line-height: 1;
}

.btn-block {
    width: 100%;
    padding: 6px 10px;
    font-size: 12px;
    line-height: 1;
}

/* Detail Section */
.detail-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 150px;
    overflow: hidden;
}

.detail-actions {
    display: flex;
    gap: 4px;
}

.detail-actions .btn-icon {
    width: 24px;
    height: 24px;
    font-size: 11px;
}

.detail-content {
    flex: 1;
    overflow: auto;
    padding: 8px;
}

.detail-content .empty-state {
    padding: 16px;
}

.detail-info {
    margin-bottom: 8px;
}

.detail-info-row {
    display: flex;
    padding: 4px 0;
    font-size: 13px;
    line-height: 1;
}

.detail-info-label {
    width: 60px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.detail-info-value {
    color: var(--text-color);
    word-break: break-all;
}

/* Two-column payload layout: markers | JSON */
.payload-two-column {
    display: flex;
    background-color: #1e1e1e;
    border-radius: 6px;
    overflow: hidden;
    margin-top: 8px;
}

.payload-markers {
    display: flex;
    flex-direction: column;
    background-color: #252526;
    border-right: 1px solid #3c3c3c;
    padding: 8px 0;
    min-width: 24px;
}

.payload-markers .chart-marker,
.payload-markers .chart-marker-empty {
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

.payload-markers .chart-marker {
    color: var(--success-color);
    cursor: pointer;
    transition: all 0.15s;
}

.payload-markers .chart-marker:hover {
    color: #fff;
    background-color: var(--success-color);
}

.payload-markers .chart-marker i {
    font-size: 11px;
}

.payload-json {
    flex: 1;
    padding: 8px 12px;
    overflow-x: auto;
}

.payload-content {
    font-size: 14px;
    color: #d4d4d4;
    white-space: pre;
    word-break: normal;
    line-height: 20px;
    margin: 0;
}

/* JSON Syntax Highlighting */
.json-key { color: #9cdcfe; }
.json-string { color: #ce9178; }
.json-number { color: #b5cea8; }
.json-boolean { color: #569cd6; }
.json-null { color: #569cd6; }

/* Charts Area - floating cards grid */
.charts-area {
    position: absolute;
    top: 60px;
    left: 220px;
    right: 0;
    z-index: 50;
    display: none;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px;
    pointer-events: none;
}

.charts-area.has-charts {
    display: flex;
}

.chart-card {
    width: 320px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    overflow: hidden;
    pointer-events: auto;
}

.chart-card-header {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: #f8f9fa;
    border-bottom: 1px solid var(--border-color);
    gap: 8px;
}

.chart-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
}

.chart-card-subtitle {
    flex: 1;
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chart-card-actions {
    display: flex;
    gap: 4px;
}

.chart-btn {
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.15s;
}

.chart-btn:hover {
    background: var(--border-color);
    color: var(--text-color);
}

.chart-btn.paused {
    color: var(--success-color);
}

.chart-card-body {
    padding: 12px;
    background: #fff;
}

.chart-line-container {
    display: flex;
    gap: 8px;
    height: 100px;
}

.chart-y-axis {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-muted);
    text-align: right;
    min-width: 36px;
    padding: 2px 0;
}

.chart-area {
    flex: 1;
    background: #fafafa;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.chart-area svg {
    width: 100%;
    height: 100%;
}

.chart-dot {
    cursor: pointer;
}

.chart-dot:hover {
    r: 5;
}

/* History Section - hidden by default, replaced by chart container */
.history-section {
    display: none;
}

/* Collapsible Topic Panel */
.topic-panel.collapsed {
    flex: 0 0 32px !important;
    min-width: 32px !important;
    max-width: 32px !important;
    resize: none;
}

.topic-panel.collapsed .panel-toolbar,
.topic-panel.collapsed .panel-content {
    display: none;
}

.topic-panel.collapsed .panel-header {
    flex-direction: column;
    padding: 8px 4px;
    height: 100%;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    justify-content: flex-start;
    cursor: pointer;
}

.topic-panel.collapsed .panel-header h3 {
    flex-direction: column;
}

.topic-panel.collapsed .topic-stats {
    display: none;
}

.panel-collapse-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 10px;
    line-height: 1;
    border-radius: 3px;
    transition: all 0.1s;
}

.panel-collapse-btn:hover {
    background-color: var(--bg-color);
    color: var(--text-color);
}

/* Responsive - MQTT Explorer */
@media (max-width: 1200px) {
    .detail-panel {
        flex: 0 0 280px;
    }
}

@media (max-width: 992px) {
    .mqtt-explorer-container {
        flex-direction: column;
        height: auto;
        overflow-y: auto;
    }

    .topic-panel,
    .messages-panel,
    .detail-panel {
        flex: none;
        max-width: none;
        min-width: 0;
        width: 100%;
        resize: none;
    }

    .topic-panel {
        height: 160px;
        border-bottom: 1px solid var(--border-color);
    }

    .topic-panel.collapsed {
        height: 28px;
        min-width: 100%;
        max-width: 100%;
    }

    .topic-panel.collapsed .panel-header {
        writing-mode: horizontal-tb;
        flex-direction: row;
        padding: 4px 8px;
    }

    .messages-panel {
        height: 240px;
        border-bottom: 1px solid var(--border-color);
    }

    .detail-panel {
        height: auto;
        flex-direction: column;
    }

    .publish-section,
    .detail-section,
    .history-section {
        border-bottom: 1px solid var(--border-color);
    }

    .detail-section {
        min-height: 150px;
    }
}

@media (max-width: 768px) {
    .mqtt-explorer-page .admin-main {
        height: auto;
        min-height: 100vh;
    }

    .mqtt-explorer-page .admin-topbar {
        padding: 4px 8px;
        gap: 6px;
    }

    .mqtt-explorer-page .topbar-left h1 {
        font-size: 12px;
    }

    .connection-badge {
        padding: 2px 6px;
        font-size: 9px;
    }

    .connection-badge span {
        display: none;
    }

    .topic-panel {
        height: 140px;
    }

    .messages-panel {
        height: 220px;
    }

    .mqtt-panel .panel-header {
        padding: 4px 6px;
    }

    .mqtt-panel .panel-header h3 {
        font-size: 10px;
    }

    .mqtt-panel .panel-header h3 i {
        font-size: 9px;
    }

    .panel-toolbar {
        padding: 3px 6px;
    }

    .search-input {
        font-size: 10px;
        padding: 2px 6px;
    }

    .topic-tree-item {
        padding: 2px 4px;
    }

    .topic-name {
        font-size: 10px;
    }

    .topic-badge {
        font-size: 8px;
        padding: 0 4px;
    }

    .message-list {
        padding: 3px;
    }

    .message-item {
        padding: 4px 6px;
        margin-bottom: 2px;
    }

    .message-topic {
        font-size: 9px;
    }

    .message-time {
        font-size: 8px;
    }

    .message-preview {
        font-size: 9px;
    }

    .message-meta {
        font-size: 8px;
        margin-top: 2px;
        gap: 6px;
    }

    .publish-form {
        padding: 6px;
    }

    .publish-form .form-group {
        margin-bottom: 4px;
    }

    .publish-form label {
        font-size: 9px;
        margin-bottom: 2px;
    }

    .publish-form input,
    .publish-form select,
    .publish-form textarea {
        padding: 2px 4px;
        font-size: 10px;
    }

    .publish-form textarea {
        min-height: 40px;
    }

    .form-row {
        gap: 6px;
    }

    .form-group-sm .checkbox-label {
        margin-top: 12px;
        font-size: 9px;
    }

    .btn-block {
        padding: 4px 8px;
        font-size: 10px;
    }

    .detail-content {
        padding: 6px;
    }

    .detail-info-row {
        padding: 2px 0;
        font-size: 9px;
    }

    .detail-info-label {
        width: 50px;
    }

    .payload-container {
        padding: 6px;
    }

    .payload-content {
        font-size: 9px;
        line-height: 1.2;
    }

    .history-content {
        padding: 6px;
        height: 60px;
    }

    .sparkline-container {
        height: 40px;
    }

    .detail-actions .btn-icon {
        width: 20px;
        height: 20px;
        font-size: 9px;
    }
}

@media (max-width: 480px) {
    .mqtt-explorer-page .admin-topbar .topbar-actions {
        gap: 4px;
    }

    .mqtt-explorer-page .admin-topbar .btn {
        padding: 3px 6px;
        font-size: 10px;
    }

    .topic-panel {
        height: 120px;
    }

    .messages-panel {
        height: 200px;
    }

    .selected-topic {
        display: none;
    }

    .checkbox-inline span {
        display: none;
    }

    .mqtt-panel .empty-state {
        font-size: 10px;
    }

    .mqtt-panel .empty-state i {
        font-size: 18px;
    }
}

/* =============================================================================
   Terminal with File Browser
   ============================================================================= */

.terminal-with-files {
    display: flex;
    height: calc(100vh - 80px);
    background: #1e1e1e;
    border-radius: 8px;
    overflow: hidden;
}

/* File Browser Sidebar */
.file-browser {
    width: 280px;
    min-width: 150px;
    max-width: 500px;
    background: #252526;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #3c3c3c;
}

.file-browser-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: #333333;
    border-bottom: 1px solid #3c3c3c;
}

.file-browser-header h4 {
    margin: 0;
    font-size: 13px;
    font-weight: 500;
    color: #cccccc;
}

.file-browser-header h4 i {
    margin-right: 8px;
    color: #569cd6;
}

.file-browser-actions {
    display: flex;
    gap: 4px;
}

.file-browser-actions .btn-icon {
    width: 26px;
    height: 26px;
    padding: 0;
    background: transparent;
    border: none;
    color: #999;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.file-browser-actions .btn-icon:hover {
    background: #444;
    color: #fff;
}

.file-browser-path {
    padding: 8px 12px;
    font-size: 11px;
    color: #888;
    background: #2d2d2d;
    border-bottom: 1px solid #3c3c3c;
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-browser-path i {
    color: #dcb67a;
    flex-shrink: 0;
}

.file-browser-content {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

/* File Items */
.file-item {
    display: flex;
    align-items: center;
    padding: 3px 12px;
    cursor: pointer;
    color: #ccc;
    font-size: 13px;
    line-height: 1;
    gap: 6px;
}

.file-item:hover {
    background: #2a2d2e;
}

.file-item:active {
    background: #094771;
}

.file-icon {
    width: 16px;
    text-align: center;
    flex-shrink: 0;
    font-size: 14px;
}

.file-icon.folder {
    color: #dcb67a;
}

.file-icon.code {
    color: #6a9955;
}

.file-icon.text {
    color: #9cdcfe;
}

.file-icon.image {
    color: #ce9178;
}

.file-icon.archive {
    color: #d7ba7d;
}

.file-icon.pdf {
    color: #f14c4c;
}

.file-icon.file {
    color: #808080;
}

.file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-size {
    font-size: 11px;
    color: #666;
    flex-shrink: 0;
}

/* Resize Handle */
.resize-handle {
    width: 4px;
    background: #3c3c3c;
    cursor: col-resize;
    flex-shrink: 0;
}

.resize-handle:hover {
    background: #569cd6;
}

/* Terminal Area */
.terminal-area {
    flex: 1;
    min-width: 0;
    background: #1e1e1e;
}

/* Context Menu */
.file-context-menu {
    position: fixed;
    background: #252526;
    border: 1px solid #3c3c3c;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 10000;
    min-width: 150px;
    padding: 4px 0;
}

.context-menu-item {
    padding: 8px 16px;
    cursor: pointer;
    color: #ccc;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.context-menu-item:hover {
    background: #094771;
}

.context-menu-item.danger {
    color: #f48771;
}

.context-menu-item.danger:hover {
    background: #5a1d1d;
}

.context-menu-item i {
    width: 14px;
    text-align: center;
}

/* File browser loading/empty states */
.file-browser .loading-spinner,
.file-browser .empty-state,
.file-browser .error-state {
    color: #888;
    padding: 20px;
    text-align: center;
    font-size: 12px;
}

.file-browser .error-state {
    color: #f48771;
}

.file-browser .error-state i,
.file-browser .empty-state i {
    display: block;
    font-size: 24px;
    margin-bottom: 8px;
}

/* Mobile: Stack vertically */
@media (max-width: 768px) {
    .terminal-with-files {
        flex-direction: column;
    }

    .file-browser {
        width: 100% !important;
        max-width: none;
        height: 200px;
        min-height: 150px;
        border-right: none;
        border-bottom: 1px solid #3c3c3c;
    }

    .resize-handle {
        width: 100%;
        height: 4px;
        cursor: row-resize;
    }

    .terminal-area {
        flex: 1;
        min-height: 200px;
    }
}

/* =============================================================================
   VNC Styles
   ============================================================================= */

.btn-vnc {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #8b5cf6;
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-vnc:hover {
    background: #7c3aed;
}

.btn-vnc i {
    font-size: 11px;
}

.vnc-container {
    width: 100%;
    height: calc(100vh - 70px);
    background: #1e1e1e;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    position: relative;
}

.vnc-container iframe {
    width: 100% !important;
    height: 100% !important;
    border: none;
    display: block;
}

.vnc-loading {
    text-align: center;
    color: #888;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.vnc-loading p {
    margin-top: 1rem;
}
