@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Space+Grotesk:wght@400;500;700&display=swap');

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body,
#root {
  margin: 0;
  min-height: 100%;
}

body {
  min-width: 320px;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background:
    radial-gradient(circle at 10% 14%, var(--gradient-start) 0%, transparent 45%),
    radial-gradient(circle at 92% 88%, var(--gradient-end) 0%, transparent 40%),
    var(--surface-0);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-strong);
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  min-height: 100vh;
}

.app-shell__background {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 16%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 36%),
    radial-gradient(circle at 78% 80%, color-mix(in srgb, var(--accent) 15%, transparent), transparent 35%);
  z-index: 0;
}

.app-shell__sidebar {
  position: relative;
  z-index: 1;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  backdrop-filter: blur(8px);
  padding: var(--space-7) var(--space-5);
}

.app-shell__brand {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  color: var(--text-muted);
}

.app-shell__title {
  margin: var(--space-3) 0 var(--space-6);
  font-size: clamp(1.35rem, 2vw, 1.8rem);
}

.app-shell__nav {
  display: grid;
  gap: var(--space-2);
}

.nav-link {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.62rem 0.78rem;
  color: var(--text-secondary);
  transition:
    border-color var(--duration-fast) ease,
    color var(--duration-fast) ease,
    background-color var(--duration-fast) ease;
}

.nav-link:hover {
  border-color: var(--line);
  color: var(--text-primary);
  background: color-mix(in srgb, var(--surface-2) 65%, transparent);
}

.nav-link--active {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  color: var(--text-primary);
}

.app-shell__main {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.app-shell__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  border-bottom: 1px solid var(--line);
  padding: var(--space-4) var(--space-6);
  backdrop-filter: blur(8px);
  background: color-mix(in srgb, var(--surface-0) 92%, transparent);
}

.app-shell__header-text {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-shell__content {
  padding: var(--space-6);
}

.page {
  display: grid;
  gap: var(--space-5);
}

.page__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.page__title {
  margin: 0;
  font-size: clamp(1.6rem, 2.4vw, 2.2rem);
  line-height: 1.15;
}

.page__lead {
  margin: var(--space-2) 0 0;
  color: var(--text-secondary);
}

.grid {
  display: grid;
  gap: var(--space-4);
}

.grid--cards {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  background: var(--surface-elevated);
  backdrop-filter: blur(8px);
  padding: var(--space-4);
  display: grid;
  gap: var(--space-4);
}

.card__header {
  display: grid;
  gap: var(--space-1);
}

.card__title {
  margin: 0;
  font-size: 1rem;
}

.card__subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.86rem;
  font-family: var(--font-mono);
}

.card__body {
  min-height: 52px;
}

.metric {
  margin: 0;
  font-size: 1.22rem;
  font-weight: 600;
}

.muted {
  margin: 0;
  color: var(--text-secondary);
}

.subtle {
  margin: var(--space-2) 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.error-text {
  margin: 0;
  color: var(--danger);
}

.inline-form {
  display: grid;
  gap: var(--space-3);
}

.inline-form__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.field-label {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-1) 85%, transparent);
  color: var(--text-primary);
  padding: 0.62rem 0.75rem;
  font: inherit;
}

.input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}

.clips-filter-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.camera-form-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.clips-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.clips-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.clips-table th,
.clips-table td {
  text-align: left;
  padding: 0.64rem 0.72rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.clips-table thead th {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

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

.clips-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-1) 75%, transparent);
  padding: 0.14rem 0.5rem;
  font-size: 0.74rem;
  line-height: 1.2;
  color: var(--text-secondary);
}

.camera-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-1) 75%, transparent);
  padding: 0.14rem 0.5rem;
  font-size: 0.74rem;
  line-height: 1.2;
  color: var(--text-secondary);
}

.clips-mobile-list {
  display: none;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: var(--space-3);
}

.clips-mobile-item {
  display: grid;
  gap: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-1) 78%, transparent);
  padding: var(--space-3);
}

.clips-mobile-id {
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.clips-mobile-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.clips-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.clip-detail-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.form-checkbox-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: 1.75rem;
}

.form-checkbox-field input {
  margin: 0;
}

.camera-source-config {
  min-height: 220px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 0.84rem;
}

.camera-add-flow {
  display: grid;
  gap: var(--space-3);
}

.camera-add-flow__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.camera-add-flow__title,
.backend-picker__title {
  margin: 0;
  font-size: 1.02rem;
}

.camera-add-flow__backend-grid,
.backend-picker__grid {
  display: grid;
  gap: var(--space-2);
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.camera-add-flow__backend-card,
.backend-picker__card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-1) 72%, transparent);
  color: var(--text-primary);
  padding: var(--space-3);
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 0.35rem;
}

.camera-add-flow__backend-card:hover:not(:disabled),
.backend-picker__card:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.camera-add-flow__backend-card:disabled,
.backend-picker__card:disabled {
  opacity: 0.62;
  cursor: wait;
}

.camera-add-flow__backend-title,
.backend-picker__title-text {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.camera-add-flow__backend-description,
.backend-picker__description {
  margin: 0;
  color: var(--text-secondary);
}

.camera-add-flow__test-result,
.test-connection__result {
  display: grid;
  gap: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  background: color-mix(in srgb, var(--surface-1) 70%, transparent);
}

.camera-restart-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
  border: 1px solid color-mix(in srgb, var(--warning) 40%, transparent);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warning) 10%, transparent);
  padding: 0.65rem 0.75rem;
}

