:root {
  --bg: #edf1f7;
  --bg-grad-1: rgba(67, 102, 255, 0.11);
  --bg-grad-2: rgba(85, 208, 255, 0.12);
  --card: #f8fafc;
  --panel: rgba(255,255,255,0.75);
  --border: #dbe4f0;
  --line: #e7edf5;
  --text: #1f2f58;
  --muted: #8997b4;
  --primary: #2f5cff;
  --primary-soft: #e8eeff;
  --green: #33b864;
  --green-soft: #e4f6ea;
  --red: #ef6b6b;
  --red-soft: #faebeb;
  --purple: #7865f7;
  --purple-soft: #efecff;
  --gray-soft: #eff3f8;
  --shadow: 0 18px 40px rgba(48, 76, 140, 0.08);
  --radius-xl: 22px;
  --radius-lg: 18px;
  --radius-md: 14px;
}

html[data-theme="dark"] {
  --bg: #111827;
  --bg-grad-1: rgba(59,130,246,.2);
  --bg-grad-2: rgba(16,185,129,.15);
  --card: #172033;
  --panel: rgba(23,32,51,.9);
  --border: #29364f;
  --line: #273348;
  --text: #eff5ff;
  --muted: #96a5c3;
  --primary-soft: rgba(47,92,255,.18);
  --green-soft: rgba(51,184,100,.18);
  --red-soft: rgba(239,107,107,.17);
  --purple-soft: rgba(120,101,247,.18);
  --gray-soft: rgba(255,255,255,.04);
  --shadow: 0 18px 44px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Tahoma, "Segoe UI", Arial, sans-serif;
  font-variant-numeric: lining-nums tabular-nums;
  direction: rtl;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 18%, var(--bg-grad-1), transparent 22%),
    radial-gradient(circle at 88% 10%, var(--bg-grad-2), transparent 26%),
    var(--bg);
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }

