:root {
    color-scheme: light;
    --bg: #f5f7f2;
    --surface: #ffffff;
    --surface-strong: #eef4ed;
    --ink: #1d2a22;
    --muted: #68746d;
    --line: #d7dfd4;
    --green: #1f7a4d;
    --green-dark: #165a39;
    --mint: #d9efe2;
    --blue: #244c77;
    --amber: #b36a16;
    --red: #b23a32;
    --shadow: 0 18px 50px rgba(38, 58, 45, .12);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

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

button,
input {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

a {
    color: inherit;
}

.app-shell {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 28px;
    height: 100vh;
    padding: 28px 22px;
    background: #17251e;
    color: #f4fbf6;
}

.brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    text-align: center;
}

.brand-logo-frame {
    display: grid;
    place-items: center;
    width: 60%;
    max-width: 160px;
    padding: 12px;
    border: 1px solid rgba(242, 232, 139, .2);
    border-radius: 12px;
    background:
        radial-gradient(circle at 52% 28%, rgba(255, 224, 72, .42), transparent 38%),
        linear-gradient(155deg, rgba(232, 245, 211, .18), rgba(206, 230, 176, .08));
    box-shadow: 0 18px 42px rgba(0, 0, 0, .22);
}

.brand-logo {
    display: block;
    width: 100%;
    aspect-ratio: 2 / 3;
    height: auto;
    border-radius: 8px;
    object-fit: cover;
    object-position: center;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .28);
}

.brand-text {
    display: grid;
    gap: 2px;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: #bfd4c5;
    font-size: .84rem;
}

.nav-menu {
    display: grid;
    gap: 8px;
}

.nav-group {
    display: grid;
    gap: 6px;
}

.nav-menu a {
    padding: 12px 14px;
    border-radius: 8px;
    color: #dfece4;
    text-decoration: none;
}

.nav-menu a.active,
.nav-menu a:hover {
    background: rgba(255, 255, 255, .1);
    color: #ffffff;
}

.nav-submenu {
    display: grid;
    gap: 4px;
    margin-left: 10px;
    padding-left: 10px;
    border-left: 1px solid rgba(255, 255, 255, .16);
}

.nav-submenu a {
    padding: 9px 12px;
    color: #bfd4c5;
    font-size: .92rem;
}

.nav-submenu a.active,
.nav-submenu a:hover {
    background: rgba(255, 255, 255, .08);
    color: #ffffff;
}

.content-shell {
    width: min(1480px, 100%);
    padding: 34px;
}

.logout-form {
    margin-top: auto;
}

.full-width {
    width: 100%;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
}

.page-header h1 {
    margin: 2px 0 8px;
    font-size: clamp(2rem, 4vw, 3.2rem);
    line-height: 1.05;
    letter-spacing: 0;
}

.page-header h2,
.settings-panel h2,
.section-title h2 {
    margin: 0;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--green);
    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.muted {
    margin: 0;
    color: var(--muted);
}

.header-actions,
.button-row,
.input-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.primary-button,
.secondary-button,
.menu-button,
.chip button,
.menu-popover button {
    border: 0;
    cursor: pointer;
}

.primary-button,
.secondary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 700;
    white-space: nowrap;
}

.primary-button {
    background: var(--green);
    color: #ffffff;
    box-shadow: 0 10px 24px rgba(31, 122, 77, .22);
}

.primary-button:hover {
    background: var(--green-dark);
}

.secondary-button {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
}

.primary-button:disabled,
.secondary-button:disabled {
    cursor: wait;
    opacity: .6;
}

