:root {
    --bg: #f6f7f5;
    --surface: #ffffff;
    --surface-soft: #eef3f0;
    --text: #202624;
    --muted: #65716c;
    --border: #d9dfdb;
    --teal: #0f766e;
    --teal-dark: #115e59;
    --green: #15803d;
    --amber: #b45309;
    --red: #b42318;
    --ink: #26312d;
    --shadow: 0 12px 32px rgba(32, 38, 36, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

button,
input,
select {
    font: inherit;
}

button,
a.link-btn {
    min-height: 40px;
}

button,
.primary-btn,
.ghost-btn,
.danger-btn,
.tab-btn {
    min-width: 0;
}

.primary-btn,
.ghost-btn,
.danger-btn {
    width: auto;
}

button {
    cursor: pointer;
}

a {
    color: inherit;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(15, 118, 110, 0.12), rgba(180, 83, 9, 0.10)),
        var(--bg);
}

.login-shell {
    width: min(100%, 420px);
}

.login-panel,
.panel,
.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.login-panel {
    padding: 28px;
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 26px;
}

.brand-lockup.compact {
    margin: 0;
}

.brand-icon {
    width: 46px;
    height: 46px;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 8px;
    color: #fff;
    background: var(--teal);
}

.brand-icon svg {
    width: 26px;
    height: 26px;
}

.eyebrow {
    margin: 0 0 2px;
    color: var(--teal-dark);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: 1.2rem;
    line-height: 1.2;
}

h2 {
    margin-bottom: 0;
    font-size: 1.5rem;
}

h3 {
    margin-bottom: 0;
    font-size: 1rem;
}

.alert {
    margin-bottom: 18px;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 0.92rem;
}

.alert-danger {
    color: #7f1d1d;
    background: #fee2e2;
    border: 1px solid #fecaca;
}

.stack-form,
.inline-form,
.filter-form {
    display: grid;
    gap: 14px;
}

.stack-form label,
.inline-form label,
.filter-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 700;
}

input,
select {
    width: 100%;
    min-height: 42px;
    padding: 9px 11px;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.primary-btn,
.ghost-btn,
.danger-btn,
.tab-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 13px;
    border-radius: 8px;
    border: 1px solid transparent;
    text-decoration: none;
    font-weight: 800;
    white-space: nowrap;
}

.primary-btn svg,
.ghost-btn svg,
.danger-btn svg,
.tab-btn svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.primary-btn {
    color: #fff;
    background: var(--teal);
}

.primary-btn:hover {
    background: var(--teal-dark);
}

.danger-btn {
    color: #fff;
    background: var(--red);
}

.danger-btn:hover {
    background: #8f1d14;
}

.ghost-btn {
    color: var(--ink);
    background: #fff;
    border-color: var(--border);
}

.ghost-btn:hover {
    background: var(--surface-soft);
}

.app-page {
    min-height: 100vh;
}

.topbar {
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 0 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-pill,
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 800;
    white-space: nowrap;
}

.status-pill svg,
.badge svg {
    width: 15px;
    height: 15px;
}

.status-pill.online,
.badge.success,
.badge.registered {
    color: #14532d;
    background: #dcfce7;
}

.status-pill.offline,
.badge.failed,
.badge.unregistered {
    color: #7f1d1d;
    background: #fee2e2;
}

.status-pill.muted,
.badge.pending,
.badge.processing {
    color: #713f12;
    background: #fef3c7;
}

.badge.neutral {
    color: var(--muted);
    background: var(--surface-soft);
}

.app-layout {
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
    min-height: calc(100vh - 72px);
}

.sidebar {
    padding: 18px 14px;
    background: #26312d;
    border-right: 1px solid #1f2724;
}

.tab-btn {
    width: 100%;
    justify-content: flex-start;
    margin-bottom: 8px;
    color: #d9e5df;
    background: transparent;
    border-color: transparent;
}

.tab-btn:hover,
.tab-btn.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.11);
}

