:root {
    --bg: #f5efe7;
    --card: rgba(255, 251, 246, 0.94);
    --panel: #fffdfa;
    --ink: #22313b;
    --muted: #6f7d84;
    --line: rgba(72, 84, 92, 0.14);
    --accent: #b65c2c;
    --success: #1f7a57;
    --error: #b33a30;
    --shadow: 0 18px 48px rgba(60, 42, 24, 0.08);
}

html {
    -webkit-text-size-adjust: 100%;
}

:root[data-theme="dark"] {
    --bg: #0d1117;
    --card: rgba(22, 27, 34, 0.96);
    --panel: #161b22;
    --ink: #e6edf3;
    --muted: #8b949e;
    --line: rgba(240, 246, 252, 0.1);
    --accent: #1f6feb;
    --success: #3fb950;
    --error: #f85149;
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.42);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-width: 320px;
    font-family: "Segoe UI", "Hiragino Sans", sans-serif;
    font-size: 15px;
    color: var(--ink);
    overflow-x: hidden;
    background:
        radial-gradient(circle at top left, rgba(255, 242, 226, 0.95) 0, transparent 34%),
        radial-gradient(circle at right 18%, rgba(217, 233, 228, 0.65) 0, transparent 28%),
        linear-gradient(180deg, #fbf7f2 0%, var(--bg) 100%);
}

:root[data-theme="dark"] body {
    background:
        radial-gradient(circle at top left, rgba(9, 105, 218, 0.1) 0, transparent 28%),
        radial-gradient(circle at right 18%, rgba(47, 129, 247, 0.08) 0, transparent 24%),
        linear-gradient(180deg, #0d1117 0%, #11161d 100%);
}

main {
    width: min(100%, 1360px);
    max-width: 1360px;
    margin: 0 auto;
    padding: calc(24px + env(safe-area-inset-top, 0px)) 16px calc(48px + env(safe-area-inset-bottom, 0px));
}

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

.hero,
.section {
    background: var(--card);
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 28px;
    box-shadow: var(--shadow);
}

.dashboard > *,
.stack > *,
.field-grid > *,
.current-grid > * {
    min-width: 0;
}

:root[data-theme="dark"] .hero,
:root[data-theme="dark"] .section {
    border-color: var(--line);
}

.hero {
    padding: 18px 22px;
    margin-bottom: 16px;
}

.hero-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.hero-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.hero h1 {
    font-size: clamp(1.55rem, 3.2vw, 2.5rem);
    line-height: 1.05;
    letter-spacing: -0.03em;
}

.dashboard,
.stack,
.field-grid,
.device-tabs,
.command-tabs,
.chips,
.actions,
.quick-list,
.graph-tabs,
.current-grid {
    display: grid;
    gap: 14px;
}

.dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
}

.section,
.stack>section {
    padding: 22px;
}

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

.head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.sub,
small,
.quick-item span,
.graph-meta {
    color: var(--muted);
    line-height: 1.6;
}

.device-tabs {
    grid-template-columns: repeat(3, 1fr);
    margin-bottom: 14px;
}

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

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

.full {
    grid-column: 1 / -1;
}

.field,
.panel,
.recent-card,
.graph-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 16px;
    min-width: 0;
}

:root[data-theme="dark"] .field,
:root[data-theme="dark"] .panel,
:root[data-theme="dark"] .recent-card,
:root[data-theme="dark"] .graph-card {
    box-shadow: inset 0 1px 0 rgba(240, 246, 252, 0.02);
}

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

input,
select,
button {
    font: inherit;
    min-width: 0;
}

input,
select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 12px 14px;
    min-height: 46px;
    font-size: 16px;
    border-radius: 14px;
    border: 1px solid #d9d0c3;
    background: #fff;
    color: var(--ink);
}

:root[data-theme="dark"] input,
:root[data-theme="dark"] select {
    border-color: rgba(196, 214, 223, 0.12);
    background: #0d1117;
    color: var(--ink);
}

.tab,
.command-tab,
.chip,
.primary,
.ghost,
.quick-item,
.graph-tab {
    border: none;
    cursor: pointer;
    transition: transform 120ms ease, background 120ms ease;
}

