/* ==========================================================================
   مانیتور سردخانه — قالب اختصاصی
   Bootstrap 5.3 (RTL)  +  jQuery  +  Chart.js
   همه رنگ‌ها و شعاع‌ها با متغیرهای زیر کنترل می‌شوند.
   ========================================================================== */

:root {
  --bg: #eef3f9;
  --surface: #ffffff;
  --surface-2: #f7fafd;
  --line: #e3eaf3;
  --line-strong: #d2dde9;

  --ink: #0c1a29;
  --ink-2: #31465c;
  --muted: #6b7f95;

  --brand: #0b1a2b;
  --brand-2: #132a44;
  --accent: #0e7490;
  --accent-ink: #0a5e75;
  --accent-soft: #e1f4f9;
  --ice: #38bdf8;

  --ok: #0f8a67;
  --ok-soft: #e0f6ee;
  --warn: #a96c12;
  --warn-soft: #fdf2e0;
  --danger: #c93f3f;
  --danger-soft: #fdeceb;
  --off: #64748b;
  --off-soft: #eef2f7;

  --r: 16px;
  --r-sm: 11px;
  --r-xs: 8px;

  --shadow: 0 1px 2px rgba(12, 26, 41, 0.05), 0 14px 30px -22px rgba(12, 26, 41, 0.4);
  --shadow-lg: 0 26px 60px -30px rgba(12, 26, 41, 0.45);

  --sidebar-w: 266px;
  --font: "Vazirmatn", ui-sans-serif, system-ui, sans-serif;
}

* { -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 100% -10%, #e6f2fb 0%, rgba(230, 242, 251, 0) 60%),
    var(--bg);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); }

