/* ---------------- RMS Tracker overrides on top of Bootstrap 5.3 + AdminLTE 4 (dark) ---------------- */
:root {
    --rms-muted: var(--bs-secondary-color);
    --rms-border: var(--bs-border-color);
    --rms-surface: var(--bs-tertiary-bg);
    --rms-bg: var(--bs-body-bg);
    --rms-radius: var(--bs-border-radius);
    --rms-radius-lg: var(--bs-border-radius-lg);
    --rms-primary: var(--bs-primary);
    --rms-success: var(--bs-success);
    --rms-danger: var(--bs-danger);
    --rms-warning: var(--bs-warning);
    --rms-info: var(--bs-info);
}

body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

.muted { color: var(--rms-muted); }
.mono { font-family: 'Consolas', 'SFMono-Regular', monospace; font-size: .85rem; letter-spacing: .2px; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rms-border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--rms-muted); }

/* ---------------- AdminLTE shell tweaks ---------------- */
.card-header { display: flex; align-items: center; justify-content: space-between; }
.card-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.table-vcenter th, .table-vcenter td { vertical-align: middle; }
.card-table { margin-bottom: 0; }

.sidebar-brand .brand-image {
    width: 34px; height: 34px;
    background: rgba(13,110,253,.22);
    color: var(--bs-primary);
}

/* ---------------- Responsive content width ---------------- */
.app-content > .container-fluid,
.app-content-header > .container-fluid {
    max-width: 1600px;
}

/* ---------------- Live indicator ---------------- */
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bs-secondary); transition: all .3s; flex-shrink: 0; }
.live-dot.online { background: var(--bs-success); box-shadow: 0 0 10px rgba(25,135,84,.8); animation: pulse 2s infinite; }
.live-dot.error { background: var(--bs-danger); box-shadow: 0 0 10px rgba(220,53,69,.8); }
.live-label { font-size: 12px; font-weight: 600; color: var(--rms-muted); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

/* ---------------- KPI cards ---------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: 16px; }
.kpi {
    position: relative; overflow: hidden;
    background: var(--rms-bg);
    border: 1px solid var(--rms-border);
    border-radius: var(--rms-radius-lg);
    padding: 16px;
    transition: transform .15s ease, border-color .15s ease;
}
.kpi:hover { transform: translateY(-2px); border-color: var(--rms-primary); }
.kpi .kpi-ico {
    width: 40px; height: 40px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center; font-size: 19px;
    margin-bottom: 12px;
}
.kpi .kpi-label { color: var(--rms-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.kpi .kpi-value { font-size: 26px; font-weight: 800; margin-top: 2px; letter-spacing: -.5px; }
.kpi .kpi-sub { color: var(--rms-muted); font-size: 12px; margin-top: 4px; }

.ico-blue   { background: rgba(66,134,244,.16); }
.ico-green  { background: rgba(45,212,191,.16); }
.ico-amber  { background: rgba(251,191,36,.16); }
.ico-red    { background: rgba(214,69,69,.16); }
.ico-cyan   { background: rgba(0,186,224,.16); }
.ico-purple { background: rgba(151,117,250,.16); }
.ico-pink   { background: rgba(244,114,182,.16); }

/* ---------------- Status pills ---------------- */
.pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 11px; border-radius: 999px;
    font-size: 12px; font-weight: 700; white-space: nowrap;
}
.pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.running { color: var(--bs-success); background: rgba(25,135,84,.16); }
.pill.stopped { color: var(--bs-warning); background: rgba(255,193,7,.16); }
.pill.fault   { color: var(--bs-danger); background: rgba(220,53,69,.16); }
.pill.offline { color: var(--bs-secondary); background: rgba(108,117,125,.18); }
.pill.success { color: var(--bs-success); background: rgba(25,135,84,.16); }
.pill.failed  { color: var(--bs-danger); background: rgba(220,53,69,.16); }

