:root {
    --bg: #f6f4ee;
    --bg-soft: #fbfaf7;
    --card: rgba(255, 255, 255, 0.92);
    --card-strong: #ffffff;
    --line: rgba(89, 106, 90, 0.12);
    --line-strong: rgba(89, 106, 90, 0.2);
    --text: #172017;
    --muted: #667368;
    --soft: #8f9a91;
    --green: #6f8f5e;
    --green-deep: #37513c;
    --green-soft: rgba(111, 143, 94, 0.12);
    --warning: #d39a1b;
    --warning-soft: #fff3d4;
    --critical: #d9423a;
    --critical-soft: #ffe5e2;
    --blue-soft: #e7f0ff;
    --radius-lg: 30px;
    --radius-md: 22px;
    --radius-sm: 16px;
    --shadow: 0 18px 40px rgba(39, 56, 42, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(111, 143, 94, 0.18), transparent 24%),
        radial-gradient(circle at bottom right, rgba(139, 115, 85, 0.1), transparent 20%),
        linear-gradient(180deg, #faf9f5 0%, #f5f3ed 100%);
}

a {
    color: inherit;
    text-decoration: none;
}

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

.page-frame {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr;
}

.main-panel {
    min-width: 0;
}

.side-nav {
    position: sticky;
    top: 0;
    z-index: 30;
}

.side-nav-card {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 18px 16px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
}

.side-nav-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-badge {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--green), #8ea97d);
    color: #fff;
    font-weight: 800;
    letter-spacing: 0.06em;
}

.side-nav-brand strong {
    display: block;
    color: var(--green-deep);
    font-size: 18px;
}

.nav-list {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.nav-item,
.nav-button {
    appearance: none;
    width: 100%;
    border: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 10px;
    border-radius: 18px;
    color: var(--muted);
    cursor: pointer;
    text-align: center;
}

.nav-item strong,
.nav-button strong {
    display: block;
    font-size: 13px;
}

.nav-item small,
.nav-button small {
    display: none;
    color: var(--soft);
    font-size: 12px;
}

.nav-item.active {
    color: var(--green-deep);
    background: linear-gradient(135deg, rgba(111, 143, 94, 0.18), rgba(111, 143, 94, 0.08));
    box-shadow: inset 0 0 0 1px rgba(111, 143, 94, 0.18);
}

.nav-icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 8px 18px rgba(38, 52, 40, 0.06);
    font-size: 18px;
}

.topbar {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 24px 18px 10px;
}

.topbar-copy {
    display: grid;
    gap: 8px;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 11px;
    color: var(--green);
    font-weight: 800;
}

.topbar-copy h1,
.section-head h2,
.section-head h3,
.hero-top h2,
.panel-card h3,
.empty-card h2,
.clear-card h3,
.device-row-summary h3,
.device-modal-head h2 {
    margin: 0;
}

.topbar-copy h1 {
    color: var(--green-deep);
    font-size: clamp(28px, 3vw, 42px);
    line-height: 1.05;
}

.topbar-copy p,
.section-caption,
.panel-card p,
.sensor-card p,
.empty-card p,
.clear-card p,
.alert-body p,
.alert-body small,
.setting-row p,
.wifi-network p,
.device-row-summary p,
.chart-empty,
.empty-inline-text {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
}

.header-actions {
    display: grid;
    gap: 14px;
}

.device-picker,
.device-admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: end;
}

.field-label {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--muted);
    font-weight: 700;
}

.device-picker select,
.device-form input,
.device-form textarea {
    width: 100%;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--line-strong);
    background: rgba(255, 255, 255, 0.96);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.device-form .input-validation-error {
    border-color: rgba(217, 66, 58, 0.55);
    background: rgba(255, 245, 244, 0.98);
    box-shadow: 0 0 0 4px rgba(217, 66, 58, 0.1);
}

.device-picker select:focus,
.device-form input:focus,
.device-form textarea:focus {
    border-color: rgba(111, 143, 94, 0.4);
    box-shadow: 0 0 0 4px rgba(111, 143, 94, 0.12);
}

.content-shell {
    padding: 12px 18px 32px;
}

.content-stack,
.dashboard-primary,
.dashboard-secondary,
.data-section,
.settings-grid,
.setting-list,
.network-list,
.alert-list,
.device-management-shell,
.device-list-pane,
.device-help-pane {
    display: grid;
    gap: 20px;
}

.dashboard-grid {
    display: grid;
    gap: 22px;
}