.esm-topbar {
  width: calc(100% - 32px);
  margin: 16px auto 0;
  min-height: 74px;
  padding: 14px 24px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.esm-topbar-title {
  margin: 0;
  justify-self: center;
  color: var(--primary);
  font-size: 28px;
  font-weight: 800;
}
.esm-topbar-actions {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 14px;
  direction: rtl;
}
.esm-brand-mark {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 16px;
  direction: ltr;
}
.esm-brand-name { font-size: 25px; font-weight: 800; letter-spacing: 11px; padding-left: 10px; }
.esm-brand-sub { font-size: 12px; color: var(--muted); letter-spacing: 4px; margin-top: 6px; }
.esm-brand-name--small { font-size: 16px; letter-spacing: 8px; padding-left: 8px; }
.esm-brand-sub--small { font-size: 10px; letter-spacing: 2px; }
.esm-brand-dots { display: grid; grid-template-columns: repeat(3, 9px); gap: 6px; }
.esm-brand-dots span { width: 9px; height: 9px; background: var(--primary); border-radius: 999px; display: block; }
.esm-brand-dots--small { grid-template-columns: repeat(3, 7px); gap: 5px; }
.esm-brand-dots--small span { width: 7px; height: 7px; }

.esm-soft-btn {
  min-height: 40px;
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid #ced8e8;
  background: linear-gradient(180deg, rgba(255,255,255,.95), rgba(240,244,250,.95));
  color: var(--text);
  display: inline-flex; align-items: center; gap: 8px;
}
.esm-theme-btn { width: 48px; justify-content: center; padding: 0; color: #f6b11a; font-size: 20px; }
.esm-btn-icon svg { width: 18px; height: 18px; stroke: var(--primary); fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.esm-mobile-menu-toggle { display: none; position: fixed; top: 22px; right: 18px; z-index: 60; width: 46px; height: 46px; border: 0; border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); }
.esm-mobile-menu-toggle span { display: block; width: 22px; height: 2px; background: var(--primary); margin: 5px auto; }

.esm-app-shell {
  width: calc(100% - 32px);
  margin: 14px auto 24px;
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.esm-sidebar {
  position: sticky;
  top: 14px;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 120px);
  padding: 16px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.esm-sidebar-brand { text-align: center; padding: 8px 0 18px; display: grid; gap: 10px; justify-items: center; }
.esm-sidebar-brand-text { text-align: center; }
.esm-sidebar-nav { display: grid; gap: 12px; }
.esm-nav-link {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 14px 8px;
  border-radius: 18px;
  color: var(--muted);
  border: 1px solid transparent;
}
.esm-nav-link.active { background: var(--primary-soft); color: var(--primary); border-color: #dce5ff; font-weight: 700; }
.esm-nav-link.is-disabled { opacity: 0.6; cursor: default; }
.esm-nav-link small { font-size: 11px; }
.esm-nav-link--button { width: 100%; background: transparent; }
.esm-sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); }
.esm-nav-icon { width: 26px; height: 26px; position: relative; display: block; }
.esm-nav-text { font-size: 14px; }
.esm-icon-grid::before, .esm-icon-grid::after, .esm-icon-device::before, .esm-icon-scenario::before, .esm-icon-report::before, .esm-icon-settings::before, .esm-icon-logout::before { content: ''; position: absolute; inset: 0; }
.esm-icon-grid::before { border: 2px solid var(--primary); border-radius: 8px; box-shadow: 10px 0 0 -8px var(--primary), 0 10px 0 -8px var(--primary), 10px 10px 0 -8px var(--primary); width: 8px; height: 8px; top: 2px; right: 2px; }
.esm-icon-device::before { width: 18px; height: 20px; border: 2px solid currentColor; border-radius: 5px; top: 2px; right: 4px; }
.esm-icon-device::after { content:''; position:absolute; width:8px; height:2px; background: currentColor; top: 7px; right: 9px; box-shadow: 0 5px 0 currentColor; }
.esm-icon-scenario::before { width: 8px; height: 8px; border: 2px solid currentColor; border-radius: 50%; top: 9px; right: 2px; box-shadow: 14px -8px 0 -2px transparent, 14px 8px 0 -2px transparent; }
.esm-icon-scenario::after { content:''; position:absolute; width:16px; height:2px; background: currentColor; top: 12px; right: 5px; transform: rotate(-18deg); box-shadow: 0 8px 0 currentColor; }
.esm-icon-report::before { width: 4px; height: 18px; background: currentColor; right: 5px; bottom: 2px; box-shadow: 8px -4px 0 currentColor, 16px -10px 0 currentColor; border-radius: 3px; }
.esm-icon-settings::before { width: 18px; height: 18px; border: 2px solid currentColor; border-radius: 50%; top: 4px; right: 4px; }
.esm-icon-settings::after { content:''; position:absolute; width:4px; height:4px; background: currentColor; border-radius:50%; top:11px; right:11px; box-shadow: 0 -12px 0 currentColor, 0 12px 0 currentColor, 12px 0 0 currentColor, -12px 0 0 currentColor; }
.esm-icon-logout::before { width: 16px; height: 16px; border: 2px solid currentColor; border-left: 0; border-radius: 4px; top: 5px; right: 7px; }
.esm-icon-logout::after { content:''; position:absolute; width: 12px; height: 2px; background: currentColor; top: 12px; right: 4px; box-shadow: -4px -4px 0 -1px transparent; }

.esm-sidebar-overlay { display: none; }
.esm-content-area { min-width: 0; }

.esm-welcome-card {
  min-height: 122px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 22px;
  padding: 14px 28px;
  margin-bottom: 18px;
}
.esm-welcome-icon { flex: 0 0 auto; }
.esm-icon-surface {
  width: 76px; height: 76px; border-radius: 18px; background: var(--primary-soft); border: 1px solid #d7e3ff; display: grid; place-items: center;
}
.esm-icon-grid-sm { width: 28px; height: 28px; display: grid; grid-template-columns: repeat(4,1fr); gap: 2px; }
.esm-icon-grid-sm::before { content: ''; width: 100%; height: 100%; display: block; }
.esm-icon-grid-sm { background:
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 0 0 / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 33% 0 / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 66% 0 / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 100% 0 / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 0 33% / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 33% 33% / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 66% 33% / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 100% 33% / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 0 66% / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 33% 66% / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 66% 66% / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 100% 66% / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 0 100% / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 33% 100% / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 66% 100% / 25% 25%,
  radial-gradient(circle, var(--primary) 45%, transparent 48%) 100% 100% / 25% 25%;
  background-repeat: no-repeat;
}
.esm-welcome-text { text-align: right; }
.esm-welcome-text h2 { margin: 0 0 8px; color: var(--primary); font-size: 34px; font-weight: 800; }
.esm-welcome-text p { margin: 0; color: var(--muted); font-size: 16px; }

.esm-stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.esm-stat-card, .esm-panel, .esm-welcome-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.esm-stat-card { min-height: 136px; padding: 24px 24px; display: flex; align-items: center; justify-content: space-between; }
.esm-stat-copy h3 { margin: 0 0 10px; font-size: 18px; }
.esm-stat-copy strong { display:block; font-size: 28px; line-height: 1; margin-bottom: 10px; }
.esm-stat-copy p { margin:0; color: var(--muted); font-size: 14px; }
.esm-stat-icon { width: 72px; height: 72px; border-radius: 18px; }
.esm-stat-icon--blue { background: var(--primary-soft); position: relative; }
.esm-stat-icon--blue::before { content:''; position:absolute; width:24px; height:20px; border: 2px solid var(--primary); border-radius: 4px; top:24px; right:24px; }
.esm-stat-icon--green { background: var(--green-soft); position: relative; }
.esm-stat-icon--green::before { content:''; position:absolute; width: 28px; height: 22px; right: 22px; top: 26px; border-bottom: 4px solid var(--green); border-left: 4px solid transparent; border-right: 4px solid transparent; border-radius: 50%; transform: rotate(0deg); }
.esm-stat-icon--green::after { content:''; position:absolute; width: 8px; height: 8px; background: var(--green); border-radius: 50%; right: 34px; top: 36px; box-shadow: -12px 4px 0 var(--green), 12px 4px 0 var(--green); }
.esm-stat-icon--purple { background: var(--purple-soft); position: relative; }
.esm-stat-icon--purple::before { content:''; position:absolute; width: 12px; height: 12px; border: 3px solid var(--purple); border-radius: 50%; right: 18px; top: 30px; box-shadow: 22px 0 0 -3px transparent; }
.esm-stat-icon--purple::after { content:''; position:absolute; width: 28px; height: 3px; background: var(--purple); right: 22px; top: 35px; box-shadow: -16px 0 0 var(--purple); }
.esm-stat-icon--red { background: var(--red-soft); position: relative; }
.esm-stat-icon--red::before { content:'⚡'; position:absolute; right: 24px; top: 14px; color: var(--red); font-size: 34px; }

.esm-middle-grid { display: grid; grid-template-columns: 1.12fr 1.1fr 0.96fr; gap: 16px; margin-bottom: 18px; }
.esm-panel { padding: 18px 18px 16px; }
.esm-panel-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.esm-panel-header h3 { margin: 0; font-size: 18px; }
.esm-mini-icon, .esm-link-mark, .esm-bolt-mark {
  width: 28px; height: 28px; border-radius: 9px; background: var(--primary-soft); border: 1px solid #dce5ff; display: inline-flex; align-items: center; justify-content: center;
}
.esm-link-mark::before { content:''; width: 14px; height: 6px; border: 3px solid var(--primary); border-radius: 999px; }
.esm-bolt-mark::before { content:'⚡'; color: var(--primary); }
.esm-mini-icon::before { content:''; width:12px; height:12px; border: 2px solid var(--primary); box-shadow: 8px 0 0 -2px var(--primary), 0 8px 0 -2px var(--primary), 8px 8px 0 -2px var(--primary); }

.esm-devices-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.esm-devices-table th, .esm-devices-table td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: right; }
.esm-devices-table thead th { color: var(--muted); font-size: 13px; font-weight: 700; }
.esm-chip { display:inline-flex; padding: 6px 10px; background: var(--gray-soft); border: 1px solid var(--border); border-radius: 12px; font-size: 13px; direction:ltr; }
.esm-status-label { display:inline-flex; align-items:center; gap:8px; }
.esm-status-label::before { content:''; width: 10px; height: 10px; border-radius: 50%; background: #9aa5b1; }
.esm-status-label.online::before { background: var(--green); }
.esm-status-label.offline::before { background: #98a4b8; }
.esm-device-title-row { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.esm-device-mini-icon { width: 18px; height: 18px; border:2px solid #b6c4e9; border-radius: 999px; display:inline-block; position:relative; }
.esm-device-mini-icon::before { content:''; position:absolute; inset:5px; border:2px solid var(--primary); border-radius: 4px; }
.esm-panel-link { display:inline-flex; align-items:center; gap:6px; margin-top: 12px; color: var(--primary); font-size: 14px; }
.esm-panel-link::before { content:'←'; }
.esm-empty-row { text-align:center !important; color: var(--muted); }

.esm-latest-scenarios-list { display: grid; gap: 14px; min-height: 190px; }
.esm-scenario-row-card { border:1px solid var(--line); border-radius: 18px; padding: 14px 16px; display:flex; align-items:center; gap:12px; background: rgba(255,255,255,.35); }
.esm-scenario-badge { background: var(--green-soft); color: var(--green); padding: 8px 14px; border-radius: 14px; font-size: 14px; font-weight: 700; }
.esm-scenario-info { flex: 1; }
.esm-scenario-info h4 { margin: 0 0 8px; font-size: 16px; }
.esm-scenario-info p { margin: 0; color: var(--muted); direction:ltr; text-align:right; }
.esm-scenario-arrow { color: var(--muted); font-size: 28px; line-height: 1; }
.esm-empty-scenario-card { height: 100%; min-height: 190px; display:grid; align-content:center; justify-items:center; text-align:center; color: var(--muted); gap:10px; }
.esm-empty-scenario-icon { width: 44px; height: 44px; border-radius: 16px; background: var(--purple-soft); position: relative; }
.esm-empty-scenario-icon::before { content:''; position:absolute; width:18px; height:8px; border:3px solid var(--purple); border-radius: 999px; top:15px; right:13px; }
.esm-empty-scenario-card h4 { margin:0; color: var(--text); }
.esm-empty-scenario-card p { margin:0; line-height:1.9; max-width: 300px; }

.esm-action-buttons { display:grid; gap:14px; }
.esm-action-btn { min-height: 56px; border-radius: 16px; border:1px solid var(--border); display:flex; align-items:center; justify-content:center; gap:10px; font-size:18px; font-weight:700; }
.esm-action-btn--primary { background: linear-gradient(90deg, #3e6dff, #2752e6); color:#fff; }
.esm-action-btn--muted { background: #edf2ff; color: var(--primary); }
.esm-action-btn--soft { background: #f0ebff; color: var(--purple); }
.esm-action-btn--success { background: #edf8f0; color: var(--green); }
.esm-action-btn[disabled] { cursor: not-allowed; }
.square-ico, .link-ico, .bars-ico { width:18px; height:18px; display:inline-block; }
.square-ico { border: 2px solid currentColor; border-radius: 4px; }
.link-ico { border: 3px solid currentColor; border-radius: 999px; width: 20px; height: 9px; }
.bars-ico { background: linear-gradient(currentColor,currentColor) 0 100%/3px 10px no-repeat, linear-gradient(currentColor,currentColor) 7px 100%/3px 14px no-repeat, linear-gradient(currentColor,currentColor) 14px 100%/3px 18px no-repeat; }

.esm-bottom-grid { display:grid; grid-template-columns: 1.65fr 1fr; gap:16px; }
.esm-chart-toolbar { display:flex; align-items:center; justify-content:space-between; margin-bottom: 16px; }
.esm-range-btn { min-height: 40px; border-radius: 12px; border:1px solid var(--border); background:#fff; padding:0 14px; color: var(--text); }
.esm-chart-legend { display:flex; gap:18px; color: var(--muted); font-size:13px; }
.legend-swatch { width:16px; height:8px; display:inline-block; border-radius:4px; margin-left:6px; }
.legend-online { background:#79d08d; }
.legend-offline { background:#b8c0d2; }
.esm-bar-chart { height: 170px; display:flex; align-items:flex-end; justify-content:space-between; gap:16px; padding: 12px 10px 2px; border-top:1px dashed #dbe4f0; }
.esm-bar-col { display:grid; justify-items:center; gap:10px; flex:1; }
.esm-bar-stack { height: 124px; width: 36px; display:flex; flex-direction:column; justify-content:flex-end; gap:4px; }
.esm-bar { display:block; width:100%; border-radius: 10px 10px 0 0; }
.esm-bar-online { background:#7ad08d; }
.esm-bar-offline { background:#c4cbd8; }
.esm-bar-label { color: var(--muted); font-size: 13px; }

.esm-donut-wrap { display:grid; grid-template-columns: 180px 1fr; gap: 18px; align-items:center; }
.esm-donut { --donut-angle: 50%; width: 180px; height: 180px; border-radius: 50%; background: conic-gradient(#8ed6a0 0 var(--donut-angle), #d5dde9 var(--donut-angle) 100%); display:grid; place-items:center; }
.esm-donut::before { content:''; width: 124px; height: 124px; border-radius: 50%; background: var(--panel); box-shadow: inset 0 0 0 1px var(--border); }
.esm-donut-center { position:absolute; text-align:center; }
.esm-donut-center strong { display:block; font-size: 30px; }
.esm-donut-center span { color: var(--muted); }
.esm-donut-legend { display:grid; gap: 18px; font-size: 16px; }
.esm-donut-legend div { color: var(--text); }
.esm-donut-legend small { color: var(--muted); font-size: 15px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display:inline-block; margin-left:8px; }
.dot-green { background: var(--green); }
.dot-gray { background: #c9cfdb; }

@media (max-width: 1400px) {
  .esm-middle-grid { grid-template-columns: 1fr 1fr; }
  .esm-panel-actions { grid-column: 1 / -1; }
}

@media (max-width: 1100px) {
  .esm-mobile-menu-toggle { display: block; }
  .esm-app-shell { grid-template-columns: 1fr; }
  .esm-sidebar {
    position: fixed;
    top: 0; bottom: 0; right: 0;
    width: 280px;
    min-height: 100vh;
    border-radius: 0;
    transform: translateX(110%);
    transition: transform .25s ease;
    z-index: 100;
  }
  .esm-sidebar.is-open { transform: translateX(0); }
  .esm-sidebar-overlay { display:block; position: fixed; inset:0; background: rgba(15,23,42,.35); opacity:0; visibility:hidden; transition: .25s; z-index: 90; }
  .esm-sidebar-overlay.is-visible { opacity:1; visibility:visible; }
  .esm-content-area { width: 100%; }
  .esm-stats-grid, .esm-middle-grid, .esm-bottom-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 820px) {
  .esm-topbar { grid-template-columns: 1fr; gap: 14px; justify-items:center; padding-top: 16px; padding-bottom: 16px; }
  .esm-topbar-actions, .esm-brand-mark { justify-self: center; }
  .esm-topbar-title { font-size: 24px; }
  .esm-welcome-card { flex-direction: column; align-items: flex-start; }
  .esm-stats-grid, .esm-middle-grid, .esm-bottom-grid { grid-template-columns: 1fr; }
  .esm-donut-wrap { grid-template-columns: 1fr; justify-items: center; }
}

@media (max-width: 640px) {
  .esm-app-shell, .esm-topbar { width: calc(100% - 20px); }
  .esm-topbar { margin-top: 12px; }
  .esm-brand-name { font-size: 21px; letter-spacing: 8px; }
  .esm-soft-btn { min-height: 36px; padding: 0 14px; }
  .esm-stat-card { padding: 18px; min-height: 120px; }
  .esm-stat-copy strong { font-size: 24px; }
  .esm-welcome-text h2 { font-size: 28px; }
  .esm-panel { padding: 14px; }
  .esm-action-btn { font-size: 16px; }
}

/* ===== v3 refinements: closer to reference ===== */
body { font-size: 14px; }

.esm-topbar {
  direction: ltr;
  min-height: 72px;
  padding: 12px 22px;
  border-radius: 22px;
}
.esm-topbar-title {
  font-size: 24px;
  letter-spacing: 0;
}
.esm-topbar-actions {
  justify-self: start;
  gap: 12px;
}
.esm-brand-mark {
  justify-self: end;
  gap: 14px;
}
.esm-brand-name { font-size: 21px; letter-spacing: 9px; padding-left: 8px; }
.esm-brand-sub { font-size: 11px; letter-spacing: 3px; }
.esm-soft-btn { min-height: 42px; padding: 0 16px; border-radius: 15px; }
.esm-theme-btn { width: 42px; font-size: 18px; }

.esm-app-shell {
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 16px;
}
.esm-sidebar {
  padding: 14px 10px;
  border-radius: 24px;
}
.esm-sidebar-brand { padding: 6px 0 14px; gap: 8px; }
.esm-nav-link {
  gap: 8px;
  padding: 12px 6px;
  border-radius: 16px;
}
.esm-nav-text { font-size: 13px; }
.esm-nav-icon { width: 22px; height: 22px; }
.esm-brand-name--small { font-size: 14px; letter-spacing: 7px; }
.esm-brand-sub--small { font-size: 9px; letter-spacing: 1.8px; }

.esm-content-area { padding-top: 0; }
.esm-welcome-card {
  min-height: 118px;
  padding: 20px 26px;
  gap: 18px;
  margin-bottom: 16px;
}
.esm-icon-surface {
  width: 84px;
  height: 84px;
  border-radius: 20px;
}
.esm-welcome-text h2 { font-size: 26px; margin-bottom: 6px; }
.esm-welcome-text p { font-size: 14px; }

.esm-stats-grid,
.esm-middle-grid,
.esm-bottom-grid { gap: 14px; }

.esm-stat-card,
.esm-panel,
.esm-welcome-card {
  border-radius: 24px;
}
.esm-stat-card {
  min-height: 126px;
  padding: 18px 22px;
}
.esm-stat-copy h3 { font-size: 16px; margin-bottom: 10px; }
.esm-stat-copy strong { font-size: 24px; margin-bottom: 8px; }
.esm-stat-copy p { font-size: 13px; }
.esm-stat-icon { width: 58px; height: 58px; border-radius: 16px; flex: 0 0 auto; }
.esm-stat-icon--blue::before {
  width: 20px; height: 16px; top: 19px; right: 19px;
}
.esm-stat-icon--green::before,
.esm-stat-icon--green::after,
.esm-stat-icon--purple::before,
.esm-stat-icon--purple::after { box-shadow: none; }
.esm-stat-icon--green::before {
  content: '';
  position: absolute;
  inset: 14px;
  background:
    radial-gradient(circle at 50% 100%, var(--green) 0 3px, transparent 3.5px),
    radial-gradient(circle at 50% 100%, transparent 0 10px, var(--green) 10px 12px, transparent 12.5px),
    radial-gradient(circle at 50% 100%, transparent 0 17px, var(--green) 17px 19px, transparent 19.5px),
    radial-gradient(circle at 50% 100%, transparent 0 24px, var(--green) 24px 26px, transparent 26.5px);
  transform: rotate(180deg);
}
.esm-stat-icon--green::after { content: none; }
.esm-stat-icon--purple::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle, var(--purple) 0 4px, transparent 4.5px) 17px 29px / 8px 8px no-repeat,
    radial-gradient(circle, var(--purple) 0 4px, transparent 4.5px) 33px 29px / 8px 8px no-repeat,
    linear-gradient(var(--purple), var(--purple)) 24px 32px / 12px 2px no-repeat;
}
.esm-stat-icon--purple::after { content: none; }
.esm-stat-icon--red::before {
  font-size: 28px;
  top: 12px;
  right: 18px;
}

.esm-panel { padding: 16px 16px 14px; }
.esm-panel-header { margin-bottom: 12px; }
.esm-panel-header h3 { font-size: 16px; }
.esm-mini-icon, .esm-link-mark, .esm-bolt-mark {
  width: 24px;
  height: 24px;
  border-radius: 8px;
}
.esm-link-mark::before {
  width: 12px;
  height: 5px;
  border-width: 2px;
}
.esm-bolt-mark::before { font-size: 14px; }
.esm-mini-icon::before {
  width: 10px;
  height: 10px;
  box-shadow: 7px 0 0 -2px var(--primary), 0 7px 0 -2px var(--primary), 7px 7px 0 -2px var(--primary);
}

.esm-devices-table { font-size: 13px; }
.esm-devices-table th,
.esm-devices-table td { padding: 11px 10px; }
.esm-devices-table thead th { font-size: 12px; }
.esm-chip { padding: 5px 9px; font-size: 12px; }
.esm-panel-link { font-size: 13px; }

.esm-latest-scenarios-list { min-height: 180px; }
.esm-scenario-row-card {
  padding: 12px 14px;
  border-radius: 16px;
}
.esm-scenario-badge {
  padding: 6px 11px;
  border-radius: 12px;
  font-size: 12px;
}
.esm-scenario-info h4 { font-size: 15px; margin-bottom: 6px; }
.esm-scenario-info p { font-size: 13px; }
.esm-scenario-arrow { font-size: 22px; }
.esm-empty-scenario-card { min-height: 180px; gap: 8px; }
.esm-empty-scenario-icon { width: 40px; height: 40px; border-radius: 14px; }
.esm-empty-scenario-icon::before { width: 16px; height: 6px; border-width: 2px; top: 15px; right: 12px; }
.esm-empty-scenario-card h4 { font-size: 15px; }
.esm-empty-scenario-card p { font-size: 13px; line-height: 1.8; }

.esm-action-buttons { gap: 12px; }
.esm-action-btn {
  min-height: 54px;
  border-radius: 15px;
  font-size: 15px;
  font-weight: 700;
}
.square-ico, .link-ico, .bars-ico { width: 16px; height: 16px; }
.square-ico { border-width: 1.8px; }
.link-ico {
  border: 0;
  width: 18px;
  height: 12px;
  position: relative;
}
.link-ico::before,
.link-ico::after {
  content: '';
  position: absolute;
  top: 1px;
  width: 7px;
  height: 7px;
  border: 2px solid currentColor;
  border-radius: 50%;
}
.link-ico::before { right: 0; }
.link-ico::after { left: 0; }
.link-ico { background: linear-gradient(currentColor,currentColor) center 50% / 8px 2px no-repeat; }
.bars-ico { background: linear-gradient(currentColor,currentColor) 0 100%/3px 9px no-repeat, linear-gradient(currentColor,currentColor) 6px 100%/3px 13px no-repeat, linear-gradient(currentColor,currentColor) 12px 100%/3px 16px no-repeat; }

.esm-chart-toolbar { margin-bottom: 12px; }
.esm-range-btn { min-height: 36px; font-size: 13px; }
.esm-chart-legend { font-size: 12px; gap: 14px; }
.esm-bar-chart { height: 154px; gap: 12px; }
.esm-bar-stack { height: 110px; width: 30px; }
.esm-bar-label { font-size: 12px; }

.esm-donut-wrap { grid-template-columns: 160px 1fr; gap: 16px; }
.esm-donut { width: 160px; height: 160px; }
.esm-donut::before { width: 112px; height: 112px; }
.esm-donut-center strong { font-size: 26px; }
.esm-donut-center span { font-size: 13px; }
.esm-donut-legend { gap: 14px; font-size: 14px; }
.esm-donut-legend small { font-size: 13px; }

/* better mobile */
@media (max-width: 1100px) {
  .esm-sidebar { width: 260px; }
}

@media (max-width: 820px) {
  .esm-topbar {
    width: calc(100% - 20px);
    grid-template-columns: 1fr;
    gap: 10px;
    justify-items: center;
  }
  .esm-topbar-title { font-size: 22px; }
  .esm-welcome-card { padding: 18px; }
  .esm-stat-card { min-height: 118px; }
}

@media (max-width: 640px) {
  .esm-app-shell { width: calc(100% - 20px); }
  .esm-topbar-actions { gap: 8px; }
  .esm-brand-name { font-size: 18px; letter-spacing: 7px; }
  .esm-brand-sub { font-size: 10px; letter-spacing: 2px; }
  .esm-icon-surface { width: 72px; height: 72px; }
  .esm-welcome-text h2 { font-size: 22px; }
  .esm-stat-card { padding: 16px; }
  .esm-action-btn { min-height: 50px; font-size: 14px; }
}


/* ===== v4 exact bottom analytics section ===== */
.esm-bottom-grid {
  display: grid;
  grid-template-columns: minmax(0, 2.15fr) minmax(330px, 0.95fr);
  grid-template-areas: "chart donut";
  gap: 14px;
  direction: ltr;
  align-items: stretch;
}
.esm-panel-chart {
  grid-area: chart;
  direction: rtl;
  min-width: 0;
  min-height: 238px;
  padding: 14px 16px 12px;
}
.esm-panel-donut {
  grid-area: donut;
  direction: rtl;
  min-width: 0;
  min-height: 238px;
  padding: 14px 16px 10px;
  display: flex;
  flex-direction: column;
}
.esm-panel-donut .esm-panel-header { margin-bottom: 2px; }
.esm-panel-donut .esm-panel-header h3 { font-size: 15px; font-weight: 800; }
.esm-chart-toolbar { position: relative; min-height: 34px; margin-bottom: 2px; direction: ltr; }
.esm-range-btn {
  position: absolute;
  left: 0;
  top: 0;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.72);
  color: var(--text);
  font-size: 12px;
}
.esm-range-btn::before { content: '⌄'; margin-right: 8px; color: var(--muted); }
.esm-chart-legend {
  width: 100%;
  justify-content: center;
  gap: 30px;
  direction: rtl;
  font-size: 11px;
  color: var(--muted);
  padding-top: 7px;
}
.legend-swatch { width: 16px; height: 7px; margin-left: 6px; border-radius: 2px; }
.legend-online { background: #6fc582; }
.legend-offline { background: #aeb8c9; }
.esm-bar-chart { height: 178px; width: 100%; padding: 0; border: 0; display: block; overflow: hidden; }
.esm-chart-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.esm-chart-grid-line { stroke: #d9e1ec; stroke-width: 1; stroke-dasharray: 4 4; }
.esm-chart-y-label, .esm-chart-x-label {
  fill: #7886a3;
  font-family: Tahoma, "Segoe UI", Arial, sans-serif;
  font-size: 11px;
}
.esm-chart-bar-online { fill: #70c284; }
.esm-chart-bar-offline { fill: #aeb7c7; }
.esm-donut-wrap {
  flex: 1;
  grid-template-columns: 156px 1fr;
  gap: 14px;
  align-items: center;
  padding: 2px 6px 2px;
}
.esm-donut {
  width: 150px;
  height: 150px;
  justify-self: center;
  background: conic-gradient(#83cf96 0 var(--donut-angle), #d7dee9 var(--donut-angle) 100%);
}
.esm-donut::before { width: 108px; height: 108px; }
.esm-donut-center strong { font-size: 24px; margin-bottom: 3px; }
.esm-donut-center span { font-size: 12px; }
.esm-donut-legend { gap: 18px; font-size: 12px; }
.esm-donut-legend div {
  display: grid;
  grid-template-columns: 12px minmax(92px, 1fr) auto auto;
  align-items: center;
  column-gap: 8px;
  white-space: nowrap;
}
.esm-donut-legend b { min-width: 16px; text-align: center; }
.esm-donut-legend small { font-size: 11px; color: var(--muted); }
.esm-donut-legend .dot { width: 10px; height: 10px; margin: 0; }
.esm-panel-donut .esm-panel-link {
  margin-top: auto;
  padding-top: 9px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
@media (max-width: 1100px) {
  .esm-bottom-grid { grid-template-columns: 1fr; grid-template-areas: "chart" "donut"; }
  .esm-panel-chart, .esm-panel-donut { min-height: 224px; }
}
@media (max-width: 620px) {
  .esm-chart-toolbar { min-height: 62px; }
  .esm-range-btn { top: 30px; }
  .esm-chart-legend { justify-content: flex-start; }
  .esm-bar-chart { height: 220px; overflow-x: auto; }
  .esm-chart-svg { min-width: 720px; }
  .esm-donut-wrap { grid-template-columns: 1fr; justify-items: center; }
  .esm-donut-legend { width: 100%; }
}


/* Chart.js canvases */
.esm-chart-canvas-wrap { position: relative; width: 100%; height: 178px; }
.esm-donut-canvas-wrap { position: relative; width: 150px; height: 150px; justify-self: center; }
.esm-donut-canvas-wrap canvas { width: 100% !important; height: 100% !important; }
.esm-chart-canvas-wrap canvas { width: 100% !important; height: 100% !important; }
.esm-donut-canvas-wrap .esm-donut-center { position: absolute; inset: 0; display: grid; place-content: center; pointer-events: none; }
@media (max-width:620px){ .esm-chart-canvas-wrap{height:220px;} }

/* ===== v7 functional sidebar icons and range select ===== */
.sr-only { position:absolute!important; width:1px!important; height:1px!important; padding:0!important; margin:-1px!important; overflow:hidden!important; clip:rect(0,0,0,0)!important; white-space:nowrap!important; border:0!important; }
.esm-nav-icon-img { width: 24px; height: 24px; display:block; object-fit:contain; opacity:.82; filter: grayscale(1) sepia(.15) hue-rotate(180deg) saturate(1.8); }
.esm-nav-link.active .esm-nav-icon-img { opacity:1; filter: brightness(0) saturate(100%) invert(38%) sepia(98%) saturate(3768%) hue-rotate(219deg) brightness(100%) contrast(101%); }
.esm-nav-link:hover { background: rgba(47,92,255,.06); color: var(--primary); }
.esm-nav-link:hover .esm-nav-icon-img { opacity:1; }
.esm-sidebar-nav .esm-nav-link { min-height: 78px; }
.esm-sidebar-footer .esm-nav-link { min-height: 66px; border:0; }

.esm-range-control { position:absolute; left:0; top:0; }
.esm-range-select {
  min-width: 118px;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.86);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor:pointer;
  outline:none;
}
.esm-range-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,92,255,.10); }
.esm-range-btn { display:none !important; }
@media (max-width:620px){ .esm-range-control{top:30px;} }


/* ===== v8 sidebar: compact reference layout, no top logo ===== */
.esm-app-shell {
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 16px;
}
.esm-sidebar {
  min-height: calc(100vh - 118px);
  padding: 12px 8px;
  border-radius: 20px;
}
.esm-sidebar-nav {
  display: grid;
  gap: 10px;
  padding-top: 0;
}
.esm-nav-link {
  min-height: 74px;
  padding: 11px 5px;
  gap: 8px;
  border-radius: 15px;
}
.esm-nav-link.active {
  background: #edf2ff;
  border-color: #e3e9fb;
  box-shadow: none;
}
.esm-nav-icon-img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  opacity: .78;
  filter: none;
}
.esm-nav-link.active .esm-nav-icon-img {
  opacity: 1;
}
.esm-nav-text {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}
.esm-sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.esm-sidebar-footer .esm-nav-link {
  min-height: 72px;
}

@media (max-width: 1100px) {
  .esm-sidebar {
    width: 220px;
    padding: 14px 12px;
  }
  .esm-nav-link {
    grid-template-columns: 28px 1fr;
    justify-items: start;
    align-items: center;
    min-height: 54px;
    padding: 10px 12px;
    text-align: right;
  }
  .esm-nav-text {
    font-size: 14px;
  }
}

/* ===== v9: restore original header layout ===== */
.esm-topbar {
  direction: ltr;
  width: calc(100% - 32px);
  min-height: 96px;
  margin: 16px auto 0;
  padding: 16px 30px;
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  column-gap: 24px;
  align-items: center;
  border-radius: 0 0 22px 22px;
}

.esm-topbar-actions {
  grid-column: 1;
  justify-self: start;
  display: flex;
  flex-direction: row;
  direction: ltr;
  gap: 12px;
  align-items: center;
}

.esm-topbar-actions .esm-soft-btn {
  direction: rtl;
}

.esm-topbar-title {
  grid-column: 2;
  justify-self: center;
  direction: rtl;
  unicode-bidi: isolate;
  white-space: nowrap;
  font-size: 25px;
  line-height: 1;
  letter-spacing: 0;
}

.esm-brand-mark {
  grid-column: 3;
  justify-self: end;
  direction: ltr;
  gap: 16px;
}

.esm-brand-name {
  font-size: 22px;
  letter-spacing: 10px;
}

.esm-brand-sub {
  margin-top: 7px;
  font-size: 10px;
  letter-spacing: 4px;
}

.esm-brand-dots {
  grid-template-columns: repeat(3, 8px);
  gap: 6px;
}

.esm-brand-dots span {
  width: 8px;
  height: 8px;
}

.esm-soft-btn {
  min-height: 46px;
  border-radius: 14px;
}

.esm-logout-btn {
  min-width: 112px;
  justify-content: center;
}

.esm-theme-btn {
  width: 52px;
  min-width: 52px;
}

@media (max-width: 820px) {
  .esm-topbar {
    width: calc(100% - 20px);
    min-height: auto;
    padding: 14px 16px;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand actions"
      "title title";
    row-gap: 14px;
    border-radius: 18px;
  }

  .esm-brand-mark {
    grid-area: brand;
    justify-self: start;
  }

  .esm-topbar-actions {
    grid-area: actions;
    justify-self: end;
  }

  .esm-topbar-title {
    grid-area: title;
    justify-self: center;
    font-size: 22px;
  }
}

@media (max-width: 520px) {
  .esm-topbar {
    grid-template-columns: 1fr;
    grid-template-areas:
      "brand"
      "title"
      "actions";
    justify-items: center;
  }

  .esm-brand-mark,
  .esm-topbar-actions,
  .esm-topbar-title {
    justify-self: center;
  }

  .esm-brand-name {
    font-size: 19px;
    letter-spacing: 8px;
  }

  .esm-logout-btn {
    min-width: 102px;
  }
}


/* ===== v10 exact header from reference ===== */
.esm-topbar {
  direction: ltr !important;
  width: calc(100% - 36px) !important;
  min-height: 100px !important;
  margin: 18px auto 0 !important;
  padding: 16px 32px !important;
  display: grid !important;
  grid-template-columns: minmax(250px,1fr) auto minmax(250px,1fr) !important;
  align-items: center !important;
  column-gap: 24px !important;
  background: rgba(255,255,255,.78) !important;
  border: 1px solid #dce5f2 !important;
  border-radius: 0 0 22px 22px !important;
  box-shadow: 0 18px 42px rgba(50,77,137,.09) !important;
}
.esm-topbar-actions {
  grid-column: 1 !important;
  justify-self: start !important;
  display: flex !important;
  flex-direction: row-reverse !important;
  align-items: center !important;
  gap: 12px !important;
  direction: ltr !important;
}
.esm-topbar-title {
  grid-column: 2 !important;
  justify-self: center !important;
  display: inline-flex !important;
  flex-direction: row-reverse !important;
  align-items: baseline !important;
  gap: 8px !important;
  margin: 0 !important;
  color: #2554d9 !important;
  font-size: 28px !important;
  font-weight: 900 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  direction: ltr !important;
  unicode-bidi: isolate !important;
}
.esm-title-fa { direction: rtl; unicode-bidi: isolate; }
.esm-title-iot { direction: ltr; unicode-bidi: isolate; font-family: Georgia, 'Times New Roman', serif; font-weight: 800; }
.esm-brand-mark {
  grid-column: 3 !important;
  justify-self: end !important;
  display: flex !important;
  align-items: center !important;
  gap: 14px !important;
  direction: ltr !important;
}
.esm-brand-name {
  font-size: 22px !important;
  font-weight: 900 !important;
  letter-spacing: 10px !important;
  padding-left: 10px !important;
  line-height: 1 !important;
}
.esm-brand-sub {
  margin-top: 8px !important;
  font-size: 10px !important;
  letter-spacing: 4px !important;
}
.esm-brand-dots {
  grid-template-columns: repeat(3, 8px) !important;
  gap: 6px !important;
}
.esm-brand-dots span { width: 8px !important; height: 8px !important; }
.esm-soft-btn {
  min-height: 48px !important;
  border-radius: 14px !important;
  border: 1px solid #cdd9ea !important;
  background: rgba(255,255,255,.78) !important;
  box-shadow: none !important;
}
.esm-theme-btn {
  width: 52px !important;
  min-width: 52px !important;
  padding: 0 !important;
  font-size: 19px !important;
}
.esm-logout-btn {
  min-width: 138px !important;
  padding: 0 20px !important;
  justify-content: center !important;
  gap: 10px !important;
  direction: rtl !important;
}
.esm-btn-icon {
  width: 30px !important;
  height: 30px !important;
  border-radius: 9px !important;
  background: #edf2ff !important;
  display: grid !important;
  place-items: center !important;
}
.esm-btn-icon svg { width: 16px !important; height: 16px !important; }

@media (max-width: 820px) {
  .esm-topbar {
    width: calc(100% - 20px) !important;
    min-height: auto !important;
    padding: 14px 16px !important;
    grid-template-columns: 1fr auto !important;
    grid-template-areas: 'actions brand' 'title title' !important;
    row-gap: 14px !important;
    border-radius: 18px !important;
  }
  .esm-topbar-actions { grid-area: actions !important; justify-self: start !important; }
  .esm-brand-mark { grid-area: brand !important; justify-self: end !important; }
  .esm-topbar-title { grid-area: title !important; font-size: 23px !important; }
}
@media (max-width: 520px) {
  .esm-topbar {
    grid-template-columns: 1fr !important;
    grid-template-areas: 'brand' 'title' 'actions' !important;
    justify-items: center !important;
  }
  .esm-topbar-actions,.esm-brand-mark,.esm-topbar-title { justify-self: center !important; }
  .esm-logout-btn { min-width: 118px !important; }
}


/* ===== Original project header restored exactly ===== */
.app-header {
    width: calc(100% - 32px);
    margin: 16px auto 0;
    min-height: 118px;
    padding: 26px 36px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    direction: ltr;
    border: 1px solid var(--border);
    border-radius: 0 0 28px 28px;
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}
.header-actions {
    grid-column: 1;
    justify-self: start;
    display: flex;
    gap: 14px;
    align-items: center;
    direction: rtl;
}
.app-title {
    grid-column: 2;
    margin: 0;
    color: var(--primary);
    font-size: clamp(1.55rem, 2.1vw, 2.6rem);
    font-weight: 900;
    letter-spacing: 1.5px;
    direction: rtl;
    text-shadow: 0 8px 22px rgba(38, 93, 244, 0.18);
}
.brand-logo {
    grid-column: 3;
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 18px;
    direction: ltr;
}
.brand-text { text-align: center; }
.main-brand {
    display: block;
    color: var(--text);
    font-size: clamp(1.75rem, 2.1vw, 2.45rem);
    line-height: 1;
    font-weight: 900;
    letter-spacing: 13px;
    padding-left: 13px;
}
.tagline {
    display: block;
    margin-top: 10px;
    color: var(--muted);
    font-size: .9rem;
    letter-spacing: 5px;
    white-space: nowrap;
}
.brand-dots {
    width: 48px;
    display: grid;
    grid-template-columns: repeat(3, 10px);
    gap: 8px;
}
.brand-dots span {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: var(--primary);
    box-shadow: 0 4px 12px rgba(38, 93, 244, .35);
}
.soft-button {
    min-height: 58px;
    padding: 0 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text);
    background: var(--panel);
    box-shadow: 0 10px 30px rgba(39,57,101,.08);
    cursor: pointer;
    transition: transform .2s ease, border-color .2s ease, background .2s ease;
}
.soft-button:hover { transform: translateY(-2px); }
.theme-toggle {
    width: 58px;
    padding: 0;
    color: var(--primary);
    background: var(--primary-soft);
}
.logout-button {
    min-width: 146px;
    padding-inline: 16px 14px;
    gap: 12px;
    border-color: rgba(38,93,244,.12);
    background: linear-gradient(180deg, rgba(255,255,255,.96), rgba(244,247,255,.98));
}
.logout-icon { width: 26px; height: 26px; display: inline-flex; align-items:center; justify-content:center; border-radius: 8px; background: var(--primary-soft); }
.logout-icon svg { width: 17px; height: 17px; fill:none; stroke:var(--primary); stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
.logout-text { font-weight: 800; }
html[data-theme="dark"] .logout-button { background: linear-gradient(180deg, rgba(24,34,59,.96), rgba(20,29,51,.98)); }

@media (max-width: 850px) {
  .app-header {
    grid-template-columns: 1fr;
    gap: 22px;
    direction: rtl;
    padding: 24px;
  }
  .brand-logo, .app-title, .header-actions { grid-column: 1; justify-self: center; }
  .brand-logo { grid-row: 1; }
  .app-title { grid-row: 2; }
  .header-actions { grid-row: 3; }
}
@media (max-width: 520px) {
  .app-header { width: calc(100% - 20px); padding: 20px 14px; min-height: auto; }
  .main-brand { font-size: 1.5rem; letter-spacing: 9px; padding-left: 9px; }
  .tagline { font-size: .7rem; letter-spacing: 3px; }
  .brand-dots { width: 38px; grid-template-columns: repeat(3,8px); gap:6px; }
  .brand-dots span { width:8px; height:8px; }
  .soft-button { min-height: 48px; }
  .theme-toggle { width:48px; }
  .logout-button { min-width: 122px; }
}

/* ===== v12: exact compact header dimensions from original project ===== */
.app-header {
  width: calc(100% - 28px) !important;
  min-height: 82px !important;
  height: 82px !important;
  margin: 10px auto 0 !important;
  padding: 14px 26px !important;
  display: grid !important;
  grid-template-columns: 1fr auto 1fr !important;
  align-items: center !important;
  direction: ltr !important;
  border: 1px solid var(--border) !important;
  border-radius: 0 0 18px 18px !important;
  background: var(--panel) !important;
  box-shadow: var(--shadow) !important;
  backdrop-filter: blur(18px) !important;
}

.app-header .header-actions {
  grid-column: 1 !important;
  justify-self: start !important;
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  direction: rtl !important;
}

.app-header .app-title {
  grid-column: 2 !important;
  justify-self: center !important;
  margin: 0 !important;
  color: var(--primary) !important;
  font-size: clamp(1.25rem, 1.45vw, 1.75rem) !important;
  font-weight: 900 !important;
  letter-spacing: .8px !important;
  line-height: 1.2 !important;
  direction: rtl !important;
  white-space: nowrap !important;
  text-shadow: 0 8px 22px rgba(38,93,244,.14) !important;
}

.app-header .brand-logo {
  grid-column: 3 !important;
  justify-self: end !important;
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
  direction: ltr !important;
}

.app-header .brand-text {
  text-align: center !important;
}

.app-header .main-brand {
  display: block !important;
  color: var(--text) !important;
  font-size: clamp(1.35rem, 1.55vw, 1.75rem) !important;
  line-height: 1 !important;
  font-weight: 900 !important;
  letter-spacing: 8px !important;
  padding-left: 8px !important;
  white-space: nowrap !important;
}

.app-header .tagline {
  display: block !important;
  margin-top: 6px !important;
  color: var(--muted) !important;
  font-size: .68rem !important;
  letter-spacing: 3.5px !important;
  white-space: nowrap !important;
}

.app-header .brand-dots {
  width: 34px !important;
  display: grid !important;
  grid-template-columns: repeat(3, 7px) !important;
  gap: 6px !important;
}

.app-header .brand-dots span {
  width: 7px !important;
  height: 7px !important;
  border-radius: 999px !important;
  background: var(--primary) !important;
  box-shadow: 0 3px 8px rgba(38,93,244,.24) !important;
}

.app-header .soft-button {
  min-height: 40px !important;
  height: 40px !important;
  padding: 0 16px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 7px !important;
  border: 1px solid var(--border) !important;
  border-radius: 11px !important;
  color: var(--text) !important;
  background: var(--panel) !important;
  box-shadow: var(--shadow-soft) !important;
  font-size: .88rem !important;
}

.app-header .theme-toggle {
  width: 40px !important;
  min-width: 40px !important;
  padding: 0 !important;
  color: #f6b11a !important;
  background: var(--primary-soft) !important;
  font-size: 1rem !important;
}

.app-header .logout-button {
  min-width: 110px !important;
  padding-inline: 12px 11px !important;
  gap: 8px !important;
}

.app-header .logout-text {
  font-size: .88rem !important;
  font-weight: 900 !important;
  line-height: 1 !important;
}

.app-header .logout-icon {
  width: 26px !important;
  height: 26px !important;
  flex: 0 0 26px !important;
  display: grid !important;
  place-items: center !important;
  border-radius: 8px !important;
  color: var(--primary) !important;
  background: var(--primary-soft) !important;
}

.app-header .logout-icon svg {
  width: 14px !important;
  height: 14px !important;
  display: block !important;
  fill: none !important;
  stroke: currentColor !important;
  stroke-width: 1.9 !important;
  stroke-linecap: round !important;
  stroke-linejoin: round !important;
}

@media (max-width: 850px) {
  .app-header {
    width: calc(100% - 20px) !important;
    height: auto !important;
    min-height: 72px !important;
    padding: 12px 14px !important;
    gap: 10px !important;
  }

  .app-header .app-title {
    font-size: 1.15rem !important;
  }

  .app-header .main-brand {
    font-size: 1.15rem !important;
    letter-spacing: 6px !important;
  }

  .app-header .tagline {
    font-size: .58rem !important;
    letter-spacing: 2.6px !important;
  }

  .app-header .brand-dots {
    width: 28px !important;
    grid-template-columns: repeat(3, 6px) !important;
    gap: 5px !important;
  }

  .app-header .brand-dots span {
    width: 6px !important;
    height: 6px !important;
  }
}

@media (max-width: 620px) {
  .app-header {
    grid-template-columns: auto 1fr auto !important;
    min-height: 64px !important;
    padding: 10px 12px !important;
  }

  .app-header .header-actions {
    gap: 6px !important;
  }

  .app-header .soft-button {
    min-height: 36px !important;
    height: 36px !important;
    padding: 0 10px !important;
  }

  .app-header .theme-toggle {
    width: 36px !important;
    min-width: 36px !important;
  }

  .app-header .logout-button {
    min-width: 82px !important;
  }

  .app-header .logout-icon {
    width: 23px !important;
    height: 23px !important;
    flex-basis: 23px !important;
  }

  .app-header .app-title {
    font-size: 1rem !important;
  }

  .app-header .brand-logo {
    gap: 7px !important;
  }

  .app-header .main-brand {
    font-size: .95rem !important;
    letter-spacing: 4px !important;
    padding-left: 4px !important;
  }

  .app-header .tagline {
    display: none !important;
  }

  .app-header .brand-dots {
    width: 22px !important;
    grid-template-columns: repeat(3, 5px) !important;
    gap: 3px !important;
  }

  .app-header .brand-dots span {
    width: 5px !important;
    height: 5px !important;
  }
}


/* ===== Welcome section: plain text, no card, no icon ===== */
.esm-welcome-card.esm-welcome-card--plain {
  min-height: 92px !important;
  margin: 0 0 10px !important;
  padding: 18px 28px 12px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: 0 !important;
  background: transparent !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
}

.esm-welcome-card--plain .esm-welcome-text {
  width: 100% !important;
  text-align: right !important;
}

.esm-welcome-card--plain .esm-welcome-text h2 {
  margin: 0 0 8px !important;
  color: var(--primary) !important;
  font-size: 30px !important;
  line-height: 1.15 !important;
  font-weight: 800 !important;
  letter-spacing: 0 !important;
  text-shadow: none !important;
}

.esm-welcome-card--plain .esm-welcome-text p {
  margin: 0 !important;
  color: var(--muted) !important;
  font-size: 14px !important;
  line-height: 1.8 !important;
}

@media (max-width: 820px) {
  .esm-welcome-card.esm-welcome-card--plain {
    min-height: 82px !important;
    padding: 14px 16px 10px !important;
    align-items: center !important;
  }

  .esm-welcome-card--plain .esm-welcome-text h2 {
    font-size: 25px !important;
  }

  .esm-welcome-card--plain .esm-welcome-text p {
    font-size: 13px !important;
  }
}

@media (max-width: 520px) {
  .esm-welcome-card.esm-welcome-card--plain {
    min-height: 74px !important;
    padding: 12px 8px 8px !important;
  }

  .esm-welcome-card--plain .esm-welcome-text h2 {
    font-size: 22px !important;
    margin-bottom: 5px !important;
  }
}


/* ===== v15 exact summary cards ===== */
.esm-stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin: 0 0 18px;
  direction: rtl;
}

.esm-stat-card {
  min-width: 0;
  min-height: 128px;
  height: 128px;
  padding: 18px 22px;
  border-radius: 13px;
  border: 1px solid #e1e7f0;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 9px 25px rgba(51, 73, 125, 0.07);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  direction: ltr;
}

.esm-stat-copy {
  flex: 1;
  min-width: 0;
  text-align: right;
  direction: rtl;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.esm-stat-copy h3 {
  margin: 0 0 12px;
  color: #172347;
  font-family: Tahoma, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.35;
  font-weight: 800;
  white-space: nowrap;
}

.esm-stat-copy strong {
  display: block;
  margin: 0 0 8px;
  color: #16234a;
  font-family: Tahoma, "Segoe UI", Arial, sans-serif;
  font-size: 27px;
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: lining-nums tabular-nums;
  direction: ltr;
  text-align: right;
}

.esm-stat-copy p {
  margin: 0;
  color: #8694b2;
  font-family: Tahoma, "Segoe UI", Arial, sans-serif;
  font-size: 13px;
  line-height: 1.4;
  font-weight: 400;
  white-space: nowrap;
}

.esm-stat-icon {
  width: 66px;
  height: 66px;
  flex: 0 0 66px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}
.esm-stat-icon::before,
.esm-stat-icon::after {
  content: none !important;
  display: none !important;
}
.esm-stat-icon img {
  display: block;
  width: 34px;
  height: 34px;
  object-fit: contain;
}
.esm-stat-icon--blue { background: #eef2ff; }
.esm-stat-icon--green { background: #edf8f1; }
.esm-stat-icon--purple { background: #f2efff; }
.esm-stat-icon--red { background: #fff0f0; }
.esm-stat-icon--blue img {
  filter: invert(29%) sepia(95%) saturate(3160%) hue-rotate(220deg) brightness(96%) contrast(101%);
}
.esm-stat-icon--green img {
  filter: invert(54%) sepia(57%) saturate(590%) hue-rotate(79deg) brightness(93%) contrast(91%);
}
.esm-stat-icon--purple img {
  filter: invert(33%) sepia(88%) saturate(2222%) hue-rotate(235deg) brightness(102%) contrast(100%);
}
.esm-stat-icon--red img {
  filter: invert(52%) sepia(90%) saturate(1647%) hue-rotate(326deg) brightness(103%) contrast(95%);
}

@media (max-width: 1180px) {
  .esm-stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .esm-stats-grid { grid-template-columns: 1fr; gap: 12px; }
  .esm-stat-card { height: 116px; min-height: 116px; padding: 16px 18px; }
  .esm-stat-icon { width: 58px; height: 58px; flex-basis: 58px; border-radius: 15px; }
  .esm-stat-icon img { width: 30px; height: 30px; }
  .esm-stat-copy h3 { font-size: 13px; margin-bottom: 9px; }
  .esm-stat-copy strong { font-size: 24px; margin-bottom: 7px; }
  .esm-stat-copy p { font-size: 12px; }
}


/* ===== v16 exact middle dashboard panels ===== */
.esm-middle-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.06fr) minmax(0, 1.08fr) minmax(300px, .88fr);
  grid-template-areas: "devices scenarios actions";
  gap: 16px;
  direction: ltr;
  align-items: stretch;
  margin-bottom: 18px;
}
.esm-panel-table { grid-area: devices; direction: rtl; }
.esm-panel-scenarios { grid-area: scenarios; direction: rtl; }
.esm-panel-actions { grid-area: actions; direction: rtl; }

.esm-middle-grid .esm-panel {
  min-height: 286px;
  padding: 15px 16px 12px;
  border-radius: 18px;
  background: rgba(255,255,255,.78);
  border: 1px solid #dfe6f1;
  box-shadow: 0 10px 26px rgba(51,73,125,.07);
  overflow: hidden;
}
.esm-middle-grid .esm-panel-header {
  min-height: 30px;
  margin-bottom: 12px;
}
.esm-middle-grid .esm-panel-header h3 {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
}
.esm-middle-grid .esm-mini-icon,
.esm-middle-grid .esm-link-mark,
.esm-middle-grid .esm-bolt-mark {
  width: 27px;
  height: 27px;
  border: 0;
  background: transparent;
}
.esm-middle-grid .esm-mini-icon::before {
  width: 11px;
  height: 11px;
  border-width: 1.8px;
  box-shadow: 7px 0 0 -2px var(--primary), 0 7px 0 -2px var(--primary), 7px 7px 0 -2px var(--primary);
}
.esm-middle-grid .esm-link-mark::before {
  width: 13px;
  height: 6px;
  border-width: 2px;
}
.esm-middle-grid .esm-bolt-mark::before {
  font-size: 16px;
}

/* devices table */
.esm-panel-table { display: flex; flex-direction: column; }
.esm-devices-table-wrap { flex: 1; margin: 0 -16px; }
.esm-devices-table {
  font-size: 12px;
  table-layout: fixed;
}
.esm-devices-table th,
.esm-devices-table td {
  padding: 9px 14px;
  border-bottom: 1px solid #e4e9f1;
  vertical-align: middle;
}
.esm-devices-table thead th {
  font-size: 11px;
  color: #7e8ba8;
  font-weight: 700;
}
.esm-devices-table th:nth-child(1), .esm-devices-table td:nth-child(1) { width: 28%; }
.esm-devices-table th:nth-child(2), .esm-devices-table td:nth-child(2) { width: 46%; }
.esm-devices-table th:nth-child(3), .esm-devices-table td:nth-child(3) { width: 26%; }
.esm-chip {
  padding: 5px 9px;
  min-width: 58px;
  justify-content: center;
  border-radius: 10px;
  font-size: 11px;
  background: #f2f5fa;
}
.esm-device-title-row { justify-content: flex-start; gap: 9px; }
.esm-device-mini-icon { order: -1; width: 24px; height: 24px; border-width: 1px; background: #f6f8fc; }
.esm-device-mini-icon::before { inset: 7px; border-width: 1.5px; }
.esm-status-label { gap: 6px; font-size: 12px; font-weight: 700; }
.esm-status-label::before { width: 8px; height: 8px; }

/* scenario rows and empty state */
.esm-panel-scenarios { display: flex; flex-direction: column; }
.esm-latest-scenarios-list {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.esm-scenario-row-card {
  min-height: 73px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid #dde4ee;
  background: rgba(255,255,255,.54);
  gap: 10px;
}
.esm-scenario-badge {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 11px;
  order: 3;
}
.esm-scenario-badge::after {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
  margin-right: 5px;
}
.esm-scenario-info { text-align: right; }
.esm-scenario-info h4 { margin: 0 0 6px; font-size: 13px; line-height: 1.5; }
.esm-scenario-info p { font-size: 11px; color: #7180a0; direction: ltr; text-align: right; }
.esm-scenario-arrow { order: -1; font-size: 20px; color: #7f8dac; }
.esm-empty-scenario-card {
  flex: 1;
  min-height: 184px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  text-align: center;
  padding: 20px;
}
.esm-empty-scenario-icon {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: #f1edff;
  display: grid;
  place-items: center;
}
.esm-empty-scenario-icon::before { content: none; }
.esm-empty-scenario-icon img {
  width: 23px;
  height: 23px;
  filter: invert(37%) sepia(85%) saturate(1621%) hue-rotate(225deg) brightness(99%) contrast(96%);
}
.esm-empty-scenario-card h4 { margin: 0; font-size: 14px; color: var(--text); }
.esm-empty-scenario-card p {
  margin: 0;
  max-width: 330px;
  font-size: 12px;
  line-height: 1.9;
  color: #8491ae;
}

/* quick actions */
.esm-panel-actions { display: flex; flex-direction: column; }
.esm-action-buttons {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.esm-action-btn {
  min-height: 54px;
  border-radius: 13px;
  border: 1px solid #dce4f0;
  font-size: 14px;
  font-weight: 800;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
}
.esm-action-btn--primary {
  color: #245cf5;
  background: linear-gradient(180deg,#f4f7ff,#edf2ff);
}
.esm-action-btn--soft {
  color: #6551f4;
  background: linear-gradient(180deg,#faf8ff,#f3efff);
}
.esm-action-btn--success {
  color: #35ae58;
  background: linear-gradient(180deg,#f6fcf7,#edf9f0);
}
.esm-action-symbol { font-size: 20px; line-height: 1; font-weight: 400; }
.link-ico { width: 19px; height: 12px; }
.bars-ico { width: 18px; height: 18px; }

/* exact footer links */
.esm-middle-grid .esm-panel-link {
  width: calc(100% + 32px);
  margin: auto -16px -12px;
  min-height: 35px;
  padding: 9px 16px;
  border-top: 1px solid #e4e9f1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  color: #2460ef;
  font-size: 11px;
  font-weight: 700;
  background: rgba(255,255,255,.32);
}
.esm-middle-grid .esm-panel-link::before { content: none; }

@media (max-width: 1180px) {
  .esm-middle-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "scenarios actions"
      "devices devices";
  }
}
@media (max-width: 760px) {
  .esm-middle-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "actions"
      "scenarios"
      "devices";
  }
  .esm-middle-grid .esm-panel { min-height: auto; }
  .esm-latest-scenarios-list { min-height: 180px; }
}


/* ===== v17 exact quick actions and footer links ===== */
.esm-panel-actions .esm-panel-header {
  direction: rtl;
  justify-content: space-between;
}
.esm-panel-actions .esm-panel-header h3 {
  order: 1;
  margin: 0;
  text-align: right;
}
.esm-panel-actions .esm-bolt-mark {
  order: 2;
  flex: 0 0 24px;
  display: grid;
  place-items: center;
}
.esm-panel-actions .esm-bolt-mark::before {
  content: 'ϟ';
  color: #245cf5;
  font-size: 21px;
  font-family: Arial, sans-serif;
  line-height: 1;
}

.esm-panel-actions .esm-action-buttons {
  gap: 14px;
  padding-top: 2px;
}
.esm-panel-actions .esm-action-btn {
  width: 100%;
  min-height: 54px;
  padding: 0 18px;
  border-radius: 13px;
  direction: rtl;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.esm-action-inner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
  direction: rtl;
  line-height: 1;
}
.esm-action-label {
  display: inline-block;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  line-height: 1.4;
}
.esm-action-symbol,
.esm-action-image {
  flex: 0 0 auto;
  order: 2;
}
.esm-action-label { order: 1; }
.esm-plus-icon {
  font-size: 21px;
  font-weight: 400;
  transform: translateY(-1px);
}
.esm-action-image {
  width: 19px;
  height: 19px;
  object-fit: contain;
}
.esm-action-btn--soft .esm-action-image {
  filter: invert(34%) sepia(84%) saturate(2297%) hue-rotate(233deg) brightness(103%) contrast(101%);
}
.esm-action-btn--success .esm-action-image {
  filter: invert(55%) sepia(54%) saturate(650%) hue-rotate(78deg) brightness(96%) contrast(90%);
}

/* links below devices/scenarios exactly aligned with arrow */
.esm-middle-grid .esm-panel-link {
  direction: rtl;
  justify-content: space-between;
  gap: 10px;
  text-decoration: none;
}
.esm-middle-grid .esm-panel-link > span:first-child {
  order: 1;
  text-align: right;
}
.esm-footer-arrow {
  order: 2;
  color: #2460ef;
  font-size: 15px;
  line-height: 1;
  transform: translateY(-1px);
}
.esm-middle-grid .esm-panel-link:hover {
  background: rgba(238,244,255,.72);
}

@media (max-width: 760px) {
  .esm-panel-actions .esm-action-btn { min-height: 52px; }
  .esm-action-label { font-size: 13px; }
  .esm-action-image { width: 18px; height: 18px; }
}


/* v18: remove requested decorative icons */
.esm-mini-icon,
.esm-link-mark,
.esm-bolt-mark,
.esm-device-mini-icon {
  display: none !important;
}


/* Align device and relay footer links to the end */
.esm-panel-link--end {
  width: 100%;
  justify-content: flex-end !important;
}


/* v20: identical footer links for devices, scenarios and relays */
.esm-panel-link--matching {
  width: calc(100% + 32px) !important;
  margin: auto -16px -12px !important;
  min-height: 35px;
  padding: 9px 16px !important;
  border-top: 1px solid #e4e9f1 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 10px !important;
  direction: rtl !important;
  color: #2460ef !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  text-decoration: none !important;
  background: rgba(255,255,255,.32) !important;
}
.esm-panel-link--matching::before { content: none !important; }
.esm-panel-link--matching > span:first-child {
  order: 1;
  text-align: right;
}
.esm-panel-link--matching .esm-footer-arrow {
  order: 2;
  color: #2460ef;
  font-size: 15px;
  line-height: 1;
  transform: translateY(-1px);
}
.esm-panel-link--matching:hover { background: rgba(238,244,255,.72) !important; }

/* ===== v21 responsive system ===== */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

img, svg, canvas {
  max-width: 100%;
}

.esm-content-area,
.esm-panel,
.esm-stat-card,
.esm-middle-grid > *,
.esm-bottom-grid > * {
  min-width: 0;
}

/* Large desktop */
@media (min-width: 1441px) {
  .app-header,
  .esm-app-shell {
    width: min(1880px, calc(100% - 32px));
  }
}

/* Laptop and small desktop */
@media (max-width: 1366px) {
  .app-header,
  .esm-app-shell {
    width: calc(100% - 24px);
  }

  .esm-app-shell {
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 14px;
  }

  .esm-sidebar {
    padding-inline: 8px;
  }

  .esm-stats-grid {
    gap: 12px;
  }

  .esm-stat-card {
    padding: 16px;
  }

  .esm-stat-icon {
    width: 54px;
    height: 54px;
  }

  .esm-stat-icon img {
    width: 28px;
    height: 28px;
  }

  .esm-middle-grid,
  .esm-bottom-grid {
    gap: 12px;
  }
}

/* Tablet landscape */
@media (max-width: 1100px) {
  .app-header {
    grid-template-columns: auto 1fr auto;
    gap: 14px;
    padding-inline: 18px;
  }

  .app-title {
    font-size: 1.25rem;
    white-space: nowrap;
  }

  .main-brand {
    font-size: 1rem;
    letter-spacing: 6px;
  }

  .tagline {
    font-size: .58rem;
  }

  .brand-dots {
    gap: 4px;
  }

  .brand-dots span {
    width: 6px;
    height: 6px;
  }

  .esm-mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 120;
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--panel);
    box-shadow: var(--shadow);
  }

  .esm-mobile-menu-toggle span {
    width: 20px;
    height: 2px;
    margin: 2.5px 0;
    border-radius: 999px;
    background: var(--primary);
  }

  .esm-app-shell {
    display: block;
  }

  .esm-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 110;
    width: min(280px, 84vw);
    min-height: 100dvh;
    border-radius: 0;
    transform: translateX(105%);
    transition: transform .24s ease;
    overflow-y: auto;
    padding: 78px 14px 18px;
  }

  .esm-sidebar.is-open {
    transform: translateX(0);
  }

  .esm-sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(15, 23, 42, .38);
    opacity: 0;
    visibility: hidden;
    transition: opacity .24s ease, visibility .24s ease;
  }

  .esm-sidebar-overlay.is-visible {
    opacity: 1;
    visibility: visible;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .esm-nav-link {
    grid-template-columns: 26px 1fr;
    justify-items: start;
    align-items: center;
    gap: 12px;
    padding: 13px 14px;
  }

  .esm-nav-text {
    font-size: 14px;
  }

  .esm-sidebar-footer {
    margin-top: 18px;
  }

  .esm-content-area {
    width: 100%;
  }

  .esm-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .esm-middle-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "actions scenarios"
      "devices devices";
  }

  .esm-panel-actions { grid-area: actions; }
  .esm-panel-scenarios { grid-area: scenarios; }
  .esm-panel-table { grid-area: devices; }

  .esm-bottom-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "chart"
      "donut";
  }

  .esm-panel-chart { grid-area: chart; }
  .esm-panel-donut { grid-area: donut; }
}

/* Tablet portrait */
@media (max-width: 820px) {
  .app-header {
    width: calc(100% - 20px);
    min-height: 68px;
    padding: 10px 14px;
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "actions title";
  }

  .header-actions {
    grid-area: actions;
    gap: 8px;
  }

  .app-title {
    grid-area: title;
    justify-self: end;
    padding-right: 50px;
    font-size: 1.1rem;
  }

  .brand-logo {
    display: none;
  }

  .soft-button {
    min-height: 38px;
  }

  .logout-button {
    padding-inline: 12px;
  }

  .theme-toggle {
    width: 40px;
  }

  .esm-app-shell {
    width: calc(100% - 20px);
    margin-top: 10px;
  }

  .esm-welcome-card--plain {
    min-height: 88px;
    padding: 14px 4px;
  }

  .esm-welcome-text h2 {
    font-size: 1.55rem;
  }

  .esm-welcome-text p {
    font-size: .86rem;
  }

  .esm-middle-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "actions"
      "scenarios"
      "devices";
  }

  .esm-panel,
  .esm-stat-card {
    border-radius: 18px;
  }

  .esm-devices-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .esm-devices-table {
    min-width: 560px;
  }

  .esm-chart-toolbar {
    flex-wrap: wrap;
    gap: 10px;
  }

  .esm-chart-canvas-wrap {
    min-height: 260px;
  }

  .esm-donut-wrap {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .esm-donut-legend {
    width: 100%;
  }
}

/* Mobile */
@media (max-width: 560px) {
  .app-header {
    width: calc(100% - 16px);
    margin-top: 8px;
    padding: 8px 10px;
    min-height: 62px;
  }

  .app-title {
    padding-right: 44px;
    font-size: .98rem;
  }

  .logout-text {
    display: none;
  }

  .logout-button {
    width: 40px;
    padding: 0;
    justify-content: center;
  }

  .theme-toggle {
    width: 38px;
  }

  .esm-mobile-menu-toggle {
    top: 17px;
    right: 14px;
    width: 38px;
    height: 38px;
  }

  .esm-app-shell {
    width: calc(100% - 16px);
  }

  .esm-welcome-card--plain {
    min-height: 76px;
    margin-bottom: 10px;
  }

  .esm-welcome-text h2 {
    font-size: 1.3rem;
    margin-bottom: 5px;
  }

  .esm-welcome-text p {
    font-size: .78rem;
    line-height: 1.8;
  }

  .esm-stats-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .esm-stat-card {
    min-height: 104px;
    padding: 14px 16px;
  }

  .esm-stat-copy h3 {
    font-size: .92rem;
    margin-bottom: 8px;
  }

  .esm-stat-copy strong {
    font-size: 1.55rem;
    margin-bottom: 6px;
  }

  .esm-stat-copy p {
    font-size: .78rem;
  }

  .esm-stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 14px;
  }

  .esm-stat-icon img {
    width: 25px;
    height: 25px;
  }

  .esm-panel {
    padding: 14px;
  }

  .esm-panel-header h3 {
    font-size: .95rem;
  }

  .esm-action-btn {
    min-height: 48px !important;
    padding-inline: 12px !important;
  }

  .esm-action-label {
    font-size: 12.5px !important;
  }

  .esm-latest-scenarios-list,
  .esm-empty-scenario-card {
    min-height: 150px;
  }

  .esm-middle-grid .esm-panel-link,
  .esm-panel-link--matching {
    width: calc(100% + 28px) !important;
    margin-inline: -14px !important;
    margin-bottom: -10px !important;
    padding-inline: 14px !important;
  }

  .esm-chart-toolbar {
    align-items: stretch;
  }

  .esm-range-control,
  .esm-range-select {
    width: 100%;
  }

  .esm-chart-legend {
    width: 100%;
    justify-content: center;
  }

  .esm-chart-canvas-wrap {
    min-height: 220px;
  }

  .esm-donut-canvas-wrap {
    width: 180px;
    height: 180px;
  }

  .esm-donut-legend div {
    grid-template-columns: 10px 1fr auto auto;
    font-size: 12px;
  }
}


/* ===== Mobile sidebar opaque panel + close button ===== */
.esm-sidebar-mobile-head {
  display: none;
}

@media (max-width: 1100px) {
  .esm-sidebar {
    background: #ffffff !important;
    background-image: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    opacity: 1 !important;
    box-shadow: -18px 0 42px rgba(24, 42, 82, 0.16) !important;
    border-left: 1px solid #e1e7f0 !important;
    padding-top: 18px !important;
  }

  html[data-theme="dark"] .esm-sidebar {
    background: #ffffff !important;
    color: #1f2f58 !important;
  }

  .esm-sidebar-mobile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 52px;
    margin-bottom: 12px;
    padding: 0 4px 0 2px;
    border-bottom: 1px solid #edf1f6;
  }

  .esm-sidebar-mobile-title {
    font-size: 15px;
    font-weight: 800;
    color: #1f2f58;
  }

  .esm-sidebar-close-btn {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid #d9e2ef;
    border-radius: 13px;
    background: #ffffff;
    color: #2f5cff;
    font-family: Arial, sans-serif;
    font-size: 30px;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 8px 22px rgba(47, 92, 255, 0.09);
  }

  .esm-sidebar-close-btn:active {
    transform: scale(0.96);
  }

  body.sidebar-open .esm-mobile-menu-toggle {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  .esm-mobile-menu-toggle {
    transition: opacity .18s ease, visibility .18s ease, transform .18s ease;
  }

  .esm-sidebar .esm-nav-link,
  .esm-sidebar .esm-nav-text,
  .esm-sidebar .esm-sidebar-footer {
    opacity: 1 !important;
  }

  .esm-sidebar .esm-nav-link {
    background-color: transparent;
  }

  .esm-sidebar .esm-nav-link.active {
    background: #eef3ff !important;
  }
}
