/* Password fields using type=text to prevent browser autofill detection */
.password-field {
    -webkit-text-security: disc;
    text-security: disc;
}

:root {
    --primary: #5865f2;
    --primary-hover: #4752c4;
    --primary-glow: rgba(88, 101, 242, 0.4);
    --bg-dark: #1e1f22;
    --card-bg: rgba(43, 45, 49, 0.8);
    --sidebar-bg: rgba(30, 31, 34, 0.95);
    --text-main: #f2f3f5;
    --text-dim: #949ba4;
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-border-bright: rgba(255, 255, 255, 0.15);
    --success: #23a55a;
    --danger: #f23f42;
    --input-bg: rgba(30, 31, 34, 0.6);
    --panel-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

[data-theme="light"] {
    --primary: #5865f2;
    --primary-hover: #4752c4;
    --primary-glow: rgba(88, 101, 242, 0.2);
    --bg-dark: #f2f3f5;
    --card-bg: rgba(255, 255, 255, 0.9);
    --sidebar-bg: rgba(227, 229, 232, 0.95);
    --text-main: #2e3338;
    --text-dim: #5c6068;
    --glass-border: rgba(0, 0, 0, 0.08);
    --glass-border-bright: rgba(0, 0, 0, 0.15);
    --success: #1e8a49;
    --danger: #da373c;
    --input-bg: rgba(255, 255, 255, 0.8);
    --panel-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
}

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

html { overflow-x: hidden; }

body {
    font-family: 'Outfit', 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

body::before {
    content: ''; position: fixed; inset: 0;
    background: 
        radial-gradient(circle at 0% 0%, rgba(88, 101, 242, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 100% 100%, rgba(35, 165, 90, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 50% 50%, rgba(88, 101, 242, 0.05) 0%, transparent 60%);
    opacity: 1; z-index: -1;
    filter: blur(80px);
}

.hidden { display: none !important; }

/* ─── Overlays (Login, 2FA enforcement) ──────────────────────────────────── */
.overlay {
    position: fixed; inset: 0; z-index: 900;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-dark); overflow-y: auto; padding: 20px;
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */

header {
    display: flex; flex-direction: column; gap: 12px;
    padding: 12px 40px; border-bottom: 1px solid var(--glass-border);
    background: var(--sidebar-bg); backdrop-filter: blur(20px);
    position: sticky; top: 0; z-index: 100;
}

header > :first-child {
    display: flex; justify-content: space-between; align-items: center;
}

.logo { display: flex; align-items: center; gap: 15px; }
.header-logo { height: 42px; width: auto; filter: drop-shadow(0 0 8px rgba(255,255,255,0.1)); }
.login-logo { height: 80px; width: auto; margin-bottom: 24px; filter: drop-shadow(0 0 15px rgba(255,255,255,0.2)); }
.user-info { display: flex; align-items: center; gap: 12px; }

.search-container {
    max-width: 500px; position: relative; width: 100%;
    display: flex; justify-content: center;
}
#global-search, #structure-search {
    width: 100%; background: var(--input-bg); border: 1px solid var(--glass-border);
    padding: 10px 18px; border-radius: 10px; color: var(--text-main); outline: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
}
#global-search:focus, #structure-search:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 20px var(--primary-glow);
}

.main-nav { display: flex; gap: 6px; background: rgba(0,0,0,0.2); padding: 4px; border-radius: 12px; justify-content: center; }
.nav-item {
    background: transparent; color: var(--text-dim); border: none;
    padding: 8px 18px; cursor: pointer; border-radius: 8px;
    font-weight: 500; transition: all 0.2s ease;
    font-size: 0.9rem;
}
.nav-item.active { background: var(--primary); color: white; box-shadow: 0 4px 12px var(--primary-glow); }
.nav-item:hover:not(.active) { background: rgba(255,255,255,0.05); color: white; }

main { padding: 40px; max-width: 1600px; margin: 0 auto; min-height: calc(100vh - 70px); }

.tab-content { display: none; animation: tabFadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1); }
.tab-content.active { display: block; }

@keyframes tabFadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    gap: 20px;
    flex-wrap: wrap;
}
.section-header .actions-left {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}
.section-header .search-container {
    max-width: 350px;
}
.welcome-section { margin-bottom: 30px; }

/* ─── Components ─────────────────────────────────────────────────────────── */

.glass-card {
    background: var(--card-bg); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--glass-border); border-radius: 20px; padding: 24px;
    box-shadow: var(--panel-shadow);
    transition: border-color 0.3s ease;
}
.glass-card:hover { border-color: var(--glass-border-bright); }

