:root {
    --bg-dark: #0f111a;
    --bg-panel: rgba(25, 28, 41, 0.65);
    --bg-card: rgba(30, 35, 50, 0.5);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(0, 240, 255, 0.3);
    
    --text-main: #f0f4f8;
    --text-muted: #8b949e;
    
    --accent-primary: #00f0ff;
    --accent-hover: #00c3ff;
    --accent-glow: rgba(0, 240, 255, 0.4);
    
    --status-online: #00ff88;
    --status-offline: #8b949e;
    --status-error: #ff0000;
    
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    --radius-lg: 16px;
    --radius-md: 8px;
    --radius-sm: 4px;
    
    --transition: 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-dark);
    /* Subtle background grid pattern */
    background-image: 
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    color: var(--text-main);
    line-height: 1.4;
    height: 100vh;
    overflow: hidden;
}

/* --- Global Scrollbar Styling --- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    border: 2px solid var(--bg-dark);
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}


input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    position: relative;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

input[type="checkbox"]:checked {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    width: 4px;
    height: 8px;
    border: solid #000;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-top: -2px;
}

input[type="checkbox"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(0, 240, 255, 0.1);
}

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

.global-header {
    height: 60px;
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: rgba(15, 17, 26, 0.8);
    backdrop-filter: blur(10px);
    z-index: 100;
    flex-shrink: 0;
}

.main-header-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 24px;
    padding: 0 24px;
}

.main-header-content h1 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: 0.5px;
    color: #00ffff;
}

.app-body {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Glassmorphism utility */
.glass {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
}

/* Sidebar */
.sidebar {
    width: 240px; /* Default */
    min-width: 180px;
    max-width: 600px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.sidebar-resizer {
    width: 4px;
    margin-right: -4px;
    cursor: col-resize;
    z-index: 20;
    transition: background 0.2s;
    background: transparent;
}

.sidebar-resizer:hover, .is-resizing .sidebar-resizer {
    background: var(--accent-primary);
    box-shadow: 0 0 10px var(--accent-glow);
}

body.is-resizing {
    cursor: col-resize;
    user-select: none;
    -webkit-user-select: none;
}

/* System Health Indicators */
.system-health {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.health-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.health-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4a4d5e;
    transition: all 0.3s ease;
}

.health-dot.online {
    background: var(--status-online);
    box-shadow: 0 0 8px var(--status-online);
}

.health-dot.offline {
    background: var(--status-error);
    box-shadow: 0 0 8px var(--status-error);
}

.health-dot.broker-online {
    background: #00d2ff;
    box-shadow: 0 0 8px #00d2ff;
}

.health-label {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.logo-container {
    width: 240px; /* Default sidebar width */
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 0 24px;
    gap: 12px;
}

.logo-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-primary);
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.logo-container h2 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 1px;
    line-height: 1;
    color: #00ffff;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden;
}

.section-title {
    padding: 12px 16px 6px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.badge {
    background: rgba(0, 240, 255, 0.1);
    color: var(--accent-primary);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
}

.nodes-list {
    list-style: none;
    overflow-y: auto;
    padding: 4px 8px;
    flex-grow: 1;
}

.nodes-list {
    list-style: none;
    overflow-y: auto;
    padding: 4px 8px;
    flex-grow: 1;
}

.node-item {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 2px;
    border: 1px solid transparent;
    position: relative;
    overflow: hidden;
}

.node-item:hover {
    background: rgba(255,255,255,0.03);
}

.node-item.active {
    background: rgba(0, 240, 255, 0.08);
    border-color: var(--border-highlight);
    box-shadow: inset 0 0 15px rgba(0, 240, 255, 0.05);
}

.node-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 12px;
    background: var(--status-offline);
    transition: var(--transition);
}

.node-status.online {
    background: var(--status-online);
    box-shadow: 0 0 10px var(--status-online);
}

.node-item.active .node-name {
    color: #fff;
    font-weight: 600;
}

.node-name {
    font-size: 0.9rem;
    color: #cbd5e1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 32px; /* Ensure space for right-aligned icon */
    width: 100%;
}

