/* ==========================================================================
   ISENS – theme derived from the logo (indigo → blue → teal)
   ========================================================================== */
:root {
    --brand-indigo: #2E3192;
    --brand-blue:   #3559A3;
    --brand-teal:   #2FACB6;
    --brand-teal-2: #3FC1C0;
    --brand-grad:   linear-gradient(120deg, #2E3192 0%, #3559A3 50%, #2FACB6 100%);
    --brand-grad-soft: linear-gradient(120deg, rgba(46,49,146,.08), rgba(47,172,182,.10));

    --bg:        #F3F6FB;
    --surface:   #FFFFFF;
    --ink:       #1B2140;
    --ink-2:     #4A5272;
    --muted:     #8A91AA;
    --line:      #E7EBF3;

    --ok:     #1FA971;
    --warn:   #E8A317;
    --danger: #E5484D;
    --temp:   #F06A3B;
    --hum:    #2FACB6;

    --radius: 16px;
    --shadow: 0 1px 2px rgba(27,33,64,.04), 0 6px 24px rgba(27,33,64,.06);
    --sidebar-w: 256px;

    --bs-primary: #2E3192;
    --bs-primary-rgb: 46,49,146;
    --bs-link-color: #2E3192;
    --bs-link-color-rgb: 46,49,146;
    --bs-link-hover-color: #2FACB6;
    --bs-body-font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --bs-body-color: var(--ink);
    --bs-body-bg: var(--bg);
    --bs-border-color: var(--line);
}

body { background: var(--bg); color: var(--ink); font-size: .92rem; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, h5, .brand-font { font-family: "Montserrat", var(--bs-body-font-family); }
a { text-decoration: none; }
.text-muted { color: var(--muted) !important; }
.text-brand { color: var(--brand-indigo) !important; }
.text-gradient { background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
    background: var(--surface); border-right: 1px solid var(--line);
    position: fixed; inset: 0 auto 0 0; z-index: 1040;
    display: flex; flex-direction: column; padding: 18px 14px;
    transition: transform .25s ease;
}
.sidebar-brand { padding: 4px 10px 18px; border-bottom: 1px dashed var(--line); margin-bottom: 14px; }
.brand-logo { height: 52px; width: auto; display: block; }
.sidebar-caption { font-size: .68rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); padding: 4px 12px 8px; font-weight: 600; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item-link {
    display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px;
    color: var(--ink-2); font-weight: 600; font-size: .9rem; transition: background .15s, color .15s;
}
.nav-item-link i { font-size: 1.1rem; color: var(--muted); transition: color .15s; }
.nav-item-link:hover { background: var(--brand-grad-soft); color: var(--brand-indigo); }
.nav-item-link:hover i { color: var(--brand-teal); }
.nav-item-link.active { background: var(--brand-grad); color: #fff; box-shadow: 0 8px 20px -8px rgba(46,49,146,.55); }
.nav-item-link.active i { color: #fff; }
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: .7rem; border-radius: 999px; padding: 1px 8px; }
.nav-item-link.active .nav-badge { background: rgba(255,255,255,.25); }
.sidebar-status { margin-top: auto; background: var(--brand-grad-soft); border-radius: 14px; padding: 12px 14px; }

.pulse-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; position: relative; flex: 0 0 10px; }
.pulse-dot.ok { background: var(--ok); box-shadow: 0 0 0 0 rgba(31,169,113,.6); animation: pulse 2s infinite; }
.pulse-dot.bad { background: var(--danger); }
.pulse-dot.idle { background: #C3C8D8; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(31,169,113,.55); } 70% { box-shadow: 0 0 0 8px rgba(31,169,113,0); } 100% { box-shadow: 0 0 0 0 rgba(31,169,113,0); } }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; gap: 12px;
    background: rgba(243,246,251,.85); backdrop-filter: blur(10px);
    padding: 16px 28px; border-bottom: 1px solid transparent;
}
.topbar-title h1 { font-size: 1.35rem; font-weight: 800; margin: 0; color: var(--ink); }
.topbar-title p { margin: 2px 0 0; color: var(--muted); font-size: .82rem; }
.topbar-clock { align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-size: .8rem; color: var(--ink-2); font-weight: 600; }
.topbar-clock i { color: var(--brand-teal); }
.btn-icon { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); padding: 0; }
.btn-icon:hover { color: var(--brand-indigo); border-color: #cfd6e6; }
.dot-badge { position: absolute; top: -5px; right: -6px; background: var(--danger); color: #fff; font-size: .65rem; font-weight: 700; border-radius: 999px; padding: 1px 6px; border: 2px solid var(--bg); }
.user-chip { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px 4px 4px; font-weight: 600; color: var(--ink); font-size: .85rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-grad); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-family: Montserrat, sans-serif; }
.content { padding: 8px 28px 28px; flex: 1; }
.app-footer { display: flex; justify-content: space-between; padding: 14px 28px; color: var(--muted); font-size: .75rem; border-top: 1px solid var(--line); }

.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.15); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(27,33,64,.35); z-index: 1035; }
    .main { margin-left: 0; }
    .topbar { padding: 12px 16px; }
    .content { padding: 8px 16px 20px; }
    .app-footer { padding: 12px 16px; }
}

