@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

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

:root {
  --header-bg:    #0f1e35;
  --accent:       #1e87c8;
  --accent-dark:  #1670a8;
  --bg:           #f2f4f7;
  --surface:      #ffffff;
  --text:         #1a1f2e;
  --text-muted:   #6b7280;
  --text-light:   #9ca3af;
  --border:       #e2e6ea;
  --border-soft:  #f0f2f5;
  --success:      #10b981;
  --danger:       #ef4444;
  --warning:      #f59e0b;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 1px 3px rgba(0,0,0,.07), 0 4px 12px rgba(0,0,0,.05);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.12);
  --header-h:     64px;
}

html { font-size: 15px; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* ── HEADER ───────────────────────────────────────────────── */
.site-header {
  background: var(--header-bg);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-header-inner {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 32px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.header-logo-link {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.header-logo-img { height: 28px; width: auto; }

.header-divider {
  width: 1px;
  height: 18px;
  background: rgba(255,255,255,.18);
}

.header-site-name {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,.45);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-user-name {
  font-size: .85rem;
  font-weight: 500;
  color: rgba(255,255,255,.75);
}

.header-user-email {
  font-size: .75rem;
  color: rgba(255,255,255,.4);
}

.header-sign-out {
  font-size: .78rem;
  font-weight: 600;
  color: rgba(255,255,255,.45);
  text-decoration: none;
  padding: 5px 12px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 20px;
  transition: color .15s, border-color .15s;
}

.header-sign-out:hover {
  color: rgba(255,255,255,.8);
  border-color: rgba(255,255,255,.3);
  text-decoration: none;
}

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: .75rem;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  color: rgba(255,255,255,.5);
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 20px;
  padding: 5px 14px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  flex-shrink: 0;
}

.theme-toggle-btn:hover {
  color: rgba(255,255,255,.85);
  border-color: rgba(255,255,255,.25);
}

/* ── LOGIN PAGE ───────────────────────────────────────────── */
.login-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background: var(--header-bg);
  background-image: radial-gradient(ellipse at 60% 20%, rgba(30,135,200,.12) 0%, transparent 60%);
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 48px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo {
  height: 36px;
  margin-bottom: 28px;
}

.login-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: -.3px;
}

.login-subtitle {
  font-size: .9rem;
  color: var(--text-muted);
  margin-bottom: 36px;
}

.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 13px 20px;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .95rem;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, background .15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.google-btn:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(30,135,200,.15);
  text-decoration: none;
  background: #fafcff;
}

.google-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.login-domain-note {
  margin-top: 14px;
  font-size: .78rem;
  color: var(--text-light);
}

.login-error {
  margin-top: 20px;
  padding: 12px 16px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  color: #b91c1c;
  font-size: .85rem;
  text-align: left;
}

/* ── MAIN CONTENT ─────────────────────────────────────────── */
.admin-main {
  flex: 1;
  padding: 40px 32px 80px;
}

.admin-container {
  max-width: 1140px;
  margin: 0 auto;
}

/* ── PAGE HEADER ──────────────────────────────────────────── */
.admin-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.admin-page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.3px;
}

/* ── CARDS ────────────────────────────────────────────────── */
.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ── USERS TABLE ──────────────────────────────────────────── */
.users-table {
  width: 100%;
  border-collapse: collapse;
}

.users-table thead {
  background: var(--border-soft);
  border-bottom: 1px solid var(--border);
}

.users-table th {
  padding: 11px 16px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  text-align: left;
}

.users-table th.col-perm {
  text-align: center;
  min-width: 76px;
  white-space: nowrap;
}

.users-table th.col-status {
  text-align: center;
  min-width: 100px;
}

.users-table tbody tr {
  border-bottom: 1px solid var(--border-soft);
  transition: background .1s;
}

