:root {
    color-scheme: light;
    --bg: #f5f7f3;
    --surface: #ffffff;
    --surface-soft: #eef5f7;
    --text: #18211f;
    --muted: #65706d;
    --line: #d8e0dc;
    --brand: #167c80;
    --brand-dark: #0e5558;
    --warning: #9a6116;
    --danger: #b33232;
    --good: #257a4d;
    --shadow: 0 18px 40px rgba(25, 37, 35, 0.08);
}

* {
    box-sizing: border-box;
}

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

button {
    font: inherit;
}

.app-shell {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.header-actions {
    display: flex;
    gap: 10px;
}

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

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

h1 {
    margin-bottom: 0;
    font-size: clamp(28px, 5vw, 46px);
    line-height: 1;
}

.icon-button,
.tab-button {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.icon-button {
    min-height: 44px;
    padding: 0 16px;
    font-weight: 750;
    box-shadow: var(--shadow);
}

.icon-button.secondary {
    box-shadow: none;
}

.icon-button:hover,
.tab-button:hover {
    border-color: var(--brand);
}

.icon-button:focus-visible,
.tab-button:focus-visible {
    outline: 3px solid rgba(22, 124, 128, 0.22);
    outline-offset: 2px;
}

.login-view {
    display: grid;
    place-items: center;
    min-height: 58vh;
}

.login-view[hidden] {
    display: none;
}

.login-panel {
    display: grid;
    width: min(420px, 100%);
    gap: 12px;
    padding: 26px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.login-panel h2 {
    margin-bottom: 6px;
    font-size: 24px;
}

.login-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.login-input,
.login-button {
    min-height: 44px;
    border-radius: 8px;
    font: inherit;
}

.login-input {
    border: 1px solid var(--line);
    padding: 0 12px;
}

.login-button {
    border: 1px solid var(--brand);
    background: var(--brand);
    color: #ffffff;
    cursor: pointer;
    font-weight: 850;
}

.login-button:disabled {
    cursor: wait;
    opacity: 0.7;
}

.login-message {
    min-height: 18px;
    margin-bottom: 0;
    color: var(--danger);
    font-size: 13px;
    font-weight: 750;
}

.dashboard {
    display: grid;
    gap: 18px;
}

.state-panel {
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.state-panel p {
    margin-bottom: 0;
    color: var(--muted);
}

.tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.tab-button {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 0 14px;
    color: var(--muted);
    font-weight: 750;
    white-space: nowrap;
}

.tab-button[aria-selected="true"] {
    border-color: var(--brand);
    background: var(--brand);
    color: #ffffff;
}

.device-panel {
    display: grid;
    gap: 18px;
}

.hero-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 20px;
    align-items: start;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.device-title {
    margin-bottom: 8px;
    font-size: 30px;
    line-height: 1.1;
}

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

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.status-pill.online {
    background: #e8f6ee;
    color: var(--good);
}

.status-pill.offline {
    background: #faeeee;
    color: var(--danger);
}

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

.metric-card,
.controls-panel,
.details-panel,
.modes-panel,
.energy-panel,
.notice-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.metric-card {
    min-height: 130px;
    padding: 18px;
}

.identity-grid .metric-card {
    min-height: 118px;
}

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

.metric-value {
    margin-bottom: 6px;
    font-size: 30px;
    font-weight: 850;
    line-height: 1;
    overflow-wrap: anywhere;
}

.identity-grid .metric-value {
    font-size: 24px;
    line-height: 1.12;
}

.metric-note {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 13px;
}

.metric-card.warning .metric-value {
    color: var(--warning);
}

.metric-card.good .metric-value {
    color: var(--good);
}

.lower-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 0.75fr);
    gap: 18px;
}

.modes-panel,
.controls-panel,
.details-panel,
.energy-panel,
.notice-panel {
    padding: 20px;
}

.controls-panel {
    display: grid;
    gap: 14px;
}

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

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

.control-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.control-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

.mode-row {
    grid-template-columns: minmax(0, 1fr) 92px auto;
}

.control-input,
.control-button {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.control-input {
    width: 100%;
    padding: 0 11px;
    background: #ffffff;
    color: var(--text);
}

.control-button {
    padding: 0 16px;
    background: var(--brand);
    color: #ffffff;
    cursor: pointer;
    font-weight: 800;
}

.control-button:disabled,
.control-input:disabled {
    cursor: wait;
    opacity: 0.65;
}

.control-help,
.control-message {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 13px;
}

.control-message.success {
    color: var(--good);
    font-weight: 800;
}

.control-message.error {
    color: var(--danger);
    font-weight: 800;
}

.energy-panel {
    display: grid;
    gap: 14px;
    position: relative;
}

.energy-header,
.energy-footer {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.energy-header .section-title {
    margin-bottom: 4px;
}

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

.energy-total {
    margin-bottom: 0;
    color: var(--brand-dark);
    font-size: 24px;
    font-weight: 850;
    white-space: nowrap;
}

.energy-summary {
    text-align: right;
}

.energy-lifetime {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 750;
    white-space: nowrap;
}

.energy-chart {
    width: 100%;
    min-height: 180px;
    border-radius: 8px;
    background: linear-gradient(180deg, #f7fbfb 0%, #eef6f4 100%);
}

.chart-axis {
    stroke: #bdd1ce;
    stroke-width: 2;
}

.chart-line {
    fill: none;
    stroke: var(--brand);
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 4;
}

.chart-point {
    fill: var(--surface);
    stroke: var(--brand-dark);
    stroke-width: 3;
    pointer-events: none;
}

.chart-hit-area {
    fill: transparent;
    cursor: crosshair;
}

.chart-hit-area:focus-visible {
    outline: none;
}

.chart-tooltip {
    position: absolute;
    z-index: 2;
    max-width: 180px;
    transform: translate(-50%, calc(-100% - 12px));
    padding: 8px 10px;
    border-radius: 8px;
    background: #17201e;
    color: #ffffff;
    font-size: 13px;
    font-weight: 800;
    line-height: 1.25;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 10px 22px rgba(23, 32, 30, 0.22);
}

.chart-tooltip[hidden] {
    display: none;
}

.energy-footer {
    color: var(--muted);
    font-size: 13px;
}

.notice-panel {
    border-color: #ecd7b8;
    background: #fff8ed;
}

.notice-panel p {
    margin-bottom: 0;
    color: #68471e;
}

.section-title {
    margin-bottom: 14px;
    font-size: 18px;
}

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

.mode-chip {
    min-height: 36px;
    padding: 8px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--muted);
    font-size: 13px;
    font-weight: 760;
}

.mode-chip.active {
    border-color: var(--brand);
    background: #e4f4f5;
    color: var(--brand-dark);
}

.detail-list {
    display: grid;
    gap: 10px;
    margin: 0;
}

.detail-row {
    display: grid;
    grid-template-columns: 120px minmax(0, 1fr);
    gap: 12px;
    align-items: baseline;
}

.detail-row dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.detail-row dd {
    margin: 0;
    overflow-wrap: anywhere;
}

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

@media (max-width: 620px) {
    .app-shell {
        width: min(100% - 24px, 1120px);
        padding: 22px 0;
    }

    .app-header,
    .hero-panel,
    .lower-grid {
        grid-template-columns: 1fr;
    }

    .app-header {
        align-items: stretch;
    }

    .header-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .icon-button {
        width: 100%;
    }

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

    .controls-grid,
    .control-row,
    .mode-row {
        grid-template-columns: 1fr;
    }

    .detail-row {
        grid-template-columns: 1fr;
        gap: 3px;
    }
}
