/* --- Reset & base --------------------------------------------------------- */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg:          #1a1a2e;
    --bg-card:     #16213e;
    --bg-card-alt: #0f3460;
    --accent:      #e94560;
    --text:        #eee;
    --text-dim:    #8a8a9a;
    --text-unit:   #6a6a7a;
    --radius:      12px;
    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left:   env(safe-area-inset-left, 0px);
    --safe-right:  env(safe-area-inset-right, 0px);
}

html {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

body {
    min-height: 100dvh;
    padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 16px) calc(var(--safe-left) + 16px);
}

/* --- Header --------------------------------------------------------------- */

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

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.status {
    font-size: 0.75rem;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 500;
    white-space: nowrap;
}

.status--connecting { background: #e9a54033; color: #e9a540; }
.status--connected  { background: #40e97033; color: #40e970; }
.status--error      { background: #e9456033; color: #e94560; }

/* --- Sensor grid ---------------------------------------------------------- */

#grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

/* --- Sensor card ---------------------------------------------------------- */

.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: background 0.3s ease;
}

.card.flash {
    background: var(--bg-card-alt);
}

.card__name {
    font-size: 0.8rem;
    color: var(--text-dim);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card__value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
    transition: transform 0.15s ease;
}

.card.flash .card__value {
    transform: scale(1.05);
}

.card__unit {
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-unit);
    margin-left: 2px;
}

.card__updated {
    font-size: 0.65rem;
    color: var(--text-dim);
}

/* --- Domain group headers ------------------------------------------------- */

.domain-header {
    grid-column: 1 / -1;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    padding: 12px 0 0;
    border-top: 1px solid #ffffff10;
}

.domain-header:first-child {
    padding-top: 0;
    border-top: none;
}

/* --- Empty state ---------------------------------------------------------- */

.empty {
    text-align: center;
    margin-top: 30vh;
    color: var(--text-dim);
}

.empty p {
    font-size: 1rem;
    margin-bottom: 8px;
}

.empty__hint {
    font-size: 0.8rem;
}

/* --- Responsive tweaks ---------------------------------------------------- */

@media (min-width: 400px) {
    #grid {
        grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    }
}

@media (min-width: 768px) {
    body {
        max-width: 720px;
        margin: 0 auto;
    }
}
