:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --border: #e0e0e3;
  --text: #1c1c1f;
  --text-muted: #6b6b70;
  --accent: #0f8a55;
  --accent-hover: #0b6e44;
  --row-hover: #f0faf5;
  --selected-bg: #e6f6ed;
}

* { box-sizing: border-box; }

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

.topbar {
  padding: 16px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.brand-logo {
  display: block;
  height: 36px;
  width: auto;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.userbar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

.search-row {
  display: flex;
  gap: 8px;
}

#searchInput {
  flex: 1;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.filters-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* Multiselect filter (searchable checkbox dropdown) */
.multiselect {
  position: relative;
  min-width: 180px;
  max-width: 220px;
}

.multiselect-trigger {
  width: 100%;
  text-align: left;
  padding: 10px 28px 10px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  position: relative;
}
.multiselect-trigger::after {
  content: "▾";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-muted);
}
.multiselect-trigger.active {
  border-color: var(--accent);
  color: var(--text);
}
.multiselect.has-selection .multiselect-trigger {
  border-color: var(--accent);
  background: var(--selected-bg);
  font-weight: 500;
}

.multiselect-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: max(100%, 260px);
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 20;
  display: flex;
  flex-direction: column;
  max-height: 340px;
}
/* Author `display: flex` above otherwise beats the UA's `[hidden]{display:none}`
   at equal specificity — this raises specificity so hidden actually hides it. */
.multiselect-panel[hidden] {
  display: none;
}

.multiselect-search {
  margin: 8px;
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.multiselect-options {
  overflow-y: auto;
  flex: 1;
  padding: 0 4px;
}

.multiselect-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  font-size: 13px;
  border-radius: 4px;
  cursor: pointer;
}
.multiselect-option:hover { background: var(--row-hover); }

.multiselect-option .option-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.multiselect-option .option-count {
  font-size: 11px;
  color: var(--text-muted);
}

.multiselect-empty {
  padding: 12px 8px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

.multiselect-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.multiselect-clear {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  padding: 2px 6px;
  cursor: pointer;
}
.multiselect-clear:hover { text-decoration: underline; }

main {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  padding: 16px 24px;
  align-items: start;
}

.results-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.results-meta {
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: #fafafa;
}

.col-check { width: 32px; }

th.sortable {
  cursor: pointer;
  user-select: none;
}
th.sortable:hover { color: var(--text); }

.sort-indicator {
  display: inline-block;
  width: 10px;
  margin-left: 2px;
  font-size: 10px;
  color: var(--accent);
}

tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--row-hover); }
tbody tr.selected { background: var(--selected-bg); }

td.email { font-variant-numeric: tabular-nums; }
td.empty-email { color: var(--text-muted); font-style: italic; }

.load-more-row {
  padding: 12px;
  text-align: center;
}

.selection-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  position: sticky;
  top: 100px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
}

.selection-panel h2 {
  margin: 0 0 4px;
  font-size: 15px;
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 12px;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}

.options select {
  margin-left: 8px;
  padding: 4px 6px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

button {
  cursor: pointer;
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: white;
  flex: 1;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary.copied { background: #16a34a; }

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

.note {
  font-size: 12px;
  color: #b45309;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 8px;
}

#selectedList {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  border-top: 1px solid var(--border);
}

#selectedList li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

#selectedList .who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#selectedList .who small {
  display: block;
  color: var(--text-muted);
}

#selectedList .remove {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 14px;
  padding: 0 4px;
}
#selectedList .remove:hover { color: #dc2626; }

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
}

.login-card h1 {
  margin: 0 0 24px;
}

.login-logo {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  margin: 0 auto;
}

.login-card label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.login-card input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.login-card button[type=submit] {
  width: 100%;
  margin-top: 4px;
}

.login-error {
  margin: 0 0 12px;
  font-size: 13px;
  color: #b91c1c;
}

.multiselect-option .option-icon {
  flex: none;
  width: 1.4em;
  text-align: center;
  font-size: 15px;
  line-height: 1;
}