/* ---------- Cards ---------- */
.card-x { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-x .card-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-x .card-head h5 { margin: 0; font-size: .98rem; font-weight: 700; }
.card-x .card-head .sub { color: var(--muted); font-size: .78rem; }
.card-x .card-body-x { padding: 18px 20px; }
.head-icon { width: 34px; height: 34px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; background: var(--brand-grad-soft); color: var(--brand-indigo); }

/* KPI tiles */
.kpi { position: relative; overflow: hidden; padding: 18px 20px; }
.kpi .kpi-label { color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.kpi .kpi-value { font-family: Montserrat, sans-serif; font-weight: 800; font-size: 2rem; line-height: 1.15; margin-top: 6px; color: var(--ink); }
.kpi .kpi-value small { font-size: 1rem; font-weight: 700; color: var(--ink-2); }
.kpi .kpi-foot { font-size: .78rem; color: var(--ink-2); margin-top: 6px; }
.kpi .kpi-icon { position: absolute; right: 16px; top: 16px; width: 44px; height: 44px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; }
.kpi.hero { background: var(--brand-grad); border: 0; color: #fff; }
.kpi.hero .kpi-label, .kpi.hero .kpi-foot, .kpi.hero .kpi-value, .kpi.hero .kpi-value small { color: #fff; }
.kpi.hero .kpi-label { opacity: .8; }
.kpi.hero .kpi-icon { background: rgba(255,255,255,.18); color: #fff; }
.kpi.hero::after { content: ""; position: absolute; right: -40px; bottom: -60px; width: 180px; height: 180px; border-radius: 50%; border: 26px solid rgba(255,255,255,.08); }
.ic-temp { background: rgba(240,106,59,.12); color: var(--temp); }
.ic-hum  { background: rgba(47,172,182,.14); color: var(--hum); }
.ic-ok   { background: rgba(31,169,113,.12); color: var(--ok); }
.ic-bad  { background: rgba(229,72,77,.12); color: var(--danger); }
.ic-brand{ background: var(--brand-grad-soft); color: var(--brand-indigo); }

/* Live sensor tiles */
.sensor-tile { padding: 16px 18px; height: 100%; transition: transform .15s, box-shadow .15s; border-top: 3px solid transparent; }
.sensor-tile:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(27,33,64,.09); }
.sensor-tile.state-ok { border-top-color: var(--brand-teal); }
.sensor-tile.state-alarm { border-top-color: var(--danger); background: linear-gradient(180deg, rgba(229,72,77,.04), #fff 60%); }
.sensor-tile.state-offline { border-top-color: #C3C8D8; opacity: .85; }
.sensor-tile .s-name { font-weight: 700; font-size: .95rem; }
.sensor-tile .s-loc { color: var(--muted); font-size: .76rem; }
.sensor-tile .s-reading { display: flex; gap: 18px; margin: 12px 0 10px; }
.sensor-tile .s-val { font-family: Montserrat, sans-serif; font-size: 1.6rem; font-weight: 800; line-height: 1; }
.sensor-tile .s-val small { font-size: .85rem; font-weight: 700; color: var(--ink-2); margin-left: 1px; }
.sensor-tile .s-cap { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-top: 4px; }
.sensor-tile .s-temp { color: var(--temp); }
.sensor-tile .s-hum { color: var(--hum); }
.sensor-tile .val-alarm { color: var(--danger) !important; }
.sensor-tile .s-meta { display: flex; justify-content: space-between; align-items: center; font-size: .75rem; color: var(--ink-2); border-top: 1px dashed var(--line); padding-top: 10px; gap: 8px; }

/* Status pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-ok { background: rgba(31,169,113,.12); color: var(--ok); }
.pill-bad { background: rgba(229,72,77,.12); color: var(--danger); }
.pill-warn { background: rgba(232,163,23,.14); color: #B57B00; }
.pill-idle { background: #EEF0F6; color: var(--muted); }
.pill.no-dot::before { display: none; }

/* Battery meter */
.batt { display: inline-flex; align-items: center; gap: 8px; min-width: 120px; }
.batt-bar { flex: 1; height: 8px; border-radius: 99px; background: #EEF0F6; overflow: hidden; min-width: 60px; }
.batt-bar > span { display: block; height: 100%; border-radius: 99px; }
.batt-success > span { background: linear-gradient(90deg, #1FA971, #3FC1C0); }
.batt-warning > span { background: linear-gradient(90deg, #E8A317, #F3C55A); }
.batt-danger > span { background: linear-gradient(90deg, #E5484D, #F07C7F); }
.batt-secondary > span { background: #C3C8D8; }
.batt-num { font-weight: 700; font-size: .8rem; min-width: 36px; text-align: right; }

/* Tables */
.table-x { margin: 0; --bs-table-bg: transparent; }
.table-x thead th { background: #F7F9FC; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; border-bottom: 1px solid var(--line); padding: 11px 14px; white-space: nowrap; }
.table-x tbody td { padding: 12px 14px; vertical-align: middle; border-color: var(--line); }
.table-x tbody tr:hover td { background: #FAFBFE; }
.table-x .mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; color: var(--ink-2); }
.cell-title { font-weight: 700; color: var(--ink); }
.cell-sub { font-size: .75rem; color: var(--muted); }
.out-range { color: var(--danger); font-weight: 700; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state i { font-size: 2.4rem; display: block; margin-bottom: 8px; background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* Buttons & forms */
.btn { border-radius: 11px; font-weight: 600; font-size: .86rem; padding: .5rem 1rem; }
.btn-brand { background: var(--brand-grad); color: #fff; border: 0; box-shadow: 0 6px 16px -6px rgba(46,49,146,.55); }
.btn-brand:hover, .btn-brand:focus { color: #fff; filter: brightness(1.07); }
.btn-soft { background: var(--brand-grad-soft); color: var(--brand-indigo); border: 0; }
.btn-soft:hover { background: rgba(46,49,146,.14); color: var(--brand-indigo); }
.btn-light-x { background: #fff; border: 1px solid var(--line); color: var(--ink-2); }
.btn-light-x:hover { border-color: #cfd6e6; color: var(--brand-indigo); }
.btn-act { width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 9px; }
.form-control, .form-select { border-radius: 11px; border-color: var(--line); padding: .55rem .8rem; font-size: .88rem; }
.form-control:focus, .form-select:focus { border-color: var(--brand-teal); box-shadow: 0 0 0 .2rem rgba(47,172,182,.18); }
.form-label { font-weight: 600; font-size: .8rem; color: var(--ink-2); margin-bottom: .35rem; }
.form-text { font-size: .74rem; }
.form-check-input:checked { background-color: var(--brand-indigo); border-color: var(--brand-indigo); }
.input-group-text { border-radius: 11px; border-color: var(--line); background: #F7F9FC; color: var(--muted); font-size: .85rem; }
.modal-content { border: 0; border-radius: 18px; }
.modal-header { border-bottom: 1px solid var(--line); padding: 18px 22px; }
.modal-header .modal-title { font-weight: 800; font-size: 1.05rem; }
.modal-body { padding: 20px 22px; }
.modal-footer { border-top: 1px solid var(--line); padding: 14px 22px; }
.section-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; color: var(--brand-teal); font-weight: 700; margin: 6px 0 10px; }

/* Segmented control */
.seg { display: inline-flex; background: #EEF1F7; border-radius: 11px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 9px; font-size: .78rem; font-weight: 700; color: var(--ink-2); }
.seg button.active { background: #fff; color: var(--brand-indigo); box-shadow: 0 1px 4px rgba(27,33,64,.12); }

/* Settings tabs */
.settings-nav .nav-link { color: var(--ink-2); font-weight: 600; border-radius: 12px; padding: 10px 14px; display: flex; align-items: center; gap: 10px; font-size: .88rem; }
.settings-nav .nav-link i { color: var(--muted); }
.settings-nav .nav-link.active { background: var(--brand-grad); color: #fff; }
.settings-nav .nav-link.active i { color: #fff; }

/* Alerts list */
.alert-row { display: flex; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.alert-row:last-child { border-bottom: 0; }
.alert-ic { width: 36px; height: 36px; border-radius: 11px; display: flex; align-items: center; justify-content: center; flex: 0 0 36px; }
.alert-row .a-msg { font-weight: 600; font-size: .85rem; }
.alert-row .a-meta { font-size: .74rem; color: var(--muted); }

/* Login */
.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--surface); }
.login-art { background: var(--brand-grad); position: relative; overflow: hidden; color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: flex-end; }
.login-art::before, .login-art::after { content: ""; position: absolute; border-radius: 50%; border: 40px solid rgba(255,255,255,.07); }
.login-art::before { width: 520px; height: 520px; top: -160px; right: -160px; }
.login-art::after { width: 300px; height: 300px; bottom: 120px; left: -120px; }
.login-art h2 { font-weight: 800; font-size: 2.2rem; line-height: 1.2; position: relative; }
.login-art p { opacity: .85; max-width: 440px; position: relative; }
.login-icon { width: 96px; position: relative; margin-bottom: 26px; filter: drop-shadow(0 10px 20px rgba(0,0,0,.2)); border-radius: 50%; background:#fff; padding: 6px; }
.login-form-wrap { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.login-card { width: 100%; max-width: 380px; }
.login-stats { display: flex; gap: 28px; margin-top: 28px; position: relative; }
.login-stats div { font-size: .8rem; opacity: .85; }
.login-stats b { display: block; font-size: 1.3rem; font-family: Montserrat, sans-serif; opacity: 1; }
@media (max-width: 860px) { .login-page { grid-template-columns: 1fr; } .login-art { display: none; } }

.chart-box { position: relative; height: 300px; }
.chart-box.sm { height: 240px; }
.refresh-ind { font-size: .75rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.spin { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.fade-in { animation: fadeIn .35s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.toast { border: 0; border-radius: 14px; box-shadow: 0 10px 30px rgba(27,33,64,.18); }
pre.log-box { background: #0F1530; color: #CFE9F1; border-radius: 12px; padding: 14px; font-size: .75rem; max-height: 320px; overflow: auto; white-space: pre-wrap; }
.pagination { --bs-pagination-active-bg: #2E3192; --bs-pagination-active-border-color: #2E3192; --bs-pagination-color: #3559A3; --bs-pagination-border-radius: 9px; }
