:root {
  color-scheme: dark;

  --blue: #3261a5;
  --blue-dark: #1a3e72;
  --blue-light: #4d7fc4;

  --bg: #0d1625;
  --panel: #131e2f;
  --surface: #182438;
  --hover: #1d2c43;

  --border: rgba(95, 135, 191, 0.28);

  --text: #f4f7fb;
  --soft: #a9b7ca;
  --muted: #7f90a7;

  --green: #42c78a;
  --red: #d95c68;
  --yellow: #e1ad54;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

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

.header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  min-height: 94px;
  padding: 16px 20px;
  border-radius: 12px;
  background:
    linear-gradient(
      105deg,
      var(--blue-dark),
      var(--blue)
    );
  box-shadow:
    0 14px 35px rgba(0, 0, 0, 0.25);
}

.header img {
  width: auto;
  height: 58px;
  max-width: 250px;
  object-fit: contain;
}

.header-title {
  padding-left: 22px;
  border-left:
    1px solid rgba(255, 255, 255, 0.23);
}

.header-title span,
.kicker {
  display: block;
  margin-bottom: 4px;
  color: #cfe0fa;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.15em;
}

.header-title h1 {
  margin: 0;
  font-size: 1.45rem;
}

.back-link {
  padding: 10px 14px;
  border:
    1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  background:
    rgba(5, 20, 45, 0.24);
  color: white;
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: none;
}

main {
  padding-top: 32px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.topbar h2 {
  margin: 0;
  font-size: 1.7rem;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--soft);
  font-size: 0.85rem;
}

.filters {
  display: flex;
  gap: 10px;
}

.filters label,
.form-grid label {
  display: grid;
  gap: 6px;
}

.filters label > span,
.form-grid label > span {
  color: var(--soft);
  font-size: 0.72rem;
  font-weight: 700;
}

input,
select {
  min-height: 40px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: var(--surface);
  color: var(--text);
}

input:focus,
select:focus {
  border-color: var(--blue-light);
  box-shadow:
    0 0 0 3px rgba(50, 97, 165, 0.16);
}

.filters input {
  width: 260px;
}

.filters select {
  width: 170px;
}

.panel {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.18);
}

.table-heading {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 14px;
  border-bottom:
    1px solid rgba(95, 135, 191, 0.13);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

td {
  font-size: 0.79rem;
}

tbody tr:hover {
  background: rgba(50, 97, 165, 0.07);
}

.camera-id,
.camera-ip,
.stream-cell {
  color: var(--muted);
  font-family:
    ui-monospace,
    SFMono-Regular,
    Menlo,
    monospace;
  font-size: 0.7rem;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
}

.status::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  content: "";
}

.status.enabled {
  background: rgba(66, 199, 138, 0.12);
  color: #91e4b8;
}

.status.enabled::before {
  background: var(--green);
}

.status.disabled {
  background: rgba(217, 92, 104, 0.12);
  color: #ef9ca5;
}

.status.disabled::before {
  background: var(--red);
}

.actions-cell {
  text-align: right;
}

.edit-button,
.button,
.icon-button {
  border: 0;
  cursor: pointer;
}

.edit-button {
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background:
    rgba(50, 97, 165, 0.1);
  color: #dce9fb;
  font-size: 0.7rem;
  font-weight: 700;
}

.edit-button:hover {
  border-color: var(--blue-light);
  background:
    rgba(50, 97, 165, 0.2);
}

