:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1b1f24;
  --muted: #6b7280;
  --border: #d9dce1;
  --accent: #2563eb;
  --accent-text: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card-bg: #1d2126;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --border: #33383f;
    --accent: #3b82f6;
    --accent-text: #0b0f14;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
}

header h1 { margin: 0; font-size: 1.25rem; }

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.user-info button {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

body.role-user .admin-only { display: none !important; }
body:not(.role-user) .user-only { display: none !important; }

nav { display: flex; gap: 0.5rem; }

.tab-btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.tab-btn.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

main { padding: 1.5rem; max-width: 960px; margin: 0 auto; }

.tab { display: none; }
.tab.active { display: block; }

h2 { font-size: 1rem; margin: 1.5rem 0 0.5rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
h2:first-child { margin-top: 0; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.card.inline { flex-direction: row; flex-wrap: wrap; align-items: center; }

label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; color: var(--muted); }
label.checkbox { flex-direction: row; align-items: center; gap: 0.4rem; }

input, select {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

small { color: var(--muted); font-size: 0.75rem; }

button {
  align-self: flex-start;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-size: 0.85rem;
}

button:hover { opacity: 0.9; }

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

th { color: var(--muted); font-weight: 600; }

tr:last-child td { border-bottom: none; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-size: 0.85rem;
}

.hidden { display: none !important; }

.status { color: var(--muted); font-size: 0.85rem; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--border);
}

.badge.ok { background: #16a34a; color: white; }
.badge.error { background: #dc2626; color: white; }
.badge.warn { background: #d97706; color: white; }

.badge-lg { font-size: 0.9rem; padding: 0.2rem 0.7rem; }

.actions-select {
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.85rem;
}

.log-tail-toggle { display: block; margin: 0.5rem 0; color: var(--muted); font-size: 0.9rem; }

.log-output {
  background: #0b0f14;
  color: #d7dbe0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.8rem;
  line-height: 1.4;
  padding: 0.75rem 1rem;
  height: 480px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 1rem;
  z-index: 100;
  overflow-y: auto;
}

.modal-card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0.25rem;
}

.modal-form { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1rem; }

.site-picker-list {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.site-picker-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.site-picker-list li:last-child { border-bottom: none; }
.site-picker-list li.status { color: var(--muted); justify-content: flex-start; }

#add-site-panel { margin-top: 0.75rem; }
#add-site-filter { width: 100%; margin-bottom: 0.5rem; }