.btn-edit-node-name {
    display: none !important;
    position: absolute !important;
    right: 12px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    color: var(--text-muted);
    background: var(--bg-panel) !important;
    border: none !important;
    box-shadow: none !important;
    padding: 2px !important;
    margin: 0 !important;
    cursor: pointer;
    z-index: 20;
}

.node-item.active .btn-edit-node-name {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

.btn-edit-node-name:hover {
    color: var(--accent-primary);
}

/* Main Content */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* main-header was removed, keeping only subtitle and actions for main-header-content */



.subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    gap: 8px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 14px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-main);
    outline: none;
    font-family: inherit;
    letter-spacing: 0.5px;
}

.btn:hover {
    background: rgba(0, 240, 255, 0.05);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    box-shadow: 0 0 15px var(--accent-glow);
    transform: translateY(-1px);
}

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

.btn-success {
    border-color: var(--status-online);
    color: var(--status-online);
}

.btn-success:hover {
    background: rgba(0, 255, 136, 0.05);
    border-color: var(--status-online);
    color: var(--status-online);
    box-shadow: 0 0 15px rgba(0, 255, 136, 0.3);
}

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

.btn-secondary.active {
    background: var(--accent-primary);
    color: #000;
    border-color: var(--accent-primary);
}

#btn-toggle-filter {
    color: var(--text-muted);
    transition: var(--transition);
}

#btn-toggle-filter:hover {
    color: #fff;
}

#btn-toggle-filter.active {
    color: var(--accent-primary);
}

#btn-toggle-filter.active #filter-icon {
    filter: drop-shadow(0 0 5px var(--accent-glow));
}

.btn-icon {
    padding: 8px;
    background: transparent;
    color: var(--text-muted);
}

.btn-icon:hover {
    color: var(--accent-primary);
    background: rgba(0, 240, 255, 0.1);
}

.content-body {
    flex-grow: 1;
    padding: 16px 16px 16px 8px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    backdrop-filter: blur(10px);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0,0,0,0.2);
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}
.status-dot.offline { background: var(--status-offline); }
.status-dot.online { 
    background: var(--status-online); 
    box-shadow: 0 0 8px var(--status-online);
}

.config-section {
    flex-shrink: 0;
    transition: var(--transition);
}

.config-section.collapsed .config-grid {
    display: none;
}

#config-collapse-icon {
    transition: transform 0.3s ease;
}

.config-section.collapsed #config-collapse-icon {
    transform: rotate(180deg);
}

/* Form Elements */
.config-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px 20px;
}

.config-grid-row-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.config-grid-row-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.config-grid-row-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.config-grid-row-1-3 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.form-control {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 6px 12px;
    color: #fff;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(0, 240, 255, 0.1);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 36px;
}

select.form-control option {
    background: var(--bg-dark);
    color: #fff;
}

.form-control.with-prefix {
    padding-left: 36px;
}

.input-prefix {
    position: absolute;
    left: 14px;
    color: var(--accent-primary);
    font-weight: 600;
    font-family: var(--font-mono);
    pointer-events: none;
}

/* Custom Checkbox Styling */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid #64748b; /* Distinct Gray Border */
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.3);
    cursor: pointer;
    position: relative;
    transition: var(--transition);
    flex-shrink: 0;
}

input[type="checkbox"]:checked {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 1px;
    width: 5px;
    height: 10px;
    border: solid #000;
    border-width: 0 2.5px 2.5px 0;
    transform: rotate(45deg);
}

input[type="checkbox"]:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 240, 255, 0.3);
}

input[type="checkbox"]:hover {
    border-color: #94a3b8;
}

/* Table */
.table-section {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-height: 200px;
}

.table-actions {
    display: flex;
    gap: 8px;
}

.table-container {
    flex-grow: 1;
    overflow: auto;
    max-height: calc(100vh - 350px);
}

.address-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.address-table th {
    position: sticky;
    top: 0;
    background: rgba(20, 24, 34, 0.95);
    backdrop-filter: blur(5px);
    padding: 6px 10px;
    white-space: nowrap;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
}