/* ---------------- Soft badges (Tabler bg-*-lt equivalents) ---------------- */
.badge.bg-blue-lt   { color: #7aa5ff; background: rgba(66,134,244,.16); }
.badge.bg-cyan-lt   { color: #4ecfe0; background: rgba(0,186,224,.16); }
.badge.bg-green-lt  { color: #43e0c4; background: rgba(45,212,191,.16); }
.badge.bg-purple-lt { color: #c1a5ff; background: rgba(151,117,250,.16); }
.badge.bg-red-lt    { color: #ff8a8a; background: rgba(214,69,69,.16); }

/* ---------------- Charts ---------------- */
.chart-box { position: relative; height: 270px; }
.chart-box-lg { position: relative; height: 320px; }

/* ---------------- Gauges ---------------- */
.gauge-wrap { text-align: center; padding: 4px 0; }
.gauge-label { color: var(--rms-muted); font-size: 12px; font-weight: 600; margin-top: 8px; text-transform: uppercase; letter-spacing: .4px; }
.gauge-value { font-size: 22px; font-weight: 800; }
.gauge-value .unit { font-size: 12px; color: var(--rms-muted); font-weight: 600; margin-left: 2px; }

/* ---------------- Water tank ---------------- */
.tank .tank-bar {
    height: 14px; border-radius: 8px;
    background: var(--rms-surface);
    border: 1px solid var(--rms-border); overflow: hidden;
}
.tank .tank-fill {
    height: 100%; border-radius: 8px; width: 0%;
    background: linear-gradient(90deg, var(--bs-info), var(--bs-primary));
    transition: width .6s ease;
}
.tank-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--rms-muted); margin-top: 6px; }

/* ---------------- Stat strip ---------------- */
.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat-item {
    background: var(--rms-surface);
    border: 1px solid var(--rms-border);
    border-radius: var(--rms-radius);
    padding: 14px;
}
.stat-item .si-label { color: var(--rms-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; font-weight: 700; }
.stat-item .si-value { font-size: 20px; font-weight: 800; margin-top: 2px; }

/* ---------------- Device hero ---------------- */
.device-hero {
    background: linear-gradient(120deg, rgba(66,134,244,.16), rgba(151,117,250,.07) 60%, transparent),
                var(--rms-bg);
    border: 1px solid var(--rms-border);
    border-radius: var(--rms-radius-lg);
    padding: 20px 22px;
    display: flex; flex-wrap: wrap; align-items: center; gap: 18px;
}
.device-hero .dh-title { font-size: 20px; font-weight: 800; }
.device-hero .dh-sub { color: var(--rms-muted); font-size: 13px; }
.device-hero .dh-right { margin-left: auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---------------- Map ---------------- */
#map { height: 420px; border-radius: var(--rms-radius); border: 1px solid var(--rms-border); z-index: 1; }
.leaflet-container { background: #10151f; font-family: 'Inter', sans-serif; }
.leaflet-popup-content-wrapper { background: var(--rms-bg); color: var(--bs-body-color); border: 1px solid var(--rms-border); }
.leaflet-popup-tip { background: var(--rms-bg); }
.rms-marker { background: transparent; }

/* ---------------- Expandable share-log rows ---------------- */
.expandable pre {
    background: var(--rms-surface);
    border: 1px solid var(--rms-border);
    border-radius: 8px;
    padding: 10px; font-size: 11px; max-height: 200px; overflow: auto;
    color: var(--bs-info); white-space: pre-wrap; word-break: break-word;
}

/* ---------------- Ingest token / URL boxes ---------------- */
.token-box {
    background: var(--rms-surface);
    border: 1px solid var(--rms-border);
    border-radius: var(--rms-radius);
    padding: 12px;
    word-break: break-all;
}

/* ---------------- Toasts ---------------- */
#toast-root { position: fixed; top: 18px; right: 18px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; }
.toast {
    background: var(--rms-bg);
    border: 1px solid var(--rms-border);
    padding: 12px 18px; border-radius: var(--rms-radius);
    min-width: 240px; max-width: 360px;
    box-shadow: 0 8px 24px rgba(0,0,0,.35);
    animation: slideIn .25s ease; font-size: 13px;
}
.toast.success { border-left: 3px solid var(--bs-success); }
.toast.error { border-left: 3px solid var(--bs-danger); }
.toast.info { border-left: 3px solid var(--bs-primary); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------- Searchbar (inline filter forms) ---------------- */
.searchbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.searchbar .form-control { width: 260px; }
.searchbar .form-select { width: 170px; }

/* ---------------- Auth page ---------------- */
.auth-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 20px;
    background: radial-gradient(1200px 600px at 50% -10%, rgba(66,134,244,.18), transparent 60%), var(--bs-body-bg);
}
.auth-card { width: 100%; max-width: 420px; }
.auth-logo { font-size: 40px; text-align: center; margin-bottom: 6px; }

/* ---------------- Mobile off-canvas drawer (keep the header on top so the toggle stays clickable) ---------------- */
@media (max-width: 991.98px) {
    .fixed-header .app-header { z-index: 1045; }
}

/* ---------------- Mobile (<576px) ---------------- */
@media (max-width: 575.98px) {
    .searchbar { flex-direction: column; align-items: stretch; }
    .searchbar .form-control, .searchbar .form-select { width: 100%; }

    .kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
    .kpi .kpi-value { font-size: 21px; }
    .kpi .kpi-ico { width: 34px; height: 34px; font-size: 16px; margin-bottom: 8px; }

    .chart-box { height: 220px; }
    .chart-box-lg { height: 250px; }
    #map { height: 300px; }

    .device-hero { padding: 14px 16px; gap: 12px; }
    .device-hero .dh-right { margin-left: 0; width: 100%; justify-content: flex-start; }

    .card-header { flex-wrap: wrap; gap: 8px; }
    #share-form .form-select, #share-form .btn { width: 100%; }

    .stat-strip { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
    .gauge-value { font-size: 18px; }
    .app-content-header h3 { font-size: 1.1rem; }
}
