:root {
  color-scheme: dark;
  --bg: #07080a;
  --bg-lift: #0d0f13;
  --panel: #12151a;
  --panel-soft: #191d23;
  --panel-strong: #0b0d10;
  --text: #eef4f5;
  --muted: #9aa7ad;
  --line: #2a3339;
  --accent: #21b889;
  --accent-strong: #f5c84c;
  --online: #38d98b;
  --offline: #ff5c70;
  --warn: #f5c84c;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(33, 184, 137, 0.05), transparent 220px),
    linear-gradient(135deg, #07080a 0%, #0e1015 52%, #08090b 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 20px;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

button:hover {
  border-color: rgba(33, 184, 137, 0.45);
  background: var(--panel-soft);
}

button:active {
  transform: translateY(1px);
}

.app-shell {
  width: min(1500px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 8px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0 10px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand-logo {
  display: block;
  width: min(420px, 78vw);
  height: auto;
}

.brand-logo-header {
  width: min(210px, 52vw);
  max-height: 49px;
}

.brand-logo-login {
  width: min(285px, 92%);
  margin: 0 auto 4px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.7rem);
  line-height: 0.96;
}

h2 {
  font-size: 1.2rem;
}

.topbar-status {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.pill,
.metric {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
}

.pill::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: currentColor;
}

.pill-online {
  color: var(--online);
}

.pill-offline {
  color: var(--offline);
}

.pill-warn {
  color: var(--warn);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
}

.toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 1.45rem;
  line-height: 1;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #06100d;
}

.primary:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  color: #11100a;
}

.wide {
  width: 100%;
}

.login-shell {
  width: min(430px, 100%);
}

.login-form {
  display: grid;
  gap: 12px;
  padding: 26px 26px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 92%, black);
  box-shadow: var(--shadow);
}

.login-form h1 {
  margin-bottom: 12px;
}

.login-form label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.login-form input {
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  outline: none;
}

.login-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(33, 184, 137, 0.18);
}

.login-form button {
  min-height: 46px;
  font-weight: 850;
}

.login-error {
  min-height: 0;
  margin: -2px 0 0;
  color: var(--offline);
  font-size: 0.9rem;
  font-weight: 800;
}

.login-error:empty {
  display: none;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.device-card {
  min-height: 260px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.device-card:hover {
  border-color: rgba(33, 184, 137, 0.45);
  transform: translateY(-2px);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.42);
}

.device-image {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 10;
  background: #050608;
  color: #dce5e7;
  overflow: hidden;
}

.device-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.no-image {
  color: #a9b7bc;
  font-weight: 700;
}

.device-body {
  padding: 14px;
}

.device-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.device-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1.08rem;
  font-weight: 850;
}

.device-tools {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex: 0 0 auto;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 800;
}

.status-dot::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--offline);
}

.status-dot.online::before {
  background: var(--online);
}

.device-actions {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 65px;
  justify-content: flex-end;
}

.device-action {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 8px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 900;
  line-height: 1;
}

.device-action.danger {
  color: var(--offline);
}

.device-action:hover {
  color: var(--accent-strong);
}

.device-action.danger:hover {
  border-color: rgba(255, 92, 112, 0.42);
  background: rgba(255, 92, 112, 0.1);
  color: var(--offline);
}

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

.device-meta [data-role="last-seen"] {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-meta [data-role="history-coverage"] {
  flex: 0 0 auto;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 54px 20px;
  border: 1px dashed #3b484f;
  border-radius: 8px;
  background: rgba(18, 21, 26, 0.72);
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.viewer {
  width: min(1180px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
}

.viewer::backdrop {
  background: rgba(0, 0, 0, 0.78);
}

.viewer-shell {
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto;
  min-height: min(860px, calc(100vh - 28px));
  overflow: hidden;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.viewer-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  background: #050608;
}

.viewer-stage img {
  width: 100%;
  height: 100%;
  max-height: calc(100vh - 245px);
  object-fit: contain;
  display: block;
}

.viewer-empty {
  position: absolute;
  color: #dce5e7;
  font-weight: 800;
}

.timeline-panel {
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
  background: var(--panel-soft);
}

.timeline-meta,
.timeline-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.timeline-meta {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
}

#timelineSlider {
  width: 100%;
  accent-color: var(--accent);
}

.timeline-actions {
  margin-top: 12px;
}

.timeline-actions button {
  min-width: 92px;
  min-height: 38px;
  padding: 0 14px;
  font-weight: 800;
}

.timeline-actions .media-button {
  display: inline-grid;
  place-items: center;
  min-width: 54px;
  padding: 0;
}

.timeline-actions .media-button svg {
  width: 21px;
  height: 21px;
}

.timeline-actions .primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #06100d;
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100% - 20px, 1500px);
    padding-top: 8px;
  }

  .brand-logo-header {
    width: min(190px, 62vw);
  }

  .topbar,
  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-status {
    justify-content: flex-start;
  }

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

  .viewer {
    width: 100vw;
    max-height: 100vh;
  }

  .viewer-shell {
    min-height: 100vh;
    border-radius: 0;
  }

  .timeline-actions button {
    min-width: 0;
    flex: 1;
  }
}