.address-table td {
    padding: 4px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    vertical-align: middle;
}

.address-table tbody tr {
    transition: var(--transition);
}

.address-table tbody tr:hover {
    background: rgba(255,255,255,0.02);
}

.address-table th.center, .address-table td.center { text-align: center; }
.address-table th.right, .address-table td.right { text-align: right; }

/* Fixed Width Columns based on character counts */
.col-no { width: 40px; }
.col-enabled { width: 50px; }
.col-service { width: 26ch; min-width: 228px; }
.col-addr { width: 10ch; min-width: 90px; }
.col-address { width: 18ch; min-width: 160px; }
.col-type { width: 12ch; min-width: 100px; }
.col-dp { width: 6ch; min-width: 60px; }
.col-val { width: 14ch; min-width: 130px; }

.point-cell {
    color: var(--text-muted);
}

.addr-cell {
    color: var(--accent-primary);
    font-weight: 500;
}

/* Inputs inside table */
.address-input {
    width: 100%;
    background: transparent !important;
    border: 1px solid transparent;
    color: #fff;
    padding: 3px 6px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    transition: var(--transition);
    color-scheme: dark;
}

.address-input:hover {
    border-color: rgba(255,255,255,0.1);
}

.address-input:focus {
    outline: none;
    background: rgba(0,0,0,0.2);
    border-color: var(--accent-primary);
}

.type-select, .dp-select {
    background: transparent !important;
    border: 1px solid transparent;
    color: #cbd5e1;
    padding: 3px 6px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    cursor: pointer;
    text-align: center;
    color-scheme: dark;
}

.type-select {
    width: 100px;
}

.dp-select {
    width: 60px;
}


.address-input:disabled, .type-select:disabled, .dp-select:disabled {
    background: transparent;
    color: rgba(255, 255, 255, 0.4);
    opacity: 1; /* override iOS styling */
    -webkit-text-fill-color: rgba(255, 255, 255, 0.4);
    cursor: not-allowed;
}


.type-select:hover, .dp-select:hover {
    border-color: rgba(255,255,255,0.1);
}

.type-select option, .dp-select option {
    background: var(--bg-dark);
    text-align: left;
}

/* Value animation */
.val-cell {
    font-weight: 600;
    color: #fff;
    font-variant-numeric: tabular-nums;
    transition: color 0.1s;
}

.val-cell.updating {
    color: var(--accent-primary);
    text-shadow: 0 0 10px var(--accent-glow);
}

/* Modal Styling */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.7; box-shadow: 0 0 0 0 rgba(255, 171, 0, 0.4); }
    70% { transform: scale(1); opacity: 1; box-shadow: 0 0 0 10px rgba(255, 171, 0, 0); }
    100% { transform: scale(0.95); opacity: 0.7; box-shadow: 0 0 0 0 rgba(255, 171, 0, 0); }
}

.pulse {
    animation: pulse 1.5s infinite;
}

.node-status.connecting, .status-dot.connecting {
    background: #ffab00 !important;
}

.node-status.error, .status-dot.error {
    background: var(--status-error) !important;
    box-shadow: 0 0 10px var(--status-error);
}

.node-status.validated, .status-dot.validated {
    background: #ffea00 !important;
}

.modal-content {
    width: 480px;
    max-width: 90%;
    animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    background: rgba(20, 24, 34, 0.95);
    border: 1px solid var(--border-highlight);
}

@keyframes modalPop {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background: rgba(0,0,0,0.2);
}

.sidebar-footer {
    cursor: pointer; 
    padding: 12px 20px; 
    border-top: 1px solid var(--border-color); 
    display: flex; 
    align-items: center; 
    gap: 10px; 
    transition: var(--transition);
}

.sidebar-footer:hover {
    background: rgba(255, 255, 255, 0.05);
}

.sidebar-footer:hover span, .sidebar-footer:hover svg {
    color: #fff !important;
}

/* View Mode Restrictions */
.view-mode #btn-save-sys,
.view-mode #btn-save-node,
.view-mode #btn-add-node,
.view-mode .btn-edit-node-name,
.view-mode .btn-del-node {
}

