/* ── Reset & Base ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg          : #f1f5f9;
    --surface     : #ffffff;
    --border      : #e2e8f0;
    --text        : #0f172a;
    --text-muted  : #64748b;
    --primary     : #10b981;
    --shadow      : 0 4px 20px rgba(0,0,0,.07);
    --shadow-lg   : 0 10px 40px rgba(0,0,0,.12);
    --radius      : 16px;
    --radius-sm   : 8px;
}

body {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
header {
    background: linear-gradient(135deg, #064e3b 0%, #0f172a 100%);
    padding: 18px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    box-shadow: 0 4px 24px rgba(0,0,0,.3);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-logo {
    font-size: 1.8rem;
    width: 50px;
    height: 50px;
    background: rgba(255,255,255,.1);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255,255,255,.15);
    flex-shrink: 0;
}

.brand-text h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -.01em;
}

.subtitle {
    font-size: .76rem;
    color: rgba(255,255,255,.55);
    display: block;
    margin-top: 2px;
    letter-spacing: .02em;
}

.header-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.status-pill,
.update-pill {
    display: flex;
    align-items: center;
    gap: 7px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: .8rem;
    color: rgba(255,255,255,.85);
    font-weight: 500;
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-dot.online {
    background: #34d399;
    box-shadow: 0 0 0 3px rgba(52,211,153,.3);
    animation: blink 2s infinite;
}
.status-dot.offline { background: #f87171; }

@keyframes blink {
    0%, 100% { box-shadow: 0 0 0 3px rgba(52,211,153,.3); }
    50%       { box-shadow: 0 0 0 6px rgba(52,211,153,.08); }
}

/* ── Main ────────────────────────────────────────────────────────────────────── */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 28px 24px 40px;
}

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px 16px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: flex-start;
    gap: 13px;
    border: 1px solid rgba(0,0,0,.04);
    transition: transform .2s ease, box-shadow .2s ease;
}
.card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.card-icon {
    font-size: 1.3rem;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 700;
}

.card-icon.temp { background: #fee2e2; color: #ef4444; }
.card-icon.hum  { background: #dbeafe; color: #3b82f6; }
.card-icon.ph   { background: #ede9fe; color: #8b5cf6; }
.card-icon.ec   { background: #fef3c7; color: #f59e0b; }
.card-icon.n    { background: #d1fae5; color: #059669; font-size: 1rem; letter-spacing: -.02em; }
.card-icon.p    { background: #fef9c3; color: #ca8a04; font-size: 1rem; }
.card-icon.k    { background: #cffafe; color: #0891b2; font-size: 1rem; }
.card-icon.bat  { background: #f1f5f9; color: #475569; }

.card-info { flex: 1; min-width: 0; }

.card-label {
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.card-value {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1;
    color: var(--text);
    letter-spacing: -.02em;
}

.card-value .unit {
    font-size: .75rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-left: 2px;
    letter-spacing: 0;
}

.card-sub {
    font-size: .7rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* ── Charts ──────────────────────────────────────────────────────────────────── */
.charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 20px;
}

.chart-box {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px 20px 14px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(0,0,0,.04);
}

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

.chart-title {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-muted);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chart-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

canvas { max-height: 220px; }

/* ── History ─────────────────────────────────────────────────────────────────── */
.history-section {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    border: 1px solid rgba(0,0,0,.04);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.history-header h2 {
    font-size: .95rem;
    font-weight: 600;
    color: var(--text);
}

.history-filters {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 10px;
}

.history-filters label {
    font-size: .72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.history-filters input,
.history-filters select {
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    font-size: .83rem;
    font-family: inherit;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: border-color .15s;
}
.history-filters input:focus,
.history-filters select:focus { border-color: var(--primary); }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: .83rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}
.btn:hover:not(:disabled) { filter: brightness(1.07); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary   { background: var(--primary); color: #fff; box-shadow: 0 2px 10px rgba(16,185,129,.35); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); }
.btn-page      { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); padding: 7px 16px; }

/* ── Table ───────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

#history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .82rem;
}

#history-table th {
    background: #f8fafc;
    color: var(--text-muted);
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .07em;
    padding: 12px 16px;
    text-align: right;
    white-space: nowrap;
    border-bottom: 1.5px solid var(--border);
}
#history-table th:first-child { text-align: left; }

#history-table td {
    padding: 11px 16px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
#history-table td:first-child { text-align: left; white-space: nowrap; font-weight: 500; color: var(--text-muted); }
#history-table tbody tr:hover { background: #f8fafc; }
#history-table tbody tr:last-child td { border-bottom: none; }

.table-empty {
    text-align: center !important;
    color: var(--text-muted);
    padding: 40px !important;
    font-size: .9rem;
    font-style: italic;
}

/* ── Pagination ──────────────────────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 16px;
    border-top: 1px solid var(--border);
}

#page-info { font-size: .82rem; color: var(--text-muted); font-weight: 500; }

/* ── Footer ──────────────────────────────────────────────────────────────────── */
footer {
    text-align: center;
    padding: 24px;
    font-size: .73rem;
    color: var(--text-muted);
    letter-spacing: .04em;
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .charts { grid-template-columns: 1fr; }
    .chart-full { grid-column: 1; }
}

@media (max-width: 700px) {
    header {
        flex-direction: column;
        align-items: flex-start;
        padding: 16px 20px;
        gap: 12px;
    }
    .header-meta { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
    main { padding: 16px 14px 32px; }
    .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .card { padding: 14px 12px; gap: 10px; }
    .card-icon { width: 36px; height: 36px; font-size: 1.1rem; }
    .card-value { font-size: 1.4rem; }
    .history-header { flex-direction: column; align-items: flex-start; }
    .history-filters { flex-direction: column; align-items: flex-start; width: 100%; }
    .history-filters label { width: 100%; }
    .history-filters input,
    .history-filters select { width: 100%; }
    .btn-primary, .btn-secondary { width: 100%; text-align: center; }
}

@media (max-width: 400px) {
    .cards { grid-template-columns: 1fr; }
    .update-pill { display: none; }
}
