/* =========================================================
 * SmartThermo - Dark Glassmorphism Theme
 * ========================================================= */
:root {
    --bg: #0b1220;
    --glass: rgba(15, 23, 42, 0.55);
    --glass-strong: rgba(15, 23, 42, 0.75);
    --border: rgba(148, 163, 184, 0.22);
    --text: #e2e8f0;
    --muted: #94a3b8;
    --primary: #f97316;
    --primary-soft: rgba(249, 115, 22, 0.18);
    --cyan: #38bdf8;
    --ok: #22c55e;
    --warn: #facc15;
    --danger: #ef4444;
    --radius: 18px;
    --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --mono: "JetBrains Mono", ui-monospace, monospace;
}

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

html, body { margin: 0; padding: 0; }

body {
    min-height: 100vh;
    font-family: var(--font);
    color: var(--text);
    background: transparent;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.bg-layer {
    position: fixed;
    inset: 0;
    z-index: 0;
    background-image: url("../img/background.jpg");
    background-position: center center;
    background-size: cover;
    background-repeat: no-repeat;
    pointer-events: none;
}

.dashboard-page > *:not(.bg-layer) {
    position: relative;
    z-index: 1;
}

img { max-width: 100%; display: block; }
h1, h2, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

/* ---------- Glass ---------- */
.glass {
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* ---------- Animasi ---------- */
.fade-in {
    opacity: 0;
    transform: translateY(14px);
    animation: fadeIn 0.7s ease forwards;
    animation-delay: var(--delay, 0s);
}
@keyframes fadeIn { to { opacity: 1; transform: none; } }
@keyframes pulseRed {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
    50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}
@keyframes blink { 50% { opacity: 0.35; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes flowDash { to { background-position: 24px 0; } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------- Brand ---------- */
.brand-title {
    font-size: clamp(1.6rem, 3vw, 2.2rem);
    font-weight: 800;
    letter-spacing: -0.02em;
}
.brand-title span { color: var(--primary); }
.brand-slogan { color: var(--muted); font-size: 0.85rem; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 0.75rem 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 20px rgba(249, 115, 22, 0.35); }
.btn-primary:hover { background: #ea580c; }
.btn-outline { background: transparent; border-color: var(--border); }
.btn-outline:hover { background: rgba(255, 255, 255, 0.06); }
.btn-small { padding: 0.45rem 0.85rem; font-size: 0.82rem; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-ghost {
    background: transparent;
    border: 0;
    color: var(--muted);
    padding: 0 0.85rem;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
}
.btn-ghost:hover { color: var(--text); }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ---------- Form ---------- */
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
label { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
input, select {
    width: 100%;
    background: rgba(2, 6, 23, 0.55);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.7rem 0.9rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    color-scheme: dark;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input.invalid { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 0.76rem; min-height: 1em; }
.input-group { display: flex; background: rgba(2, 6, 23, 0.55); border: 1px solid var(--border); border-radius: 12px; }
.input-group:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input-group input { border: 0; background: transparent; box-shadow: none !important; }

.alert { border-radius: 12px; padding: 0.7rem 0.9rem; font-size: 0.85rem; margin-bottom: 1rem; border: 1px solid; }
.alert-danger { background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.4); color: #fecaca; }
.alert-success { background: rgba(34, 197, 94, 0.12); border-color: rgba(34, 197, 94, 0.4); color: #bbf7d0; }
.alert-info { background: rgba(56, 189, 248, 0.12); border-color: rgba(56, 189, 248, 0.4); color: #bae6fd; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.login-card {
    width: 100%;
    max-width: 420px;
    padding: 2rem 1.75rem;
    text-align: center;
    border-color: rgba(249, 115, 22, 0.35);
    box-shadow: 0 0 60px rgba(249, 115, 22, 0.12), 0 20px 50px rgba(0, 0, 0, 0.45);
}
.login-card form { text-align: left; margin-top: 1.5rem; }
.login-logos { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-bottom: 1rem; }
.login-logos img { width: 64px; height: 64px; object-fit: contain; border-radius: 12px; background: rgba(255, 255, 255, 0.92); padding: 4px; }
.login-divider { width: 1px; height: 40px; background: var(--border); }
.login-card .brand-slogan { margin-top: 0.25rem; margin-bottom: 1.25rem; }
.login-foot { margin-top: 1.25rem; font-size: 0.72rem; color: var(--muted); letter-spacing: 0.04em; }

/* ---------- Topbar ---------- */
.topbar {
    margin: 1rem auto 0;
    max-width: 1400px;
    width: calc(100% - 2rem);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
}
.topbar-brand { text-align: center; flex: 1; }
.topbar-logo { width: 56px; height: 56px; object-fit: contain; border-radius: 12px; background: rgba(255, 255, 255, 0.92); padding: 4px; flex-shrink: 0; }

.subbar {
    max-width: 1400px;
    width: calc(100% - 2rem);
    margin: 0.75rem auto 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.subbar-left, .subbar-right { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.subbar form { margin: 0; }
.pill {
    background: var(--glass-strong);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.35rem 0.85rem;
    font-size: 0.8rem;
    backdrop-filter: blur(10px);
}
#clock { font-family: var(--mono); }
.pill-warn { border-color: rgba(250, 204, 21, 0.5); color: var(--warn); }

.overheat-banner {
    max-width: 1400px;
    width: calc(100% - 2rem);
    margin: 0.75rem auto 0;
    padding: 0.75rem 1rem;
    border-radius: 14px;
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.6);
    color: #fecaca;
    font-weight: 700;
    text-align: center;
    animation: pulseRed 1.2s infinite, blink 1.2s infinite;
}

/* ---------- Layout ---------- */
.container { max-width: 1400px; width: calc(100% - 2rem); margin: 1rem auto 2rem; display: flex; flex-direction: column; gap: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid-top { grid-template-columns: 1fr; }
.grid-bottom { grid-template-columns: 1fr; }
@media (min-width: 768px) { .grid-top { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1200px) {
    .grid-top { grid-template-columns: 1.15fr 1fr 1fr 1fr; }
    .grid-bottom { grid-template-columns: 340px 1fr; }
}

.card { padding: 1.25rem; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.card-head.wrap { flex-wrap: wrap; }
.card-head h2 { font-size: 1rem; font-weight: 700; }
.tag {
    font-family: var(--mono);
    font-size: 0.7rem;
    padding: 0.2rem 0.55rem;
    border-radius: 8px;
    background: var(--primary-soft);
    color: var(--primary);
    border: 1px solid rgba(249, 115, 22, 0.35);
}

/* ---------- Metric ---------- */
.room-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.metric {
    background: rgba(2, 6, 23, 0.4);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.metric-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; }
.metric-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-temp { background: var(--primary-soft); color: var(--primary); }
.icon-hum { background: rgba(56, 189, 248, 0.15); color: var(--cyan); }
.metric-label { font-size: 0.78rem; color: var(--muted); }
.metric-value { font-family: var(--mono); font-size: 2rem; font-weight: 700; line-height: 1.1; }
.metric-value small { font-size: 0.9rem; color: var(--muted); margin-left: 0.2rem; }
.metric-value.big { font-size: 2.4rem; }
.flash { animation: flashVal 0.6s ease; }
@keyframes flashVal { 0% { color: var(--primary); } 100% { color: inherit; } }

.hum-bar { height: 6px; background: rgba(148, 163, 184, 0.2); border-radius: 99px; overflow: hidden; margin-top: auto; }
.hum-bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), #818cf8); transition: width 0.8s ease; }

.status-chip {
    align-self: flex-start;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--muted);
}
.status-chip.normal { color: var(--ok); border-color: rgba(34, 197, 94, 0.5); background: rgba(34, 197, 94, 0.12); }
.status-chip.warning { color: var(--warn); border-color: rgba(250, 204, 21, 0.5); background: rgba(250, 204, 21, 0.12); }
.status-chip.danger { color: var(--danger); border-color: rgba(239, 68, 68, 0.5); background: rgba(239, 68, 68, 0.15); animation: blink 1s infinite; }

/* ---------- Gauge ---------- */
.gauge-wrap { display: flex; flex-direction: column; align-items: center; }
.gauge { width: 100%; max-width: 260px; overflow: visible; }
.gauge-track { fill: none; stroke: rgba(148, 163, 184, 0.18); stroke-width: 14; stroke-linecap: round; }
.gauge-zone { fill: none; stroke-width: 14; transition: d 0.6s ease; }
.zone-normal { stroke: var(--ok); }
.zone-warning { stroke: var(--warn); }
.zone-danger { stroke: var(--danger); }
.gauge-needle {
    transform-origin: 100px 100px;
    transform: rotate(-90deg);
    transition: transform 1s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.gauge-needle line { stroke: #fff; stroke-width: 3; stroke-linecap: round; filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.6)); }
.gauge-hub { fill: var(--primary); stroke: #fff; stroke-width: 2; }
.gauge-min, .gauge-max { fill: var(--muted); font-size: 10px; font-family: var(--mono); text-anchor: middle; }
.gauge-readout { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; margin-top: -0.25rem; }
.gauge-readout .status-chip { align-self: center; }

.legend { list-style: none; padding: 0; margin: 0.9rem 0 0; display: flex; justify-content: center; gap: 1rem; font-size: 0.75rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 0.35rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-normal { background: var(--ok); }
.dot-warning { background: var(--warn); }
.dot-danger { background: var(--danger); }

/* ---------- Actuators ---------- */
.actuators { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.actuator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.8rem;
    border-radius: 14px;
    background: rgba(2, 6, 23, 0.4);
    border: 1px solid var(--border);
    transition: border-color 0.3s ease, background 0.3s ease;
}
.act-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: rgba(148, 163, 184, 0.12); color: var(--muted); flex-shrink: 0; }
.act-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.act-text { flex: 1; min-width: 0; }
.act-name { font-weight: 700; font-size: 0.9rem; }
.act-desc { font-size: 0.75rem; color: var(--muted); }
.badge {
    font-family: var(--mono);
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.25rem 0.6rem;
    border-radius: 8px;
    background: rgba(148, 163, 184, 0.15);
    color: var(--muted);
    min-width: 62px;
    text-align: center;
}
.actuator.on { border-color: rgba(34, 197, 94, 0.45); background: rgba(34, 197, 94, 0.08); }
.actuator.on .act-icon { background: rgba(34, 197, 94, 0.18); color: var(--ok); }
.actuator.on .badge { background: var(--ok); color: #052e16; }
.actuator.on .fan svg { animation: spin 0.9s linear infinite; }
.actuator.alarm { border-color: rgba(239, 68, 68, 0.6); background: rgba(239, 68, 68, 0.12); animation: pulseRed 1s infinite; }
.actuator.alarm .act-icon { background: rgba(239, 68, 68, 0.2); color: var(--danger); animation: blink 0.6s infinite; }
.actuator.alarm .badge { background: var(--danger); color: #fff; }

/* ---------- Network ---------- */
.net-chain { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; align-items: center; gap: 0.35rem; }
.net-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--muted);
    text-align: center;
}
.led { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.net-node.online .led { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.net-node.online { color: var(--text); }
.net-link {
    flex: 1;
    height: 3px;
    border-radius: 3px;
    margin-bottom: 1.2rem;
    background: repeating-linear-gradient(90deg, rgba(239, 68, 68, 0.6) 0 6px, transparent 6px 12px);
}
.net-link.online {
    background: repeating-linear-gradient(90deg, var(--ok) 0 8px, transparent 8px 12px);
    background-size: 24px 3px;
    animation: flowDash 0.8s linear infinite;
}
.net-info { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.net-info div { background: rgba(2, 6, 23, 0.4); border: 1px solid var(--border); border-radius: 12px; padding: 0.55rem 0.7rem; }
.net-info dt { font-size: 0.7rem; color: var(--muted); }
.net-info dd { margin: 0; font-family: var(--mono); font-size: 0.82rem; font-weight: 700; word-break: break-word; }
.txt-ok { color: var(--ok); }
.txt-danger { color: var(--danger); }
.txt-warn { color: var(--warn); }

/* ---------- Chart ---------- */
.segmented { display: inline-flex; background: rgba(2, 6, 23, 0.5); border: 1px solid var(--border); border-radius: 12px; padding: 3px; }
.seg { background: transparent; border: 0; padding: 0.4rem 0.8rem; border-radius: 9px; font-size: 0.8rem; font-weight: 600; color: var(--muted); cursor: pointer; transition: background 0.2s ease, color 0.2s ease; }
.seg.active { background: var(--primary); color: #fff; }
.chart-box { position: relative; height: 340px; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 0.9rem; }

/* ---------- Threshold ---------- */
.th-form fieldset { border: 1px solid var(--border); border-radius: 14px; padding: 0.8rem; margin: 0 0 0.75rem; display: flex; flex-direction: column; gap: 0.35rem; }
.th-form legend { padding: 0 0.35rem; font-size: 0.8rem; font-weight: 700; color: var(--primary); }
.th-form input { margin-bottom: 0.35rem; }
.form-msg { font-size: 0.8rem; min-height: 1.2em; margin-bottom: 0.5rem; }
.form-msg.error { color: var(--danger); }
.form-msg.success { color: var(--ok); }
#th-updated { margin-top: 0.6rem; text-align: center; }

/* ---------- Log table ---------- */
.log-filters { display: grid; grid-template-columns: 1fr; gap: 0 0.75rem; }
@media (min-width: 640px) { .log-filters { grid-template-columns: 2fr 1fr 1fr 0.8fr; } }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 14px; }
.log-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; min-width: 720px; }
.log-table th, .log-table td { padding: 0.6rem 0.75rem; text-align: left; white-space: nowrap; }
.log-table thead th { background: rgba(2, 6, 23, 0.65); color: var(--muted); font-weight: 600; font-size: 0.75rem; position: sticky; top: 0; }
.log-table tbody tr { border-top: 1px solid rgba(148, 163, 184, 0.1); transition: background 0.2s ease; }
.log-table tbody tr:hover { background: rgba(255, 255, 255, 0.04); }
.log-table td.num { font-family: var(--mono); }
.log-table td.empty { text-align: center; color: var(--muted); padding: 2rem; }
.mini { font-family: var(--mono); font-size: 0.7rem; font-weight: 700; padding: 0.15rem 0.45rem; border-radius: 6px; }
.mini.on { background: rgba(34, 197, 94, 0.18); color: var(--ok); }
.mini.off { background: rgba(148, 163, 184, 0.15); color: var(--muted); }
.mini.alarm { background: rgba(239, 68, 68, 0.2); color: var(--danger); }

.pager { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-top: 0.9rem; }
.pager-btns { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.pager-btns button {
    min-width: 34px;
    height: 34px;
    padding: 0 0.6rem;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: rgba(2, 6, 23, 0.45);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
}
.pager-btns button:hover:not(:disabled) { border-color: var(--primary); }
.pager-btns button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager-btns button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Toast & Footer ---------- */
.toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 50;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    background: var(--glass-strong);
    border: 1px solid var(--border);
    backdrop-filter: blur(12px);
    font-size: 0.85rem;
    animation: fadeIn 0.3s ease forwards;
}
.toast.success { border-color: rgba(34, 197, 94, 0.6); }
.toast.error { border-color: rgba(239, 68, 68, 0.6); }
.footer { text-align: center; color: var(--muted); font-size: 0.75rem; padding: 1rem 0 0; }

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
    .topbar { padding: 0.7rem; gap: 0.5rem; }
    .topbar-logo { width: 42px; height: 42px; }
    .brand-slogan { font-size: 0.7rem; }
    .room-metrics { grid-template-columns: 1fr; }
    .metric-value { font-size: 1.7rem; }
    .chart-box { height: 280px; }
}