.tab:hover,
.command-tab:hover,
.chip:hover,
.primary:hover,
.ghost:hover,
.quick-item:hover,
.graph-tab:hover {
    transform: translateY(-1px);
}

.tab,
.command-tab,
.graph-tab {
    padding: 14px 12px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.78);
    text-align: left;
}

.tab strong,
.tab span,
.quick-item strong,
.quick-item span {
    display: block;
}

.tab.active,
.command-tab.active,
.chip.active,
.graph-tab.active,
.primary {
    background: var(--accent);
    color: #fff;
}

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

.chip,
.ghost,
.primary {
    padding: 12px 16px;
    min-height: 46px;
    border-radius: 999px;
}

.ghost {
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid var(--line);
}

:root[data-theme="dark"] .tab,
:root[data-theme="dark"] .command-tab,
:root[data-theme="dark"] .graph-tab,
:root[data-theme="dark"] .quick-item,
:root[data-theme="dark"] .ghost,
:root[data-theme="dark"] .current-tile,
:root[data-theme="dark"] .chart-shell {
    background: #21262d;
    color: var(--ink);
}

:root[data-theme="dark"] .chip {
    background: #21262d;
    color: var(--ink);
}

:root[data-theme="dark"] .switch {
    background: rgba(47, 129, 247, 0.14);
}

:root[data-theme="dark"] .track {
    background: #30363d;
    border: 1px solid rgba(240, 246, 252, 0.08);
}

:root[data-theme="dark"] .tab span,
:root[data-theme="dark"] .quick-item span,
:root[data-theme="dark"] .sub,
:root[data-theme="dark"] small,
:root[data-theme="dark"] .graph-meta,
:root[data-theme="dark"] .current-tile span,
:root[data-theme="dark"] label {
    color: var(--muted);
}

:root[data-theme="dark"] .tab.active,
:root[data-theme="dark"] .command-tab.active,
:root[data-theme="dark"] .graph-tab.active,
:root[data-theme="dark"] .chip.active {
    background: rgba(31, 111, 235, 0.2);
    border: 1px solid rgba(56, 139, 253, 0.34);
    color: #f8fbff;
    box-shadow: inset 0 1px 0 rgba(240, 246, 252, 0.04);
}

:root[data-theme="dark"] .primary {
    background: var(--accent);
    color: #f8fbff;
}

.theme-toggle {
    padding: 10px 14px;
    min-height: 42px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid var(--line);
    color: var(--ink);
}

:root[data-theme="dark"] .theme-toggle {
    background: #21262d;
    border-color: var(--line);
    color: var(--ink);
}

.actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 18px;
    padding-top: 6px;
}

.recent-inline {
    margin-top: 34px;
    border-top: 1px solid var(--line);
    padding-top: 22px;
}

.toggle-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

.switch-wrap {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.switch-state {
    min-width: 2.8rem;
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-align: right;
    color: var(--muted);
}

.switch-state.on {
    color: var(--accent);
}

.switch {
    display: inline-flex;
    padding: 4px;
    border-radius: 999px;
    background: rgba(111, 125, 132, 0.14);
}

.switch input {
    display: none;
}

.track {
    position: relative;
    width: 58px;
    height: 30px;
    border-radius: 999px;
    background: rgba(111, 125, 132, 0.24);
    border: 1px solid rgba(111, 125, 132, 0.16);
    transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
    transition: transform 120ms ease, background 120ms ease;
}

.switch input:checked+.track::after {
    transform: translateX(28px);
}

.switch input:checked+.track {
    background: rgba(182, 92, 44, 0.34);
    border-color: rgba(182, 92, 44, 0.56);
    box-shadow: 0 0 0 3px rgba(182, 92, 44, 0.12);
}

.switch input:checked+.track::after {
    background: #f8fbff;
}

:root[data-theme="dark"] .switch input:checked+.track {
    background: rgba(31, 111, 235, 0.42);
    border-color: rgba(56, 139, 253, 0.68);
    box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.14);
}

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

.current-tile {
    padding: 18px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid var(--line);
}

.current-tile span {
    display: block;
    color: var(--muted);
    margin-bottom: 10px;
}

.meter-grid {
    align-items: stretch;
}

.meter-tile {
    padding: 18px 18px 14px;
}

