@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap');

:root {
  --color-primary: #4f46e5;
  --color-primary-dark: #4338ca;
  --color-primary-light: #eef2ff;
  --color-success: #16a34a;
  --color-success-bg: #ecfdf5;
  --color-danger: #dc2626;
  --color-danger-bg: #fef2f2;
  --color-muted-bg: #f1f5f9;
  --color-text: #0f172a;
  --color-text-muted: #64748b;
  --color-border: #e5e7eb;

  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-surface-hover: #f8fafc;
  --select-arrow: #94a3b8;
}

:root {
  color-scheme: light;
}

[data-theme="dark"] {
  color-scheme: dark;
  --color-primary: #818cf8;
  --color-primary-dark: #6366f1;
  --color-primary-light: rgba(99,102,241,0.18);
  --color-success: #4ade80;
  --color-success-bg: rgba(34,197,94,0.12);
  --color-danger: #f87171;
  --color-danger-bg: rgba(248,113,113,0.12);
  --color-muted-bg: #334155;
  --color-text: #e2e8f0;
  --color-text-muted: #94a3b8;
  --color-border: #334155;

  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-surface-hover: #263246;
  --select-arrow: #94a3b8;
}

* {
  font-family: 'Vazirmatn', sans-serif;
}

html, body {
  background-color: var(--color-bg);
  color: var(--color-text);
  transition: background-color 0.15s, color 0.15s;
}

/* ---------- Status badges & dots ---------- */
.status-up {
  background-color: var(--color-success-bg);
  color: var(--color-success);
}

.status-down {
  background-color: var(--color-danger-bg);
  color: var(--color-danger);
}

.status-unknown {
  background-color: var(--color-muted-bg);
  color: var(--color-text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
}

.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-up { background-color: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,0.15); }
.dot-down { background-color: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,0.15); }
.dot-unknown { background-color: #94a3b8; box-shadow: 0 0 0 3px rgba(148,163,184,0.15); }

/* Shared visual language for the landing demo and real monitor timeline. */
.status-bars {
  display: flex;
  align-items: stretch;
  gap: 3px;
  width: 100%;
  height: 28px;
}
.status-bar {
  flex: 1 1 0;
  min-width: 2px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: var(--color-muted-bg);
  cursor: pointer;
}
.status-bar:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.status-bar-up { background: var(--color-success); }
.status-bar-down { background: var(--color-danger); }
.status-bar-unknown { background: #94a3b8; }
.status-legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  vertical-align: middle;
  margin-inline-end: 3px;
}
.status-legend-up { background: var(--color-success); }
.status-legend-down { background: var(--color-danger); }
.status-legend-unknown { background: #94a3b8; }
.sensor-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}
.sensor-summary-card {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--color-muted-bg);
}
@media (max-width: 480px) {
  .status-bars { gap: 2px; }
  .sensor-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Form inputs ---------- */
input[type="text"], input[type="number"], input[type="password"],
input[type="url"], input[type="tel"], input[type="email"],
input[type="date"], input[type="time"], input[type="datetime-local"], select, textarea {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: 0.6rem;
  padding: 0.55rem 0.8rem;
  font-size: 0.875rem;
  background-color: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s, color 0.15s;
  line-height: 1.4;
}

/* Inputs and selects share the same fixed height so dropdowns line up
   with text fields (selects otherwise get extra height from the native
   appearance/indicator). Textareas keep their natural height. */
input[type="text"], input[type="number"], input[type="password"],
input[type="url"], input[type="tel"], input[type="email"],
input[type="date"], input[type="time"], input[type="datetime-local"], select {
  height: 2.5rem;
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-left: 2.25rem;
  background-repeat: no-repeat;
  background-position: left 0.75rem center;
  background-size: 1rem 1rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

label {
  color: var(--color-text);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  border-radius: 0.6rem;
  padding: 0.55rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s, box-shadow 0.15s, color 0.15s, border-color 0.15s;
  border: 1px solid transparent;
}

.btn-primary {
  background-color: var(--color-primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(79,70,229,0.3);
}
.btn-primary:hover { background-color: var(--color-primary-dark); }

.btn-secondary {
  background-color: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { background-color: var(--color-surface-hover); }

.btn-danger {
  background-color: var(--color-danger-bg);
  color: var(--color-danger);
}
.btn-danger:hover { background-color: var(--color-danger-bg); filter: brightness(0.95); }

.btn-ghost {
  background-color: transparent;
  color: var(--color-text-muted);
  padding: 0.3rem 0.6rem;
}
.btn-ghost:hover { color: var(--color-text); background-color: var(--color-muted-bg); }

/* ---------- Theme toggle ---------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 0.6rem;
  background-color: var(--color-muted-bg);
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 1rem;
  border: 1px solid var(--color-border);
  transition: background-color 0.15s, color 0.15s;
}
.theme-toggle:hover {
  color: var(--color-primary);
}

/* ---------- Authenticated application shell ---------- */
:root {
  --app-sidebar-width: 15rem;
  --app-sidebar-collapsed-width: 4.75rem;
  --app-mobile-nav-height: 4.25rem;
}

.app-shell-page {
  padding-inline-start: var(--app-sidebar-width);
  transition: padding-inline-start 0.2s ease;
}

.app-shell-page.app-sidebar-collapsed {
  padding-inline-start: var(--app-sidebar-collapsed-width);
}

.app-sidebar {
  position: fixed;
  z-index: 45;
  inset-block: 0;
  inset-inline-start: 0;
  width: var(--app-sidebar-width);
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-inline-end: 1px solid var(--color-border);
  box-shadow: 0 0 24px rgba(15, 23, 42, 0.04);
  transition: width 0.2s ease, background-color 0.15s, border-color 0.15s;
}

.app-sidebar-brand {
  height: 4.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--color-border);
}

.app-brand-link,
.app-mobile-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  color: var(--color-text);
  font-weight: 800;
}

.app-brand-text { font-size: 1rem; white-space: nowrap; }

.app-sidebar-toggle {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: var(--color-text-muted);
  background: var(--color-muted-bg);
  border: 1px solid var(--color-border);
  border-radius: 0.55rem;
  transition: color 0.15s, transform 0.2s;
}

.app-sidebar-toggle:hover { color: var(--color-primary); }
.app-sidebar-toggle svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 2; }

.app-sidebar-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.85rem 0.7rem;
}