.notice,
.empty-state {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.notice {
    margin-bottom: 18px;
    padding: 14px 16px;
    font-weight: 700;
}

.notice.success {
    border-color: #b9d8c4;
    background: #edf8f0;
    color: #175f3a;
}

.notice.error {
    border-color: #efc2bd;
    background: #fff1ef;
    color: var(--red);
}

.empty-state {
    padding: 28px;
}

.empty-state.compact {
    box-shadow: none;
}

.empty-state h2 {
    margin: 0 0 8px;
}

.login-shell {
    min-height: 100vh;
    background:
        radial-gradient(circle at 50% 22%, rgba(238, 203, 44, .18), transparent 34%),
        #17251e;
}

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

.login-panel {
    display: grid;
    gap: 18px;
    width: min(440px, 100%);
    padding: 26px;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 8px;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 24px 70px rgba(0, 0, 0, .32);
}

.login-logo {
    width: min(220px, 62%);
    aspect-ratio: 2 / 3;
    justify-self: center;
    border-radius: 8px;
    object-fit: cover;
    box-shadow: 0 18px 40px rgba(31, 42, 23, .24);
}

.login-copy {
    display: grid;
    gap: 6px;
    text-align: center;
}

.login-copy h1 {
    margin: 0;
    font-size: 2rem;
    line-height: 1.05;
}

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

.code-input {
    height: 64px;
    padding: 0;
    text-align: center;
    font-size: 2rem;
    font-weight: 850;
}

.login-actions {
    justify-content: center;
}

.alert-strip {
    display: grid;
    gap: 8px;
    margin-bottom: 20px;
}

.alert-strip div {
    display: flex;
    gap: 12px;
    align-items: baseline;
    padding: 12px 14px;
    border-left: 4px solid var(--amber);
    border-radius: 8px;
    background: #fff8ea;
    color: #5d3a12;
}

.status-grid,
.sensor-settings {
    display: grid;
    gap: 18px;
}

.status-grid {
    grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
}

.status-card,
.sensor-config-card,
.settings-panel {
    position: relative;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.status-card,
.sensor-config-card {
    padding: 20px;
}

.status-card.is-dry {
    border-color: #efcf9b;
}

.status-card.is-stale {
    border-color: #e7b0aa;
}

.status-card.is-watering {
    border-color: #9ec8e5;
    background: #f5fbff;
}

.card-header,
.section-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

.card-header h2,
.card-header h3 {
    margin: 0;
    font-size: 1.3rem;
    letter-spacing: 0;
}

.card-tools {
    display: flex;
    align-items: center;
    gap: 10px;
}

.warning-button {
    position: relative;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
}

.warning-symbol {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #fff2d6;
    color: var(--amber);
    font-size: 1.15rem;
}

.warning-button:hover .warning-symbol {
    background: #ffe8ad;
}

.warning-badge {
    position: absolute;
    top: 0;
    right: 0;
    display: grid;
    place-items: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border: 2px solid var(--surface);
    border-radius: 999px;
    background: var(--red);
    color: #ffffff;
    font-size: .68rem;
    font-weight: 850;
    line-height: 1;
}

.menu-button {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--surface-strong);
    color: var(--ink);
    font-weight: 800;
}

.menu-popover {
    position: absolute;
    z-index: 5;
    top: 62px;
    right: 20px;
    display: grid;
    min-width: 210px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.menu-popover button {
    padding: 10px 12px;
    border-radius: 7px;
    background: transparent;
    color: var(--ink);
    text-align: left;
}

.menu-popover button:hover {
    background: var(--surface-strong);
}

.moisture-readout {
    display: grid;
    grid-template-columns: minmax(110px, auto) minmax(190px, 1fr);
    align-items: stretch;
    gap: 16px;
    margin: 28px 0 20px;
}

.moisture-primary {
    display: grid;
    align-content: center;
    gap: 9px;
    min-width: 0;
}

.moisture-primary > span {
    font-size: 3.2rem;
    font-weight: 850;
    line-height: 1;
}

.sparkline-panel {
    display: grid;
    align-content: stretch;
    gap: 5px;
    min-width: 0;
    min-height: 118px;
    padding: 12px 14px 10px;
    border: 1px solid rgba(31, 122, 77, .12);
    border-radius: 8px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, .94), rgba(239, 246, 238, .86));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .62);
}

.sparkline {
    width: 100%;
    height: 88px;
    overflow: visible;
}

.sparkline-chart {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: stretch;
    gap: 7px;
    min-width: 0;
}

.sparkline-axis-labels {
    display: grid;
    grid-template-rows: repeat(3, 1fr);
    height: 88px;
    padding: 4px 0 7px;
    color: var(--muted);
    font-size: .66rem;
    font-weight: 850;
    line-height: 1;
    text-align: right;
}

.sparkline-axis-labels span {
    align-self: start;
}

.sparkline-axis-labels span:nth-child(2) {
    align-self: center;
}

.sparkline-axis-labels span:nth-child(3) {
    align-self: end;
}

.sparkline-grid {
    stroke: rgba(104, 116, 109, .16);
    stroke-width: 1;
    vector-effect: non-scaling-stroke;
}

.sparkline-area {
    stroke: none;
}

.sparkline-line {
    fill: none;
    stroke: var(--green);
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 4.5;
    vector-effect: non-scaling-stroke;
}

.sparkline-threshold {
    stroke: rgba(179, 106, 22, .45);
    stroke-dasharray: 6 6;
    stroke-width: 2;
    vector-effect: non-scaling-stroke;
}

.sparkline-dot {
    fill: #ffffff;
    stroke: var(--green);
    stroke-width: 3;
    vector-effect: non-scaling-stroke;
}

.sparkline-labels {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: var(--muted);
    font-size: .76rem;
    font-weight: 800;
}

.sparkline-empty {
    display: grid;
    place-content: center;
    min-height: 100px;
    color: var(--muted);
    text-align: center;
}

.sparkline-empty span {
    font-size: .76rem;
    font-weight: 800;
}

.sparkline-empty strong {
    color: var(--ink);
    font-size: .9rem;
}

.state-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: .92rem;
    font-weight: 800;
    white-space: nowrap;
}

.state-badge.is-ok {
    border-color: #b9d8c4;
    background: #e4f4ea;
    color: #155d39;
}

.state-badge.is-dry {
    border-color: #efcf9b;
    background: #fff2d6;
    color: #70430e;
}