.content {
    min-width: 0;
    padding: 24px;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

.section-heading,
.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.panel {
    padding: 18px;
    margin-bottom: 18px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.metric-card {
    padding: 16px;
}

.metric-card p {
    margin: 12px 0 4px;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 700;
}

.metric-card strong {
    display: block;
    font-size: 2rem;
    line-height: 1;
}

.metric-icon {
    width: 36px;
    height: 36px;
    display: inline-grid;
    place-items: center;
    border-radius: 8px;
}

.metric-icon svg {
    width: 20px;
    height: 20px;
}

.metric-icon.teal {
    color: #0f766e;
    background: #ccfbf1;
}

.metric-icon.green {
    color: #15803d;
    background: #dcfce7;
}

.metric-icon.amber {
    color: #b45309;
    background: #fef3c7;
}

.metric-icon.red {
    color: #b42318;
    background: #fee2e2;
}

.bar-chart {
    display: grid;
    grid-template-columns: repeat(7, minmax(34px, 1fr));
    gap: 12px;
    align-items: end;
    min-height: 190px;
}

.bar-item {
    display: grid;
    gap: 8px;
    justify-items: center;
}

.bar-track {
    width: 100%;
    height: 132px;
    display: flex;
    align-items: flex-end;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.bar-fill {
    width: 100%;
    min-height: 4px;
    background: var(--teal);
}

.bar-value {
    font-size: 0.8rem;
    font-weight: 800;
}

.bar-label {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.inline-form {
    grid-template-columns: minmax(220px, 1.2fr) minmax(180px, 0.8fr) auto;
    align-items: end;
}

.filter-form {
    grid-template-columns: repeat(4, minmax(140px, 1fr)) auto auto auto;
    align-items: end;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        width: 100%;
        min-width: 0;
        border-collapse: collapse;
    }

    th,
    td {
        padding: 11px 10px;
        text-align: left;
        border-bottom: 1px solid var(--border);
        vertical-align: middle;
        white-space: normal;
        word-break: break-word;
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
}

td {
    font-size: 0.92rem;
}

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

.small-btn {
    min-height: 34px;
    padding: 7px 9px;
    font-size: 0.82rem;
}

.device-panel {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.muted-label {
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.device-panel strong {
    overflow-wrap: anywhere;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    max-width: min(360px, calc(100vw - 36px));
    padding: 12px 14px;
    color: #fff;
    background: var(--ink);
    border-radius: 8px;
    box-shadow: var(--shadow);
    transform: translateY(18px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease, transform 160ms ease;
    z-index: 50;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.empty-row {
    color: var(--muted);
    text-align: center;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(32, 38, 36, 0.42);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-panel {
    width: min(100%, 460px);
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.modal-title {
    margin-bottom: 4px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

@media (max-width: 1080px) {
    .metric-grid,
    .device-panel {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .inline-form {
        grid-template-columns: repeat(2, minmax(220px, 1fr));
    }

    .filter-form {
        grid-template-columns: repeat(2, minmax(160px, 1fr));
    }
}

@media (max-width: 900px) {
    .topbar {
        padding: 14px;
    }

    .content {
        padding: 20px;
    }
}

@media (max-width: 760px) {
    .topbar {
        height: auto;
        align-items: flex-start;
        flex-direction: column;
        padding: 14px;
    }

    .topbar-actions {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .app-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: sticky;
        top: 0;
        z-index: 19;
        display: grid;
        grid-template-columns: repeat(5, minmax(58px, 1fr));
        gap: 6px;
        padding: 8px;
        overflow-x: auto;
    }

    .tab-btn {
        min-height: 52px;
        justify-content: center;
        margin-bottom: 0;
        padding: 8px;
    }

    .tab-btn span {
        display: none;
    }

    .content {
        padding: 16px;
    }

    .section-heading,
    .panel-title {
        align-items: flex-start;
        flex-direction: column;
    }

    .metric-grid,
    .device-panel,
    .inline-form,
    .filter-form {
        grid-template-columns: 1fr;
    }

    .inline-form button,
    .filter-form button,
    .filter-form a {
        width: 100%;
    }

    .table-wrap {
        max-width: 100%;
    }

    .bar-chart {
        gap: 8px;
    }

    .brand-lockup.compact h1 {
        font-size: 1rem;
    }
}

@media (max-width: 520px) {
    .topbar {
        padding: 12px;
    }

    .sidebar {
        grid-template-columns: repeat(5, minmax(48px, 1fr));
    }

    .tab-btn {
        min-height: 48px;
        padding: 6px;
    }

    .section-heading,
    .panel-title {
        gap: 10px;
    }

    .panel {
        padding: 16px;
    }

    .login-shell {
        width: min(100%, 100vw - 32px);
    }
}
