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

:root {
  --color-bg:             #f5f6fa;
  --color-surface:        #ffffff;
  --color-border:         #e2e4ea;
  --color-primary:        #ff6b35;
  --color-primary-h:      #e55a28;
  --color-primary-light:  #fff5f1;
  --color-text:           #1a1d23;
  --color-muted:          #6b7280;
  --color-error:          #dc2626;
  --color-success:        #16a34a;
  --color-google:         #ffffff;
  --color-banned-bg:      #fff5f5;
  --color-banned-border:  #fecaca;
  --radius:               10px;
  --shadow:               0 2px 12px rgba(0,0,0,.08);
  --shadow-lg:            0 8px 32px rgba(0,0,0,.14);
  --transition:           .18s ease;
  --sidebar-w:            220px;
  --topbar-h:             60px;
}

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

/* ── Screens ──────────────────────────────────────────── */
.screen { display: flex; flex-direction: column; min-height: 100vh; }
.hidden { display: none !important; }

/* ── Login ────────────────────────────────────────────── */
#screen-login {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fff5f1 0%, #ffeee8 100%);
}

.login-card {
  background: var(--color-surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 48px 40px;
  width: min(420px, 90vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.brand { text-align: center; }
.brand h1 { font-size: 1.6rem; font-weight: 700; color: var(--color-primary); }

/* Logo image — login card (large) and topbar (small) */
.brand-logo {
  display: block;
  margin: 0 auto 8px;
  width: 80px;
  height: 80px;
  object-fit: contain;
}
.topbar-brand .brand-logo {
  width: 32px;
  height: 32px;
  margin: 0;
}
.brand-sub { color: var(--color-muted); font-size: .9rem; margin-top: 4px; }

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition), color var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-google {
  width: 100%;
  background: var(--color-google);
  border: 1.5px solid var(--color-border);
  color: var(--color-text);
  padding: 12px 20px;
  font-size: 1rem;
  gap: 10px;
}
.btn-google:hover:not(:disabled) { background: #f8f9fa; }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  padding: 10px 22px;
  font-size: .95rem;
}
.btn-primary:hover:not(:disabled) { background: var(--color-primary-h); }

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1.5px solid var(--color-border);
}
.btn-secondary:hover:not(:disabled) { background: var(--color-border); }

.btn-ghost {
  background: transparent;
  color: var(--color-muted);
  font-size: .85rem;
  padding: 6px 10px;
}
.btn-ghost:hover:not(:disabled) { color: var(--color-text); background: var(--color-bg); }

.btn-icon {
  padding: 4px 8px;
  font-size: 1rem;
  line-height: 1;
}

.btn-danger {
  background: transparent;
  color: var(--color-error);
  border: 1.5px solid transparent;
  font-size: .82rem;
  padding: 5px 10px;
}
.btn-danger:hover:not(:disabled) { background: #fff1f1; border-color: #fecaca; }

.btn-action {
  background: transparent;
  color: var(--color-muted);
  border: 1.5px solid transparent;
  font-size: .82rem;
  padding: 5px 10px;
}
.btn-action:hover:not(:disabled) { background: var(--color-bg); border-color: var(--color-border); color: var(--color-text); }

/* ── Top bar ──────────────────────────────────────────── */
.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: var(--topbar-h);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-shrink: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-primary);
}
.topbar-brand .brand-icon { font-size: 1.4rem; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--color-border);
  background: var(--color-bg);
}

#user-name {
  font-size: .9rem;
  color: var(--color-muted);
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── App body (sidebar + content) ─────────────────────── */
.app-body {
  display: flex;
  flex: 1;
  min-height: calc(100vh - var(--topbar-h));
}

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 16px 0;
  flex-shrink: 0;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}

.nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: none;
  border: none;
  border-radius: 8px;
  font-size: .92rem;
  font-weight: 500;
  color: var(--color-muted);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--color-bg); color: var(--color-text); }
.nav-item.active { background: var(--color-primary-light); color: var(--color-primary); font-weight: 600; }

.nav-icon { font-size: 1.1rem; flex-shrink: 0; }