/* Modals — visibility controlled by .hidden class in JS */

.input-group { margin-bottom: 20px; }
.input-group label { display: block; margin-bottom: 8px; font-weight: 600; font-size: 0.8rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }

input[type="text"], input[type="password"], input[type="number"], select.form-select, textarea {
    width: 100%; background: var(--input-bg); border: 1px solid var(--glass-border);
    padding: 12px 16px; border-radius: 12px; color: var(--text-main); outline: none;
    transition: all 0.2s ease; font-family: inherit; font-size: 0.95rem;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); background: rgba(255,255,255,0.08); box-shadow: 0 0 15px var(--primary-glow); }

.checkbox-group { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; cursor: pointer; transition: all 0.2s; padding: 8px; border-radius: 10px; }
.checkbox-group:hover { background: rgba(255,255,255,0.04); }
.checkbox-group input { width: 20px; height: 20px; accent-color: var(--primary); cursor: pointer; }
.checkbox-group label { cursor: pointer; font-size: 0.9rem; line-height: 1.4; color: var(--text-main); }

.modal-actions { display: flex; gap: 12px; margin-top: 30px; border-top: 1px solid var(--glass-border); padding-top: 24px; justify-content: flex-end; }

.btn-primary {
    background: var(--primary); color: white; border: none; padding: 10px 24px;
    border-radius: 10px; font-weight: 600; cursor: pointer; transition: all 0.3s ease;
    text-decoration: none;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 12px var(--primary-glow);
}
.btn-primary:hover { 
    background: var(--primary-hover);
    transform: translateY(-2px); 
    box-shadow: 0 6px 20px var(--primary-glow); 
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: rgba(255,255,255,0.08); color: white; border: 1px solid var(--glass-border);
    padding: 9px 18px; border-radius: 10px; cursor: pointer; transition: all 0.2s;
    text-decoration: none;
    display: flex; align-items: center; justify-content: center;
}
.btn-secondary:hover { background: rgba(255,255,255,0.14); border-color: var(--glass-border-bright); }

.btn-ghost { background: transparent; color: var(--text-dim); border: none; cursor: pointer; transition: all 0.2s; padding: 6px 12px; border-radius: 6px; }
.btn-ghost:hover { color: white; background: rgba(255,255,255,0.05); }
.btn-ghost.danger:hover { color: white; background: var(--danger); }

/* ─── Devices Grid ───────────────────────────────────────────────────────── */

.device-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 28px; margin-top: 30px;
}

.device-card { 
    position: relative; 
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
    cursor: default; 
    display: flex;
    flex-direction: column;
}
.device-card:hover { 
    border-color: var(--primary); 
    transform: translateY(-5px) scale(1.02); 
    box-shadow: 0 12px 40px rgba(0,0,0,0.4), 0 0 20px var(--primary-glow);
}

.device-status {
    position: absolute; top: 24px; right: 24px; width: 12px; height: 12px;
    border-radius: 50%; background: #333;
    border: 2px solid var(--card-bg);
}
.device-status.online {
    background: var(--success);
    box-shadow: 0 0 12px var(--success);
    animation: status-pulse 2s infinite;
}
/* Estado desconhecido: o hbbs não respondeu (reachable_known === false). Cinza neutro,
   nunca vermelho — não afirmamos offline sem dado. */
