:root {
    color-scheme: light;
    --bg: #f6f8fb;
    --bg-soft: #eef4ff;
    --panel: #ffffff;
    --panel-2: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --line-strong: #cbd5e1;
    --accent: #2563eb;
    --accent-soft: #dbeafe;
    --accent-text: #1e3a8a;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --success: #059669;
    --success-soft: #dcfce7;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --shadow: 0 18px 48px rgba(15, 23, 42, .08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, .12), transparent 32rem),
        linear-gradient(180deg, #ffffff 0, var(--bg) 280px);
    color: var(--text);
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; font-weight: 650; }
a:hover { text-decoration: underline; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 28px;
    border-bottom: 1px solid rgba(226, 232, 240, .9);
    background: rgba(255, 255, 255, .82);
    backdrop-filter: blur(14px);
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 900;
    font-size: 22px;
    letter-spacing: -.03em;
    color: var(--text);
}
.brand::before {
    content: "";
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 7px var(--accent-soft);
}
.topbar nav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.topbar nav a, .link-button {
    border-radius: 999px;
    padding: 8px 12px;
    color: var(--muted);
    font-weight: 700;
}
.topbar nav a:hover, .link-button:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }

.container { width: min(1160px, calc(100% - 32px)); margin: 34px auto 56px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
h1 { font-size: clamp(32px, 5vw, 56px); letter-spacing: -.055em; margin: 0 0 8px; }
h2, h3 { letter-spacing: -.025em; margin-top: 0; }
.lead { color: var(--muted); font-size: 18px; line-height: 1.6; max-width: 760px; }

.hero { padding: 72px 0 34px; display: grid; gap: 22px; }
.hero h1 { font-size: clamp(54px, 10vw, 112px); line-height: .9; }
.hero p { max-width: 800px; color: var(--muted); font-size: clamp(18px, 2vw, 22px); line-height: 1.55; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }

.grid { display: grid; gap: 18px; margin: 18px 0; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card, .metric-card, .empty-state {
    background: rgba(255, 255, 255, .92);
    border: 1px solid rgba(226, 232, 240, .9);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}
.card p, .metric-card p, .empty-state p { color: var(--muted); line-height: 1.6; }
.metric-card { position: relative; overflow: hidden; }
.metric-card::after {
    content: "";
    position: absolute;
    right: -28px;
    top: -28px;
    width: 90px;
    height: 90px;
    border-radius: 999px;
    background: var(--accent-soft);
}
.metric-label { color: var(--muted); font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.metric-value { font-size: 34px; font-weight: 900; letter-spacing: -.04em; margin: 6px 0; }
.metric-hint { color: var(--muted); font-size: 14px; }

.narrow { max-width: 620px; margin: 0 auto; }
.stack { display: grid; gap: 12px; }
.oauth-buttons { display: grid; gap: 12px; margin-top: 18px; }
.section-head, .chart-controls { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.chart-controls label { min-width: 180px; }

.button, button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 11px 16px;
    background: var(--accent);
    color: #ffffff;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 10px 22px rgba(37, 99, 235, .18);
}
.button:hover { text-decoration: none; }
.button.secondary, button.secondary { background: var(--panel); color: var(--text); border-color: var(--line); box-shadow: none; }
.button.small, button.small { padding: 7px 10px; font-size: 13px; border-radius: 10px; }
.button.disabled { opacity: .45; cursor: not-allowed; }
button.danger, .danger { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(220, 38, 38, .25); box-shadow: none; }
.link-button { background: transparent; border: 0; box-shadow: none; color: var(--muted); padding: 8px 12px; }
.inline-form { display: inline; margin: 0; }

label { display: grid; gap: 6px; color: var(--muted); font-weight: 700; }
input, select {
    width: 100%;
    background: #ffffff;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    color: var(--text);
    padding: 10px 12px;
    outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

pre, code { background: #f1f5f9; border: 1px solid var(--line); border-radius: 8px; padding: 2px 6px; color: #334155; }
pre { overflow-x: auto; padding: 14px; }

.alert { border-radius: 14px; padding: 14px 16px; margin-bottom: 16px; border: 1px solid var(--line); }
.alert.success { color: var(--success); background: var(--success-soft); border-color: rgba(5, 150, 105, .24); }
.alert.error { color: var(--danger); background: var(--danger-soft); border-color: rgba(220, 38, 38, .24); }
.token-box code { display: block; word-break: break-all; padding: 12px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); font-size: 12px; font-weight: 800; }
.badge.success { background: var(--success-soft); color: var(--success); border-color: rgba(5,150,105,.2); }
.badge.warning { background: var(--warning-soft); color: var(--warning); border-color: rgba(217,119,6,.2); }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(220,38,38,.2); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; }
table { border-collapse: collapse; width: 100%; background: var(--panel); }
th, td { border-bottom: 1px solid var(--line); padding: 13px 12px; text-align: left; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th { color: var(--muted); font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .06em; background: var(--panel-2); }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-form { display: contents; }

.empty-state { text-align: center; padding: 48px 24px; }
.empty-state h1, .empty-state h2 { margin-bottom: 8px; }
.empty-state p { max-width: 560px; margin: 0 auto 18px; }
.empty-code { font-size: 76px; line-height: .9; font-weight: 950; letter-spacing: -.08em; color: var(--accent); }

.sensor-name { font-weight: 850; }
.sensor-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.temp-value { font-size: 20px; font-weight: 900; letter-spacing: -.03em; }

@media (max-width: 900px) {
    .grid.three, .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
    .grid.two, .grid.three, .grid.four { grid-template-columns: 1fr; }
    .page-head { align-items: flex-start; flex-direction: column; }
    .topbar { align-items: flex-start; gap: 12px; flex-direction: column; }
    .topbar nav { flex-wrap: wrap; }
    .hero { padding-top: 42px; }
}
@media (max-width: 640px) {
    .container { width: min(100% - 20px, 1160px); margin-top: 22px; }
    .topbar { padding: 12px 14px; }
    .topbar nav { width: 100%; gap: 6px; }
    .topbar nav a, .link-button { padding: 7px 9px; }
    .card, .metric-card, .empty-state { padding: 16px; border-radius: 16px; }
    .page-head .actions, .section-head .actions, .actions { width: 100%; }
    .actions .button, .actions button { flex: 1 1 auto; }
    .table-wrap { border: 0; overflow: visible; }
    table.responsive-table { display: block; background: transparent; }
    table.responsive-table thead { display: none; }
    table.responsive-table tbody { display: grid; gap: 12px; }
    table.responsive-table tr {
        display: grid;
        gap: 10px;
        padding: 14px;
        border: 1px solid var(--line);
        border-radius: 16px;
        background: var(--panel);
        box-shadow: 0 10px 26px rgba(15, 23, 42, .06);
    }
    table.responsive-table td {
        display: grid;
        grid-template-columns: minmax(92px, 38%) minmax(0, 1fr);
        gap: 10px;
        align-items: start;
        padding: 0;
        border: 0;
        word-break: break-word;
    }
    table.responsive-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 12px;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: .06em;
    }
    table.responsive-table td[data-label=""]::before { display: none; }
    table.responsive-table td[data-label=""] { grid-template-columns: 1fr; }
    table.responsive-table td .actions,
    table.responsive-table td form.actions { width: 100%; }
    table.responsive-table input,
    table.responsive-table select { min-width: 0; }
}