/* ── Page content ─────────────────────────────────────── */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px 60px;
  min-width: 0;
}

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

.page-header {
  margin-bottom: 20px;
}
.page-header h2 { font-size: 1.4rem; font-weight: 700; }

/* ── Users toolbar ────────────────────────────────────── */
.users-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  align-items: center;
}

.search-input {
  flex: 1;
  min-width: 200px;
  max-width: 340px;
  padding: 9px 13px;
  border: 1.5px solid var(--color-border);
  border-radius: 8px;
  font-size: .92rem;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(255,107,53,.1);
}

.filter-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.filter-tab {
  padding: 7px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-surface);
  color: var(--color-muted);
  font-size: .84rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.filter-tab:hover { border-color: var(--color-primary); color: var(--color-primary); }
.filter-tab.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

/* ── Table ────────────────────────────────────────────── */
.table-wrapper {
  background: var(--color-surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.users-table thead {
  background: var(--color-bg);
  border-bottom: 1.5px solid var(--color-border);
}

.users-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-muted);
}

.users-table tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition);
}
.users-table tbody tr:last-child { border-bottom: none; }
.users-table tbody tr:hover { background: var(--color-bg); }
.users-table tbody tr.row-banned { background: var(--color-banned-bg); border-left: 3px solid #f87171; }
.users-table tbody tr.row-banned:hover { background: #ffe4e4; }

.users-table td {
  padding: 11px 14px;
  font-size: .9rem;
  vertical-align: middle;
}

/* Avatar cell */
.row-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--color-border);
  background: var(--color-bg);
  display: block;
}

.avatar-placeholder {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  color: var(--color-muted);
}

/* Row name */
.row-name { font-weight: 600; }
.row-username { font-size: .82rem; color: var(--color-muted); }

/* ── Role badges ──────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: .76rem;
  font-weight: 600;
}
.badge-professional { background: #fff3ed; color: #c2410c; border: 1.5px solid #fed7aa; }
.badge-customer     { background: #eff6ff; color: #1d4ed8; border: 1.5px solid #bfdbfe; }
.badge-company_admin{ background: #f5f3ff; color: #6d28d9; border: 1.5px solid #ddd6fe; }

/* ── Status cell ──────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: .82rem;
  font-weight: 500;
}
.status-active { color: var(--color-success); }
.status-banned { color: var(--color-error); }

/* ── Row actions ──────────────────────────────────────── */
.row-actions { display: flex; gap: 4px; align-items: center; }

/* ── Skeleton ─────────────────────────────────────────── */
.skeleton-list { padding: 8px 16px; display: flex; flex-direction: column; gap: 10px; }
.skeleton-row {
  height: 44px;
  border-radius: 8px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Empty state ──────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 16px;
  color: var(--color-muted);
  font-size: .92rem;
}
.empty-icon { font-size: 2rem; }

/* ── Load more ────────────────────────────────────────── */
.load-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

/* ── Form card (add professional) ─────────────────────── */
.form-card {
  background: var(--color-surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 36px 36px 28px;
  width: min(680px, 100%);
}

.form-desc {
  color: var(--color-muted);
  font-size: .9rem;
  margin-bottom: 24px;
}

/* ── Fieldset ─────────────────────────────────────────── */
.fieldset {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  padding: 18px 18px 10px;
  margin-bottom: 18px;
}
.fieldset legend {
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-muted);
  padding: 0 6px;
}