.camera-runtime-kv {
  margin: var(--space-3) 0 0;
  display: grid;
  gap: var(--space-2);
}

.camera-runtime-row {
  display: grid;
  gap: 0.4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-1) 72%, transparent);
  padding: 0.6rem 0.7rem;
}

.camera-runtime-row dt {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.camera-runtime-row dd {
  margin: 0;
  color: var(--text-primary);
}

.camera-mono {
  font-family: var(--font-mono);
  word-break: break-word;
}

.cameras-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.camera-item {
  display: grid;
  gap: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-1) 72%, transparent);
  padding: var(--space-3);
}

.camera-item__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.camera-item__name {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.camera-item__badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem;
}

.camera-item__meta {
  margin: 0;
  display: grid;
  gap: 0.35rem;
}

.camera-item__meta-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2);
}

.camera-item__meta-row dt {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.camera-item__meta-row dd {
  margin: 0;
  color: var(--text-primary);
}

.camera-item__config {
  margin: 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-0) 80%, transparent);
  padding: 0.55rem 0.62rem;
  font-size: 0.78rem;
  line-height: 1.4;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.camera-config-editor {
  display: grid;
  gap: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-1) 72%, transparent);
  padding: 0.65rem 0.7rem;
}

.onvif-wizard {
  display: grid;
  gap: var(--space-3);
}

.onvif-wizard__step {
  display: grid;
  gap: var(--space-3);
}

.onvif-step-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.onvif-step-title {
  margin: 0;
  font-size: 1.02rem;
}

.onvif-camera-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.onvif-camera-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-1) 72%, transparent);
  color: var(--text-primary);
  padding: var(--space-3);
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 0.35rem;
}

.onvif-camera-card:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.onvif-camera-card__title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 600;
}

.onvif-camera-card__line {
  margin: 0;
  word-break: break-word;
}

.onvif-profile-list {
  display: grid;
  gap: var(--space-2);
}

.onvif-profile-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-1) 72%, transparent);
  color: var(--text-primary);
  padding: var(--space-3);
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 0.25rem;
}

.onvif-profile-card:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.onvif-profile-card--selected {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.onvif-profile-card--disabled {
  opacity: 0.72;
  cursor: not-allowed;
}

.onvif-profile-card__title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.onvif-profile-card__line {
  margin: 0;
  word-break: break-word;
}

.onvif-device-info {
  display: grid;
  gap: 0.3rem;
}

.onvif-device-info p {
  margin: 0;
}

.clip-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.clip-detail-video-shell {
  margin-bottom: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-1) 72%, transparent);
  overflow: hidden;
}

.clip-detail-video {
  display: block;
  width: 100%;
  max-height: min(60vh, 560px);
  background: #000;
}

.clip-detail-link-list {
  display: grid;
  gap: var(--space-2);
}

.clip-detail-kv {
  margin: 0;
  display: grid;
  gap: var(--space-2);
}

.clip-detail-kv-row {
  display: grid;
  gap: 0.4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-1) 72%, transparent);
  padding: 0.6rem 0.7rem;
}

.clip-detail-kv-row dt {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.clip-detail-kv-row dd {
  margin: 0;
  color: var(--text-primary);
}

.clip-detail-mono {
  font-family: var(--font-mono);
  word-break: break-word;
}

.button {
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    transform var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    background-color var(--duration-fast) ease,
    color var(--duration-fast) ease;
  padding: 0.54rem 0.9rem;
}

.button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button--primary {
  background: var(--accent);
  color: var(--accent-contrast);
}

.button--primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.button--ghost {
  border-color: var(--line);
  background: color-mix(in srgb, var(--surface-1) 72%, transparent);
  color: var(--text-primary);
}

.button--ghost:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.2rem 0.58rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.status-badge--healthy {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 35%, transparent);
  background: color-mix(in srgb, var(--success) 12%, transparent);
}

.status-badge--degraded {
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 40%, transparent);
  background: color-mix(in srgb, var(--warning) 12%, transparent);
}

.status-badge--unhealthy {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.status-badge--unknown {
  color: var(--text-secondary);
  border-color: var(--line);
  background: color-mix(in srgb, var(--surface-2) 75%, transparent);
}

.fade-in-up {
  animation: fade-in-up var(--duration-normal) ease-out both;
}

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

  .app-shell__sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: var(--space-4) var(--space-5);
  }

  .app-shell__title {
    margin-bottom: var(--space-4);
  }

  .app-shell__nav {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .app-shell__header {
    padding: var(--space-4) var(--space-5);
  }

  .app-shell__content {
    padding: var(--space-5);
  }
}

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

  .page__header {
    flex-direction: column;
  }

  .clips-filter-grid {
    grid-template-columns: 1fr;
  }

  .camera-form-grid {
    grid-template-columns: 1fr;
  }

  .clips-table-wrap {
    display: none;
  }

  .clips-mobile-list {
    display: grid;
  }

  .clips-pagination {
    flex-direction: column;
    align-items: flex-start;
  }

  .clip-detail-grid {
    grid-template-columns: 1fr;
  }

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

  .onvif-camera-grid {
    grid-template-columns: 1fr;
  }

  .camera-item__header {
    flex-direction: column;
  }

  .camera-item__badges {
    justify-content: flex-start;
  }
}
