:root {
    --bg: #f3f6f8;
    --panel: #ffffff;
    --ink: #1c2b33;
    --muted: #5b6b74;
    --line: #d7e0e6;
    --accent: #214069;
    --accent-dark: #1a3354;
    --sidebar: #214069;
    --sidebar-ink: #e8eef4;
    --danger: #b42318;
    --ok: #027a48;
    --warn: #b54708;
    --sidebar-width: 240px;
}

* { box-sizing: border-box; }
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
html, body { margin: 0; padding: 0; }
body.app-body {
    font-family: "Segoe UI", system-ui, sans-serif;
    background: var(--bg);
    color: var(--ink);
    min-width: 0;
}

.layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
}

.nav-overlay {
    display: none;
}

.sidebar {
    background: var(--sidebar);
    color: var(--sidebar-ink);
    padding: 24px 16px;
}

.sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 28px;
}

.brand {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.nav a {
    display: block;
    color: var(--sidebar-ink);
    text-decoration: none;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 4px;
}

.nav a:hover,
.nav a.active {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.icon-btn {
    border: 0;
    background: transparent;
    color: inherit;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.12); }
.icon-btn.menu-btn { color: var(--ink); background: var(--panel); border: 1px solid var(--line); }
.icon-btn.menu-btn:hover { background: #e8eef4; }

.hamburger,
.hamburger::before,
.hamburger::after {
    display: block;
    width: 18px;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
    position: relative;
}
.hamburger::before,
.hamburger::after {
    content: "";
    position: absolute;
    left: 0;
}
.hamburger::before { top: -6px; }
.hamburger::after { top: 6px; }

.nav-close {
    font-size: 28px;
    line-height: 1;
}

.content {
    padding: 16px;
    min-width: 0;
}
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.topbar-start {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.topbar h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.2;
    overflow-wrap: anywhere;
}
.muted { color: var(--muted); }

.user-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 14px;
    flex-wrap: wrap;
}
.user-meta .user-email {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.user-meta button, .btn {
    border: 0;
    background: var(--accent);
    color: white;
    border-radius: 8px;
    padding: 10px 14px;
    min-height: 44px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}
.btn:hover { background: var(--accent-dark); }
.btn.secondary { background: #4a6080; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #8f1d16; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.mapping-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.mapping-pin-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: 0;
}
.mapping-actions .btn,
.mapping-pin-form .btn {
    width: auto;
    min-height: 40px;
    padding: 8px 12px;
}
.mapping-pin-form input {
    width: 8.5rem;
    min-height: 40px;
    font-size: inherit;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.card, .panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px;
    min-width: 0;
}
.panel + .panel { margin-top: 16px; }
.card .label { color: var(--muted); font-size: 13px; }
.card .value { font-size: 24px; font-weight: 700; margin-top: 6px; }

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
    padding-bottom: 4px;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    min-width: 560px;
}
th, td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
    white-space: nowrap;
}
td.wrap,
p.wrap {
    white-space: normal;
    overflow-wrap: anywhere;
}
th { color: var(--muted); font-weight: 600; }
code {
    font-size: 12px;
    overflow-wrap: anywhere;
    word-break: break-all;
    white-space: pre-wrap;
}

