/* Admin Panel Styles - McHub */
/* Uses CSS variables from app.css */

html, body { height: 100%; margin: 0; }

.admin-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---- Sidebar ---- */
.admin-sidebar {
  width: 240px;
  background: var(--bg-sidebar);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.admin-sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.admin-sidebar-header .logo {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-light);
}

.admin-sidebar-header .logo span {
  color: var(--primary);
}

.admin-badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--primary-light);
  margin-top: 4px;
  font-weight: 600;
}

.admin-nav {
  flex: 1;
  padding: 12px 0;
}

.admin-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
}

.admin-nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-light);
  text-decoration: none;
}

.admin-nav-item.active {
  background: var(--bg-sidebar-active);
  color: var(--text-light);
  border-left-color: var(--primary);
}

.nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-icon .material-icons {
  font-size: 20px;
}

.stat-icon .material-icons {
  font-size: 28px;
}

.admin-sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.back-link {
  color: rgba(255,255,255,0.6);
  font-size: 13px;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.back-link:hover {
  color: var(--text-light);
  text-decoration: none;
}

/* ---- Main ---- */
.admin-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #f8f9fa;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-main);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.admin-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.admin-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.biz-label {
  font-size: 13px;
  color: var(--text-muted);
}

.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ---- Tab panels ---- */
.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ---- Stats grid ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.stat-icon {
  font-size: 32px;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-input);
  border-radius: 12px;
  flex-shrink: 0;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---- Toolbar ---- */
.tab-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.admin-search {
  flex: 1;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--bg-main);
  outline: none;
  transition: border-color 0.2s;
}

.admin-search:focus {
  border-color: var(--primary);
}

/* ---- Tables ---- */
.admin-table-wrap {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.admin-table thead {
  background: var(--bg-input);
}

.admin-table th {
  text-align: left;
  padding: 10px 16px;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.admin-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  vertical-align: middle;
}

.admin-table tr:last-child td {
  border-bottom: none;
}

.admin-table tr:hover td {
  background: var(--bg-hover);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 16px !important;
  font-style: italic;
}

.user-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-cell .text-muted {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.actions-cell {
  white-space: nowrap;
}

.desc-cell {
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Status dots ---- */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #888;
}

.status-dot.online { background: var(--online); }
.status-dot.away { background: var(--away); }
.status-dot.busy { background: var(--busy); }
.status-dot.offline { background: #888; }

/* ---- Badges ---- */
.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
}

.role-owner {
  background: #fff3e0;
  color: #e65100;
}

.role-admin {
  background: #e3f2fd;
  color: #1565c0;
}

.role-member {
  background: var(--bg-input);
  color: var(--text-secondary);
}

.type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}

.type-public {
  background: #e8f5e9;
  color: #2e7d32;
}

.type-private {
  background: #fce4ec;
  color: #c62828;
}

.role-select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--bg-main);
  cursor: pointer;
}

/* ---- Danger button ---- */
.btn-danger {
  background: var(--busy);
  color: #fff;
  border-radius: var(--radius);
}

.btn-danger:hover {
  background: #d32f2f;
}

/* ---- Settings ---- */
.settings-form {
  max-width: 960px;
}

.settings-section {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.settings-section h3 {
  font-size: 16px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
}

.settings-form .form-group {
  margin-bottom: 14px;
}

.settings-form .form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.settings-form .form-group input,
.settings-form .form-group textarea,
.settings-form .form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--bg-main);
  outline: none;
  transition: border-color 0.2s;
}

.settings-form .form-group input:focus,
.settings-form .form-group textarea:focus {
  border-color: var(--primary);
}

.settings-actions {
  padding-top: 8px;
}

/* ---- Temp password display ---- */
.temp-password {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-family: monospace;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 2px;
  margin-top: 12px;
  user-select: all;
  color: var(--primary-dark);
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .admin-sidebar {
    width: 56px;
    overflow: hidden;
  }

  .admin-sidebar-header .logo,
  .admin-badge,
  .admin-nav-item span:not(.nav-icon),
  .back-link span,
  .biz-label {
    display: none;
  }

  .admin-nav-item {
    padding: 12px 0;
    justify-content: center;
  }

  .nav-icon {
    font-size: 20px;
  }

  .back-link {
    justify-content: center;
    font-size: 18px;
  }

  .admin-content {
    padding: 16px;
  }

  .admin-header {
    padding: 12px 16px;
  }

  .admin-header h1 {
    font-size: 18px;
  }

  .tab-toolbar {
    flex-direction: column;
  }

  .admin-search {
    width: 100%;
  }

  .admin-table {
    font-size: 13px;
  }

  .admin-table th,
  .admin-table td {
    padding: 8px 10px;
  }
}

