:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-muted: #eef1f6;
  --border: #d8dee8;
  --text: #1a2332;
  --muted: #5c6b7f;
  --accent: #2a6fa8;
  --accent-hover: #235a8a;
  --accent-soft: #e8f1f8;
  --success: #1d7a4a;
  --success-bg: #dff3e8;
  --danger: #c53030;
  --danger-bg: #fde8e8;
  --warn: #9a6b16;
  --warn-bg: #fdf3d9;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(26, 35, 50, 0.06), 0 8px 24px rgba(26, 35, 50, 0.06);
  --sidebar-w: 240px;
}

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

body {
  margin: 0;
  font-family: "DM Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  align-items: stretch;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.sidebar-brand {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent) 0%, #1a4d6e 100%);
  box-shadow: 0 4px 12px rgba(42, 111, 168, 0.25);
}

.brand-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.brand-sub {
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-link {
  display: block;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--muted);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}

.nav-link:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.nav-link.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar-foot {
  margin: auto 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.4;
}

.app-main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.main {
  flex: 1;
  padding: 1.75rem 1.75rem 2.5rem;
  width: 100%;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header--stack {
  flex-direction: column;
  align-items: stretch;
}

.page-header-text {
  min-width: 0;
}

.page-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-desc {
  margin: 0.4rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  max-width: 52ch;
}

.page-header-action {
  margin: 0;
}

.sites-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem 1.5rem;
  margin-bottom: 0.75rem;
  padding: 1rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toolbar-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}

.toolbar-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.toolbar-select {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 2rem 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-width: 10rem;
  cursor: pointer;
}

.toolbar-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sites-meta {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.pagination-status {
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 500;
}

.pagination-link {
  text-decoration: none;
}

.pagination-disabled {
  opacity: 0.45;
  pointer-events: none;
  cursor: default;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  box-shadow: var(--shadow);
}

.panel--form {
  max-width: 520px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1rem;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin-top: 0.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

input[type="url"],
input[type="text"] {
  font: inherit;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1.1rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.08s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

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

.btn-secondary:hover {
  background: var(--surface-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid transparent;
}

.btn-ghost:hover {
  background: var(--accent-soft);
}

.btn-small {
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-danger:hover {
  background: var(--danger-bg);
}

.hint {
  margin: 1rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

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

.inline-form {
  display: inline;
  margin: 0;
}

.site-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.site-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.site-expand {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-expand:focus-visible + .site-row .expand-toggle {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.site-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  padding: 0.9rem 1rem 0.9rem 0.35rem;
}

.site-primary {
  flex: 1 1 220px;
  min-width: 0;
}

.site-status-wrap {
  flex-shrink: 0;
}

.site-actions {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-left: auto;
}

@media (max-width: 640px) {
  .site-actions {
    flex-basis: 100%;
    margin-left: 0;
    padding-left: 2.6rem;
  }
}

.expand-toggle {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  transition: background 0.12s, color 0.12s;
}

.expand-toggle:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.chevron {
  display: block;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.2s ease;
  margin-top: -0.1rem;
}

.site-expand:checked + .site-row .chevron {
  transform: rotate(45deg);
  margin-top: 0.15rem;
}

.site-name {
  margin: 0;
  font-weight: 600;
  font-size: 0.95rem;
  word-break: break-word;
}

.site-url {
  margin: 0.15rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  word-break: break-all;
}

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  white-space: nowrap;
}

.badge-up {
  background: var(--success-bg);
  color: var(--success);
}

.badge-down {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge-client {
  background: #fff4e0;
  color: #9a5f00;
  border: 1px solid #f0d9b0;
}

.badge-server,
.badge-network {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge-unknown {
  background: var(--warn-bg);
  color: var(--warn);
}

.site-details {
  display: none;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
}

.site-expand:checked ~ .site-details {
  display: block;
}

.site-details-inner {
  padding: 1rem 1rem 1rem 3.1rem;
  font-size: 0.88rem;
  color: var(--text);
}

.site-details-inner p {
  margin: 0 0 0.5rem;
}

.site-details-inner p:last-child {
  margin-bottom: 0;
}

.detail-break {
  margin-top: 0.65rem !important;
}

.ctype {
  font-size: 0.85rem;
  background: var(--surface);
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.error-line {
  color: var(--danger);
  font-weight: 500;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-brand {
    flex: 1;
    min-width: 200px;
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidebar-foot {
    width: 100%;
    margin: 0;
    order: 3;
  }

  .main {
    padding: 1.25rem 1rem 2rem;
  }

  .site-details-inner {
    padding-left: 1rem;
  }
}

/* Overlay de carregamento (varredura / verificar todos) */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  pointer-events: none;
}

.loading-overlay.is-visible {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.loading-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(244, 246, 249, 0.82);
  backdrop-filter: blur(6px);
}

.loading-overlay-card {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 1.75rem 2rem;
  max-width: 22rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(26, 35, 50, 0.12), 0 4px 16px rgba(26, 35, 50, 0.08);
}

.loading-spinner {
  width: 2.5rem;
  height: 2.5rem;
  margin: 0 auto 1rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: loading-spin 0.75s linear infinite;
}

.loading-overlay-text {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.loading-overlay-hint {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

body.loading-overlay-open {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .loading-overlay {
    transition: none;
  }

  .loading-spinner {
    animation: none;
    border-top-color: var(--border);
    opacity: 0.7;
  }
}
