/* ─── AK Chat Platform — Admin Panel Styles ──────────────────────────────────── */

/* ── Admin layout ───────────────────────────────────────────────────────────── */
body.admin-page {
  overflow: auto;
  min-height: 100vh;
  background: var(--bg-dark);
}

#admin-wrap {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
#admin-wrap.ab-active {
  height: 100vh;
  overflow: hidden;
}

/* Admin header */
#admin-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  height: 60px;
  background: var(--secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 6px var(--primary);
}

.admin-brand-name { font-size: 15px; font-weight: 700; }
.admin-badge {
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.admin-header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background: var(--tertiary);
  border-radius: 20px;
  font-size: 13px;
}

/* Admin body */
#admin-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Admin sidebar nav */
#admin-nav {
  width: 210px;
  min-width: 210px;
  background: var(--secondary);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-dim);
  padding: 12px 18px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
  position: relative;
}

.nav-item:hover  { background: var(--tertiary); color: var(--text); }
.nav-item.active {
  background: rgba(255,107,0,0.1);
  color: var(--primary);
  border-left-color: var(--primary);
}

/* Admin main content */
#admin-content {
  flex: 1;
  padding: 28px;
  overflow-y: auto;
  max-width: 1100px;
}

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

/* Agent Builder embedded in admin — full-bleed, no padding */
#admin-content.ab-fullbleed {
  max-width: none;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
#tab-build-agent {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
#tab-build-agent.active {
  display: flex;
}
#tab-build-agent #ab-layout {
  flex: 1;
  height: auto !important;
  min-height: 0;
}
#tab-build-agent #ab-settings-drawer {
  height: calc(100vh - 60px - 58px);
}

/* Page title */
.page-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}
.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* ── Stats grid ─────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--primary);
}
.stat-card:hover { border-color: var(--border-light); }
.stat-card-accent::before { background: var(--accent, #f59e0b); }
.stat-card-accent .stat-icon { color: var(--accent, #f59e0b); }

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.stat-icon {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.12;
  color: var(--primary);
}

/* ── Section card ───────────────────────────────────────────────────────────── */
.section-card {
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

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

.section-card-title {
  font-size: 14px;
  font-weight: 700;
}

/* ── Data table ─────────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 10px 16px;
  text-align: left;
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover   { background: rgba(255,255,255,0.02); }

/* Role / status badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}
.badge-admin  { background: rgba(255,107,0,0.15); color: var(--primary); }
.badge-member { background: rgba(255,255,255,0.08); color: var(--text-muted); }
.badge-active   { background: rgba(56,161,105,0.15); color: var(--success); }
.badge-inactive { background: rgba(255,255,255,0.06); color: var(--text-dim); }

/* Table actions */
.table-actions { display: flex; gap: 6px; }
.btn-table {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.btn-edit   { background: var(--tertiary); color: var(--text-muted); }
.btn-edit:hover   { color: var(--text); background: var(--border-light); }
.btn-delete { background: rgba(229,62,62,0.1); color: var(--danger); }
.btn-delete:hover { background: rgba(229,62,62,0.2); }

/* ── Form sections ──────────────────────────────────────────────────────────── */
.form-section { padding: 20px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.form-row { display: flex; gap: 14px; }
.form-row .form-group { flex: 1; }

/* Color input */
.color-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  overflow: hidden;
  flex-shrink: 0;
}
.color-swatch input[type="color"] {
  width: 200%;
  height: 200%;
  margin: -50%;
  border: none;
  padding: 0;
  cursor: pointer;
  background: none;
}

/* Toggle switch */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 22px;
  cursor: pointer;
  transition: background var(--transition);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }
.toggle-label { font-size: 13px; color: var(--text-muted); }

/* Agent access checkboxes */
.agent-access-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}
.agent-access-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition);
}
.agent-access-item:hover   { border-color: var(--border-light); }
.agent-access-item input[type="checkbox"] { accent-color: var(--primary); }
.agent-access-item span { font-size: 12px; }

/* ── Upload field ───────────────────────────────────────────────────────────── */
.upload-field-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}
.upload-field-wrap .form-input { flex: 1; }

.btn-upload {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  background: var(--tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.btn-upload:hover { background: var(--border-light); color: var(--text); border-color: var(--border-light); }
.btn-upload.uploading { opacity: 0.6; cursor: wait; }

.upload-preview {
  margin-top: 8px;
  display: none;
}
.upload-preview.visible { display: block; }
.upload-preview img {
  height: 48px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-dark);
  object-fit: contain;
  padding: 4px;
}

/* ── Calendar Manager ───────────────────────────────────────────────────────── */
.cal-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  flex-wrap: wrap;
}

.cal-controls-right {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

.cal-brand-tabs {
  display: flex;
  background: var(--bg-dark);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border);
}

.cal-brand-tab {
  padding: 6px 16px;
  border-radius: calc(var(--radius-sm) - 2px);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.cal-brand-tab:hover  { color: var(--text); }
.cal-brand-tab.active { background: var(--primary); color: #fff; }

.cal-filename {
  font-size: 11px;
  font-family: monospace;
  color: var(--text-muted);
  background: var(--bg-dark);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* Calendar grid rows */
.cal-weekend td { background: rgba(255,255,255,0.02); }

.cal-notes-cell { min-width: 200px; }

.cal-notes {
  resize: vertical;
  min-height: 48px;
  width: 100%;
}

.cal-notes-counter {
  font-size: 10px;
  color: var(--text-dim);
  text-align: right;
  margin-top: 2px;
}

.cal-day-cell {
  white-space: nowrap;
  color: var(--text);
}

.cal-day-name {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

#cal-grid .form-input,
#cal-grid .form-select {
  padding: 6px 10px;
  font-size: 12px;
  height: 32px;
}

#cal-grid td { padding: 5px 10px; }

/* ── Mobile nav toggle button ───────────────────────────────────────────────── */
#admin-nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: background var(--transition);
}
#admin-nav-toggle:hover { background: var(--tertiary); }

/* Mobile nav overlay */
#admin-nav-overlay {
  display: none;
  position: fixed;
  inset: 60px 0 0 0;
  background: rgba(0,0,0,0.55);
  z-index: 149;
}
#admin-nav-overlay.open { display: block; }

/* Mobile account actions — hidden on desktop, shown in nav on mobile */
.nav-mobile-actions { display: none; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  #admin-nav-toggle { display: flex; }

  /* Move account actions into nav, hide from header */
  .admin-header-right { display: none; }
  .nav-mobile-actions {
    display: block;
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding-top: 8px;
  }

  #admin-nav {
    position: fixed;
    top: 60px;
    left: 0;
    bottom: 0;
    z-index: 150;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    width: 220px;
    min-width: 220px;
    height: calc(100vh - 60px);
    overflow-y: auto;
  }
  #admin-nav.open { transform: translateX(0); }

  #admin-content { padding: 16px; }

  .section-card-header { flex-direction: column; align-items: flex-start; gap: 10px; }
}

/* ── Workflow Builder ─────────────────────────────────────────────────────────── */

.wf-mode-toggle {
  display: flex;
  gap: 8px;
}

.wf-mode-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: border-color var(--transition), color var(--transition), background var(--transition);
  user-select: none;
}
.wf-mode-opt input[type="radio"] { display: none; }
.wf-mode-opt:has(input:checked),
.wf-mode-opt.active {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(255,107,0,0.07);
}
.wf-mode-opt:hover { border-color: var(--primary); color: var(--text); }

