/* ============================================================
   PRIMETOUCH — ADMIN DASHBOARD
   Data tables, modals, CRUD controls, pills, inline edits
   ============================================================ */

/* ── Admin shell overrides ───────────────────────────────────── */
.admin-shell {
  display: flex;
  min-height: 100vh;
  background: var(--bg-primary);
}

/* Wider sidebar for admin */
.admin-shell .sidebar { width: 230px; }
.admin-shell .dash-main { margin-left: 230px; }

@media (max-width: 900px) {
  .admin-shell .dash-main { margin-left: 0; }
}

/* ── Section header ──────────────────────────────────────────── */
.section-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.section-subtitle {
  font-size: .84rem;
  color: var(--text-muted);
}

/* ── Toolbar (search + actions) ──────────────────────────────── */
.admin-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
  margin-bottom: var(--space-lg);
}

.admin-toolbar-right {
  margin-left: auto;
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.admin-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  min-width: 220px;
  transition: border-color var(--trans-fast);
}

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

.admin-search input {
  background: none;
  border: none;
  outline: none;
  font-size: .88rem;
  color: var(--text-primary);
  width: 100%;
}

.admin-search input::placeholder { color: var(--text-muted); }

/* ── Data Table ──────────────────────────────────────────────── */
.admin-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .86rem;
}

.admin-table thead tr {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.admin-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.admin-table th:hover { color: var(--text-secondary); }
.admin-table th.sorted-asc::after  { content: ' ↑'; color: var(--gold); }
.admin-table th.sorted-desc::after { content: ' ↓'; color: var(--gold); }

.admin-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: middle;
}

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

.admin-table tbody tr:hover td {
  background: rgba(255,255,255,0.02);
}

.admin-table .col-actions {
  text-align: right;
  white-space: nowrap;
}

.admin-table .col-narrow { width: 1%; white-space: nowrap; }

/* Row actions */
.row-actions {
  display: flex;
  gap: 5px;
  justify-content: flex-end;
  align-items: center;
}

.btn-icon-sm {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  transition: all var(--trans-fast);
}

.btn-icon-sm:hover              { background: rgba(255,255,255,.05); color: var(--text-primary); border-color: var(--border-light); }
.btn-icon-sm.edit:hover         { background: var(--info-bg);    color: var(--info);    border-color: rgba(59,130,246,.3); }
.btn-icon-sm.delete:hover       { background: var(--error-bg);   color: var(--error);   border-color: rgba(239,68,68,.3); }
.btn-icon-sm.toggle-on:hover    { background: var(--error-bg);   color: var(--error); }
.btn-icon-sm.toggle-off:hover   { background: var(--success-bg); color: var(--success); }
.btn-icon-sm.view:hover         { background: var(--gold-muted); color: var(--gold); }
.btn-icon-sm.assign:hover       { background: var(--info-bg);    color: var(--info); }

/* ── Empty state ─────────────────────────────────────────────── */
.admin-empty {
  text-align: center;
  padding: var(--space-3xl) var(--space-lg);
  color: var(--text-muted);
}

.admin-empty-icon { font-size: 2.5rem; margin-bottom: var(--space-md); }
.admin-empty-text { font-size: .9rem; }

/* ── Pagination ──────────────────────────────────────────────── */
.admin-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
  font-size: .82rem;
  color: var(--text-muted);
  gap: var(--space-md);
  flex-wrap: wrap;
}

.pagination-btns {
  display: flex;
  gap: 4px;
}

.page-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: .82rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--trans-fast);
}

.page-btn:hover     { background: rgba(255,255,255,.04); border-color: var(--border-light); }
.page-btn.active    { background: var(--gold); color: var(--navy); border-color: var(--gold); font-weight: 700; }
.page-btn:disabled  { opacity: .35; cursor: not-allowed; }

/* ── Inline status badge (clickable) ─────────────────────────── */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: .72rem;
  font-weight: 700;
  text-transform: capitalize;
  cursor: default;
  white-space: nowrap;
}