dialog {
  width: min(720px, calc(100% - 28px));
  max-height: calc(100dvh - 30px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  box-shadow:
    0 25px 80px rgba(0, 0, 0, 0.55);
}

dialog::backdrop {
  background: rgba(2, 8, 18, 0.78);
  backdrop-filter: blur(3px);
}

dialog form {
  padding: 20px;
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.icon-button {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 7px;
  background: transparent;
  color: var(--soft);
  font-size: 1.25rem;
}

.icon-button:hover {
  background:
    rgba(255, 255, 255, 0.06);
  color: white;
}

.form-grid {
  display: grid;
  grid-template-columns:
    repeat(2, minmax(0, 1fr));
  gap: 15px;
}

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

.form-grid small {
  color: var(--muted);
  font-size: 0.65rem;
}

input:disabled {
  opacity: 0.6;
}

.switch-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background:
    rgba(50, 97, 165, 0.05);
}

.switch-row > span {
  display: grid !important;
  gap: 4px;
}

.switch-row strong {
  color: var(--text);
  font-size: 0.78rem;
}

.switch-row input {
  width: 20px;
  height: 20px;
  min-height: auto;
  accent-color: var(--blue);
}

.probe-result {
  display: none;
  margin-top: 14px;
  padding: 12px;
  border-radius: 9px;
  font-size: 0.75rem;
}

.probe-result.testing,
.probe-result.success,
.probe-result.error {
  display: block;
}

.probe-result.testing {
  border: 1px solid rgba(225, 173, 84, 0.35);
  background: rgba(225, 173, 84, 0.08);
  color: #f0ca88;
}

.probe-result.success {
  border: 1px solid rgba(66, 199, 138, 0.35);
  background: rgba(66, 199, 138, 0.08);
  color: #a9ebc6;
}

.probe-result.error {
  border: 1px solid rgba(217, 92, 104, 0.35);
  background: rgba(217, 92, 104, 0.08);
  color: #f1aab1;
}

.probe-result strong {
  display: block;
  margin-bottom: 8px;
}

.probe-details {
  display: grid;
  grid-template-columns:
    repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.probe-details span {
  padding: 7px;
  border-radius: 6px;
  background:
    rgba(255, 255, 255, 0.04);
  color: var(--soft);
  text-align: center;
}

.probe-warning {
  margin: 10px 0 0;
  padding-top: 9px;
  border-top:
    1px solid rgba(225, 173, 84, 0.25);
  color: #f0ca88;
  line-height: 1.45;
}

.form-message {
  min-height: 21px;
  margin-top: 10px;
  color: var(--red);
  font-size: 0.74rem;
}

.dialog-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
}

.dialog-spacer {
  flex: 1;
}

.button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  font-size: 0.74rem;
  font-weight: 800;
}

.button.primary {
  background: var(--blue);
  color: white;
}

.button.primary:hover {
  background: var(--blue-light);
}

.button.secondary {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.button.test {
  border: 1px solid rgba(66, 199, 138, 0.35);
  background: rgba(66, 199, 138, 0.1);
  color: #a9ebc6;
}

.button.test:hover {
  background: rgba(66, 199, 138, 0.18);
}

.button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.notification {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  max-width: calc(100% - 36px);
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #18263b;
  color: var(--text);
  box-shadow:
    0 16px 40px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition:
    opacity 150ms ease,
    transform 150ms ease;
}

.notification.visible {
  opacity: 1;
  transform: translateY(0);
}

.empty-row {
  padding: 30px !important;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 760px) {
  .shell {
    width: calc(100% - 18px);
    padding-top: 9px;
  }

  .header {
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: 70px;
    padding: 10px 14px;
  }

  .header img {
    height: 44px;
  }

  .header-title {
    display: none;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .filters {
    flex-direction: column;
  }

  .filters input,
  .filters select {
    width: 100%;
  }

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

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

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

  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .dialog-spacer {
    display: none;
  }

  .button {
    width: 100%;
  }
}

/* Alta de cámaras */
.topbar-actions {
  display: flex;
  align-items: flex-end;
  gap: 14px;
}

.topbar-actions > .button {
  flex: 0 0 auto;
  margin-bottom: 1px;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions > .button {
    width: 100%;
  }
}

/* Eliminación de cámaras */
.button.danger {
  border: 1px solid rgba(217, 92, 104, 0.45);
  background: rgba(217, 92, 104, 0.12);
  color: #f1aab1;
}

.button.danger:hover {
  border-color: #d95c68;
  background: rgba(217, 92, 104, 0.22);
  color: #ffffff;
}

.button.danger[hidden] {
  display: none;
}
