:root {
  color-scheme: light;
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background: #f6f7f9;
  color: #1f2933;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

button,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
}

button:disabled {
  cursor: progress;
  opacity: 0.7;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

.secondary-button {
  border: 1px solid #94a3b8;
  background: #fff;
  color: #334155;
}

.icon-button {
  width: 32px;
  min-height: 32px;
  padding: 0;
  background: transparent;
  color: #475569;
  font-size: 22px;
  line-height: 1;
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
}

label span {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  color: #475569;
}

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-shell {
  width: min(100%, 420px);
}

.panel {
  border: 1px solid #d8dee8;
  border-radius: 8px;
  background: #fff;
  padding: 20px;
}

.auth-panel h1,
.panel h2 {
  margin: 0 0 16px;
}

.stack {
  display: grid;
  gap: 16px;
}

.inline-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

[hidden] {
  display: none !important;
}

.message {
  min-height: 22px;
  margin: 0;
  color: #b91c1c;
}

.message.success {
  color: #047857;
}

.notification-region {
  position: fixed;
  z-index: 1000;
  top: 16px;
  right: 16px;
  display: grid;
  gap: 10px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.notification {
  display: grid;
  grid-template-columns: 5px minmax(0, 1fr) 36px;
  min-height: 76px;
  overflow: hidden;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 32px rgb(15 23 42 / 20%);
  opacity: 0;
  pointer-events: auto;
  transform: translateY(-8px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.notification.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.notification-accent {
  background: #2563eb;
}

.notification[data-type="success"] .notification-accent {
  background: #059669;
}

.notification[data-type="warning"] .notification-accent {
  background: #d97706;
}

.notification[data-type="error"] .notification-accent {
  background: #dc2626;
}

.notification-content {
  align-self: center;
  min-width: 0;
  padding: 13px 10px 13px 14px;
}

.notification-content strong,
.notification-content p {
  display: block;
  margin: 0;
  overflow-wrap: anywhere;
}

.notification-content strong {
  margin-bottom: 4px;
  color: #111827;
  font-size: 14px;
}

.notification-content p {
  color: #475569;
  font-size: 14px;
  line-height: 1.45;
}

.notification-close {
  align-self: start;
  width: 36px;
  min-height: 36px;
  padding: 0;
  background: transparent;
  color: #64748b;
  font-size: 22px;
  line-height: 1;
}

.notification-close:hover {
  background: #f1f5f9;
  color: #111827;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid #d8dee8;
  background: #fff;
}

.topbar > div {
  display: grid;
  gap: 4px;
}

.dashboard {
  display: grid;
  gap: 20px;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.section-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.section-heading h2,
.section-heading p {
  margin-bottom: 4px;
}

.source-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  gap: 8px;
  margin: 16px 0 8px;
}

.selected-sources {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 20px;
  margin-top: 12px;
  border-top: 1px solid #e2e8f0;
}

.selected-source {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(140px, 0.8fr) 32px;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 8px 0;
  border-bottom: 1px solid #e2e8f0;
}

.selected-source-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.source-alias-input {
  min-width: 0;
  min-height: 36px;
}

.compact-text {
  margin: 10px 0 0;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.runtime-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin: 8px 0 0;
  border-top: 1px solid #e2e8f0;
}

.runtime-metrics > div {
  min-width: 0;
  padding: 14px 16px 4px 0;
}

.runtime-metrics dt {
  margin-bottom: 6px;
  color: #64748b;
  font-size: 13px;
}

.runtime-metrics dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.delivery-list {
  margin-top: 10px;
  border-top: 1px solid #e2e8f0;
}

.delivery-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.3fr) minmax(155px, 1fr) 90px minmax(150px, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 48px;
  padding: 9px 0;
  border-bottom: 1px solid #e2e8f0;
  font-size: 14px;
}

.delivery-row > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.delivery-source {
  font-weight: 600;
}

.delivery-status[data-status="sent"] {
  color: #047857;
}

.delivery-status[data-status="failed"] {
  color: #b91c1c;
}

.delivery-status[data-status="pending"],
.delivery-status[data-status="sending"] {
  color: #9a6700;
}

.source-list {
  min-height: 52px;
  max-height: 420px;
  overflow-y: auto;
  border-top: 1px solid #e2e8f0;
}

.source-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 9px 4px;
  border-bottom: 1px solid #e2e8f0;
  cursor: pointer;
}

.source-row:hover {
  background: #f8fafc;
}

.source-row input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  margin: 0;
}

.source-details {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.source-details strong,
.source-metadata {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#source-load-more-button {
  width: 100%;
  margin-top: 10px;
}

.muted {
  color: #64748b;
}

@media (max-width: 720px) {
  .notification-region {
    top: 10px;
    right: 10px;
    width: calc(100vw - 20px);
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .status-grid {
    grid-template-columns: 1fr;
  }

  .dashboard {
    padding: 16px;
  }

  .panel {
    padding: 16px;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .source-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .source-toolbar input {
    grid-column: 1 / -1;
  }

  .selected-sources {
    grid-template-columns: 1fr;
  }

  .selected-source {
    grid-template-columns: minmax(0, 1fr) 32px;
  }

  .source-alias-input {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .runtime-metrics {
    grid-template-columns: 1fr 1fr;
  }

  .delivery-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .delivery-recipient,
  .delivery-time {
    color: #64748b;
  }
}

@media (max-width: 420px) {
  .auth-page,
  .dashboard {
    padding: 12px;
  }

  .source-toolbar {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  button:active:not(:disabled),
  .notification {
    transition: none;
    transform: none;
  }
}