.panel-card,
.hero-card,
.sensor-card,
.alert-card,
.empty-card,
.clear-card,
.feedback-card,
.device-row-card,
.scan-button,
.wifi-network {
    border-radius: var(--radius-md);
    border: 1px solid var(--line);
    background: var(--card);
    box-shadow: var(--shadow);
}

.panel-card,
.empty-card,
.clear-card,
.feedback-card,
.wifi-network {
    padding: 24px;
}

.section-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 12px;
}

.compact-row {
    align-items: center;
}

.inline-link {
    color: var(--green-deep);
    font-weight: 700;
    white-space: nowrap;
}

.inline-form {
    display: inline-flex;
}

.device-chip,
.refresh-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(89, 106, 90, 0.08);
    color: var(--green-deep);
}

.chip-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: #6ac17c;
    box-shadow: 0 0 0 6px rgba(106, 193, 124, 0.14);
}

.refresh-chip strong {
    font-size: 12px;
}

.hero-card {
    padding: 28px;
    color: #fff;
}

.hero-healthy {
    background: linear-gradient(135deg, #64895a 0%, #8aad76 100%);
}

.hero-warning {
    background: linear-gradient(135deg, #d9a229 0%, #f0b73d 100%);
}

.hero-critical {
    background: linear-gradient(135deg, #de4539 0%, #f35e51 100%);
}

.hero-top {
    display: flex;
    gap: 16px;
    align-items: start;
}

.hero-icon {
    width: 58px;
    height: 58px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    font-size: 30px;
    font-weight: 800;
    background: rgba(255, 255, 255, 0.18);
    flex-shrink: 0;
}

.hero-top p {
    color: rgba(255, 255, 255, 0.9);
}

.hero-stats {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.22);
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.hero-stats span {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    opacity: 0.82;
}

.hero-stats strong {
    font-size: 20px;
}

.sensor-grid {
    display: grid;
    grid-template-columns: repeat(1, minmax(0, 1fr));
    gap: 16px;
}

.sensor-card {
    padding: 22px;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.sensor-card-head {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--muted);
    font-size: 14px;
}

.metric-icon {
    color: var(--green-deep);
}

.large-icon {
    font-size: 26px;
}

.sensor-reading {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin: 10px 0 8px;
}

.sensor-reading strong {
    font-size: clamp(34px, 4vw, 44px);
    line-height: 1;
    color: var(--text);
}

.sensor-reading span {
    color: var(--soft);
    font-size: 20px;
}

.sensor-warning {
    background: linear-gradient(180deg, #fffaf0 0%, #fff 100%);
    border-color: rgba(211, 154, 27, 0.28);
}

.sensor-critical {
    background: linear-gradient(180deg, #fff1ef 0%, #fff 100%);
    border-color: rgba(217, 66, 58, 0.28);
}

.overview-list {
    margin: 18px 0 0;
    display: grid;
    gap: 14px;
}

.overview-list div {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.overview-list dt {
    color: var(--muted);
    font-size: 13px;
}

.overview-list dd {
    margin: 0;
    font-weight: 800;
}

.mini-alert-list {
    display: grid;
}

.mini-alert {
    display: flex;
    gap: 12px;
    align-items: start;
    padding: 14px 0;
    border-top: 1px solid var(--line);
}

.mini-alert:first-child {
    padding-top: 0;
    border-top: 0;
}

.mini-alert-icon,
.alert-icon,
.wifi-network-icon,
.insight-icon,
.clear-icon {
    display: grid;
    place-items: center;
}

.mini-alert-icon {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    background: #f4f5f1;
}

.mini-critical .mini-alert-icon {
    background: var(--critical-soft);
}

.mini-warning .mini-alert-icon {
    background: var(--warning-soft);
}

.mini-info .mini-alert-icon {
    background: var(--blue-soft);
}

.range-filter {
    display: inline-grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 6px;
    gap: 6px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid var(--line);
    width: min(100%, 380px);
}

.range-filter a {
    text-align: center;
    padding: 12px 14px;
    border-radius: 14px;
    color: var(--muted);
    font-weight: 700;
}

.range-filter a.active {
    background: linear-gradient(135deg, var(--green-soft), rgba(111, 143, 94, 0.08));
    color: var(--green-deep);
}

.chart-grid {
    display: grid;
    gap: 20px;
}

.chart-panel {
    padding: 22px;
}

.chart-panel-head {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 10px;
    margin-bottom: 16px;
}

.apex-chart {
    min-height: 320px;
}

.insight-card {
    display: flex;
    gap: 16px;
    padding: 24px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, rgba(111, 143, 94, 0.12), rgba(111, 143, 94, 0.05));
    border: 1px solid rgba(111, 143, 94, 0.18);
    box-shadow: var(--shadow);
}

.insight-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: var(--green);
    color: #fff;
    font-weight: 800;
    flex-shrink: 0;
}

.insight-card ul {
    margin: 12px 0 0;
    padding-left: 18px;
    color: var(--text);
    display: grid;
    gap: 8px;
}

.alert-list {
    display: grid;
    gap: 16px;
}

.alert-card {
    display: flex;
    gap: 16px;
    padding: 22px;
}

.alert-icon {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: #f4f5f1;
    flex-shrink: 0;
}

.severity-critical {
    border-color: rgba(217, 66, 58, 0.22);
}

.severity-warning {
    border-color: rgba(211, 154, 27, 0.22);
}

.severity-info {
    border-color: rgba(59, 92, 164, 0.14);
}

.severity-critical .alert-icon {
    background: var(--critical-soft);
}

.severity-warning .alert-icon {
    background: var(--warning-soft);
}

.severity-info .alert-icon {
    background: var(--blue-soft);
}

.alert-body {
    flex: 1;
    min-width: 0;
}

.alert-title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.alert-pill,
.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 6px 12px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
}

.pill-active,
.badge-error {
    background: var(--critical-soft);
    color: #b72e27;
}

.pill-warning,
.badge-warning {
    background: var(--warning-soft);
    color: #996700;
}

.pill-resolved,
.badge-success {
    background: rgba(111, 143, 94, 0.15);
    color: var(--green-deep);
}

.badge-neutral {
    background: rgba(230, 233, 228, 0.9);
    color: #4b584c;
}

.clear-card {
    text-align: center;
    background: linear-gradient(180deg, rgba(111, 143, 94, 0.12), rgba(255, 255, 255, 0.95));
}

.clear-icon {
    width: 68px;
    height: 68px;
    margin: 0 auto 16px;
    border-radius: 999px;
    background: var(--green);
    color: #fff;
    font-size: 28px;
}

.settings-grid {
    grid-template-columns: 1fr;
}

.setting-list {
    gap: 0;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 18px 0;
    border-top: 1px solid var(--line);
}

.setting-row:first-child {
    border-top: 0;
    padding-top: 0;
}

.setting-row strong {
    display: block;
    margin-bottom: 4px;
}

.plain-value {
    font-weight: 800;
}

.toggle {
    position: relative;
    width: 54px;
    height: 30px;
    border-radius: 999px;
    background: #d0d8d0;
    display: inline-block;
}

.toggle::after {
    content: "";
    position: absolute;
    top: 4px;
    left: 4px;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    background: #fff;
}

.toggle.on {
    background: var(--green);
}

.toggle.on::after {
    left: 28px;
}

.back-link-wrap {
    display: flex;
    gap: 14px;
    align-items: center;
}

.back-button {
    width: 46px;
    height: 46px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid var(--line);
    color: var(--green-deep);
    font-size: 28px;
}

.scan-button {
    padding: 18px;
    background: rgba(255, 255, 255, 0.88);
    color: var(--green-deep);
    font-weight: 700;
}

.wifi-network {
    display: flex;
    align-items: center;
    gap: 16px;
}

.wifi-network-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: rgba(111, 143, 94, 0.12);
    color: var(--green-deep);
    flex-shrink: 0;
}

.wifi-network-body {
    flex: 1;
}

.wifi-network-body h4 {
    margin: 0 0 4px;
}

.wifi-signal {
    color: var(--soft);
    font-weight: 700;
}

.disabled {
    opacity: 0.72;
}

.feedback-card {
    font-weight: 700;
}

.success-card {
    background: rgba(111, 143, 94, 0.14);
    color: var(--green-deep);
}

.error-card {
    background: rgba(217, 66, 58, 0.12);
    color: #a92d28;
}

.device-management-shell {
    grid-template-columns: 1fr;
}

.device-row-card {
    background: rgba(255, 255, 255, 0.88);
    overflow: hidden;
}

.device-row-summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 16px;
    padding: 22px;
}

.device-row-summary::-webkit-details-marker {
    display: none;
}

.device-row-summary h3 {
    margin-top: 6px;
    color: var(--green-deep);
    font-size: 24px;
}

.device-row-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: end;
}