/* ════ Mobile: sidebar becomes a top nav bar; content gets room ════ */
@media (max-width: 600px) {
  .admin-layout {
    flex-direction: column;
    height: 100dvh;
  }
  .admin-sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    overflow: visible;
    padding: 0 4px;
  }
  .admin-sidebar-header { display: none; }
  .admin-nav {
    display: flex;
    flex-direction: row;
    flex: 1;
    justify-content: space-around;
    padding: 0;
  }
  .admin-nav-item {
    flex-direction: column;
    gap: 2px;
    padding: 8px 6px;
    font-size: 10px;
    border-left: none;
    border-bottom: 3px solid transparent;
  }
  .admin-nav-item.active { border-left: none; border-bottom-color: var(--primary); }
  /* show labels again (the 768px rules hid them for the icon rail) */
  .admin-nav-item span:not(.nav-icon) { display: inline; }
  .admin-sidebar-footer {
    border-top: none;
    padding: 0 8px;
  }
  .back-link span { display: inline; font-size: 18px; }
  .admin-main { min-height: 0; }
  .admin-content {
    padding: 12px;
    padding-bottom: 90px; /* keep clear of the mobile tab bar */
    overflow-y: auto;
  }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .admin-header { flex-wrap: wrap; row-gap: 8px; }
  .admin-header-right { flex: 1 1 100%; }
  .admin-header-right .business-select { width: 100%; max-width: none; }
  .admin-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ── Workspace Branding ─────────────────────────────────────────────── */
.brand-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.brand-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.brand-field label span { font-weight: 400; color: var(--text-muted); }
.brand-input { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: var(--radius); padding: 5px 8px; background: var(--surface); }
.brand-input input[type="color"] { width: 30px; height: 30px; padding: 0; border: none; background: none; border-radius: 8px; cursor: pointer; flex-shrink: 0; }
.brand-input input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.brand-input input[type="color"]::-webkit-color-swatch { border: 1px solid rgba(0,0,0,0.1); border-radius: 8px; }
.brand-input input[type="text"] { flex: 1; min-width: 0; border: none; outline: none; background: none; font-size: 13px; font-weight: 600; letter-spacing: 0.3px; text-transform: uppercase; color: var(--text-primary); }

.brand-presets { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.brand-presets-label { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-right: 2px; }
.brand-preset { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px 5px 6px; border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--surface); font-size: 12px; font-weight: 600; color: var(--text-secondary); transition: border-color 0.15s, box-shadow 0.15s; }
.brand-preset:hover { border-color: var(--primary); box-shadow: 0 1px 6px rgba(16,24,40,0.08); }
.brand-preset i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.brand-preset i + i { margin-left: -4px; }
.brand-preset span { margin-left: 4px; }

.brand-preview { display: flex; gap: 0; margin-top: 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; background: var(--surface); }
.bp-rail { width: 52px; background: var(--bg-sidebar); display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 14px 0; color: rgba(255,255,255,0.85); }
.bp-rail .material-icons { font-size: 20px; }
.bp-body { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.bp-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bp-link { color: var(--primary); font-size: 13px; font-weight: 600; }
.bp-msg { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-secondary); }
.bp-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }

@media (max-width: 600px) {
  .brand-grid { grid-template-columns: 1fr; }
}

/* Settings tab: paired fields sit side by side on wide screens and stack into
   a single readable column on narrow ones (was a cramped inline 1fr 1fr). */
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
@media (max-width: 820px) {
  .form-grid-2 { grid-template-columns: 1fr; }
  .settings-section { padding: 16px 14px; }
}

/* Admin sections as horizontal tabs; the left rail is now the shared app
   sidebar (chat channels/DMs), same as every page. */
.admin-nav-tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  padding: 8px 24px 0; background: var(--bg-main, #fff);
  border-bottom: 1px solid var(--border);
}
.admin-nav-tabs .admin-nav-item {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-muted); text-decoration: none;
  font-size: 13.5px; font-weight: 600;
  padding: 10px 14px; border-bottom: 3px solid transparent; border-radius: 0;
}
.admin-nav-tabs .admin-nav-item:hover { color: var(--text-primary); background: none; }
.admin-nav-tabs .admin-nav-item.active {
  color: var(--primary); border-bottom-color: var(--primary); background: none;
}
.admin-nav-tabs .nav-icon .material-icons { font-size: 18px; vertical-align: middle; }
/* The old two-pane admin layout is now a single main pane. */
.admin-layout { display: block; }
.admin-main { width: 100%; }
@media (max-width: 600px) {
  .admin-nav-tabs { padding: 4px 8px 0; overflow-x: auto; flex-wrap: nowrap; }
  .admin-nav-tabs .admin-nav-item { white-space: nowrap; }
}

/* With the shared app header above the panel, the old inner-scroll model
   (100vh layout + overflow:hidden + scrolling .admin-content) clipped the
   bottom of every tab. The panel now scrolls like every other page. */
.admin-layout { height: auto; overflow: visible; }
.admin-main { overflow: visible; height: auto; }
.admin-content { overflow: visible; height: auto; }

/* Add User dialog - segmented tabs for "existing account" vs "new account" */
.aut-tabs {
  display: flex; gap: 6px; margin-bottom: 16px;
  background: var(--bg-subtle, #f1f3f5);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 4px;
}
.aut-tab {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 10px; border: 0; border-radius: 7px;
  background: transparent; color: var(--text-muted);
  font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.aut-tab.active {
  background: var(--bg-card, #fff); color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
