/* cores do logo: azul #0890f8 e verde #90f840 (versoes mais escuras no tema claro para contraste) */
:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e4e8ee;
    --border-strong: #d3d9e2;
    --text: #131a24;
    --muted: #677385;
    --primary: #0874d1;
    --primary-hover: #0666b8;
    --primary-soft: rgba(8, 116, 209, .1);
    --primary-text: #ffffff;
    --brand-green: #3a9512;
    --ok: #16883a;
    --ok-soft: rgba(22, 136, 58, .1);
    --warn: #a86a00;
    --warn-soft: rgba(168, 106, 0, .12);
    --bad: #d1242f;
    --bad-soft: rgba(209, 36, 47, .1);
    --chip: #eef1f5;
    --row-hover: #f6f9fc;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
    --focus: 0 0 0 3px rgba(8, 116, 209, .22);

    /* menu lateral e login: sempre no escuro da marca */
    --side-bg: #14171b;
    --side-text: #c9d0db;
    --side-muted: #7d8696;
    --side-border: #23272e;
    --side-active: rgba(43, 155, 248, .14);
    --brand-bg: #26292e;

    --radius: 10px;
    --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1114;
        --surface: #171a1f;
        --surface-2: #1c2026;
        --border: #262b33;
        --border-strong: #323843;
        --text: #e7eaf0;
        --muted: #8c95a5;
        --primary: #2b9bf8;
        --primary-hover: #4aaafa;
        --primary-soft: rgba(43, 155, 248, .14);
        --primary-text: #ffffff;
        --brand-green: #90f840;
        --ok: #4cc764;
        --ok-soft: rgba(76, 199, 100, .14);
        --warn: #e0a83a;
        --warn-soft: rgba(224, 168, 58, .14);
        --bad: #f56565;
        --bad-soft: rgba(245, 101, 101, .14);
        --chip: #232830;
        --row-hover: #1b1f25;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3);
        --shadow-lg: 0 16px 40px rgba(0, 0, 0, .5);
        --focus: 0 0 0 3px rgba(43, 155, 248, .3);
        --side-bg: #0b0d10;
        --side-border: #1c2026;
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font: 14px/1.5 var(--font);
    font-feature-settings: "cv11", "ss01";
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- formularios ---------- */

input, select, textarea, button { font: inherit; color: inherit; }

input, select, textarea {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 8px 11px;
    min-width: 0;
    height: 38px;
    transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; width: 100%; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .6; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
input[type=checkbox] { height: 16px; width: 16px; accent-color: var(--primary); }
input:disabled, textarea:disabled { opacity: .55; }

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    border-radius: 8px;
    padding: 0 14px;
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s;
}
button:hover { background: var(--surface-2); border-color: var(--muted); }
button:focus-visible { outline: none; box-shadow: var(--focus); }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button.danger { color: var(--bad); }
button.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
button.ghost { border-color: transparent; background: transparent; height: 32px; padding: 0 10px; }
button.ghost:hover { background: var(--chip); }
button.block { width: 100%; }
button:disabled { opacity: .45; cursor: default; }

.icon-button { width: 36px; height: 36px; padding: 0; border-color: transparent; background: transparent; }

/* ---------- estrutura: menu lateral + conteudo ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    width: 248px;
    flex: none;
    display: flex;
    flex-direction: column;
    background: var(--side-bg);
    color: var(--side-text);
    border-right: 1px solid var(--side-border);
    padding: 18px 12px 12px;
    z-index: 1500;
}

.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; font-size: 16px; letter-spacing: .1px; text-decoration: none !important; }
.brand b { color: #90f840; font-weight: 700; }
.sidebar .brand { padding: 0 8px 18px; margin-bottom: 8px; border-bottom: 1px solid var(--side-border); }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.sidebar nav a {
    position: relative;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--side-text);
    font-weight: 500;
    text-decoration: none;
    transition: background .15s, color .15s;
}
.sidebar nav a .icon { color: var(--side-muted); transition: color .15s; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.sidebar nav a.active { background: var(--side-active); color: #fff; }
.sidebar nav a.active .icon { color: #4aaafa; }
.sidebar nav a.active::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: linear-gradient(#0890f8, #90f840);
}
.nav-section { margin: 18px 12px 6px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--side-muted); }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 6px 2px 8px;
    margin-top: 8px;
    border-top: 1px solid var(--side-border);
}
.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    flex: none;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #0890f8, #4fc24a);
}
.sidebar-user .who { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.sidebar-user .who strong { color: #fff; font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user .who span { color: var(--side-muted); font-size: 12px; }
.sidebar-user .icon-button { color: var(--side-muted); width: 32px; height: 32px; }
.sidebar-user .icon-button:hover { color: #fff; background: rgba(255, 255, 255, .07); }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mobilebar { display: none; }
.sidebar-backdrop { display: none; }

main { padding: 28px 32px 40px; width: 100%; max-width: 1480px; margin: 0 auto; }

/* titulo e subtitulo das paginas */
main > h2 { margin: 0 0 20px; font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
main > h2:has(+ p.muted) { margin-bottom: 4px; }
main > h2 + p.muted { margin: 0 0 20px; max-width: 760px; }
h3 { margin: 28px 0 12px; font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* ---------- blocos ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 16px;
}

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 8px; }

