/* Dashboard + login (extends styles.css tokens) */
body.dash-body {
  display: block;
  min-height: 100vh;
  background:
    radial-gradient(1000px 520px at 10% -8%, rgba(37, 99, 235, 0.16) 0%, transparent 62%),
    radial-gradient(900px 480px at 92% 0%, rgba(14, 165, 233, 0.14) 0%, transparent 58%),
    linear-gradient(180deg, #f7faff 0%, #eff4fb 100%),
    var(--bg);
}

.app-body {
  margin: 0;
  min-height: 100vh;
  display: block;
  align-items: unset;
  justify-content: unset;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px 1fr;
}

.app-sidebar {
  border-right: 1px solid #d8e4f8;
  background: linear-gradient(180deg, #ffffff, #f6f9ff);
  padding: 20px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 4px 0 16px rgba(15, 23, 42, 0.04);
  /* Stay in the viewport while the main column scrolls; logout stays at bottom of sidebar. */
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  max-height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand h2 {
  margin: 2px 0 0;
  font-size: 1.08rem;
  letter-spacing: 0.2px;
}

.sidebar-eyebrow {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.7px;
  color: #2563eb;
  text-transform: uppercase;
}

.sidebar-nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: block;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid #d5e2fb;
  color: #1e293b;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.88rem;
  background: #f4f8ff;
  transition: all 0.18s ease;
}

.nav-item:hover {
  border-color: #93c5fd;
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(37, 99, 235, 0.12);
}

.nav-item.active {
  background: #dbeafe;
  border-color: #60a5fa;
}

.sidebar-logout {
  margin-top: auto;
}

.sidebar-logout .btn {
  width: 100%;
}

.pw-wrap {
  position: relative;
}

.pw-wrap input {
  padding-right: 78px;
}

.pw-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
  border-radius: 7px;
  font-size: 0.73rem;
  font-weight: 700;
  padding: 5px 9px;
  cursor: pointer;
}

.pw-toggle:hover {
  border-color: #93c5fd;
}

.app-content {
  padding: 18px 20px;
}

.app-content .page {
  width: min(1400px, 100%);
  margin: 0 auto;
}

.dash-shell {
  border-radius: 20px;
  padding: 22px 22px 18px;
  border: 1px solid #d9e6fa;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(248, 252, 255, 0.95));
  backdrop-filter: blur(8px);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.09);
  min-width: 0;
}

.card-lite {
  border: 1px solid #dce8fa;
  border-radius: 14px;
  background: linear-gradient(180deg, #fcfeff, #f7faff);
  padding: 12px;
  min-width: 0;
}

.dash-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.dash-title-wrap h1 {
  margin: 0;
  font-size: clamp(1.15rem, 2vw, 1.55rem);
  letter-spacing: 0.2px;
}

.dash-eyebrow {
  margin: 0 0 4px;
  font-size: 0.74rem;
  font-weight: 700;
  color: #2563eb;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.dash-subtitle {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.dash-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.total-pill,
.page-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid #bfdbfe;
  background: linear-gradient(180deg, #eef5ff, #e4efff);
  color: #1e3a8a;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0 12px;
}

/* --- Device heartbeat LED (top-right of the dashboard header) --- */
.device-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 4px 12px 4px 10px;
  border-radius: 999px;
  border: 1px solid #d8e4f8;
  background: #ffffff;
  color: #1e293b;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.15;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  user-select: none;
}

.device-status-text {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
}

.device-status-label {
  color: #64748b;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.device-status-detail {
  color: #1e293b;
  font-size: 0.82rem;
  font-weight: 700;
}

.device-led {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #94a3b8;             /* neutral grey when state unknown */
  box-shadow: 0 0 0 0 rgba(148, 163, 184, 0);
  flex: 0 0 auto;
}

.device-status.state-online {
  border-color: #bbf7d0;
  background: linear-gradient(180deg, #f0fdf4, #ecfdf5);
}
.device-status.state-online .device-led {
  background: #16a34a;             /* green */
  box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.55);
  animation: device-led-pulse 1.6s ease-out infinite;
}

.device-status.state-offline {
  border-color: #fecaca;
  background: linear-gradient(180deg, #fef2f2, #fff1f2);
}
.device-status.state-offline .device-led {
  background: #dc2626;             /* solid red, no pulse */
}

.device-status.state-unknown {
  border-color: #d8e4f8;
  background: #ffffff;
}
.device-status.state-unknown .device-led {
  background: #94a3b8;
}

@keyframes device-led-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.55);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(22, 163, 74, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(22, 163, 74, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .device-status.state-online .device-led {
    animation: none;
  }
}

.filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(145px, 1fr));
  gap: 13px;
  margin-bottom: 14px;
  align-items: end;
}

.filters .field {
  margin: 0;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  border: 1px solid #d7e3f8;
  border-radius: 12px;
  padding: 8px 10px;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.04);
  min-width: 0;
}