.app-nav-group + .app-nav-group { margin-top: 1rem; }
.app-nav-heading {
  padding: 0 0.75rem 0.4rem;
  color: var(--color-text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
}

.app-nav-link {
  position: relative;
  width: 100%;
  min-height: 2.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 0.7rem;
  color: var(--color-text-muted);
  font-size: 0.86rem;
  font-weight: 500;
  text-align: right;
  transition: color 0.15s, background-color 0.15s;
}

.app-nav-link:hover { color: var(--color-text); background: var(--color-surface-hover); }
.app-nav-link.active { color: var(--color-primary); background: var(--color-primary-light); font-weight: 700; }
.app-nav-link.active::before {
  content: "";
  position: absolute;
  inset-inline-start: -0.7rem;
  width: 3px;
  height: 1.6rem;
  border-radius: 0 3px 3px 0;
  background: var(--color-primary);
}

.app-nav-icon,
.app-action-link > svg,
.app-sheet-link > svg {
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 1.25rem;
}

.app-nav-icon svg,
.app-action-link > svg,
.app-sheet-link > svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-external { margin-inline-start: auto; font-size: 0.72rem; }
.app-shell-role-loading [data-user-only] { visibility: hidden; }

.app-sidebar-footer {
  padding: 0.7rem;
  border-top: 1px solid var(--color-border);
}

.app-action-link { background: transparent; cursor: pointer; }
.app-logout-link { color: var(--color-danger); }
.app-logout-link:hover { color: var(--color-danger); background: var(--color-danger-bg); }
.app-user-summary {
  min-height: 3.2rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.55rem;
  padding: 0.55rem 0.65rem;
  border-radius: 0.75rem;
  background: var(--color-muted-bg);
}
.app-user-avatar {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-weight: 700;
}
.app-user-copy { min-width: 0; display: flex; flex-direction: column; }
.app-user-copy strong { color: var(--color-text); font-size: 0.76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-user-copy small { color: var(--color-text-muted); font-size: 0.65rem; }

.app-sidebar-collapsed .app-sidebar { width: var(--app-sidebar-collapsed-width); }
.app-sidebar-collapsed .app-sidebar-brand { justify-content: center; padding: 0; }
.app-sidebar-collapsed .app-brand-text,
.app-sidebar-collapsed .app-nav-heading,
.app-sidebar-collapsed .app-nav-label,
.app-sidebar-collapsed .app-external,
.app-sidebar-collapsed .app-user-copy { display: none; }
.app-sidebar-collapsed .app-sidebar-toggle { position: absolute; inset-inline-end: -0.8rem; top: 1.25rem; background: var(--color-surface); }
.app-sidebar-collapsed .app-sidebar-toggle svg { transform: rotate(180deg); }
.app-sidebar-collapsed .app-nav-link { justify-content: center; padding-inline: 0; }
.app-sidebar-collapsed .app-user-summary { justify-content: center; padding-inline: 0; background: transparent; }
.app-sidebar-collapsed .app-nav-link.active::before { inset-inline-start: -0.7rem; }

.app-mobile-header,
.app-bottom-nav,
.app-sheet-backdrop,
.app-more-sheet { display: none; }

/* ---------- Monitor dashboard ---------- */
.dashboard-toolbar {
  display: grid;
  grid-template-columns: minmax(15rem, 1fr) 12rem auto auto;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 0.9rem;
  background: var(--color-surface);
}

.dashboard-search-wrap { position: relative; min-width: 0; }
.dashboard-search-wrap > svg {
  position: absolute;
  z-index: 1;
  inset-inline-start: 0.8rem;
  top: 50%;
  width: 1rem;
  height: 1rem;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--color-text-muted);
  stroke-width: 2;
  stroke-linecap: round;
}
.dashboard-search-wrap input { padding-inline-start: 2.35rem; padding-inline-end: 2rem; }
.dashboard-search-wrap input::-webkit-search-cancel-button { display: none; }
.dashboard-field-clear {
  position: absolute;
  z-index: 2;
  inset-inline-end: 0.45rem;
  top: 50%;
  width: 1.8rem;
  height: 1.8rem;
  transform: translateY(-50%);
  border-radius: 50%;
  color: var(--color-text-muted);
  font-size: 1.05rem;
}
.dashboard-field-clear:hover { color: var(--color-text); background: var(--color-muted-bg); }
.dashboard-owner-filter .owner-filter-box,
.dashboard-owner-filter input { width: 100%; max-width: none !important; }
.dashboard-filter-meta { display: flex; align-items: center; justify-content: flex-end; gap: 0.6rem; white-space: nowrap; }
.dashboard-clear-filters { color: var(--color-primary); font-size: 0.75rem; font-weight: 600; }
.dashboard-clear-filters:hover { text-decoration: underline; }
.dashboard-add-button span { font-size: 1.15rem; line-height: 1; }
.monitors-mobile-list { display: none; }

/* ---------- Cards ---------- */
.card {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.9rem;
  box-shadow: 0 1px 2px rgba(15,23,42,0.04);
  padding: 1.25rem;
  transition: background-color 0.15s, border-color 0.15s;
}

.stat-card {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.9rem;
  padding: 1.1rem 1.25rem;
  transition: background-color 0.15s, border-color 0.15s;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-bottom: 0.35rem;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--color-text);
}