.state-badge.is-stale {
    border-color: #efc2bd;
    background: #fff1ef;
    color: var(--red);
}

.state-badge.is-watering {
    border-color: #b9d4e8;
    background: #eef7ff;
    color: var(--blue);
}

.state-badge.is-inactive {
    border-color: var(--line);
    background: #eef0ec;
    color: var(--muted);
}

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

.metric-list > div,
.metric-action {
    display: grid;
    gap: 2px;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--surface-strong);
    color: var(--ink);
}

.metric-action {
    cursor: pointer;
    text-align: left;
}

.metric-action:hover,
.metric-action.active {
    border-color: #b9d8c4;
    background: #e4f2e8;
}

.metric-action:focus-visible {
    outline: 3px solid rgba(31, 122, 77, .18);
}

.metric-label {
    color: var(--muted);
    font-size: .78rem;
}

.metric-value {
    overflow-wrap: anywhere;
    font-weight: 800;
}

.log-panel,
.config-pane {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.log-panel h3,
.config-pane h4 {
    margin: 0 0 12px;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}

th,
td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: .76rem;
    text-transform: uppercase;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 12px;
}

.pagination span {
    color: var(--muted);
    font-size: .88rem;
    font-weight: 800;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(16, 29, 22, .58);
}

.warning-modal {
    display: grid;
    gap: 16px;
    width: min(520px, 100%);
    padding: 22px;
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 28px 90px rgba(0, 0, 0, .32);
}

.warning-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.warning-modal-header h2 {
    margin: 0;
    font-size: 1.7rem;
    line-height: 1.1;
}

.warning-modal p {
    margin: 0;
}

.warning-modal-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.warning-modal-meta span {
    padding: 7px 10px;
    border-radius: 8px;
    background: #fff8ea;
    color: #5d3a12;
    font-weight: 800;
}

.modal-pager,
.modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.modal-pager {
    justify-content: space-between;
}

.modal-actions {
    justify-content: flex-end;
}

.settings-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 18px;
    margin-bottom: 24px;
}

.settings-panel {
    display: grid;
    gap: 16px;
    padding: 20px;
}

.settings-panel > header {
    display: grid;
    gap: 2px;
}

.settings-panel.full-span {
    margin-bottom: 24px;
}

.current-session {
    display: inline-flex;
    margin-left: 8px;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--mint);
    color: var(--green-dark);
    font-size: .76rem;
    font-weight: 800;
}

.table-actions {
    text-align: right;
    white-space: nowrap;
}

.input-row input {
    flex: 1 1 240px;
}

.field,
.field-grid {
    display: grid;
    gap: 8px;
}

.field span {
    color: var(--muted);
    font-size: .88rem;
    font-weight: 700;
}

input {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
    padding: 9px 11px;
}

input:focus {
    border-color: var(--green);
    outline: 3px solid rgba(31, 122, 77, .14);
}

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

.chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    padding: 0 6px 0 12px;
    border-radius: 999px;
    background: var(--mint);
    font-weight: 700;
}

.chip button {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(29, 42, 34, .12);
    color: var(--ink);
}

.section-title {
    align-items: center;
    margin: 8px 0 0;
}

.section-title span {
    color: var(--muted);
    font-weight: 800;
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-weight: 800;
}

.notification-list {
    display: grid;
    gap: 10px;
}

.toggle-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-strong);
}

.toggle-row input {
    width: 18px;
    min-height: 18px;
    margin-top: 3px;
}

.toggle-row span {
    display: grid;
    gap: 3px;
}

.toggle-row small {
    color: var(--muted);
}

.toggle input {
    width: 18px;
    min-height: 18px;
}

#blazor-error-ui {
    position: fixed;
    right: 18px;
    bottom: 18px;
    display: none;
    max-width: min(460px, calc(100vw - 36px));
    padding: 14px 16px;
    border-radius: 8px;
    background: #311916;
    color: #ffffff;
    box-shadow: var(--shadow);
    z-index: 1000;
}

#blazor-error-ui .reload {
    margin-left: 10px;
    color: #ffffff;
    font-weight: 800;
}

#blazor-error-ui .dismiss {
    float: right;
    margin-left: 12px;
    cursor: pointer;
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        padding: 16px;
    }

    .brand {
        align-items: center;
        text-align: center;
    }

    .brand-logo-frame {
        width: min(60%, 220px);
        max-width: 220px;
    }

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

    .nav-group {
        min-width: 0;
    }

    .nav-submenu {
        grid-column: 1 / -1;
        margin-left: 0;
    }

    .content-shell {
        padding: 20px;
    }

    .page-header,
    .settings-layout {
        display: grid;
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .status-grid,
    .field-grid,
    .metric-list {
        grid-template-columns: 1fr;
    }

    .page-header h1 {
        font-size: 2rem;
    }

    .moisture-readout {
        grid-template-columns: 1fr;
    }

    .moisture-primary > span {
        font-size: 2.7rem;
    }

    .card-header {
        align-items: flex-start;
    }

    .modal-actions {
        display: grid;
    }
}
