:root {
    color-scheme: light;
    --bg: #f4f7f6;
    --panel: #ffffff;
    --text: #17211f;
    --muted: #667572;
    --line: #dce5e2;
    --primary: #0f766e;
    --primary-dark: #0b5f59;
    --danger: #b42318;
    --warning: #b7791f;
}

* { box-sizing: border-box; }

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

button, input {
    font: inherit;
}

button {
    border: 0;
    border-radius: 8px;
    min-height: 44px;
    padding: 0 16px;
    background: var(--primary);
    color: white;
    font-weight: 650;
}

button:disabled {
    opacity: .55;
}

input {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 10px;
    background: white;
    color: var(--text);
}

.hidden { display: none !important; }

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

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

.login-panel h1 {
    margin: 0 0 8px;
    font-size: 26px;
}

.login-panel input {
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    background: white;
}

.error {
    min-height: 20px;
    margin: 0;
    color: var(--danger);
}

.app-view {
    width: min(980px, 100%);
    margin: 0 auto;
    padding: 18px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 14px 0 18px;
}

.topbar h1 {
    margin: 0;
    font-size: 24px;
}

.topbar p {
    margin: 3px 0 0;
    color: var(--muted);
}

.ghost-button {
    background: transparent;
    color: var(--primary-dark);
    border: 1px solid var(--line);
}

.mode-band {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}

.mode-button {
    background: white;
    color: var(--text);
    border: 1px solid var(--line);
}

.mode-button.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.tools-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.tools-row button.active {
    background: var(--primary-dark);
    box-shadow: inset 0 -4px 0 rgba(255,255,255,.25);
}

.geo-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

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

.geo-header h2 {
    margin: 0;
}

.geo-header p {
    margin: 3px 0 0;
    color: var(--muted);
}

.geo-map {
    width: 100%;
    height: min(360px, 58vh);
    min-height: 260px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #edf2f1;
    overflow: hidden;
}

.geo-fields {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 12px;
}

.geo-fields label {
    display: grid;
    gap: 6px;
}

.geo-fields span {
    color: var(--muted);
    font-size: 13px;
}

.geo-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 12px;
}

section {
    margin-top: 24px;
}

section h2 {
    font-size: 17px;
    margin: 0 0 10px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.tile, .sensor-row {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.tile {
    min-height: 94px;
    display: grid;
    align-content: space-between;
    gap: 10px;
}

.tile strong, .sensor-row strong {
    display: block;
    overflow-wrap: anywhere;
}

.tile small, .sensor-row span {
    color: var(--muted);
}

.tile.on {
    border-color: var(--primary);
    box-shadow: inset 4px 0 0 var(--primary);
}

.sensor-list {
    display: grid;
    gap: 8px;
}

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

.sensor-row.alarm {
    border-color: var(--danger);
    box-shadow: inset 4px 0 0 var(--danger);
}

@media (max-width: 520px) {
    .app-view { padding: 14px; }
    .topbar { align-items: flex-start; }
    .tools-row { grid-template-columns: 1fr; }
    .geo-header { align-items: flex-start; }
    .geo-fields { grid-template-columns: 1fr; }
    .geo-actions { grid-template-columns: 1fr; }
}