.meter {
    position: relative;
    aspect-ratio: 1.6 / 1;
    width: 100%;
    max-width: 280px;
    margin: 0 auto;
    padding-bottom: 28px;
}

.meter-svg {
    display: block;
    width: calc(100% - 12px);
    margin: 0 auto;
    height: auto;
    overflow: visible;
}

.meter-track,
.meter-fill {
    fill: none;
    stroke-linecap: round;
    stroke-width: 18;
}

.meter-track {
    stroke: rgba(111, 125, 132, 0.2);
}

.meter-fill {
    stroke: var(--accent);
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 180ms ease;
}

.meter-value {
    position: absolute;
    left: 50%;
    bottom: 24%;
    transform: translateX(-50%);
    display: flex;
    align-items: flex-end;
    gap: 6px;
    font-size: clamp(1.8rem, 3vw, 2.4rem);
    line-height: 1;
    letter-spacing: -0.04em;
}

.meter-scale {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 4px;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 0.02em;
}

.meter-scale span:first-child {
    transform: translateX(-4px);
}

.meter-scale span:last-child {
    transform: translateX(4px);
}

input[type="datetime-local"] {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    inline-size: 100%;
    appearance: none;
    -webkit-appearance: none;
}

input[type="datetime-local"]::-webkit-date-and-time-value {
    text-align: left;
}

input[type="datetime-local"]::-webkit-datetime-edit {
    min-width: 0;
    padding: 0;
}

input[type="datetime-local"]::-webkit-datetime-edit-fields-wrapper {
    min-width: 0;
}

input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    margin: 0;
    padding: 0;
}

.meter-value small {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--muted);
    margin-bottom: 0.25rem;
}

.humidity-meter .meter-fill {
    stroke: #2e6c7c;
}

#currentRecordedAt {
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.5;
}

:root[data-theme="dark"] .meter-track {
    stroke: rgba(139, 148, 158, 0.28);
}

:root[data-theme="dark"] .humidity-meter .meter-fill {
    stroke: #7ee787;
}

.hidden {
    display: none;
}

.quick-list {
    grid-template-columns: 1fr;
    margin-top: 12px;
}

.quick-item {
    width: 100%;
    text-align: left;
    padding: 14px 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.8);
}

.graph-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 12px 0 16px;
}

.chart-shell {
    background: rgba(255, 255, 255, 0.72);
    border-radius: 18px;
    padding: 14px;
    margin-top: 12px;
    height: 320px;
}

.chart-shell canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.toast {
    position: fixed;
    right: 18px;
    top: 18px;
    z-index: 1000;
    min-width: 260px;
    max-width: min(420px, calc(100vw - 36px));
    padding: 14px 16px;
    border-radius: 16px;
    color: #fff;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.16);
    white-space: pre-wrap;
    line-height: 1.5;
}

.toast.info {
    background: #38556a;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--error);
}

:root[data-theme="dark"] .toast.info {
    background: #1f6feb;
}

@media (max-width: 1100px) {
    .dashboard {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {

    .device-tabs,
    .command-tabs,
    .field-grid,
    .chips,
    .actions,
    .graph-tabs,
    .current-grid {
        grid-template-columns: 1fr;
    }

    .current-tile.wide {
        grid-column: auto;
    }

    main {
        padding: calc(16px + env(safe-area-inset-top, 0px)) 12px calc(40px + env(safe-area-inset-bottom, 0px));
    }

    .hero,
    .section,
    .stack>section {
        padding: 18px;
    }

    .hero-bar {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .theme-toggle {
        width: 100%;
        justify-content: center;
    }

    .hero-actions {
        width: 100%;
    }

    .chart-shell {
        height: 260px;
    }

    .meter-scale {
        bottom: -2px;
        padding: 0 2px;
        font-size: 0.82rem;
    }

    .meter-scale span:first-child {
        transform: translateX(-8px);
    }

    .meter-scale span:last-child {
        transform: translateX(14px);
    }

    .humidity-meter .meter-scale span:last-child {
        transform: translateX(18px);
    }

    input[type="datetime-local"] {
        font-size: 15px;
        padding-left: 12px;
        padding-right: 12px;
        letter-spacing: -0.01em;
    }

    .toast {
        left: 12px;
        right: 12px;
        top: 12px;
        max-width: none;
    }
}