.badge {
    display: inline-block;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 600;
}
.badge.ok { background: #e7f8ef; color: var(--ok); }
.badge.warn { background: #fff4e5; color: var(--warn); }
.badge.neutral { background: #eef2f4; color: #34454e; }
.dot {
    width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px;
}
.dot.online { background: var(--ok); }
.dot.offline { background: #98a6ae; }

.flash {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
}
.flash.success { background: #e7f8ef; color: var(--ok); }
.flash.error { background: #fdecea; color: var(--danger); }

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 16px;
}
.form-actions label { display: none; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select {
    width: 100%;
    max-width: 100%;
    padding: 10px 12px;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
    font-size: 16px;
    line-height: 1.25;
    color: inherit;
    background: white;
}
select {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235b6b74' d='M2.5 4.5 6 8l3.5-3.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
}
.form-actions .btn { width: 100%; }
.filters { margin-bottom: 16px; }
.unmapped-item {
    border-bottom: 1px solid var(--line);
    padding: 16px 0;
}
.unmapped-item:last-child { border-bottom: 0; }
.unmapped-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.unmapped-pin {
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: #e8eef4;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 16px;
    min-width: 120px;
    flex-shrink: 0;
}
.unmapped-pin-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}
.unmapped-pin-value {
    font-size: 32px;
    font-weight: 700;
    line-height: 1.15;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}
.unmapped-meta { min-width: 0; }
.unmapped-device { margin: 0 0 4px; }
.meta-line { overflow-wrap: anywhere; }

.login-page {
    min-height: 100vh;
    font-family: "Segoe UI", system-ui, sans-serif;
    color: #f4f7fb;
    background: #1e3961;
    color-scheme: dark;
}
.login-wrap {
    position: relative;
    isolation: isolate;
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px 16px;
    overflow: hidden;
}
.login-glow {
    position: absolute;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(ellipse 70% 50% at 50% -10%, rgba(130, 168, 214, 0.28), transparent 58%),
        radial-gradient(ellipse 45% 40% at 90% 100%, rgba(20, 38, 68, 0.9), transparent 62%),
        radial-gradient(ellipse 40% 35% at 8% 85%, rgba(90, 130, 180, 0.16), transparent 55%),
        #1e3961;
}
.login-card {
    width: 100%;
    max-width: 400px;
    padding: 36px 32px 32px;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow:
        0 24px 60px rgba(8, 18, 36, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}
.login-brand {
    text-align: center;
    margin-bottom: 8px;
}
.login-logo {
    display: block;
    width: 96px;
    height: 96px;
    margin: 0 auto 16px;
    border-radius: 50%;
    object-fit: cover;
    background: #1e3961;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.18),
        0 12px 28px rgba(8, 18, 36, 0.28);
}
.login-kicker {
    margin: 0 0 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: rgba(232, 238, 244, 0.7);
}
.login-card h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 650;
    letter-spacing: -0.03em;
    line-height: 1.15;
    color: #fff;
}
.login-subtitle {
    margin: 10px 0 0;
    font-size: 14px;
    line-height: 1.45;
    color: rgba(232, 238, 244, 0.72);
}
.login-field label {
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(232, 238, 244, 0.68);
}
.login-page .login-card input {
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 12px;
    background: rgba(10, 22, 42, 0.35);
    color: #f4f7fb;
    font-size: 16px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.login-page .login-card input::placeholder {
    color: rgba(232, 238, 244, 0.38);
}
.login-page .login-card input:hover {
    border-color: rgba(255, 255, 255, 0.28);
}
.login-page .login-card input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.55);
    background: rgba(10, 22, 42, 0.5);
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.08);
}
.login-page .login-card input:-webkit-autofill,
.login-page .login-card input:-webkit-autofill:hover,
.login-page .login-card input:-webkit-autofill:focus {
    -webkit-text-fill-color: #f4f7fb;
    caret-color: #f4f7fb;
    box-shadow: 0 0 0 1000px #243a5c inset;
    transition: background-color 9999s ease-out;
}
.login-page .login-card .flash {
    margin-bottom: 0;
    border-radius: 12px;
}
.login-page .login-card .flash.error {
    background: rgba(180, 35, 24, 0.18);
    color: #ffd7d3;
    border: 1px solid rgba(255, 180, 170, 0.22);
}
.login-page .login-card .flash.success {
    background: rgba(2, 122, 72, 0.2);
    color: #c8f5dd;
    border: 1px solid rgba(160, 230, 190, 0.22);
}
.login-submit {
    width: 100%;
    min-height: 48px;
    margin-top: 4px;
    border-radius: 12px;
    background: #fff;
    color: #1e3961;
    font-weight: 650;
    letter-spacing: 0.01em;
    box-shadow: 0 10px 24px rgba(8, 18, 36, 0.22);
}
.login-submit:hover {
    background: #eef3f8;
    color: #162c4d;
}
.stack { display: grid; gap: 12px; }
.login-card.stack { gap: 16px; }
.login-card .btn { width: 100%; }

@media (max-width: 480px) {
    .login-card {
        padding: 28px 20px 24px;
        border-radius: 20px;
    }
    .login-logo {
        width: 84px;
        height: 84px;
    }
    .login-card h1 { font-size: 22px; }
}
.pager { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

@media (min-width: 640px) {
    .form-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }
    .form-actions label { display: block; }
    .form-actions .btn { width: auto; }
    .cards {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }
    .card .value { font-size: 28px; }
    input, select { font-size: inherit; min-height: 40px; padding: 8px 10px; }
    select { padding-right: 32px; background-position: right 10px center; }
}

@media (min-width: 900px) {
    .content { padding: 24px 32px 48px; }
    .topbar h1 { font-size: 24px; }
}

@media (max-width: 899px) {
    .layout { grid-template-columns: minmax(0, 1fr); }
    .menu-btn,
    .nav-close { display: inline-flex; }
    .sidebar-top { margin-bottom: 16px; }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(280px, 86vw);
        z-index: 40;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        overflow-y: auto;
        padding-top: 16px;
    }
    body.nav-open .sidebar { transform: translateX(0); }
    .nav-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(16, 24, 40, 0.45);
        z-index: 30;
    }
    body.nav-open .nav-overlay { display: block; }
    body.nav-open { overflow: hidden; }
    .user-meta .user-email { max-width: 140px; }
}