/* ---------- Tables ---------- */
table {
  border-collapse: collapse;
}

thead th {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: none;
  padding-bottom: 0.6rem;
}

tbody tr {
  transition: background-color 0.1s;
  border-color: var(--color-border) !important;
}

tbody tr:hover {
  background-color: var(--color-surface-hover);
}

thead tr, table tr.border-b {
  border-color: var(--color-border) !important;
}

/* ---------- Top navigation ---------- */
.topnav {
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  transition: background-color 0.15s, border-color 0.15s;
}

.topnav .nav-link {
  color: var(--color-text-muted);
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.4rem 0.2rem;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.topnav .nav-link:hover {
  color: var(--color-primary);
}

.topnav .nav-link.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.brand-badge {
  width: 2rem;
  height: 2rem;
  border-radius: 0.6rem;
  background: linear-gradient(135deg, var(--color-primary), #818cf8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1rem;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15,23,42,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}

.modal-box {
  background-color: var(--color-surface);
  border-radius: 1rem;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: 0 20px 50px rgba(15,23,42,0.2);
}

/* ---------- Pagination ---------- */
.pagination-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0 0.6rem;
  border-radius: 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  border: 1px solid var(--color-border);
  background-color: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.pagination-btn:hover:not(:disabled) {
  background-color: var(--color-primary-light);
  color: var(--color-primary);
}

.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------------------------------------------------------------
   Dark theme overrides for inline Tailwind utility classes used
   across the static pages (since Tailwind here runs without a
   class-based dark: config, these are mapped manually).
   ------------------------------------------------------------- */
[data-theme="dark"] .text-gray-800,
[data-theme="dark"] .text-gray-700 {
  color: var(--color-text) !important;
}

[data-theme="dark"] .text-gray-600,
[data-theme="dark"] .text-gray-500,
[data-theme="dark"] .text-gray-400 {
  color: var(--color-text-muted) !important;
}

[data-theme="dark"] .bg-white {
  background-color: var(--color-surface) !important;
}

[data-theme="dark"] .bg-gray-50 {
  background-color: var(--color-bg) !important;
}

[data-theme="dark"] .bg-gray-100 {
  background-color: var(--color-muted-bg) !important;
}

[data-theme="dark"] .border-gray-100,
[data-theme="dark"] .border-gray-200 {
  border-color: var(--color-border) !important;
}

[data-theme="dark"] .bg-indigo-50,
[data-theme="dark"] .bg-indigo-50\/40 {
  background-color: var(--color-primary-light) !important;
}

[data-theme="dark"] .border-indigo-100,
[data-theme="dark"] .border-indigo-200 {
  border-color: rgba(129,140,248,0.3) !important;
}

[data-theme="dark"] .bg-red-50 {
  background-color: var(--color-danger-bg) !important;
}

[data-theme="dark"] .text-green-600 {
  color: var(--color-success) !important;
}

[data-theme="dark"] .text-red-500,
[data-theme="dark"] .text-red-600 {
  color: var(--color-danger) !important;
}

[data-theme="dark"] .text-indigo-600,
[data-theme="dark"] .hover\:text-indigo-600:hover {
  color: var(--color-primary) !important;
}

[data-theme="dark"] .hover\:text-gray-600:hover {
  color: var(--color-text) !important;
}

/* code/config snippet block stays dark in both themes for contrast */
[data-theme="dark"] .bg-gray-900 {
  background-color: #0b1220 !important;
}

/* RTL-aware custom tooltip for timing waterfall segments */
[data-tip] {
  position: relative;
}
[data-tip]::after {
  content: attr(data-tip);
  direction: rtl;
  white-space: nowrap;
  position: absolute;
  bottom: calc(100% + 6px);
  right: 0;
  background: rgba(15,23,42,0.92);
  color: #f1f5f9;
  font-size: 11px;
  line-height: 1.5;
  padding: 4px 8px;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 100;
  font-family: Vazirmatn, sans-serif;
}
[data-tip]:hover::after {
  opacity: 1;
}

/* drag-to-reorder row highlight */
tr.drag-over {
  outline: 2px dashed var(--color-primary);
  background: var(--color-primary-light);
}

/* ---------------------------------------------------------------
   Responsive / mobile
   The pages are plain static HTML with a shared nav, so the
   responsive behaviour lives here rather than in per-page markup.
   ------------------------------------------------------------- */
@media (max-width: 768px) {
  /* Top navigation: keep the brand on the first row and let the links
     (plus theme/logout) drop to a second, horizontally-scrollable strip
     so they never overflow or get clipped on a phone. */
  .topnav > div {
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
  }
  .topnav > div > div:last-child {
    width: 100%;
    overflow-x: auto;
    gap: 1.25rem !important;
    padding-bottom: 0.15rem;
    -webkit-overflow-scrolling: touch;
  }
  .topnav .nav-link { white-space: nowrap; }

  /* Tighter page chrome and smaller hero numbers on small screens. */
  main { padding-top: 1rem !important; padding-bottom: 1.25rem !important; }
  .card, .stat-card { padding: 1rem; }
  .stat-value { font-size: 1.25rem; }
  .stat-label { font-size: 0.7rem; }

  /* Page-header rows (title + action button) stack instead of squeezing. */
  main > .flex.items-center.justify-between {
    flex-wrap: wrap;
    gap: 0.75rem;
  }
}

@media (max-width: 900px) {
  .app-shell-page,
  .app-shell-page.app-sidebar-collapsed { padding-inline-start: 0; padding-bottom: calc(var(--app-mobile-nav-height) + env(safe-area-inset-bottom)); }
  .app-sidebar { display: none; }
  .app-mobile-header {
    position: sticky;
    z-index: 35;
    top: 0;
    height: 3.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1rem;
    background: color-mix(in srgb, var(--color-surface) 94%, transparent);
    border-bottom: 1px solid var(--color-border);
    backdrop-filter: blur(12px);
  }
  .app-mobile-brand { font-size: 0.9rem; }
  .app-mobile-brand .brand-badge { width: 1.85rem; height: 1.85rem; }
  .app-mobile-page { color: var(--color-text-muted); font-size: 0.78rem; font-weight: 600; }
  .app-bottom-nav {
    position: fixed;
    z-index: 50;
    inset-inline: 0;
    bottom: 0;
    min-height: var(--app-mobile-nav-height);
    display: flex;
    align-items: flex-start;
    justify-content: space-around;
    padding: 0.45rem 0.35rem calc(0.35rem + env(safe-area-inset-bottom));
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.08);
  }
  .app-bottom-link {
    width: auto;
    min-width: 4.25rem;
    min-height: 3.2rem;
    flex-direction: column;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.3rem 0.45rem;
    border-radius: 0.65rem;
    font-size: 0.66rem;
    text-align: center;
  }
  .app-bottom-link .app-nav-icon { width: 1.35rem; height: 1.35rem; flex-basis: 1.35rem; }
  .app-bottom-link.active::before { display: none; }
  .app-sheet-backdrop {
    position: fixed;
    z-index: 55;
    inset: 0;
    display: block;
    background: rgba(15, 23, 42, 0.48);
  }
  .app-sheet-backdrop[hidden] { display: none; }
  .app-more-sheet {
    position: fixed;
    z-index: 60;
    inset-inline: 0;
    bottom: 0;
    max-height: min(82vh, 42rem);
    display: block;
    overflow-y: auto;
    padding: 0.5rem 1rem calc(1rem + env(safe-area-inset-bottom));
    border-radius: 1.25rem 1.25rem 0 0;
    background: var(--color-surface);
    box-shadow: 0 -20px 50px rgba(15, 23, 42, 0.22);
    transform: translateY(105%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0.22s;
  }
  .app-more-sheet.open { transform: translateY(0); visibility: visible; }
  .app-sheet-handle { width: 2.75rem; height: 0.28rem; margin: 0 auto 0.55rem; border-radius: 999px; background: var(--color-border); }
  .app-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 0.3rem 0.25rem 0.75rem; color: var(--color-text); }
  .app-sheet-head button { width: 2.5rem; height: 2.5rem; color: var(--color-text-muted); font-size: 1.5rem; }
  .app-sheet-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
  .app-sheet-link {
    min-height: 3.25rem;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: 0.75rem;
    color: var(--color-text-muted);
    background: var(--color-surface);
    font-size: 0.8rem;
    text-align: right;
  }
  .app-sheet-link.active { color: var(--color-primary); border-color: var(--color-primary); background: var(--color-primary-light); }
  .app-sheet-link .app-external { margin-inline-start: auto; }
  .app-sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--color-border); }
  .app-sheet-open { overflow: hidden; }
}