.stat {
    position: relative;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px;
}
.stat::after {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 2px;
    background: linear-gradient(90deg, #0890f8, #90f840);
    opacity: .7;
}
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat .value { margin-top: 6px; font-size: 26px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat .value .muted { font-size: 15px; font-weight: 500; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar input:not([type=checkbox]) { width: 260px; }

/* ---------- tabelas ---------- */

.table-wrap {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th {
    background: var(--surface-2);
    color: var(--muted);
    font-weight: 600;
    font-size: 11.5px;
    letter-spacing: .05em;
    text-transform: uppercase;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .1s; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--row-hover); }
td.wrap { white-space: normal; word-break: break-all; }
td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; }
td[colspan] { text-align: center; padding: 36px 14px; }

.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.error { color: var(--bad); }
p.error:empty { display: none; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 9px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.6;
    background: var(--chip);
    color: var(--muted);
    vertical-align: middle;
}
.badge.ok { color: var(--ok); background: var(--ok-soft); }
.badge.bad { color: var(--bad); background: var(--bad-soft); }
.badge.warn { color: var(--warn); background: var(--warn-soft); }
.badge.info { color: var(--primary); background: var(--primary-soft); }
.badge.ok::before, .badge.bad::before, .badge.warn::before, .badge.info::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); margin-right: 8px; vertical-align: middle; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 14px 0; }
.pager #count { margin-right: auto; }

#map { height: 440px; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); margin-bottom: 14px; }

.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; color: var(--text); font-size: 13px; font-weight: 500; }
.form label.check { display: flex; align-items: center; gap: 10px; font-weight: 400; font-size: 14px; }
.form .actions { display: flex; gap: 8px; padding-top: 4px; }
.form .actions .spacer { flex: 1; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chips button { height: 30px; border-radius: 99px; font-size: 12.5px; padding: 0 12px; }
.chips button.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

.device-cell { display: flex; align-items: center; }
.device-name { font-weight: 500; }
.sub { margin-top: 2px; font-size: 12px; color: var(--muted); }
.tag { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 5px; font-size: 10.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); border: 1px solid var(--border-strong); vertical-align: 1px; }

pre.hex { white-space: pre-wrap; word-break: break-all; margin: 0; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 9px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

/* ---------- painel lateral (detalhes/edicao) ---------- */

.drawer { position: fixed; inset: 0; background: rgba(8, 10, 14, .5); backdrop-filter: blur(2px); z-index: 2000; display: flex; justify-content: flex-end; animation: fade .15s ease-out; }
.drawer-panel { width: min(620px, 100%); height: 100%; overflow-y: auto; background: var(--bg); padding: 26px 26px 40px; position: relative; box-shadow: var(--shadow-lg); animation: slide .2s ease-out; }
.drawer-panel h2 { margin: 0 44px 18px 0; font-size: 19px; font-weight: 650; display: flex; align-items: center; }
.drawer-panel.wide { width: min(1080px, 100%); }
.title-id { font-size: 13px; font-weight: 400; margin-left: 10px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: -4px 0 18px; overflow-x: auto; }
.tabs button { height: 38px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: var(--muted); padding: 0 14px; }
.tabs button:hover { color: var(--text); background: transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--primary); }
.drawer-panel section > .toolbar .chips { margin-bottom: 0; }

.history-map { height: 300px; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 14px; }
table.history td { padding-top: 8px; padding-bottom: 8px; }
tr.selected { background: var(--primary-soft) !important; }
tr.detail-row > td { text-align: left; white-space: normal; background: var(--surface-2); padding: 14px 16px; }
.detail { display: grid; gap: 12px; }
.detail .kv { grid-template-columns: 170px 1fr; font-size: 13px; }
.raw pre { margin-top: 4px; padding: 10px 12px; background: var(--chip); border-radius: 8px; font-size: 12px; }