.device-edit-panel {
    padding: 0 22px 22px;
    border-top: 1px solid var(--line);
}

.device-form {
    display: grid;
    gap: 14px;
}

.device-form label {
    display: grid;
    gap: 8px;
}

.device-form label > span {
    font-size: 13px;
    color: var(--muted);
    font-weight: 700;
}

.field-validation,
.field-validation-error {
    min-height: 18px;
    font-size: 12px;
    font-weight: 700;
    color: #b72e27;
}

.validation-summary,
.validation-summary-errors {
    padding: 14px 16px;
    border-radius: 16px;
    background: rgba(217, 66, 58, 0.1);
    color: #b72e27;
    border: 1px solid rgba(217, 66, 58, 0.18);
}

.validation-summary:empty {
    display: none;
}

.checkbox-row {
    grid-template-columns: 20px 1fr;
    align-items: center;
}

.checkbox-row input {
    width: 18px;
    height: 18px;
    margin: 0;
}

.secondary-link-button,
.secondary-button,
.primary-button,
.danger-button {
    min-height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 18px;
    border-radius: 16px;
    border: 1px solid var(--line-strong);
    cursor: pointer;
    font-weight: 800;
}

.secondary-link-button,
.secondary-button {
    background: rgba(255, 255, 255, 0.9);
    color: var(--green-deep);
}