@media (max-width: 768px) {
  .dashboard-heading { flex-wrap: nowrap !important; }
  .dashboard-heading > div { min-width: 0; }
  .dashboard-heading p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .dashboard-add-button { flex: 0 0 auto; padding-inline: 0.8rem; }
  .dashboard-toolbar {
    grid-template-columns: minmax(0, 1fr) minmax(7.5rem, 0.55fr);
    gap: 0.6rem;
    padding: 0.65rem;
  }
  .dashboard-search-wrap { grid-column: 1 / -1; }
  .dashboard-owner-filter { grid-column: 1 / -1; }
  .dashboard-filter-meta { min-height: 1.5rem; justify-content: flex-start; }
  .monitors-desktop-wrap { display: none; }
  .monitors-mobile-list { display: grid; gap: 0.75rem; }
  .monitor-mobile-card {
    min-width: 0;
    padding: 1rem;
    border: 1px solid var(--color-border);
    border-radius: 0.9rem;
    background: var(--color-surface);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  }
  .monitor-card-head { display: flex; align-items: flex-start; gap: 0.65rem; min-width: 0; }
  .monitor-card-head > .status-dot { margin-top: 0.4rem; }
  .monitor-card-title { min-width: 0; flex: 1; }
  .monitor-card-title > a { display: block; overflow: hidden; color: var(--color-text); font-size: 0.95rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
  .monitor-card-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.35rem; color: var(--color-text-muted); font-size: 0.66rem; }
  .monitor-card-state { flex: 0 0 auto; padding: 0.2rem 0.55rem; border-radius: 999px; background: var(--color-muted-bg); color: var(--color-text-muted); font-size: 0.68rem; font-weight: 600; }
  .monitor-card-state.state-up { color: var(--color-success); background: var(--color-success-bg); }
  .monitor-card-state.state-down { color: var(--color-danger); background: var(--color-danger-bg); }
  .monitor-card-url { margin-top: 0.8rem; overflow: hidden; color: var(--color-text-muted); font-size: 0.72rem; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
  .monitor-card-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
    margin-top: 0.75rem;
    padding: 0.7rem;
    border-radius: 0.7rem;
    background: var(--color-muted-bg);
  }
  .monitor-card-metrics > div { min-width: 0; display: flex; flex-direction: column; gap: 0.2rem; }
  .monitor-card-metrics > div + div { border-inline-start: 1px solid var(--color-border); padding-inline-start: 0.45rem; }
  .monitor-card-metrics span { color: var(--color-text-muted); font-size: 0.62rem; white-space: nowrap; }
  .monitor-card-metrics span,
  .monitor-card-metrics strong { width: 100%; text-align: right; }
  .monitor-card-metrics strong { overflow: hidden; color: var(--color-text); font-size: 0.76rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
  .monitor-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-top: 0.85rem; }
  .monitor-card-activation { min-width: 0; }
  .monitor-card-actions { display: flex; align-items: center; gap: 0.35rem; color: var(--color-primary); font-size: 0.72rem; font-weight: 600; }
  .monitor-card-actions > a,
  .monitor-card-actions > button { min-height: 2.25rem; display: inline-flex; align-items: center; padding: 0.35rem 0.55rem; border-radius: 0.55rem; }
  .monitor-card-actions > a:hover,
  .monitor-card-actions > button:hover { background: var(--color-primary-light); }
  .monitor-card-detail { background: var(--color-primary-light); }
  .monitor-card-more { position: relative; }
  .monitor-card-more > summary {
    width: 2.25rem;
    height: 2.25rem;
    display: grid;
    place-items: center;
    border-radius: 0.55rem;
    cursor: pointer;
    list-style: none;
    letter-spacing: 0.08em;
  }
  .monitor-card-more > summary::-webkit-details-marker { display: none; }
  .monitor-card-more[open] > summary { background: var(--color-primary-light); }
  .monitor-card-more[open] { z-index: 25; }
  .monitor-card-menu {
    position: absolute;
    z-index: 20;
    inset-inline-end: 0;
    top: calc(100% + 0.35rem);
    width: 11rem;
    display: grid;
    gap: 0.35rem;
    padding: 0.55rem;
    border: 1px solid var(--color-border);
    border-radius: 0.7rem;
    background: var(--color-surface);
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.16);
  }
  .monitor-card-more.drop-up .monitor-card-menu {
    top: auto;
    bottom: calc(100% + 0.35rem);
  }
  .monitor-card-menu > a,
  .monitor-card-menu > button { min-height: 2.25rem; display: flex; align-items: center; padding: 0.35rem 0.45rem; border-radius: 0.45rem; text-align: right; }
  .monitor-card-menu > a:hover,
  .monitor-card-menu > button:hover { background: var(--color-surface-hover); }
  .monitor-card-menu select { width: 100% !important; }
  .monitor-mobile-empty,
  .monitor-mobile-loading,
  .monitor-mobile-error {
    min-height: 12rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1.25rem;
    border: 1px dashed var(--color-border);
    border-radius: 0.9rem;
    color: var(--color-text-muted);
    background: var(--color-surface);
    text-align: center;
    font-size: 0.8rem;
  }
  .monitor-mobile-empty strong { color: var(--color-text); font-size: 0.95rem; }
  .monitor-mobile-error { color: var(--color-danger); }
}

@media (max-width: 480px) {
  /* Stack two-column form grids inside modals so inputs aren't cramped. */
  .modal-box .grid { grid-template-columns: 1fr !important; }
  .modal-box { padding: 1.15rem; }
}