.device-status.unknown { background: #9aa0a6; }

@keyframes status-pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

.device-icon { 
    font-size: 2.5rem; 
    margin-bottom: 20px; 
    display: block; 
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}
.device-info h3 { 
    font-size: 1.25rem; 
    margin-bottom: 8px; 
    font-weight: 700;
    color: white;
}

.id-badge {
    font-family: 'JetBrains Mono', monospace; 
    color: var(--primary); 
    cursor: pointer; 
    font-size: 0.9rem;
    transition: color 0.2s;
    background: rgba(88,101,242,0.1);
    padding: 2px 8px;
    border-radius: 6px;
}
.id-badge:hover { color: white; background: var(--primary); }

.device-meta { 
    margin: 20px 0; 
    color: var(--text-dim); 
    font-size: 0.88rem; 
    display: grid; 
    gap: 8px; 
}
.device-meta .meta-row { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(255,255,255,0.03); padding-bottom: 4px; }
.device-meta b { 
    color: var(--text-main); 
    font-weight: 500; 
    font-size: 0.8rem; 
    text-transform: uppercase; 
    letter-spacing: 0.5px;
}

.device-actions { display: flex; gap: 12px; margin-top: auto; padding-top: 15px; }
.device-actions .btn-primary, 
.device-actions .btn-secondary {
    flex: 1;
    font-size: 0.95rem;
    height: 44px;
}

/* ─── Tables ─────────────────────────────────────────────────────────────── */

.table-container { 
    padding: 0; 
    overflow-x: auto; 
    margin-top: 24px; 
    border-radius: 16px; 
    border: 1px solid var(--glass-border);
}

.modern-table { width: 100%; border-collapse: collapse; text-align: left; }
.modern-table thead { background: rgba(0,0,0,0.15); }
.modern-table th { 
    padding: 18px 24px; 
    color: var(--text-dim); 
    font-size: 0.75rem; 
    font-weight: 700; 
    text-transform: uppercase;
    letter-spacing: 1.2px;
}
.modern-table td { 
    padding: 18px 24px; 
    border-bottom: 1px solid rgba(255,255,255,0.03); 
    vertical-align: middle;
}
.modern-table tr:hover { background: rgba(255,255,255,0.02); }
.modern-table td code { 
    background: rgba(0,0,0,0.4); 
    padding: 4px 10px; 
    border-radius: 6px; 
    font-family: 'JetBrains Mono', monospace; 
    font-size: 0.85rem; 
    color: var(--primary);
    border: 1px solid rgba(255,255,255,0.05);
}

/* Tree Picker inside Profiles */
.groups-tree-picker {
    max-height: 320px; overflow-y: auto;
    background: rgba(0,0,0,0.2); border: 1px solid var(--glass-border);
    border-radius: 12px; padding: 6px; margin-top: 8px;
}
.groups-tree-picker::-webkit-scrollbar { width: 4px; }
.groups-tree-picker::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

.tp-row { display: flex; align-items: center; gap: 2px; }

.tp-toggle {
    background: none; border: none; color: rgba(255,255,255,0.2); cursor: pointer;
    font-size: 0.5rem; width: 18px; height: 18px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 4px; transition: color 0.15s;
}
.tp-toggle:hover { color: rgba(255,255,255,0.6); }

.tp-children {
    border-left: 1px solid rgba(255,255,255,0.08);
    margin-left: 12px; padding-left: 4px;
}

.tree-picker-row {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    cursor: pointer; flex: 1; padding: 5px 8px;
    border-radius: 7px; transition: background 0.12s;
    font-size: 0.84rem; font-weight: 400; color: var(--text-dim);
    min-height: 30px;
}
.tree-picker-row:hover { background: rgba(255,255,255,0.05); color: var(--text-main); }
.tree-picker-row.tree-picker-parent-row { font-weight: 600; color: var(--text-main); }
.tree-picker-row.tree-picker-blocked {
    background: rgba(242,63,66,0.1);
    border-radius: 7px;
}
.tree-picker-row.tree-picker-blocked .tp-name { color: rgba(242,63,66,0.85); }

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

/* ─── Custom checkbox ────────────────────────────────────────────────────── */
.tp-check-wrap { position: relative; width: 20px; height: 20px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.tree-picker-cb { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.tp-check-icon {
    width: 17px; height: 17px;
    border: 1.5px solid rgba(255,255,255,0.15); border-radius: 5px;
    background: transparent; transition: all 0.15s;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.55rem; font-weight: 900; color: transparent;
}
.tree-picker-row:hover .tp-check-icon { border-color: rgba(255,255,255,0.35); }
.tp-check-icon.tp-check-active {
    background: var(--danger); border-color: var(--danger); color: white;
}
.tp-check-icon.tp-check-active::before { content: '✕'; }

/* ─── Modals ─────────────────────────────────────────────────────────────── */

.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.7);
    display: flex; align-items: center; justify-content: center; z-index: 3000;
    backdrop-filter: blur(8px);
    transition: all 0.3s ease;
    animation: fadeIn 0.2s ease;
    padding: 20px;
}
.modal-content {
    width: 95%; max-width: 600px; max-height: 90vh; overflow-y: auto;
    padding: 32px; border-radius: 24px;
    background: var(--card-bg);
    animation: modalSlideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid var(--glass-border-bright);
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
.modal-content::-webkit-scrollbar { width: 6px; }
.modal-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
.company-member-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 240px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.12) transparent;
}
.company-member-list::-webkit-scrollbar { width: 3px; }
.company-member-list::-webkit-scrollbar-track { background: transparent; }
.company-member-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 10px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalSlideUp { from { opacity: 0; transform: translateY(30px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }

.modal-content h3 { margin-bottom: 25px; font-size: 1.5rem; color: white; }

.input-group { margin-bottom: 20px; }
.input-group label { display: block; margin-bottom: 8px; color: var(--text-dim); font-size: 0.85rem; font-weight: 500; }
.input-group input {
    width: 100%; background: var(--input-bg); border: 1px solid var(--glass-border);
    padding: 12px 16px; border-radius: 10px; color: var(--text-main); outline: none;
    transition: all 0.2s; font-size: 0.95rem;
}
.input-group input:focus { border-color: var(--primary); background: rgba(255,255,255,0.05); }

#edit-id-static {
    padding: 14px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--primary);
    font-weight: 600;
    font-size: 1.1rem;
    text-align: center;
    letter-spacing: 1px;
}