.sample pre { margin: 4px 0 12px; padding: 10px 12px; background: var(--chip); border-radius: 8px; font-size: 12px; max-height: 320px; overflow: auto; }
.sample-head { display: flex; gap: 12px; align-items: baseline; margin-bottom: 10px; flex-wrap: wrap; }
.warn-text { color: var(--warn); margin: 0 0 10px; }
.notes-list { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
td.notes { font-size: 12.5px; color: var(--warn); min-width: 260px; }

.page-tabs { margin-top: 4px; }

.fields-editor { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; background: var(--surface-2); }
.fields-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.fields-head p { margin: 2px 0 0; font-size: 12.5px; }
.field-rows { display: grid; gap: 2px; max-height: 360px; overflow-y: auto; }
.field-row { display: grid; grid-template-columns: 18px 1fr 170px; gap: 10px; align-items: center; padding: 4px 6px; border-radius: 6px; }
.field-row:hover { background: var(--chip); }
.field-row input.mono { height: 32px; font-size: 12.5px; }
.field-row.off .field-label { color: var(--muted); }
.field-row.off input.mono { opacity: .45; }
pre.preview { margin: 0; padding: 10px 12px; background: var(--chip); border-radius: 8px; font-size: 12px; max-height: 260px; overflow: auto; }

.send-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.unit-field { display: flex; align-items: center; gap: 8px; }
.unit-field input { width: 120px; }
.unit-field span { font-size: 12.5px; font-weight: 400; }
#log-stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
td.response { max-width: 360px; overflow: hidden; text-overflow: ellipsis; }

.catalog { padding: 0; overflow: hidden; }
.catalog-head { display: flex; gap: 14px; align-items: baseline; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.catalog-head strong { font-size: 15px; }
.catalog td.wrap { word-break: normal; }
.catalog-note { margin: 0; padding: 10px 16px; border-top: 1px solid var(--border); }

.drawer .close { position: absolute; top: 18px; right: 18px; font-size: 22px; color: var(--muted); }
.drawer .close:hover { background: var(--chip); color: var(--text); }

@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(24px); opacity: .6; } }

.toast {
    position: fixed;
    bottom: 22px;
    left: 50%;
    transform: translateX(-50%);
    background: #1b1f25;
    color: #fff;
    padding: 10px 18px;
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    z-index: 3000;
    font-weight: 500;
    animation: fade .2s;
}

/* ---------- login ---------- */

.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(400px, .9fr); }

.login-hero {
    position: relative;
    overflow: hidden;
    display: grid;
    place-items: center;
    padding: 48px;
    color: #c9d0db;
    background:
        radial-gradient(600px 400px at 20% 15%, rgba(8, 144, 248, .18), transparent 70%),
        radial-gradient(500px 380px at 85% 90%, rgba(144, 248, 64, .12), transparent 70%),
        linear-gradient(160deg, #1d2025, #121417);
}
/* malha leve de "mapa" no fundo */
.login-hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: linear-gradient(rgba(255, 255, 255, .035) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .035) 1px, transparent 1px);
    background-size: 44px 44px;
    mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
}
.login-hero-inner { position: relative; max-width: 460px; width: 100%; }
.login-logo { width: 100%; max-width: 400px; height: auto; display: block; margin: 0 auto 28px; }
.login-tagline { font-size: 16px; line-height: 1.6; color: #aab3c2; margin: 0 0 22px; text-align: center; }
.login-features { list-style: none; padding: 0; margin: 0 auto; display: grid; gap: 10px; width: fit-content; }
.login-features li { display: flex; align-items: center; gap: 10px; color: #c9d0db; }
.login-features .icon { color: #90f840; width: 16px; height: 16px; stroke-width: 2.4; }

.login-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 24px; background: var(--bg); }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 18px; }
.login-card h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.login-card h1 + p { margin: 4px 0 4px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; }
.login-mark { display: none; }
.login-foot { margin-top: 40px; color: var(--muted); font-size: 12px; }

.field { position: relative; display: block; }
.field > .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.field input { width: 100%; height: 44px; padding-left: 40px; font-size: 15px; }
.field .reveal { position: absolute; right: 4px; top: 4px; height: 36px; width: 38px; padding: 0; border: 0; background: transparent; color: var(--muted); }
.field .reveal:hover { color: var(--text); background: transparent; }
.field:has(.reveal) input { padding-right: 44px; }
.login-card button.primary { height: 44px; font-size: 15px; font-weight: 600; }

/* ---------- celular / tablet ---------- */

@media (max-width: 960px) {
    .login { grid-template-columns: 1fr; }
    .login-hero { display: none; }
    .login-panel { background: linear-gradient(170deg, #1d2025, #121417); color: #e7eaf0; }
    .login-panel .muted, .login-foot { color: #8c95a5; }
    .login-panel input { background: #171a1f; border-color: #323843; color: #e7eaf0; }
    .login-mark { display: block; width: 240px; max-width: 80%; height: auto; margin: 0 auto 8px; }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform .2s ease-out;
        box-shadow: var(--shadow-lg);
    }
    .shell.menu-open .sidebar { transform: none; }
    .shell.menu-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(8, 10, 14, .5); z-index: 1400; }

    .mobilebar {
        display: flex;
        align-items: center;
        gap: 6px;
        position: sticky;
        top: 0;
        z-index: 1000;
        height: 56px;
        padding: 0 10px;
        background: var(--side-bg);
        color: #fff;
    }
    .mobilebar .icon-button { color: #fff; }
    .mobilebar .brand { font-size: 15px; }

    main { padding: 20px 16px 32px; }
    .toolbar input:not([type=checkbox]) { width: 100%; }
    .toolbar select { flex: 1 1 140px; }
}

@media (max-width: 640px) {
    .kv { grid-template-columns: 1fr; gap: 2px; }
    .kv dd { margin-bottom: 8px; }
    .drawer-panel { padding: 20px 16px 32px; }
    .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat { padding: 12px 14px; }
    .stat .value { font-size: 21px; }
}