.wf-builder {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--tertiary);
  padding: 12px;
}

.wf-empty {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.wf-step-card {
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
  transition: border-color var(--transition);
}
.wf-step-card:last-child { margin-bottom: 0; }
.wf-step-card:hover { border-color: rgba(255,107,0,0.35); }

.wf-step-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: default;
}

.wf-step-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--tertiary);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-muted);
}

.wf-step-badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.wf-step-summary {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wf-step-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.wf-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
  line-height: 1;
}
.wf-icon-btn:hover   { background: var(--tertiary); color: var(--text); }
.wf-del-btn:hover    { background: rgba(239,68,68,0.15); color: #ef4444; }

.wf-step-body {
  display: none;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-dark);
}
.wf-step-body.open { display: block; }

.wf-add-row {
  position: relative;
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.wf-step-picker {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  min-width: 220px;
}
.wf-step-picker.open { display: block; }

.wf-picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  transition: background var(--transition);
}
.wf-picker-item:hover { background: var(--tertiary); }

/* ── Modal structure helpers ─────────────────────────────────────────────────── */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  font-size: 16px;
  font-weight: 700;
}
.modal-body  { display: flex; flex-direction: column; gap: 16px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 4px;
  transition: color var(--transition);
}
.modal-close:hover { color: var(--text); }

/* ── Dashboard Charts ────────────────────────────────────────────────────────── */
.dash-chart-wrap {
  padding: 16px 20px 4px;
  min-height: 140px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  overflow-x: auto;
}
.dash-chart-wrap:empty { display: none; }

.dash-bar-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 44px;
  max-width: 80px;
}
.dash-bar-outer {
  width: 100%;
  height: 100px;
  display: flex;
  align-items: flex-end;
}
.dash-bar {
  width: 100%;
  border-radius: 4px 4px 0 0;
  background: var(--primary, #6c63ff);
  min-height: 3px;
  position: relative;
  transition: opacity 0.15s;
  cursor: default;
}
.dash-bar:hover { opacity: 0.8; }
.dash-bar-tip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-darker, #1a1a2e);
  color: var(--text, #e2e8f0);
  font-size: 11px;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.dash-bar:hover .dash-bar-tip { display: block; }
.dash-bar-val {
  font-size: 10px;
  color: var(--text-muted, #94a3b8);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.dash-bar-label {
  font-size: 11px;
  color: var(--text-muted, #94a3b8);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ── Schedules ───────────────────────────────────────────────────────────────── */
.sched-cron-example {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  background: var(--bg-darker);
  border-radius: 8px;
}
.sched-cron-example code {
  font-size: 12px;
  color: var(--primary);
  font-family: monospace;
}
.sched-cron-example span {
  font-size: 11px;
  color: var(--text-muted);
}

/* Status badges */
.badge-ok    { color: #48bb78; font-size: 12px; font-weight: 600; }
.badge-error { color: #f56565; font-size: 12px; font-weight: 600; }
.badge-never { color: var(--text-dim); font-size: 12px; }

/* SMTP feedback */
#smtp-feedback.success {
  background: rgba(72,187,120,0.1);
  border: 1px solid rgba(72,187,120,0.3);
  color: #48bb78;
}
#smtp-feedback.error {
  background: rgba(245,101,101,0.1);
  border: 1px solid rgba(245,101,101,0.3);
  color: #f56565;
}

/* ── Knowledge Base ──────────────────────────────────────────────────────────── */
.kb-tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.kb-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
#kb-dropzone:hover, #kb-dropzone.dragover {
  border-color: var(--primary);
  background: rgba(108,99,255,0.05);
}

.form-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: #ef4444;
}