::selection { background: #bde9f4; color: #06212b; }

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small-x { font-size: 12px; }

/* ---------------------------------------------------------------- shell -- */
.app-shell { min-height: 100vh; }

.app-main {
  margin-inline-start: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-content {
  width: 100%;
  max-width: 1480px;
  padding: 24px 28px 64px;
}

/* -------------------------------------------------------------- sidebar -- */
.sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  width: var(--sidebar-w);
  z-index: 1045;
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  background: linear-gradient(188deg, #0a1826 0%, #122a44 58%, #0d2035 100%);
  border-inline-end: 1px solid rgba(255, 255, 255, 0.06);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar::after {
  content: "";
  position: absolute;
  inset-block-start: 0;
  inset-inline: 0;
  height: 220px;
  background: radial-gradient(320px 160px at 80% 0%, rgba(56, 189, 248, 0.14), transparent 70%);
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 22px;
  position: relative;
}

.brand__mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 19px;
  color: #04222b;
  background: linear-gradient(158deg, #7dd3fc, #22d3ee 45%, #0e7490);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35), 0 8px 20px -10px rgba(34, 211, 238, 0.8);
}

.brand__name {
  font-size: 14.5px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.35;
}

.brand__sub {
  font-size: 11px;
  color: #7ea3bd;
  margin-top: 1px;
}

.nav-group {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #5d83a0;
  padding: 14px 12px 8px;
}

.nav-link-x {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 11px;
  font-size: 13.5px;
  font-weight: 500;
  color: #b7cee0;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.nav-link-x i { font-size: 15px; opacity: 0.85; }
.nav-link-x:hover { background: rgba(255, 255, 255, 0.06); color: #ffffff; }

.nav-link-x.is-active {
  color: #ffffff;
  background: linear-gradient(90deg, rgba(34, 211, 238, 0.2), rgba(34, 211, 238, 0.03));
  box-shadow: inset 0 0 0 1px rgba(34, 211, 238, 0.24);
}

.nav-link-x.is-active i { opacity: 1; }

.sidebar__foot { margin-top: auto; padding-top: 18px; }

.live-card {
  border-radius: 13px;
  padding: 12px 13px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.live-card__title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: #9ff0d6;
}

.live-card__title .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.18);
  animation: pulseDot 2s infinite;
}

.live-card__meta { font-size: 11px; color: #7ea3bd; margin-top: 5px; }
.live-card__time { font-size: 12px; color: #cfe4f3; margin-top: 3px; font-variant-numeric: tabular-nums; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 20, 32, 0.45);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 1040;
}

/* --------------------------------------------------------------- topbar -- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 28px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar__burger {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink-2);
  font-size: 17px;
}

.topbar__title { font-size: 17px; font-weight: 700; margin: 0; line-height: 1.3; }
.topbar__sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.topbar__spacer { flex: 1 1 auto; }

.live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ok);
  background: var(--ok-soft);
  padding: 5px 11px;
  border-radius: 999px;
  white-space: nowrap;
}

.live .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulseDot 2s infinite;
}

.user-chip { display: flex; align-items: center; gap: 9px; }

.user-chip__avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #0a2b38;
  background: linear-gradient(150deg, #cdeff8, #9adcef);
}

.user-chip__meta { line-height: 1.3; }
.user-chip__meta span { font-size: 12.5px; font-weight: 600; display: block; }
.user-chip__meta small { font-size: 10.5px; color: var(--muted); }

/* ------------------------------------------------------------ page head -- */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
}

.page-head__title { font-size: 21px; font-weight: 700; margin: 0; letter-spacing: -0.3px; }
.page-head__sub { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.page-head__actions { display: flex; flex-wrap: wrap; gap: 9px; }

/* -------------------------------------------------------------- surfaces -- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 20px;
  border-bottom: 1px solid var(--line);
}

.panel__title { font-size: 14.5px; font-weight: 700; margin: 0; }
.panel__sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.panel__body { padding: 20px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
  gap: 13px;
  margin-bottom: 20px;
}

/* ----------------------------------------------------------------- stats -- */
.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 15px 17px 15px 17px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 3px;
  background: var(--line-strong);
  opacity: 0.9;
}

.stat[data-tone="ok"]::before { background: var(--ok); }
.stat[data-tone="warn"]::before { background: var(--warn); }
.stat[data-tone="danger"]::before { background: var(--danger); }
.stat[data-tone="off"]::before { background: var(--off); }
.stat[data-tone="accent"]::before { background: linear-gradient(180deg, var(--ice), var(--accent)); }

.stat__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 7px;
}

.stat__label i { font-size: 12.5px; opacity: 0.8; }

.stat__value {
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.6px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.stat__unit {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  margin-inline-start: 3px;
}

.stat__meta { font-size: 11px; color: var(--muted); margin-top: 5px; }

.stat--sm { padding: 13px 15px; border-radius: 14px; }
.stat--sm .stat__value { font-size: 20px; }
.stat--sm .stat__label { font-size: 11px; margin-bottom: 5px; }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(146px, 1fr));
  gap: 11px;
}

/* ----------------------------------------------------------------- pills -- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--off-soft);
  color: var(--off);
}

.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill--ok { background: var(--ok-soft); color: var(--ok); }
.pill--warn { background: var(--warn-soft); color: var(--warn); }
.pill--danger { background: var(--danger-soft); color: var(--danger); }
.pill--off { background: var(--off-soft); color: var(--off); }
.pill--accent { background: var(--accent-soft); color: var(--accent-ink); }
.pill--plain { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }

/* --------------------------------------------------------------- toolbar -- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
}

.toolbar .field { flex: 1 1 240px; max-width: 340px; }

.field { position: relative; }

.field > i {
  position: absolute;
  inset-inline-start: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 13.5px;
  pointer-events: none;
}

.field .form-control { padding-inline-start: 36px; }

.form-control,
.form-select {
  height: 42px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  font-size: 13px;
  color: var(--ink);
  background-color: #fff;
  font-family: var(--font);
}

.form-control::placeholder { color: #9aabbc; }

.form-control:focus,
.form-select:focus {
  border-color: var(--ice);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.16);
}

.form-control-sm,
.form-select-sm { height: 36px; font-size: 12.5px; border-radius: var(--r-xs); }

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 6px;
}

.form-text { font-size: 11px; color: var(--muted); }

/* --------------------------------------------------------------- buttons -- */
.btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--r-sm);
  padding: 9px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn:active { transform: translateY(1px); }