.checkbox-group { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; cursor: pointer; user-select: none; }
.checkbox-group input { cursor: pointer; width: 18px; height: 18px; accent-color: var(--primary); }

.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 30px; }

/* ─── Custom Dropdown (Premium Select) ───────────────────────────────────── */

.custom-select {
    position: relative;
    width: 100%;
    cursor: pointer;
}
.cs-trigger {
    background: var(--input-bg);
    border: 1px solid var(--glass-border);
    padding: 10px 18px;
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
    font-size: 0.9rem;
}
.custom-select:hover .cs-trigger { border-color: var(--glass-border-bright); background: rgba(255,255,255,0.05); }
.custom-select.active .cs-trigger { border-color: var(--primary); box-shadow: 0 0 15px var(--primary-glow); }

.cs-options {
    position: absolute; top: calc(100% + 8px); left: 0; right: 0;
    background: var(--sidebar-bg);
    backdrop-filter: blur(25px);
    border: 1px solid var(--glass-border-bright);
    border-radius: 12px;
    overflow: hidden;
    z-index: 1000;
    box-shadow: var(--panel-shadow);
    display: none;
    animation: dropdownOpen 0.2s ease;
}
@keyframes dropdownOpen { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.custom-select.active .cs-options { display: block; }

.cs-option {
    padding: 10px 18px;
    font-size: 0.9rem;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 10px;
}
.cs-option:hover { background: rgba(255,255,255,0.08); color: white; }
.cs-option.selected { background: var(--primary); color: white; }

/* ─── Tree View (Legacy) ─────────────────────────────────────────────────────────── */

.tree-container { padding: 24px; min-height: 500px; }
.tree-node { margin-left: 20px; border-left: 1px solid rgba(255, 255, 255, 0.05); padding-left: 10px; }
.tree-children { display: none; }
.tree-node.expanded > .tree-children { display: block; animation: slideDown 0.2s ease-out; }

@keyframes slideDown { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

.tree-item {
    display: flex; align-items: center; padding: 8px 12px; border-radius: 10px;
    cursor: pointer; transition: all 0.2s; user-select: none; margin-bottom: 4px;
}
.tree-item:hover { background: rgba(255, 255, 255, 0.06); }
.tree-item.folder { color: #4ade80; font-weight: 600; font-size: 0.95rem; }
.tree-item.folder.level-0 { color: #818cf8; font-size: 1.1rem; border-bottom: 1px solid rgba(255,255,255,0.03); margin-top: 10px; padding: 12px; }

.tree-toggle { width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; transition: transform 0.2s; color: var(--text-dim); }
.tree-node.expanded > .tree-item .tree-toggle { transform: rotate(90deg); }

.tree-actions { display: none; gap: 6px; margin-left: auto; }
.tree-item:hover .tree-actions { display: flex; }

.btn-tree {
    background: rgba(255,255,255,0.1); border: none; color: white; padding: 4px 10px;
    border-radius: 6px; font-size: 0.75rem; cursor: pointer; transition: all 0.2s;
}
.btn-tree:hover { background: var(--primary); }

/* ─── Miller Columns ───────────────────────────────────────────────────────────── */

.miller-container {
    min-height: 600px;
    padding: 0;
    overflow: hidden;
}

.miller-columns-container {
    display: flex;
    height: 600px;
    background: rgba(0,0,0,0.1);
}

.miller-column {
    flex: 0 0 0;
    width: 0;
    min-width: 0;
    max-width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: rgba(15, 23, 42, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.miller-column.column-active {
    flex: 1;
    width: auto;
    min-width: 280px;
    max-width: 400px;
    overflow: visible;
    border-right: 1px solid rgba(255,255,255,0.1);
    opacity: 1;
    pointer-events: auto;
}

.miller-column.column-active:last-child {
    border-right: none;
}

.miller-column-notes.column-active {
    min-width: 320px;
    max-width: 380px;
}

.column-header {
    padding: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.column-header h3 {
    margin: 0;
    font-size: 1.1em;
    flex: 1;
}

.btn-back {
    padding: 6px 12px;
    background: rgba(255,255,255,0.1);
    color: #60a5fa;
    border: 1px solid rgba(96, 165, 250, 0.3);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s;
}

.btn-back:hover {
    background: rgba(96, 165, 250, 0.2);
    border-color: #60a5fa;
}

.column-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 8px 0;
}

.column-list::-webkit-scrollbar {
    width: 6px;
}

.column-list::-webkit-scrollbar-track {
    background: transparent;
}

.column-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}

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

.miller-item {
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
}

.miller-item:hover {
    background: rgba(255,255,255,0.08);
    border-left-color: #60a5fa;
}

.miller-item.selected {
    background: rgba(96, 165, 250, 0.15);
    border-left-color: #60a5fa;
}

.miller-item-icon {
    font-size: 1.2em;
    flex-shrink: 0;
}

.miller-item-content {
    flex: 1;
    min-width: 0;
}

.miller-item-title {
    font-weight: 500;
    color: #e2e8f0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.miller-item-subtitle {
    font-size: 0.8em;
    color: rgba(226, 232, 240, 0.6);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.miller-item-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.2s;
}

.miller-item:hover .miller-item-actions {
    opacity: 1;
}

.miller-item-actions .btn-tree {
    padding: 4px 8px;
    font-size: 0.85em;
}

.column-footer {
    padding: 8px 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 0.85em;
    color: rgba(226, 232, 240, 0.6);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.btn-miller-add {
    padding: 4px 10px;
    font-size: 0.78rem;
    background: rgba(88, 166, 255, 0.12);
    color: #60a5fa;
    border: 1px solid rgba(96, 165, 250, 0.3);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-miller-add:hover {
    background: rgba(96, 165, 250, 0.25);
    border-color: #60a5fa;
}

.miller-empty {
    padding: 24px 16px;
    text-align: center;
    color: rgba(226, 232, 240, 0.5);
    font-style: italic;
}

/* ── Notes Panel (Column 4) ─────────────────────────────── */
.miller-column-notes {
    min-width: 320px;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    background: rgba(15, 20, 35, 0.6);
    border-left: 1px solid rgba(96, 165, 250, 0.25);
}

.notes-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.note-item {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    padding: 10px 12px;
}

.note-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.note-author {
    font-weight: 600;
    font-size: 0.8rem;
    color: #60a5fa;
    flex-shrink: 0;
}

.note-date {
    font-size: 0.72rem;
    color: var(--text-dim);
    flex: 1;
}

.btn-note-delete {
    background: none;
    border: none;
    color: rgba(255,100,100,0.5);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 4px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color 0.2s;
}
.btn-note-delete:hover { color: #f87171; }

.note-body {
    font-size: 0.88rem;
    color: var(--text-main);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.notes-input-area {
    padding: 10px 12px 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.notes-input-area textarea {
    width: 100%;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.88rem;
    padding: 8px 10px;
    resize: none;
    box-sizing: border-box;
    transition: border-color 0.2s;
}
.notes-input-area textarea:focus {
    outline: none;
    border-color: rgba(96,165,250,0.5);
}

.notes-send-btn {
    align-self: flex-end;
    padding: 6px 18px;
    font-size: 0.85rem;
}

.peer-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #666;
    flex-shrink: 0;
    display: inline-block;
}
.peer-status-dot.online {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}
/* Estado desconhecido (hbbs não respondeu): cinza neutro, nunca vermelho. */
.peer-status-dot.unknown { background: #9aa0a6; }

/* Responsive */
@media (max-width: 1024px) {
    .miller-column {
        max-width: none;
        min-width: 200px;
    }

    .miller-columns-container {
        height: 500px;
    }

    .miller-container {
        min-height: 500px;
    }
}

@media (max-width: 768px) {
    /* ── Layout base: padding lateral apertado pra caber em iPhone ──────── */
    header {
        padding: 10px 12px;
    }
    header > :first-child {
        flex-wrap: wrap;
        gap: 8px;
    }
    .logo { gap: 8px; }
    .logo h1 { font-size: 1.1rem; }
    .header-logo { height: 32px; }
    .user-info {
        flex-wrap: wrap;
        gap: 6px;
        font-size: 0.85rem;
    }
    .user-info .btn-ghost { padding: 4px 8px; font-size: 0.8rem; }

    /* Abas em fila com scroll horizontal próprio em vez de empurrar layout */
    .main-nav {
        overflow-x: auto;
        flex-wrap: nowrap;
        justify-content: flex-start;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .main-nav::-webkit-scrollbar { display: none; }
    .nav-item { flex-shrink: 0; padding: 8px 14px; font-size: 0.85rem; }

    main { padding: 16px; }

    .section-header { gap: 12px; margin-bottom: 18px; }
    .welcome-section { margin-bottom: 18px; }
    .welcome-section h2 { font-size: 1.2rem; }
    .welcome-section p { font-size: 0.85rem; }

    .glass-card { padding: 14px; border-radius: 14px; }

    .miller-columns-container {
        flex-direction: column;
        height: auto;
    }

    /* Especificidade casada com .miller-column.column-active pra vencer o cascade
       desktop (flex:1 + height:auto), que no Safari iOS colapsa para height:0
       quando o pai flex-column não tem altura explícita. */
    .miller-column,
    .miller-column.column-active {
        flex: none;
        border-right: none;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }

    .miller-column:not(.column-active) {
        height: 0;
        min-height: 0;
        max-height: 0;
    }

    /* O Safari iOS não trata min-height/height:auto de um flex-column como altura
       "definida", então o filho .column-list (flex:1) colapsava pra 0 e a lista
       sumia inteira — só o footer (flex-shrink:0) com a contagem "33 redes"
       continuava aparecendo. No mobile a coluna vira block e a própria lista
       controla o scroll via max-height, sem depender da resolução de altura do
       flexbox que quebra no iOS. */
    .miller-column.column-active,
    .miller-column-notes.column-active {
        display: block;
        width: 100%;
        min-width: 0;
        max-width: 100%;
        height: auto;
        min-height: 0;
        max-height: none;
    }

    .column-list {
        flex: none;
        height: auto;
        min-height: 0;
        max-height: 60vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .column-header {
        padding: 12px;
    }

    .column-header h3 {
        font-size: 1em;
    }

    .miller-item {
        padding: 10px 12px;
    }
}

/* Badges */
.badge-admin  { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 0.72rem; font-weight: 700; background: rgba(242,63,66,0.18); color: #f23f42; border: 1px solid rgba(242,63,66,0.3); }
.badge-manager { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 0.72rem; font-weight: 700; background: rgba(245,158,11,0.18); color: #f59e0b; border: 1px solid rgba(245,158,11,0.3); }
.badge-profile { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 0.72rem; font-weight: 600; background: rgba(99,102,241,0.15); color: #818cf8; border: 1px solid rgba(99,102,241,0.25); }
.role-badge { padding: 4px 10px; border-radius: 8px; font-size: 0.75rem; font-weight: 700; }
.role-pdv { background: rgba(59,130,246,0.15); color: #60a5fa; border: 1px solid rgba(59,130,246,0.25); }
.role-concentrador { background: rgba(245,158,11,0.15); color: #fbbf24; border: 1px solid rgba(245,158,11,0.25); }
.role-servidor { background: rgba(139,92,246,0.15); color: #a78bfa; border: 1px solid rgba(139,92,246,0.25); }

/* Old select overrides to avoid "cru" look while custom select logic is being built */
select.form-select {
    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='white' 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 12px center;
    background-size: 16px;
    padding-right: 40px !important; }

/* ─── Role Checkboxes (inline checkbox groups) ───────────────────────────── */
.role-checkboxes { display: flex; gap: 16px; flex-wrap: wrap; }
.check-item {
    display: flex; align-items: center; gap: 6px; cursor: pointer;
    font-size: 0.9rem; color: var(--text-main);
}
.check-item input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* ─── Pagination ─────────────────────────────────────────────────────────── */
.pagination-bar { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 16px; flex-wrap: wrap; }
.pg-btn {
    background: rgba(255,255,255,0.06); border: 1px solid var(--glass-border); color: var(--text-dim);
    padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 0.85rem; transition: all 0.2s;
}
.pg-btn:hover:not(:disabled) { background: rgba(255,255,255,0.12); color: white; }
.pg-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.pg-btn:disabled { opacity: 0.3; cursor: default; }
.pg-info { color: var(--text-dim); font-size: 0.8rem; margin-right: 8px; }
.pg-ellipsis { color: var(--text-dim); padding: 0 4px; }

/* ─── Compact variants ────────────────────────────────────────────────────── */
.input-group.compact { margin-bottom: 12px; }
.input-group.compact label { margin-bottom: 4px; font-size: 0.78rem; }
.input-group.compact input { padding: 9px 14px; font-size: 0.9rem; }

.section-label {
    color: var(--text-dim); font-size: 0.75rem; font-weight: 700;
    letter-spacing: 0.8px; margin-bottom: 12px;
    border-bottom: 1px solid var(--glass-border); padding-bottom: 6px;
}

.actions-left { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.actions-right { display: flex; gap: 12px; align-items: center; margin-left: auto; }
.flex-spacer { flex: 1; }

/* ─── Profile Modal Header ────────────────────────────────────────────────── */
.modal-header-row {
    display: flex; align-items: center; gap: 16px;
    margin-bottom: 28px; padding-bottom: 20px;
    border-bottom: 1px solid var(--glass-border);
}
.modal-header-row h3 { margin-bottom: 2px; }
.modal-header-icon {
    font-size: 1.4rem; width: 48px; height: 48px; flex-shrink: 0;
    background: rgba(88,101,242,0.15); border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
}
.modal-subtitle { color: var(--text-dim); font-size: 0.8rem; margin: 0; }

/* ─── Form Sections ──────────────────────────────────────────────────────── */
.form-section { margin-bottom: 22px; }
.form-section-title {
    font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.7px; color: var(--text-dim); margin-bottom: 10px;
}
.form-hint { font-size: 0.75rem; color: var(--text-dim); margin-top: 8px; }

/* ─── Toggle Cards ───────────────────────────────────────────────────────── */
.toggle-card {
    display: flex; align-items: center; gap: 14px;
    background: rgba(255,255,255,0.03); border: 1px solid var(--glass-border);
    border-radius: 12px; padding: 14px 16px; margin-bottom: 8px;
    cursor: pointer; transition: all 0.2s; user-select: none;
}
.toggle-card:hover { background: rgba(255,255,255,0.06); border-color: var(--glass-border-bright); }
.toggle-card-icon { font-size: 1.1rem; flex-shrink: 0; }
.toggle-card-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.toggle-card-title { font-size: 0.9rem; font-weight: 600; color: var(--text-main); }
.toggle-card-desc { font-size: 0.78rem; color: var(--text-dim); }
.toggle-switch-wrap { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch-wrap input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-knob {
    position: absolute; inset: 0; border-radius: 24px;
    background: rgba(255,255,255,0.1); border: 1px solid var(--glass-border);
    transition: all 0.25s;
}
.toggle-knob::before {
    content: ''; position: absolute;
    width: 18px; height: 18px; left: 2px; top: 2px;
    border-radius: 50%; background: rgba(255,255,255,0.4); transition: all 0.25s;
}
.toggle-switch-wrap input:checked ~ .toggle-knob { background: var(--primary); border-color: var(--primary); }
.toggle-switch-wrap input:checked ~ .toggle-knob::before { transform: translateX(20px); background: white; }

/* ─── Device Type Grid ───────────────────────────────────────────────────── */
.device-type-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.device-type-card {
    position: relative; display: flex; flex-direction: column;
    align-items: center; gap: 6px; padding: 16px 12px;
    background: rgba(255,255,255,0.03); border: 1px solid var(--glass-border);
    border-radius: 12px; cursor: pointer; transition: all 0.2s;
    text-align: center; user-select: none;
}
.device-type-card input { position: absolute; opacity: 0; width: 0; height: 0; }
.device-type-card:hover { background: rgba(255,255,255,0.07); border-color: var(--glass-border-bright); }
.device-type-card:has(input:checked) { background: rgba(242,63,66,0.12); border-color: rgba(242,63,66,0.4); }
.dtc-icon { font-size: 1.5rem; }
.dtc-name { font-size: 0.85rem; font-weight: 600; color: var(--text-main); }
.dtc-badge {
    font-size: 0.6rem; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase;
    padding: 2px 8px; border-radius: 20px;
    background: rgba(242,63,66,0.2); color: #f23f42;
    opacity: 0; transition: opacity 0.2s;
}
.device-type-card:has(input:checked) .dtc-badge { opacity: 1; }

/* ─── Company Chips (multi-select checkboxes) ────────────────────────────── */
.company-chips-wrap { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0; }
.company-chip {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 14px; border-radius: 20px;
    border: 1px solid var(--glass-border);
    cursor: pointer; font-size: 0.84rem;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    user-select: none;
}
.company-chip:hover { border-color: var(--accent); }
.company-chip-active {
    background: rgba(242,63,66,0.13);
    border-color: rgba(242,63,66,0.5);
    color: #f23f42;
    font-weight: 600;
}
.company-chip-cb { display: none; }

/* Aviso de conexão (reenquadra o prompt "Abrir SwitchDesk?" do navegador) */
.connect-hint {
    position: fixed;
    bottom: 24px;
    right: 24px;
    max-width: 380px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px 18px;
    background: var(--card-bg);
    border: 1px solid var(--glass-border-bright);
    border-left: 3px solid var(--primary);
    border-radius: 12px;
    box-shadow: var(--panel-shadow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text-main);
    z-index: 9999;
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}
.connect-hint.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.connect-hint-icon { font-size: 22px; line-height: 1.2; flex-shrink: 0; }
.connect-hint-body { display: flex; flex-direction: column; gap: 5px; font-size: 13px; line-height: 1.45; }
.connect-hint-body strong { color: var(--text-main); }
.connect-hint-body span { color: var(--text-dim); }
.connect-hint-fallback { margin-top: 2px; }
.connect-hint-fallback a { color: var(--primary); font-weight: 600; text-decoration: none; }
.connect-hint-fallback a:hover { text-decoration: underline; }
.connect-hint-close {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 14px;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}
.connect-hint-close:hover { color: var(--text-main); }

/* ─── Login (Controle) ──────────────────────────────────────────────────────
   Tela própria, sem logo. Usa as variáveis de tema (claro e escuro) do :root.
   O atributo hidden precisa vencer o display:flex dos campos. */
.ctl-login [hidden] { display: none !important; }
.ctl-login {
    position: fixed; inset: 0; z-index: 900;
    display: flex; align-items: center; justify-content: center;
    padding: 24px 16px; overflow-y: auto;
    background: var(--bg-dark);
}
.ctl-login-box { width: 100%; max-width: 360px; min-height: 0; margin: 0; padding: 0; }
.ctl-wordmark {
    margin: 0; font-size: 2rem; font-weight: 600; line-height: 1.1;
    letter-spacing: -0.03em; color: var(--text-main);
}
.ctl-wordmark::after {
    content: ""; display: block; width: 28px; height: 3px; margin-top: 12px;
    border-radius: 2px; background: var(--primary);
}
.ctl-login-sub { margin: 12px 0 28px; font-size: 0.9375rem; color: var(--text-dim); }
.ctl-login-error {
    margin: 0 0 16px; padding: 10px 12px; border-radius: 8px;
    font-size: 0.875rem; line-height: 1.4; color: var(--text-main);
    background: rgba(242, 63, 66, 0.12); border: 1px solid rgba(242, 63, 66, 0.45);
}
.ctl-login-form { display: flex; flex-direction: column; gap: 16px; }
.ctl-field { display: flex; flex-direction: column; gap: 6px; }
.ctl-field label { font-size: 0.875rem; font-weight: 600; color: var(--text-main); }
.ctl-field input {
    width: 100%; height: 44px; padding: 0 12px;
    font: inherit; font-size: 16px; color: var(--text-main);
    background: var(--input-bg); border: 1px solid var(--glass-border-bright); border-radius: 8px;
    outline: none; transition: border-color 100ms ease;
}
.ctl-field input:hover { border-color: var(--text-dim); }
.ctl-field input:focus-visible { border-color: var(--primary); outline: 2px solid var(--primary); outline-offset: 1px; }
#totp-code { letter-spacing: 0.3em; font-variant-numeric: tabular-nums; }
.ctl-hint { margin: 0; font-size: 0.8125rem; color: var(--text-dim); }
.ctl-password { position: relative; }
.ctl-password input { padding-right: 84px; }
.ctl-reveal {
    position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
    height: 32px; min-width: 64px; padding: 0 10px; border: 0; border-radius: 6px;
    font: inherit; font-size: 0.8125rem; font-weight: 600; line-height: 1;
    color: var(--text-dim); background: transparent; cursor: pointer;
}
.ctl-reveal:hover { color: var(--text-main); }
.ctl-submit {
    height: 44px; margin-top: 8px; border: 0; border-radius: 8px;
    font: inherit; font-size: 0.9375rem; font-weight: 600; line-height: 1;
    color: #fff; background: var(--primary); cursor: pointer;
    transition: background-color 100ms ease;
}
.ctl-submit:hover { background: var(--primary-hover); }
.ctl-submit.is-busy { opacity: 0.75; cursor: progress; }
.ctl-reveal:focus-visible, .ctl-submit:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
    .ctl-login *, .ctl-login *::before, .ctl-login *::after { transition-duration: .01ms !important; }
}