.status-pill.clickable { cursor: pointer; }
.status-pill.clickable:hover { filter: brightness(1.15); }

.pill-active      { background: var(--success-bg); color: var(--success); }
.pill-inactive    { background: var(--error-bg);   color: var(--error); }
.pill-pending     { background: var(--warning-bg); color: var(--warning); }
.pill-confirmed   { background: var(--info-bg);    color: var(--info); }
.pill-in_progress { background: rgba(201,168,76,.14); color: var(--gold); }
.pill-completed   { background: var(--success-bg); color: var(--success); }
.pill-cancelled   { background: var(--error-bg);   color: var(--error); }
.pill-refunded    { background: rgba(139,92,246,.12); color: #a78bfa; }
.pill-unpaid      { background: var(--warning-bg); color: var(--warning); }
.pill-paid        { background: var(--success-bg); color: var(--success); }
.pill-admin       { background: rgba(239,68,68,.1); color: #f87171; }
.pill-agent       { background: var(--info-bg);    color: var(--info); }
.pill-client      { background: var(--gold-muted); color: var(--gold); }
.pill-google      { background: rgba(66,133,244,.1); color: #4285f4; }
.pill-local       { background: var(--border);      color: var(--text-muted); }

/* ── Modal ───────────────────────────────────────────────────── */
.admin-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--space-xl) var(--space-lg);
  overflow-y: auto;
}

.admin-modal {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 680px;
  animation: modal-drop .22s ease;
  position: relative;
  margin: auto;
}

.admin-modal.modal-lg { max-width: 880px; }
.admin-modal.modal-sm { max-width: 460px; }

@keyframes modal-drop {
  from { opacity: 0; transform: translateY(-12px) scale(.97); }
  to   { opacity: 1; transform: translateY(0)     scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-xl) var(--space-xl) var(--space-lg);
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--trans-fast);
}

.modal-close:hover { background: var(--error-bg); color: var(--error); border-color: rgba(239,68,68,.3); }

.modal-body {
  padding: var(--space-xl);
  max-height: calc(90vh - 140px);
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-lg) var(--space-xl);
  border-top: 1px solid var(--border);
}

/* ── Detail view inside modal ─────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

.detail-item-label {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.detail-item-value {
  font-size: .9rem;
  color: var(--text-primary);
  font-weight: 500;
}

.detail-section-label {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--gold);
  padding: var(--space-md) 0 var(--space-sm);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-md);
  grid-column: 1/-1;
}

/* ── Confirm dialog ──────────────────────────────────────────── */
.confirm-dialog {
  max-width: 420px;
  text-align: center;
}

.confirm-icon {
  font-size: 2.8rem;
  margin-bottom: var(--space-md);
}

.confirm-title {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: var(--space-sm);
}

.confirm-desc {
  font-size: .88rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ── Tab switcher ────────────────────────────────────────────── */
.admin-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 3px;
  margin-bottom: var(--space-lg);
  width: fit-content;
}

.admin-tab {
  padding: 7px 18px;
  border-radius: calc(var(--radius-md) - 2px);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  border: none;
  background: transparent;
  transition: all var(--trans-fast);
}

.admin-tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ── Inline toggle switch ────────────────────────────────────── */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}

.toggle-switch input { display: none; }

.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 11px;
  background: var(--border);
  cursor: pointer;
  transition: background var(--trans-fast);
}

.toggle-switch input:checked + .toggle-track { background: var(--success); }

.toggle-track::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--trans-fast);
}

.toggle-switch input:checked + .toggle-track::after { transform: translateX(16px); }

/* ── KPI row ─────────────────────────────────────────────────── */
.admin-kpi-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

@media (max-width: 1100px) { .admin-kpi-row { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px)  { .admin-kpi-row { grid-template-columns: repeat(2, 1fr); } }

/* ── Mini chart bar ──────────────────────────────────────────── */
.mini-bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 40px;
}

