:root {
  color-scheme: light dark;
  --bg: #f6f7f5;
  --surface: #ffffff;
  --text: #1c2420;
  --muted: #66726b;
  --line: #dde3df;
  --accent: #3f7d62;
  --accent-text: #ffffff;
  --accent-soft: #e3f0e9;
  --danger: #b3382c;
  --warn-soft: #fbf0d9;
  --warn-text: #7a5a10;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --surface: #1a201d;
    --text: #e6ece8;
    --muted: #94a09a;
    --line: #2b3430;
    --accent: #7cc4a0;
    --accent-text: #0e1a14;
    --accent-soft: #1f3228;
    --danger: #ee7b6d;
    --warn-soft: #3a3016;
    --warn-text: #e6c66f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif;
}

body.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
.muted { color: var(--muted); margin: 0 0 16px; }
.error { color: var(--danger); margin: 0 0 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 380px;
}

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0 0 12px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 0.95rem; }

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
input[type='checkbox'] { display: inline-block; width: auto; margin: 0; }
textarea { resize: vertical; min-height: 120px; font-family: ui-monospace, Menlo, monospace; font-size: 0.85rem; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  font: inherit;
  cursor: pointer;
  padding: 9px 14px;
  color: var(--accent-text);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
}
button.ghost { color: var(--text); background: transparent; border-color: var(--line); }
button.danger { color: var(--danger); background: transparent; border-color: var(--line); }
button.small { padding: 5px 10px; font-size: 0.85rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
form .card button[type='submit'], .card form button { width: 100%; }

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

/* ---- painel */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.top .brand { font-weight: 600; }
.top .who { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.9rem; }
.top form { margin: 0; }

.wrap { max-width: 980px; margin: 0 auto; padding: 20px 16px 60px; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tabs button { color: var(--muted); background: transparent; border-color: transparent; }
.tabs button[aria-selected='true'] { color: var(--text); background: var(--surface); border-color: var(--line); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 14px; }
.toolbar label { margin: 0; flex: 1 1 140px; }
.toolbar .grow { flex: 3 1 220px; }
.toolbar button { flex: 0 0 auto; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.site-row { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: center; padding: 12px 14px; }
.site-main { min-width: 0; }
.site-host { font-weight: 600; overflow-wrap: anywhere; }
.site-name { color: var(--muted); font-size: 0.9rem; }
.site-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.site-side { display: flex; align-items: center; gap: 12px; }

.badge { font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--text); border: 1px solid var(--line); }
.badge.warn { background: var(--warn-soft); color: var(--warn-text); border-color: transparent; }

.switch { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); margin: 0; }
.switch input { accent-color: var(--accent); width: 18px; height: 18px; }

details.site-detail { border-top: 1px solid var(--line); }
details.site-detail > summary { cursor: pointer; padding: 10px 14px; color: var(--muted); font-size: 0.9rem; }
.detail-body { padding: 4px 14px 16px; display: grid; gap: 4px 16px; grid-template-columns: 1fr 1fr; }
.detail-body .full { grid-column: 1 / -1; }
.access-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px 12px; margin-bottom: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
th { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
tr:last-child td { border-bottom: 0; }
td.row-actions { text-align: right; white-space: nowrap; }
td.row-actions button { margin-left: 4px; }

dialog { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; width: min(92vw, 460px); }
dialog::backdrop { background: rgb(0 0 0 / 0.5); }
dialog .actions { justify-content: flex-end; margin-top: 8px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: 90vw;
  padding: 10px 16px;
  color: var(--accent-text);
  background: var(--text);
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
#toast.show { opacity: 1; }
#toast.bad { background: var(--danger); color: #fff; }

.empty { padding: 28px; text-align: center; color: var(--muted); }

@media (max-width: 640px) {
  .site-row { grid-template-columns: 1fr; }
  .detail-body { grid-template-columns: 1fr; }
  .top { padding: 12px 14px; }
  th:nth-child(3), td:nth-child(3) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}