.primary-button {
    background: linear-gradient(135deg, var(--green), #87a274);
    color: #fff;
    border-color: transparent;
}

.danger-button {
    background: linear-gradient(135deg, #d9423a, #ef6b63);
    color: #fff;
    border-color: transparent;
}

.device-form-actions,
.delete-device-form {
    display: flex;
    justify-content: flex-end;
}

.delete-device-form {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.device-modal {
    border: 0;
    padding: 0;
    width: min(100% - 24px, 620px);
    border-radius: 28px;
    background: transparent;
}

.device-modal::backdrop {
    background: rgba(18, 24, 19, 0.48);
    backdrop-filter: blur(8px);
}

.device-modal-shell {
    background: #fff;
    border-radius: 28px;
    padding: 24px;
    box-shadow: 0 26px 50px rgba(25, 36, 27, 0.18);
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(100%, 480px);
    padding: 32px;
    border-radius: 30px;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid var(--line);
    box-shadow: 0 28px 60px rgba(25, 36, 27, 0.14);
}

.login-copy {
    display: grid;
    gap: 10px;
    margin-bottom: 20px;
}

.login-copy h1 {
    margin: 0;
    color: var(--green-deep);
    font-size: 34px;
    line-height: 1.05;
}

.login-copy p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.login-form {
    gap: 16px;
}

.login-button {
    width: 100%;
    margin-top: 6px;
}

.device-modal-head {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 12px;
    margin-bottom: 18px;
}

.modal-close {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--green-deep);
    font-size: 24px;
    cursor: pointer;
}

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

@media (max-width: 767px) {
    .alert-card,
    .setting-row,
    .device-row-summary,
    .header-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .hero-stats {
        grid-template-columns: 1fr;
    }

    .device-row-badges {
        justify-content: start;
    }
}

@media (min-width: 768px) {
    .topbar {
        padding: 30px 28px 14px;
    }

    .content-shell {
        padding: 16px 28px 40px;
    }

    .header-actions {
        grid-template-columns: minmax(280px, 360px) auto;
        justify-content: space-between;
        align-items: end;
    }

    .sensor-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sensor-card-wide {
        grid-column: 1 / -1;
    }

    .chart-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .chart-grid .chart-panel:last-child {
        grid-column: 1 / -1;
    }

    .settings-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .device-management-shell {
        grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.8fr);
        align-items: start;
    }
}

@media (min-width: 1080px) {
    .page-frame {
        grid-template-columns: 280px minmax(0, 1fr);
    }

    .side-nav {
        height: 100vh;
        border-right: 1px solid var(--line);
        background: linear-gradient(180deg, rgba(255, 255, 255, 0.75), rgba(250, 249, 245, 0.72));
        backdrop-filter: blur(16px);
    }

    .side-nav-card {
        height: 100%;
        padding: 28px 18px;
        border-bottom: 0;
    }

    .nav-list {
        grid-template-columns: 1fr;
    }

    .nav-item,
    .nav-button {
        flex-direction: row;
        justify-content: flex-start;
        text-align: left;
        padding: 14px 14px;
    }

    .nav-item small,
    .nav-button small {
        display: block;
    }

    .main-panel {
        min-height: 100vh;
    }

    .dashboard-grid {
        grid-template-columns: minmax(0, 1.65fr) minmax(320px, 0.9fr);
        align-items: start;
    }

    .sensor-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sensor-card-wide {
        grid-column: 1 / -1;
    }
}