.mini-bar {
  flex: 1;
  background: var(--gold-muted);
  border-radius: 2px 2px 0 0;
  border: 1px solid var(--gold-border);
  min-height: 3px;
  transition: height var(--trans-base);
}

/* ── Toast (admin specific position) ────────────────────────── */
.admin-toast-area {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-sm);
  max-width: 360px;
}

/* ── Drag handle for sort order ──────────────────────────────── */
.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  padding: 0 6px;
  font-size: 1rem;
}

.drag-handle:active { cursor: grabbing; }

/* ── Color picker preview ────────────────────────────────────── */
.icon-preview {
  font-size: 1.6rem;
  min-width: 40px;
  text-align: center;
}

/* ── Price type badge ────────────────────────────────────────── */
.price-type-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: var(--radius-xs);
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.price-type-fixed  { background: rgba(59,130,246,.1);  color: var(--info); }
.price-type-hourly { background: var(--gold-muted);    color: var(--gold); }
.price-type-sqft   { background: rgba(139,92,246,.1);  color: #a78bfa; }
.price-type-quote  { background: var(--border);         color: var(--text-muted); }

/* ── Avatar cell ─────────────────────────────────────────────── */
.user-cell {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.user-cell-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
}

.user-cell-avatar-initials {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--gold-dark), var(--gold));
  color: var(--navy);
  font-weight: 700;
  font-size: .72rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-cell-name  { font-weight: 600; font-size: .88rem; }
.user-cell-email { font-size: .75rem; color: var(--text-muted); }

/* ── Includes list editor ────────────────────────────────────── */
.includes-list { display: flex; flex-direction: column; gap: 6px; }

.include-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 8px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.include-item input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: .88rem;
  color: var(--text-primary);
}

.include-remove {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--error-bg);
  color: var(--error);
  border: none;
  font-size: .8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--trans-fast);
}

.include-remove:hover { background: var(--error); color: #fff; }

/* ── Activity timeline ───────────────────────────────────────── */
.activity-timeline { display: flex; flex-direction: column; gap: 0; }

.timeline-item {
  display: flex;
  gap: var(--space-md);
  padding: 10px 0;
  position: relative;
}

.timeline-item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 30px;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

.timeline-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 3px;
  border: 2px solid var(--bg-card);
}

.timeline-content { flex: 1; min-width: 0; }

.timeline-action {
  font-size: .84rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.timeline-meta  { font-size: .75rem; color: var(--text-muted); margin-top: 2px; }
.timeline-time  { font-size: .72rem; color: var(--text-muted); margin-top: 1px; }

/* ── Settings editor ─────────────────────────────────────────── */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
}

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

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.setting-key {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── Loading skeleton ────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg,
    var(--bg-secondary) 25%, var(--bg-tertiary) 50%, var(--bg-secondary) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

.skeleton-row {
  height: 44px;
  margin-bottom: 1px;
}

/* ── Chart canvas ────────────────────────────────────────────── */
.admin-chart-wrap {
  position: relative;
  height: 220px;
  width: 100%;
}
/* Modal used by core.js */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
  z-index: 2000;
}

/* Custom modal used by admin-management.js */
.amodal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 2100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.amodal-box {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  width: 90%;
  max-width: 580px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg);
}
.amodal-header, .amodal-footer {
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--border);
}
.amodal-footer {
  border-top: 1px solid var(--border);
  border-bottom: none;
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}
.amodal-body {
  padding: var(--space-xl);
  max-height: 70vh;
  overflow-y: auto;
}
.btn-primary { background: var(--gold); color: var(--navy); }
.btn-secondary { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }

/* Form grid */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-lg);
}
@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
}
.form-grid .full {
  grid-column: 1 / -1;
}

/* Chart card */
.chart-card {
  padding: var(--space-xl);
}

/* Admin panel class */
.admin-panel {
  display: block;
}
.admin-panel.hidden {
  display: none;
}