:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --border: #e2e4e9;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #4f5bd5;
  --accent-hover: #3d47b0;
  --error: #c0392b;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.topbar h1 {
  font-size: 22px;
  margin: 0;
}

.link {
  color: var(--accent);
  text-decoration: none;
  margin-left: 16px;
  font-size: 14px;
}
.link:hover { text-decoration: underline; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 20px;
}

.card h2 {
  font-size: 15px;
  margin: 0 0 12px 0;
  color: var(--text);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px;
}

.chart-card canvas {
  max-height: 280px;
}

.explorer-chart {
  margin-bottom: 16px;
  padding: 16px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
}

.filter-field {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  gap: 6px;
}

.filter-field.wide {
  flex: 1 1 100%;
}

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

input, select, button {
  font-size: 14px;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

button {
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
}
button:hover { background: var(--accent-hover); }
button.secondary {
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--accent);
}
button.secondary:hover { background: #f0f1fd; }

.inline-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.explorer-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.checkbox-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 140px;
  overflow-y: auto;
  background: #fafbfc;
}
.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: normal;
  color: var(--text);
  font-size: 13px;
}

.filter-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}
.filter-row select, .filter-row input {
  flex: 1;
}
.filter-row .remove-btn {
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error);
  padding: 6px 10px;
  flex: 0 0 auto;
}
.filter-row .remove-btn:hover {
  background: #fdecea;
}

.explorer-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.sql-preview {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  background: #f5f6f8;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  background: #fafbfc;
  color: var(--muted);
  position: sticky;
  top: 0;
}
.table-scroll {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.error {
  color: var(--error);
  font-size: 13px;
}

.success {
  color: #1f8a4c;
  font-size: 13px;
}

.current-user {
  font-size: 13px;
  color: var(--muted);
  margin-left: 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.role-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 10px;
  background: #e2e4e9;
  color: var(--text);
}
.role-badge.role-admin {
  background: #4f5bd5;
  color: #fff;
}
.role-badge.role-agent {
  background: #e8ecff;
  color: var(--accent);
}

/* Manage Users page */
.inline-domain-form,
.inline-password-form,
.inline-delete-form {
  margin-bottom: 8px;
}
.inline-domain-form .checkbox-list {
  max-height: 100px;
  margin-bottom: 6px;
}
.inline-password-form {
  display: flex;
  gap: 6px;
}
.inline-password-form input[type="password"] {
  flex: 1;
  min-width: 0;
}

/* Login page */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}
.login-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-box h1 {
  font-size: 18px;
  margin: 0 0 10px 0;
  text-align: center;
}
