:root {
    --bg: #f5f7fb;
    --surface: rgba(255, 255, 255, 0.82);
    --line: rgba(18, 24, 38, 0.1);
    --text: #111827;
    --muted: #667085;
    --blue: #007aff;
    --green: #32d583;
    --amber: #fdb022;
    --red: #f04438;
    --shadow: 0 22px 60px rgba(31, 41, 55, 0.12);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at 18% 8%, rgba(0, 122, 255, 0.16), transparent 28%),
        linear-gradient(135deg, #f8fbff 0%, #eef3f9 45%, #ffffff 100%);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", sans-serif;
}

a { color: inherit; text-decoration: none; }
.sidebar {
    position: fixed;
    inset: 20px auto 20px 20px;
    width: 220px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.62);
    backdrop-filter: blur(24px);
    box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(150deg, #007aff, #34c759); }
nav { display: grid; gap: 6px; }
nav a, .tabs a, .secondary {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--muted);
}
nav a { justify-content: flex-start; }
nav a.active, .tabs a.active {
    color: var(--text);
    background: rgba(255, 255, 255, 0.9);
    border-color: var(--line);
}
.account { margin-top: auto; display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.account span { color: var(--text); font-weight: 700; }
.main { margin-left: 260px; padding: 28px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.eyebrow { color: var(--blue); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0; }
h1, h2, p { margin: 0; }
h1 { font-size: 38px; line-height: 1.08; }
h2 { font-size: 18px; }
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.metric, .panel, .login-panel, .weather-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    backdrop-filter: blur(24px);
    box-shadow: var(--shadow);
}
.metric { padding: 22px; display: grid; gap: 8px; min-height: 146px; }
.metric span, .metric small, .muted { color: var(--muted); }
.metric strong { font-size: 40px; line-height: 1; }
.metric.normal strong { color: var(--green); }
.metric.warning strong { color: var(--amber); }
.metric.critical strong, .danger { color: var(--red); }
.split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr); gap: 14px; }
.panel { padding: 18px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.list { display: grid; gap: 10px; }
.list-row { display: flex; align-items: flex-start; gap: 10px; padding: 12px; border-radius: 8px; background: rgba(255,255,255,.62); }
.list-row div { display: grid; gap: 4px; }
.list-row small { color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 999px; margin-top: 6px; background: var(--green); flex: 0 0 auto; }
.dot.warning { background: var(--amber); }
.dot.critical { background: var(--red); }
button, .primary {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    padding: 0 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--blue);
    color: white;
    font-weight: 800;
    cursor: pointer;
}
.compact { min-height: 38px; }
.secondary { border-color: var(--line); background: rgba(255,255,255,.7); color: var(--text); }
.form-stack { display: grid; gap: 12px; }
label { display: grid; gap: 7px; color: var(--muted); font-weight: 700; }
input, select {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    background: rgba(255,255,255,.9);
    color: var(--text);
    font: inherit;
}
.form-error { color: var(--red); font-weight: 700; }
.login-shell { min-height: calc(100vh - 56px); display: grid; place-items: center; }
.login-panel { width: min(920px, 100%); display: grid; grid-template-columns: 1fr 360px; gap: 28px; padding: 34px; }
.login-copy { display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.login-copy h1 { font-size: 58px; }
.login-copy p { color: var(--muted); font-size: 18px; max-width: 440px; }
.camera-panel { min-height: 520px; padding: 0; overflow: hidden; background: #111827; }
.camera-panel img, .camera-panel iframe { width: 100%; height: 100%; min-height: 520px; object-fit: cover; border: 0; display: block; }
.camera-empty { min-height: 520px; display: grid; place-content: center; gap: 8px; color: white; text-align: center; padding: 24px; }
.camera-empty strong { font-size: 22px; }
.camera-empty span { color: rgba(255,255,255,.72); }
.threshold-grid { display: grid; grid-template-columns: repeat(3, 1fr) auto; gap: 12px; align-items: end; }
.settings-stack { display: grid; gap: 14px; }
.user-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 12px; align-items: end; margin-bottom: 18px; }
.camera-credentials { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.compact-table { font-size: 14px; }
.weather-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.weather-card { padding: 16px; display: grid; gap: 8px; }
.weather-card span { font-size: 24px; font-weight: 800; color: var(--blue); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 6px; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.62); }
canvas { width: 100%; max-height: 360px; }

@media (max-width: 900px) {
    .sidebar { position: static; width: auto; margin: 12px; }
    .main { margin: 0; padding: 12px; }
    nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .metric-grid, .split, .login-panel, .threshold-grid, .user-grid { grid-template-columns: 1fr; }
    .page-head { align-items: flex-start; flex-direction: column; }
    h1 { font-size: 32px; }
    .login-copy h1 { font-size: 44px; }
    .tabs { width: 100%; overflow-x: auto; }
}
