/* ─── CSS Variables / Theming ──────────────────────────────────────── */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --text-primary: #212529;
  --text-secondary: #6c757d;
  --text-muted: #adb5bd;
  --border-color: #dee2e6;
  --accent: #0078d4;
  --accent-hover: #106ebe;
  --danger: #dc3545;
  --danger-hover: #c82333;
  --success: #28a745;
  --success-bg: #d4edda;
  --success-border: #c3e6cb;
  --error-bg: #f8d7da;
  --error-border: #f5c6cb;
  --warning: #ffc107;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 8px;
  --badge-bg: #e9ecef;
  --badge-text: #495057;
  --primary-tag: #cce5ff;
  --primary-tag-text: #004085;
  --table-stripe: #f8f9fa;
  --hover-bg: #f1f3f5;
}

[data-theme="dark"] {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #1f2940;
  --bg-input: #2a3550;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a8b4;
  --text-muted: #6c757d;
  --border-color: #2e3a4e;
  --accent: #4da6ff;
  --accent-hover: #80bfff;
  --danger: #ff6b7a;
  --danger-hover: #ff4d5e;
  --success: #51cf66;
  --success-bg: #1a3a2a;
  --success-border: #28543a;
  --error-bg: #3a1a1e;
  --error-border: #54282e;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
  --badge-bg: #2e3a4e;
  --badge-text: #c0c8d4;
  --primary-tag: #1a3a5c;
  --primary-tag-text: #80bfff;
  --table-stripe: #1a2438;
  --hover-bg: #253048;
}

/* ─── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ─── Navbar ───────────────────────────────────────────────────────── */
.navbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.navbar-brand:hover { text-decoration: none; color: var(--accent); }

.navbar-brand svg { width: 24px; height: 24px; fill: var(--accent); }

.navbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.navbar-user {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ─── Theme Toggle ─────────────────────────────────────────────────── */
.theme-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-primary);
  transition: all 0.2s;
}
.theme-toggle:hover { border-color: var(--accent); }

/* ─── Container ────────────────────────────────────────────────────── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* ─── Cards ────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.card-body { padding: 20px; }

/* ─── Page Header ──────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
}

/* ─── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  line-height: 1.4;
}

.btn:hover { text-decoration: none; }

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

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger-hover); color: #fff; }

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-color);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-sm { padding: 4px 10px; font-size: 13px; }

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font-size: 14px;
  cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

.btn-icon {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
}
.btn-icon:hover { border-color: var(--danger); color: var(--danger); }

/* ─── Forms ────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text-primary);
  transition: border-color 0.15s;
}

.form-control[readonly] {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: not-allowed;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,120,212,0.15);
}

.form-inline {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.form-inline .form-group { margin-bottom: 0; flex: 1; }

/* ─── Table ────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
}

th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

tbody tr:nth-child(even) { background: var(--table-stripe); }
tbody tr:hover { background: var(--hover-bg); }

/* ─── Group List Cards ─────────────────────────────────────────────── */
.group-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }

.group-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px 20px;
  transition: all 0.15s;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.group-card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
  text-decoration: none;
}

.group-card-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.group-card-email {
  font-size: 13px;
  color: var(--accent);
}

.group-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── Badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 12px;
  background: var(--badge-bg);
  color: var(--badge-text);
}

.badge-primary {
  background: var(--primary-tag);
  color: var(--primary-tag-text);
}

/* ─── Alerts ───────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
}

.alert-success {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success);
}

.alert-error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--danger);
}

.alert-announcement {
  background: var(--warning);
  border: 1px solid #e0a800;
  color: #856404;
  font-weight: 500;
  font-size: 14px;
}

[data-theme="dark"] .alert-announcement {
  background: #3d3200;
  border-color: #665200;
  color: #ffd54f;
}

.alert-info {
  background: var(--primary-tag);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 13px;
}

/* ─── Tabs ─────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 20px;
  gap: 0;
}

.tab {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.tab:hover { color: var(--accent); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

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

/* ─── User Search / Autocomplete ───────────────────────────────────── */
.search-container { position: relative; }

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  max-height: 240px;
  overflow-y: auto;
  z-index: 50;
  display: none;
}

.search-results.visible { display: block; }

.search-result-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 1px solid var(--border-color);
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--hover-bg); }

.search-result-item .name { font-weight: 500; color: var(--text-primary); }
.search-result-item .email { font-size: 12px; color: var(--text-secondary); }

/* ─── Section headers ──────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.section-count {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ─── Alias list ───────────────────────────────────────────────────── */
.alias-list { list-style: none; }

.alias-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
}

.alias-item:last-child { border-bottom: none; }

.alias-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ─── Confirm dialog ───────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.visible { display: flex; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 440px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}

.modal h3 { margin-bottom: 12px; font-size: 18px; }
.modal p { margin-bottom: 20px; color: var(--text-secondary); font-size: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

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

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 400px;
  width: 90%;
}

.login-card h1 { font-size: 24px; margin-bottom: 8px; }
.login-card p { color: var(--text-secondary); margin-bottom: 24px; font-size: 14px; }

.login-card .btn { width: 100%; justify-content: center; padding: 12px; font-size: 16px; }

/* ─── Empty state ──────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.empty-state p { font-size: 14px; }

/* ─── Utility ──────────────────────────────────────────────────────── */
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--text-secondary); }
.text-sm { font-size: 13px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }

/* ─── View Toggle ──────────────────────────────────────────────────── */
.view-toggle { display: flex; gap: 4px; }

.view-toggle-btn {
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.view-toggle-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ─── Spinner ──────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

.btn-outline .spinner,
.btn-icon .spinner {
  border-color: rgba(0,0,0,0.15);
  border-top-color: var(--accent);
}

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

/* ─── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .container { padding: 16px; }
  .group-list { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .form-inline { flex-direction: column; }
  .navbar { padding: 0 12px; }
}