.users-table tbody tr:last-child { border-bottom: none; }
.users-table tbody tr:hover { background: #fafbff; }

.users-table td {
  padding: 14px 16px;
  vertical-align: middle;
}

.users-table td.col-perm { text-align: center; }
.users-table td.col-status { text-align: center; }

.user-info { display: flex; flex-direction: column; gap: 2px; }
.user-name  { font-size: .9rem; font-weight: 600; color: var(--text); }
.user-email { font-size: .78rem; color: var(--text-muted); }

/* ── PERMISSION CHECKBOXES ────────────────────────────────── */
.perm-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  background: var(--surface);
  transition: border-color .15s, background .15s;
  position: relative;
  flex-shrink: 0;
  vertical-align: middle;
}

.perm-checkbox:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.perm-checkbox:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 6px;
  height: 10px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

.perm-checkbox:hover:not(:disabled) { border-color: var(--accent); }
.perm-checkbox:disabled { opacity: .4; cursor: not-allowed; }

.perm-checkbox.saving { opacity: .5; cursor: wait; }

/* ── STATUS TOGGLE ────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}

.status-badge.active {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #059669;
}

.status-badge.active:hover {
  background: #d1fae5;
}

.status-badge.inactive {
  background: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}

.status-badge.inactive:hover {
  background: #fee2e2;
}

/* ── BUTTONS ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background .15s, border-color .15s, box-shadow .15s;
  text-decoration: none;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  text-decoration: none;
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
}

/* ── MODAL ────────────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,30,53,.65);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
  transition: color .15s;
}

.modal-close:hover { color: var(--text); }

.modal-body { padding: 20px 24px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 24px 24px;
}

/* ── FORM GROUPS ──────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }

.form-group label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 9px 13px;
  font-size: .9rem;
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30,135,200,.12);
}

.form-hint {
  display: block;
  margin-top: 5px;
  font-size: .75rem;
  color: var(--text-light);
}

.perm-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.perm-label {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: .85rem;
  font-weight: 400 !important;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 0 !important;
}

.perm-label input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 17px;
  height: 17px;
  border: 2px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  background: var(--surface);
  transition: border-color .15s, background .15s;
  position: relative;
  flex-shrink: 0;
}

.perm-label input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.perm-label input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

/* ── TOAST NOTIFICATIONS ──────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: #1a1f2e;
  color: #fff;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: auto;
  max-width: 300px;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }

/* ── EMPTY STATE ──────────────────────────────────────────── */
.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state p { font-size: .95rem; }

/* ── DARK THEME OVERRIDES ─────────────────────────────────── */
[data-theme="dark"] {
  --bg:          #111827;
  --surface:     #1f2937;
  --text:        #f1f5f9;
  --text-muted:  #9ca3af;
  --text-light:  #6b7280;
  --border:      #374151;
  --border-soft: #1f2937;
}

[data-theme="dark"] .google-btn {
  background: #1f2937;
  border-color: #374151;
  color: #f1f5f9;
}

[data-theme="dark"] .google-btn:hover {
  background: #253141;
}

[data-theme="dark"] .users-table tbody tr:hover { background: #253141; }

[data-theme="dark"] .perm-checkbox { background: #1f2937; }

[data-theme="dark"] .perm-label input[type="checkbox"] { background: #1f2937; }

[data-theme="dark"] .form-control {
  background: #111827;
  color: #f1f5f9;
}

[data-theme="dark"] .login-card {
  background: #1f2937;
}

[data-theme="dark"] .login-title { color: #f1f5f9; }

[data-theme="dark"] .login-error {
  background: rgba(239,68,68,.1);
  border-color: rgba(239,68,68,.3);
  color: #fca5a5;
}

[data-theme="dark"] .toast { background: #374151; }

/* ── RESPONSIVE ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .site-header-inner { padding: 0 16px; }
  .admin-main { padding: 24px 16px 60px; }
  .header-user-email { display: none; }
  .users-table { font-size: .82rem; display: block; overflow-x: auto; }
  .perm-grid { grid-template-columns: 1fr; }
}