.field-span-2 {
  grid-column: span 2;
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-btn {
  border: 1px solid #cfe0fb;
  background: linear-gradient(180deg, #ffffff, #f4f8ff);
  color: #3b4c66;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
}

.chip-btn.active {
  background: linear-gradient(180deg, #edf5ff, #dfedff);
  border-color: #97bff7;
  color: #1f3f78;
}

.chip-btn:hover {
  border-color: #a8caf8;
  transform: translateY(-1px);
}

.filter-actions {
  display: flex;
  gap: 8px;
}

.filter-actions .btn {
  flex: 1;
}

.filters input,
.filters select {
  height: 41px;
  border: 1px solid #c9d9f3;
  background: #ffffff;
  border-radius: 10px;
  padding: 0 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.filters input::placeholder {
  color: #94a3b8;
}

.filters input:focus,
.filters select:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.16);
}

.filters select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #64748b 50%),
    linear-gradient(135deg, #64748b 50%, transparent 50%),
    linear-gradient(180deg, #ffffff, #f8fbff);
  background-position:
    calc(100% - 16px) 18px,
    calc(100% - 11px) 18px,
    0 0;
  background-size:
    5px 5px,
    5px 5px,
    100% 100%;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.filters .field > span {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.35px;
  color: #475569;
}

.filter-actions {
  grid-column: span 3;
  justify-content: flex-end;
  align-items: end;
  flex-wrap: wrap;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  padding: 0 !important;
}

.filter-actions .btn {
  min-width: 122px;
  flex: 0 1 auto;
}

.filter-actions .btn-icon {
  min-width: 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  border-radius: 10px;
}

.btn.btn-primary {
  background: linear-gradient(180deg, #6ea6ff, #5f97f2);
  border-color: #5f97f2;
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(59, 130, 246, 0.2);
}

.btn.btn-primary:hover {
  background: linear-gradient(180deg, #7cb0ff, #6aa0f6);
  border-color: #6aa0f6;
}

.btn.btn-ghost {
  background: linear-gradient(180deg, #f8fbff, #edf3ff);
  border-color: #b8cdee;
  color: #2f4669;
  font-weight: 700;
}

.btn.btn-ghost:hover {
  border-color: #9fbde8;
  background: linear-gradient(180deg, #f3f8ff, #e2edff);
  color: #1f3760;
}

.sidebar-logout .btn.btn-ghost {
  background: linear-gradient(180deg, #eef4ff, #dfeaff);
  border-color: #9ebae8;
  color: #1f3f78;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.14);
}

.sidebar-logout .btn.btn-ghost:hover {
  background: linear-gradient(180deg, #f4f8ff, #e7f0ff);
  border-color: #88ade4;
  color: #16386e;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: inset 0 1px 0 rgba(15, 23, 42, 0.03);
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

table.dash-table {
  width: 100%;
  min-width: 960px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.84rem;
}

table.dash-table th,
table.dash-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: middle;
}

table.dash-table th {
  color: #475569;
  font-weight: 700;
  white-space: nowrap;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.45px;
  background: linear-gradient(180deg, #f8fbff, #f0f5fc);
  position: sticky;
  top: 0;
  z-index: 1;
  user-select: none;
}

table.dash-table th.sortable {
  cursor: pointer;
}

table.dash-table th.sortable::after {
  content: "↕";
  margin-left: 6px;
  opacity: 0.35;
  font-size: 0.72rem;
}

table.dash-table th.sortable.sort-asc::after {
  content: "↑";
  opacity: 0.9;
}

table.dash-table th.sortable.sort-desc::after {
  content: "↓";
  opacity: 0.9;
}

table.dash-table tbody tr:hover td {
  background: #f2f8ff;
}

table.dash-table tbody tr {
  cursor: pointer;
}

table.dash-table tr:last-child td {
  border-bottom: none;
}

table.dash-table td.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.77rem;
  max-width: 220px;
  word-break: break-all;
}

table.dash-table a {
  color: #1d4ed8;
  font-weight: 700;
  text-decoration: none;
}

table.dash-table a:hover {
  text-decoration: underline;
}

.thumb-btn {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
  border-radius: 7px;
  padding: 4px 8px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

.thumb-btn:hover {
  background: #dbeafe;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 15px;
  color: var(--muted);
  font-size: 0.9rem;
}

.alert {
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}
.alert-warn {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  color: #92400e;
}
.alert-err {
  background: #fff1f2;
  border: 1px solid #fda4af;
  color: #9f1239;
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.25px;
}
.badge-yes {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
}
.badge-no {
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #cbd5e1;
}

.img-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 70;
}

.img-modal.hidden {
  display: none;
}

.img-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.img-panel {
  position: relative;
  z-index: 1;
  width: min(900px, calc(100vw - 30px));
  max-height: calc(100vh - 40px);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  display: grid;
  gap: 12px;
  box-shadow: 0 24px 56px rgba(15, 23, 42, 0.22);
}

.img-panel img {
  width: 100%;
  max-height: calc(100vh - 170px);
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #f8fafc;
}

/* Event-details modal can be longer than the viewport (two previews + grid),
   so enable internal scrolling inside the panel. */
.img-panel.details-panel {
  overflow-y: auto;
  padding-right: 18px;
}

.img-panel.details-panel::-webkit-scrollbar {
  width: 8px;
}

.img-panel.details-panel::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}

.img-panel.details-panel::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.img-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  font-size: 1.1rem;
  cursor: pointer;
}

.details-panel h3 {
  margin: 0 0 10px;
  font-size: 1.02rem;
  color: #1e293b;
  letter-spacing: 0.15px;
}

.details-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 46px;
  height: 46px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #1e293b;
  font-size: 1.6rem;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.details-nav:hover:not(:disabled) {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
  transform: translateY(-50%) scale(1.05);
}

.details-nav:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.details-nav-prev {
  left: max(12px, calc(50% - min(900px, calc(100vw - 30px)) / 2 - 56px));
}

.details-nav-next {
  right: max(12px, calc(50% - min(900px, calc(100vw - 30px)) / 2 - 56px));
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
}

.details-item {
  border: 1px solid #d9e4f8;
  border-radius: 10px;
  padding: 9px 11px;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  box-shadow: 0 5px 10px rgba(15, 23, 42, 0.04);
}

.details-item span {
  display: block;
  font-size: 0.7rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.35px;
  margin-bottom: 4px;
}

.details-item strong {
  font-size: 0.86rem;
  color: #172554;
  word-break: break-word;
}

.details-preview {
  margin-top: 10px;
  border: 1px solid #dbe7fb;
  border-radius: 12px;
  padding: 12px;
  background: linear-gradient(180deg, #ffffff, #f5f9ff);
}

.details-preview h4 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 10px;
  font-size: 0.78rem;
  color: #1e3a8a;
  text-transform: uppercase;
  letter-spacing: 0.55px;
  font-weight: 800;
}

.details-preview img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 4px;
}

.details-preview .zoom-wrap {
  border-radius: 8px;
}

.details-full-front {
  border-color: #c7d9f7;
  background: linear-gradient(180deg, #f5faff, #eaf1fb);
}

.details-full-front h4::before {
  content: "★";
  color: #2563eb;
  margin-right: 6px;
  font-size: 0.85rem;
}

.details-full-front img {
  max-height: 340px;
}

.details-full-front .btn {
  margin-top: 10px;
  font-size: 0.78rem;
  padding: 6px 14px;
}

.zoom-wrap {
  position: relative;
  display: inline-block;
  width: 100%;
  overflow: hidden;
  border-radius: 8px;
}

.zoom-lens {
  position: absolute;
  width: 130px;
  height: 130px;
  border-radius: 999px;
  border: 2px solid rgba(151, 183, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(226, 232, 240, 0.95), 0 10px 20px rgba(15, 23, 42, 0.25);
  pointer-events: none;
  display: none;
  background-repeat: no-repeat;
  z-index: 4;
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px;
    gap: 10px;
    position: static;
    align-self: stretch;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .sidebar-nav {
    grid-template-columns: 1fr 1fr;
  }

  .sidebar-logout {
    margin-top: 0;
  }

  .app-content {
    padding: 10px;
  }

  .dash-shell {
    padding: 14px;
  }

  .dash-top {
    flex-direction: column;
  }

  .filters {
    grid-template-columns: 1fr 1fr;
  }

  .field-span-2 {
    grid-column: 1 / -1;
  }

  .filter-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .filter-actions .btn {
    flex: 1 1 160px;
  }

  table.dash-table th,
  table.dash-table td {
    padding: 9px 8px;
  }

  table.dash-table {
    min-width: 860px;
  }

  .details-grid {
    grid-template-columns: 1fr 1fr;
  }

  .img-panel {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
    padding: 10px;
  }

  .img-panel img {
    max-height: calc(100vh - 210px);
  }

  .details-preview img,
  .details-full-front img {
    max-height: 260px;
  }

  .details-nav {
    width: 40px;
    height: 40px;
    font-size: 1.3rem;
  }

  .details-nav-prev {
    left: 6px;
  }

  .details-nav-next {
    right: 6px;
  }

}

@media (max-width: 520px) {
  .filters {
    grid-template-columns: 1fr;
  }

  .app-content {
    padding: 8px 6px;
  }

  .dash-shell {
    padding: 10px;
    border-radius: 14px;
  }

  .filters {
    gap: 8px;
  }

  .filters .field {
    padding: 7px 8px;
  }

  table.dash-table {
    min-width: 720px;
  }

  .preset-chips {
    gap: 6px;
  }

  .chip-btn {
    font-size: 0.74rem;
    padding: 6px 10px;
  }

  .filter-actions .btn {
    width: 100%;
  }

  .sidebar-nav {
    grid-template-columns: 1fr;
  }

  .total-pill,
  .page-pill {
    min-height: 32px;
    font-size: 0.75rem;
    padding: 0 10px;
  }

  .details-grid {
    grid-template-columns: 1fr;
  }

  .zoom-lens {
    width: 105px;
    height: 105px;
  }
}