/* ── Fields ───────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
}
.field:last-child { margin-bottom: 0; }

.field label {
  font-size: .86rem;
  font-weight: 600;
  color: var(--color-text);
}
.field-checkbox-row { flex-direction: row; align-items: center; }

.required { color: var(--color-primary); }

.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="url"],
.field input[type="number"],
.field input[type="search"],
.field textarea,
.field select {
  padding: 9px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: 8px;
  font-size: .92rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-bg);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  resize: vertical;
}
.field select { resize: none; cursor: pointer; }

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(255,107,53,.1);
  background: #fff;
}

.field input.invalid,
.field textarea.invalid {
  border-color: var(--color-error);
  box-shadow: 0 0 0 3px rgba(220,38,38,.1);
}

.field-hint { font-size: .78rem; color: var(--color-muted); }

.field-value {
  display: inline-block;
  padding: 4px 8px;
  background: #f3f4f6;
  border-radius: 6px;
  font-size: 13px;
  color: #374151;
}

/* ── Checkboxes ───────────────────────────────────────── */
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 7px;
  margin-top: 4px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .88rem;
  font-weight: 400;
  cursor: pointer;
  padding: 6px 10px;
  border: 1.5px solid var(--color-border);
  border-radius: 8px;
  transition: border-color var(--transition), background var(--transition);
}
.checkbox-label:hover { border-color: var(--color-primary); background: var(--color-primary-light); }
.checkbox-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--color-primary);
  cursor: pointer;
  flex-shrink: 0;
}
.checkbox-grid.invalid .checkbox-label { border-color: var(--color-error); }

/* ── Feedback banner ──────────────────────────────────── */
.feedback {
  border-radius: 8px;
  padding: 11px 14px;
  font-size: .88rem;
  font-weight: 500;
  margin-bottom: 14px;
  white-space: pre-wrap;
}
.feedback.success { background: #f0fdf4; color: var(--color-success); border: 1.5px solid #bbf7d0; }
.feedback.error   { background: #fef2f2; color: var(--color-error);   border: 1.5px solid #fecaca; }

.error-text { color: var(--color-error); font-size: .88rem; text-align: center; }

/* ── Form actions ─────────────────────────────────────── */
.form-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 6px;
}

/* ── Spinner ──────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2.5px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Edit Drawer ──────────────────────────────────────── */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 40;
  backdrop-filter: blur(2px);
  transition: opacity var(--transition);
}

.edit-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transition: transform .25s ease;
}
.edit-drawer.hidden { transform: translateX(100%); }
/* Ensure the drawer is visible when shown (override .hidden display:none) */
.edit-drawer:not(.hidden) { display: flex !important; }
.drawer-overlay:not(.hidden) { display: block !important; }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.drawer-header h3 { font-size: 1.1rem; font-weight: 700; }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.drawer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 12px;
  margin-top: 4px;
  border-top: 1px solid var(--color-border);
}

/* ── Toast ────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: var(--color-text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: .88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in .25s ease;
  max-width: 320px;
}
.toast.toast-success { background: var(--color-success); }
.toast.toast-error   { background: var(--color-error); }

@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ── Promote / Demote action buttons ─────────────────── */
.btn-promote {
  background: transparent;
  color: var(--color-success);
  border: 1.5px solid transparent;
  font-size: .82rem;
  padding: 5px 10px;
}
.btn-promote:hover:not(:disabled) { background: #f0fdf4; border-color: #bbf7d0; }

.btn-demote {
  background: transparent;
  color: #b45309;
  border: 1.5px solid transparent;
  font-size: .82rem;
  padding: 5px 10px;
}
.btn-demote:hover:not(:disabled) { background: #fffbeb; border-color: #fde68a; }

/* ── Promote modal ────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 60;
  backdrop-filter: blur(2px);
}
.modal-overlay:not(.hidden) { display: block !important; }

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(480px, 94vw);
  background: var(--color-surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  z-index: 70;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
.modal:not(.hidden) { display: flex !important; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 16px;
  margin-top: 4px;
  border-top: 1px solid var(--color-border);
}

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 56px; }
  .nav-item span:not(.nav-icon) { display: none; }
  .page-content { padding: 20px 16px 40px; }
  .form-card { padding: 24px 18px 20px; }
  .topbar { padding: 0 16px; }
  .users-table th:nth-child(5),
  .users-table td:nth-child(5),
  .users-table th:nth-child(7),
  .users-table td:nth-child(7) { display: none; }
}

@media (max-width: 520px) {
  .checkbox-grid { grid-template-columns: 1fr 1fr; }
  .filter-tabs { gap: 3px; }
  .filter-tab { padding: 5px 10px; font-size: .78rem; }
}
