: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 {
    display: block;
    width: 60%;
    max-width: 160px;
    aspect-ratio: 2 / 3;
    height: auto;
    border-radius: 8px;
    object-fit: cover;
    object-position: center;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .24);
}

.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-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;
}

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

.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;
}

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

.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: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    margin: 28px 0 20px;
}

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

.moisture-readout small {
    color: var(--muted);
    font-weight: 800;
}

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

.metric-list div {
    min-width: 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--surface-strong);
}

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

.metric-list dd {
    margin: 2px 0 0;
    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;
}

.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;
}

.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;
}

.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: flex-start;
        text-align: left;
    }

    .brand-logo {
        width: 96px;
    }

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

    .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 {
        display: grid;
    }

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

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