.btn-brand {
  border: 0;
  color: #fff;
  background: linear-gradient(180deg, #12819e, #0a5e75);
  box-shadow: 0 10px 22px -14px rgba(14, 116, 144, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.btn-brand:hover { color: #fff; background: linear-gradient(180deg, #1690b0, #0a5e75); }

.btn-ghost {
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--ink-2);
}

.btn-ghost:hover { background: var(--surface-2); color: var(--ink); border-color: #bfcedd; }

.btn-quiet {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 6px 8px;
  font-size: 13px;
}

.btn-quiet:hover { color: var(--accent-ink); background: var(--accent-soft); }

.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: var(--r-xs); }

/* ------------------------------------------------------------- segmented -- */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.segmented button {
  border: 0;
  background: transparent;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 999px;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.segmented button:hover { color: var(--ink-2); }

.segmented button.is-active {
  background: #fff;
  color: var(--accent-ink);
  box-shadow: 0 1px 3px rgba(12, 26, 41, 0.14);
}

/* ----------------------------------------------------------------- table -- */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.data-table thead th {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  text-align: start;
}

.data-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  color: var(--ink-2);
}

.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: #f8fbfe; }
.data-table .t-end { text-align: end; }

.room-cell { display: flex; align-items: center; gap: 10px; }

.room-cell__icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 15px;
  color: var(--accent-ink);
  background: var(--accent-soft);
  flex: 0 0 auto;
}

.room-cell__name { font-weight: 600; color: var(--ink); line-height: 1.35; }
.room-cell__code { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------- cards -- */
.room-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.room-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }

.room-card__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.room-card__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.room-card__grid div { font-size: 11px; color: var(--muted); }
.room-card__grid b {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 13px;
}

/* ----------------------------------------------------------------- chart -- */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 14px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 15px 17px 10px;
}

.chart-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.chart-card__title { font-size: 13px; font-weight: 700; margin: 0; }
.chart-card__value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-box { position: relative; height: 208px; }

/* ------------------------------------------------------------------ misc -- */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.kv__item span { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.kv__item b { font-size: 13px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }

.empty {
  text-align: center;
  padding: 52px 20px;
  color: var(--muted);
}

.empty i { font-size: 30px; color: var(--line-strong); display: block; margin-bottom: 10px; }
.empty b { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 4px; }

.skel {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, #eef3f9 25%, #f9fcff 50%, #eef3f9 75%);
  background-size: 200% 100%;
  animation: skel 1.3s infinite linear;
}

.payload-box {
  background: #0c1a29;
  color: #cfe6f4;
  border-radius: var(--r-sm);
  padding: 14px 16px;
  font-size: 11.5px;
  line-height: 1.75;
  max-height: 260px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  direction: ltr;
  text-align: left;
}

.toast-host {
  position: fixed;
  inset-block-end: 22px;
  inset-inline-start: 22px;
  z-index: 1090;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.toast-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 12.5px;
  font-weight: 500;
  color: #eaf4fb;
  background: #0c1a29;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.26s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.toast-item.is-ok { background: #0b3f33; color: #c9f6e7; }
.toast-item.is-err { background: #4a1b1b; color: #ffd9d6; }

/* --------------------------------------------------------------- switch -- */
.form-switch .form-check-input {
  width: 38px;
  height: 21px;
  margin-inline-start: -2.6em;
  background-color: #dbe4ee;
  border-color: #d2dde9;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23fff'/%3e%3c/svg%3e");
}

.form-switch .form-check-input:checked {
  background-color: var(--accent);
  border-color: var(--accent);
}

.form-switch .form-check-input:focus {
  border-color: var(--ice);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.16);
}

.form-check-label { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }

/* ---------------------------------------------------------------- modal -- */
.modal-content {
  border: 0;
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  font-family: var(--font);
}

.modal-header { border-bottom: 1px solid var(--line); padding: 16px 20px; }
.modal-title { font-size: 15px; font-weight: 700; }
.modal-body { padding: 20px; }
.modal-footer { border-top: 1px solid var(--line); padding: 14px 20px; }
.btn-close { margin-inline-start: 0; margin-inline-end: auto; }

/* ----------------------------------------------------------- animations -- */
@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.85); }
}

@keyframes skel {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.fade-up { animation: fadeUp 0.42s cubic-bezier(0.2, 0.9, 0.3, 1) both; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ------------------------------------------------------------ responsive -- */
@media (max-width: 1199.98px) {
  .app-content { padding: 20px 20px 56px; }
  .topbar { padding: 12px 20px; }
}

@media (max-width: 991.98px) {
  .app-main { margin-inline-start: 0; }
  .sidebar { transform: translateX(100%); box-shadow: var(--shadow-lg); }
  html[dir="ltr"] .sidebar { transform: translateX(-100%); }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop.is-open { opacity: 1; pointer-events: auto; }
  .topbar__burger { display: inline-grid; place-items: center; }
  .user-chip__meta { display: none; }
  .chart-box { height: 190px; }
}

@media (max-width: 575.98px) {
  .app-content { padding: 16px 14px 48px; }
  .topbar { padding: 10px 14px; gap: 10px; }
  .topbar__title { font-size: 15px; }
  .page-head__title { font-size: 18px; }
  .stat__value { font-size: 22px; }
  .toolbar .field { max-width: none; flex: 1 1 100%; }
}
