:root {
    --bg: #f3f6f8;
    --bg-accent: #e8eef2;
    --surface: #ffffff;
    --ink: #15202b;
    --muted: #5b6b7a;
    --line: #d7e0e7;
    --primary: #0f6e6e;
    --primary-dark: #0b5555;
    --danger: #b42318;
    --success: #067647;
    --warn: #b54708;
    --sidebar: #10243a;
    --sidebar-ink: #d7e4f0;
    --radius: 14px;
    --shadow: 0 10px 30px rgba(16, 36, 58, 0.08);
    --font: "DM Sans", sans-serif;
    --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    color: var(--ink);
    background:
        radial-gradient(circle at top right, rgba(15, 110, 110, 0.08), transparent 28%),
        linear-gradient(180deg, #f7fafb 0%, var(--bg) 40%, #eef3f6 100%);
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }

.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
    background: linear-gradient(180deg, #0d2135 0%, var(--sidebar) 100%);
    color: var(--sidebar-ink);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand { display: flex; gap: .9rem; align-items: center; }
.brand strong { display: block; color: #fff; font-size: 1.05rem; }
.brand span { font-size: .78rem; opacity: .7; }
.brand-mark {
    width: 42px; height: 42px; border-radius: 12px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #149494, #0f6e6e);
    color: #fff; box-shadow: 0 8px 20px rgba(15,110,110,.35);
}
.brand-mark.large { width: 56px; height: 56px; font-size: 1.3rem; margin: 0 auto 1rem; }
.brand-logo { width: 42px; height: 42px; object-fit: contain; border-radius: 10px; background: #fff; flex-shrink: 0; }
.brand-logo.large { width: 72px; height: 72px; display: block; margin: 0 auto 1rem; }
.logo-preview { display: block; max-width: 120px; height: auto; margin-bottom: .6rem; background: #0f2744; border-radius: 10px; padding: .4rem; }

.nav { display: flex; flex-direction: column; gap: .2rem; flex: 1; overflow-y: auto; }
.nav-group { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .65rem; }
.nav-group-label {
    display: block;
    padding: .45rem .9rem .2rem;
    font-size: .68rem;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: rgba(215, 228, 240, .45);
    font-weight: 600;
}
.nav a {
    display: flex; align-items: center; gap: .75rem;
    padding: .7rem .9rem; border-radius: 10px; color: var(--sidebar-ink); opacity: .85;
}
.nav a:hover, .nav a.active { background: rgba(255,255,255,.08); color: #fff; opacity: 1; }
.nav a.active { box-shadow: inset 3px 0 0 #2ec4b6; }

.sidebar-footer { display: flex; flex-direction: column; gap: .75rem; border-top: 1px solid rgba(255,255,255,.08); padding-top: 1rem; }
.admin-chip { display: flex; align-items: center; gap: .6rem; font-size: .9rem; }

.main { min-width: 0; }
.topbar {
    display: flex; align-items: center; gap: 1rem;
    padding: 1rem 1.5rem; border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,.72); backdrop-filter: blur(10px);
    position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; font-size: 1.25rem; flex: 1; }
.topbar-meta { color: var(--muted); font-family: var(--mono); font-size: .82rem; }
.content { padding: 1.5rem; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    display: flex; gap: .9rem; align-items: center;
    box-shadow: var(--shadow);
}
.stat-card span { display: block; color: var(--muted); font-size: .82rem; }
.stat-card strong { font-size: 1.55rem; }
.rb-filter-hint { font-size: .78rem; font-weight: 500; text-transform: none; letter-spacing: 0; }
#rbCards .rb-filter {
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: border-color .15s ease, box-shadow .15s ease;
}
#rbCards .rb-filter:hover { border-color: var(--primary); }
#rbCards .rb-filter:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
#rbCards .rb-filter.is-selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 110, 110, .18);
}
.stat-icon {
    width: 42px; height: 42px; border-radius: 12px;
    display: grid; place-items: center; color: #fff;
}
.stat-icon.teal { background: #0f6e6e; }
.stat-icon.green { background: #067647; }
.stat-icon.blue { background: #175cd3; }
.stat-icon.red { background: #b42318; }
.stat-icon.muted { background: #667085; }

/* ===== Dashboard operacional ===== */
.dash { display: flex; flex-direction: column; gap: 1.15rem; }
.dash-header {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 1rem; flex-wrap: wrap;
}
.dash-kicker {
    margin: 0 0 .2rem;
    color: var(--muted);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 600;
}
.dash-title { margin: 0; font-size: 1.35rem; font-weight: 700; }
.dash-header-meta {
    display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
}
.sys-pill {
    display: inline-flex; align-items: center; gap: .45rem;
    padding: .35rem .7rem; border-radius: 999px;
    font-size: .82rem; font-weight: 600;
    border: 1px solid var(--line); background: #fff;
}
.sys-pill i { font-size: .45rem; }
.sys-pill.ok { background: #ecfdf3; color: #067647; border-color: #abefc6; }
.sys-pill.warn { background: #fffaeb; color: #b54708; border-color: #fedf89; }
.dash-updated { font-size: .82rem; font-family: var(--mono); }

.dash-error {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .9rem 1rem; border-radius: 12px;
    background: #fef3f2; border: 1px solid #fecdca; color: #b42318;
}
.dash-error[hidden] { display: none; }
.dash-error p { margin: .2rem 0 0; }

.ops-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}
.ops-card {
    display: flex; flex-direction: column; gap: .55rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem 1.15rem;
    box-shadow: var(--shadow);
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
    cursor: pointer;
    min-height: 132px;
}
.ops-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 34px rgba(16, 36, 58, 0.12);
    border-color: #bfd0db;
}
.ops-card.has-alert { border-color: #fedf89; }
.ops-card-top {
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
}
.ops-label {
    color: var(--muted); font-size: .78rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .04em;
}
.ops-icon {
    width: 36px; height: 36px; border-radius: 10px;
    display: grid; place-items: center; color: #fff; font-size: .9rem;
}
.ops-icon.blue { background: #175cd3; }
.ops-icon.green { background: #067647; }
.ops-icon.teal { background: #0f6e6e; }
.ops-icon.warn { background: #b54708; }
.ops-icon.muted { background: #667085; }
.ops-value { font-size: 2rem; line-height: 1; font-weight: 700; }
.ops-sub { font-size: .86rem; display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.ok-text { color: var(--success); font-weight: 600; }
.danger-text { color: var(--danger); font-weight: 600; }
.sep { color: var(--muted); }

.dash-panel { margin-bottom: 0; }
.badge.warn-badge { background: #fffaeb; color: #b54708; }

.attention-list { display: flex; flex-direction: column; gap: .65rem; }
.attention-item {
    display: flex; align-items: center; gap: .85rem;
    padding: .85rem 1rem; border-radius: 12px;
    border: 1px solid var(--line); background: #fcfcfd;
    transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.attention-item:hover {
    background: #fff; border-color: #bfd0db; transform: translateY(-1px);
}
.attention-item.warn { border-left: 3px solid #f79009; }
.attention-item.danger { border-left: 3px solid #f04438; }
.attention-icon {
    width: 34px; height: 34px; border-radius: 10px;
    display: grid; place-items: center; flex-shrink: 0;
}
.attention-item.warn .attention-icon { background: #fffaeb; color: #b54708; }
.attention-item.danger .attention-icon { background: #fef3f2; color: #b42318; }
.attention-body { flex: 1; min-width: 0; }
.attention-body strong { display: block; margin-bottom: .15rem; }
.attention-body span { color: var(--muted); font-size: .86rem; }
.attention-action {
    color: var(--primary); font-size: .84rem; font-weight: 600;
    white-space: nowrap; display: inline-flex; align-items: center; gap: .35rem;
}

.rb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: .9rem;
}
.rb-card {
    display: flex; flex-direction: column; gap: .85rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 1rem;
    background: #fcfcfd;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.rb-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(16, 36, 58, 0.08);
    border-color: #bfd0db;
}
.rb-card.is-offline { border-color: #fecdca; background: #fffbfa; }
.rb-card-head {
    display: flex; align-items: center; gap: .55rem;
}
.rb-dot {
    width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
    background: #98a2b3;
}
.rb-card.is-online .rb-dot { background: #12b76a; box-shadow: 0 0 0 4px rgba(18,183,106,.15); }
.rb-card.is-offline .rb-dot { background: #f04438; box-shadow: 0 0 0 4px rgba(240,68,56,.12); }
.rb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rb-card-body {
    display: grid; grid-template-columns: 1fr 1fr; gap: .75rem;
}
.rb-card-body span { display: block; font-size: .74rem; margin-bottom: .2rem; }
.rb-card-body strong { font-size: .95rem; }
.rb-card-foot {
    display: flex; align-items: center; justify-content: space-between;
    color: var(--primary); font-size: .84rem; font-weight: 600;
    border-top: 1px solid var(--line); padding-top: .7rem;
}

.dash-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    gap: 1rem;
}
.dash-split-single { grid-template-columns: 1fr; }
.online-list { display: flex; flex-direction: column; gap: .55rem; }
.online-list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: .65rem;
}
.online-list-grid .empty-state { grid-column: 1 / -1; }
.online-item {
    display: grid;
    grid-template-columns: 10px minmax(0, 1fr) auto;
    gap: .75rem; align-items: center;
    padding: .75rem .85rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fcfcfd;
    transition: border-color .15s ease, background .15s ease;
}
.online-item:hover { border-color: #bfd0db; background: #fff; }
.online-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #12b76a; box-shadow: 0 0 0 4px rgba(18,183,106,.12);
}
.online-main strong { display: block; margin-bottom: .1rem; }
.online-main span, .online-meta span { font-size: .82rem; }
.online-meta {
    display: flex; flex-direction: column; align-items: flex-end; gap: .1rem;
    text-align: right;
}
.device-count {
    min-width: 3.25rem;
    padding: .35rem .55rem;
    border-radius: 10px;
    text-align: center;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.device-count strong {
    display: inline;
    font-size: 1.15rem;
    font-weight: 700;
}
.device-count span {
    font-size: .85rem;
    font-weight: 600;
    opacity: .9;
}
.device-count.ok {
    background: #ecfdf3;
    color: #067647;
    border: 1px solid #abefc6;
}
.device-count.danger {
    background: #fef3f2;
    color: #b42318;
    border: 1px solid #fda29b;
}
.device-count.muted-count {
    background: #f2f4f7;
    color: #475467;
    border: 1px solid var(--line);
}

.dash-table th, .dash-table td { white-space: nowrap; }
.empty-state {
    text-align: center; color: var(--muted);
    padding: 1.6rem 1rem; border: 1px dashed var(--line);
    border-radius: 12px; background: #fafbfc;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem 1.25rem 1.25rem;
    margin-bottom: 1.25rem;
}
.panel.narrow { max-width: 640px; }
.panel-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; margin-bottom: 1rem;
}
.panel-head h2 { margin: 0; font-size: 1.1rem; }

.table-wrap { overflow-x: auto; }
.table-fit { overflow-x: visible; }
.table-fit .data-table th,
.table-fit .data-table td { padding: .6rem .35rem; font-size: .84rem; }
.table-fit .data-table th { letter-spacing: .02em; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
    text-align: left; padding: .75rem .6rem;
    border-bottom: 1px solid var(--line); vertical-align: middle;
    font-size: .92rem;
}
.data-table th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.data-table tr.empty td { text-align: center; color: var(--muted); padding: 2rem; }
.mono { font-family: var(--mono); font-size: .85rem; }
.muted { color: var(--muted); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    border: 1px solid transparent; border-radius: 10px;
    padding: .65rem 1rem; cursor: pointer; background: var(--bg-accent); color: var(--ink);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e8eef2; }
.btn-danger { background: #fef3f2; color: var(--danger); border-color: #fecdca; }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn-sm { padding: .4rem .6rem; font-size: .85rem; }
.btn-icon { width: 40px; height: 40px; padding: 0; }
.btn-block { width: 100%; }
.inline { display: inline; }
.actions { display: flex; gap: .25rem; align-items: center; flex-wrap: wrap; }

.panel .info { color: var(--muted); margin: 0 0 1rem; }
.page-tabs { display: flex; gap: .4rem; margin-bottom: .8rem; }
.page-tabs a {
    display: inline-flex; align-items: center;
    border: 1px solid var(--line); border-radius: 10px;
    padding: .45rem .85rem; background: #fff; color: inherit; text-decoration: none;
}
.page-tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.filters {
    display: flex; flex-wrap: wrap; gap: .6rem;
    margin-bottom: 1rem;
}
.data-table select,
.filters input, .filters select,
.form-grid input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.form-grid select, .form-grid textarea {
    border: 1px solid var(--line); border-radius: 10px;
    padding: .65rem .8rem; background: #fff; min-width: 140px;
}
.form-grid input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.form-grid select { width: 100%; box-sizing: border-box; }
.form-grid { display: grid; gap: 1rem; }
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid > label > span,
.fieldset legend { display: block; margin-bottom: .4rem; color: var(--muted); font-size: .88rem; }
.form-actions-full { grid-column: 1 / -1; }
.script-box {
    width: 100%;
    font-family: var(--mono);
    font-size: .82rem;
    line-height: 1.45;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 1rem;
    background: #0f172a;
    color: #e2e8f0;
    resize: vertical;
    min-height: 320px;
}
@media (max-width: 800px) {
    .form-grid-2 { grid-template-columns: 1fr; }
}
.checkbox, .radio {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: .55rem;
    width: auto;
    max-width: 100%;
    cursor: pointer;
}
.checkbox input[type="checkbox"],
.radio input[type="radio"] {
    width: 1.05rem;
    height: 1.05rem;
    min-width: 1.05rem;
    margin: 0;
    padding: 0;
    flex: 0 0 auto;
    accent-color: var(--brand, #0f766e);
    border: none;
    border-radius: 3px;
}
.checkbox > span,
.radio > span {
    display: inline;
    margin: 0;
    color: inherit;
    font-size: .95rem;
    line-height: 1.35;
}
.form-grid .checkbox,
.form-grid .radio,
.fieldset .checkbox,
.fieldset .radio {
    width: fit-content;
}
.fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 1rem; }
.form-actions { display: flex; gap: .75rem; }

.status {
    display: inline-flex; align-items: center; padding: .2rem .55rem;
    border-radius: 999px; font-size: .75rem; font-weight: 600;
    background: #f2f4f7; color: #344054;
}
.status.online, .status.ONLINE { background: #ecfdf3; color: #067647; }
.status.offline, .status.OFFLINE, .status.ENCERRADA { background: #f2f4f7; color: #475467; }
.status.EXPIRADA, .status.expirada, .status.warn { background: #fffaeb; color: #b54708; }
.status.danger { background: #fef3f2; color: #b42318; }
.row-alert { background: #fef3f2 !important; }
.online-item.has-alert { border-color: #fda29b; background: #fef3f2; }

.badge {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .25rem .55rem; border-radius: 999px;
    background: #eef4ff; color: #3538cd; font-size: .75rem; font-weight: 600;
}
.badge.live { background: #ecfdf3; color: #067647; }
.badge.live i { font-size: .45rem; animation: pulse 1.4s infinite; }

.alert {
    border-radius: 12px; padding: .85rem 1rem; margin-bottom: 1rem;
    display: flex; gap: .6rem; align-items: center;
}
.alert-success { background: #ecfdf3; color: #067647; border: 1px solid #abefc6; }
.alert-error { background: #fef3f2; color: #b42318; border: 1px solid #fecdca; }

.auth-body {
    min-height: 100vh;
    display: grid; place-items: center;
    background:
        linear-gradient(135deg, rgba(15,110,110,.12), transparent 40%),
        linear-gradient(180deg, #0d2135, #16324d 55%, #1d4563);
}
.auth-wrap { width: min(420px, calc(100% - 2rem)); }
.auth-panel {
    background: rgba(255,255,255,.96);
    border-radius: 20px; padding: 2rem;
    box-shadow: 0 30px 80px rgba(0,0,0,.28);
}
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.auth-brand h1 { margin: 0 0 .35rem; font-size: 1.45rem; }
.auth-brand p { margin: 0; color: var(--muted); font-size: .92rem; }
.auth-form { display: grid; gap: 1rem; }
.auth-form label span { display: block; margin-bottom: .4rem; color: var(--muted); }
.auth-form input {
    width: 100%; border: 1px solid var(--line); border-radius: 10px;
    padding: .75rem .9rem;
}

.modal[hidden] { display: none; }
.modal {
    position: fixed; inset: 0; z-index: 40;
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
}
.modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(16, 36, 58, .45);
}
.modal-card {
    position: relative; z-index: 1;
    width: min(440px, 100%);
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem 1.2rem 1.2rem;
}
.modal-checks { display: grid; gap: .45rem; max-height: 240px; overflow: auto; }
body.modal-open { overflow: hidden; }

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

@media (max-width: 1200px) {
    .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .ops-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dash-split { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; inset: 0 auto 0 0; width: 260px;
        transform: translateX(-105%); transition: transform .2s ease; z-index: 20;
    }
    .sidebar.open { transform: translateX(0); }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .stats-grid { grid-template-columns: 1fr; }
    .ops-grid { grid-template-columns: 1fr; }
    .content { padding: 1rem; }
    .panel-head { flex-direction: column; align-items: flex-start; }
    .rb-card-body { grid-template-columns: 1fr; }
    .online-item {
        grid-template-columns: 10px minmax(0, 1fr);
    }
    .online-meta {
        grid-column: 2;
        align-items: flex-start;
        text-align: left;
    }
    .attention-item { flex-wrap: wrap; }
    .attention-action { width: 100%; justify-content: flex-end; }
}
