/**
 * Admin UI styles — built on tokens.css.
 *
 * Structure:
 *   1. Layout shell (sidebar + header + main)
 *   2. Sidebar navigation
 *   3. Topbar
 *   4. Content primitives (page header, cards, sections)
 *   5. Buttons (admin variants)
 *   6. Forms (inputs, selects, textarea, checkboxes, JSON editor)
 *   7. Tables (data, with hover + status indicators)
 *   8. Badges, alerts, toasts
 *   9. Dashboard (stats grid, recent leads)
 *  10. Editor (product-edit, page-edit) — toolbar, character counter, slug hint
 *  11. Detail (lead-detail, metadata)
 *  12. Empty states
 *  13. Login page (two-pane brand + form)
 *  14. Tabs (admin/config: brand / settings / db-test / backups)
 *  15. Responsive overrides
 */

@import url("/css/tokens.css");

/* ==========================================================================
   1. Shell
   ========================================================================== */
.admin-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-areas:
    "sidebar header"
    "sidebar main";
  min-height: 100vh;
  background: var(--color-bg);
}

.admin-header {
  grid-area: header;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  position: sticky;
  top: 0;
  z-index: 20;
}

.admin-header-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.admin-header-title h1 {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  margin: 0;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.admin-header-title .breadcrumb {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.admin-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.admin-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-left: var(--space-3);
  border-left: 1px solid var(--color-border);
}
.admin-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: var(--color-text-inverse);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
}
.admin-user-name {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: var(--weight-medium);
}

.admin-main {
  grid-area: main;
  padding: var(--space-8) var(--space-6) var(--space-12);
  overflow-x: hidden;
}
.admin-main .container { max-width: var(--container-max); }

/* ==========================================================================
   2. Sidebar
   ========================================================================== */
.admin-sidebar {
  grid-area: sidebar;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
}
.admin-sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5);
  border-bottom: 1px solid var(--color-border-subtle);
  height: var(--header-height);
  flex: 0 0 auto;
}
.admin-sidebar-brand img {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}
.admin-sidebar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.admin-sidebar-brand-text .title {
  font-weight: var(--weight-semibold);
  font-size: var(--text-base);
  color: var(--color-text);
}
.admin-sidebar-brand-text .sub {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.admin-sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-4) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.admin-sidebar-section {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
  padding: var(--space-4) var(--space-3) var(--space-2);
}
.admin-sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  text-decoration: none;
  transition:
    background var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
  position: relative;
}
.admin-sidebar-link:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
  text-decoration: none;
}
.admin-sidebar-link.is-active {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  box-shadow: var(--shadow-sm);
}
.admin-sidebar-link.is-active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--color-accent);
  border-radius: 0 2px 2px 0;
}
.admin-sidebar-link svg {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  opacity: 0.85;
}
.admin-sidebar-link .count {
  margin-left: auto;
  font-size: var(--text-xs);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--color-bg-subtle);
  color: var(--color-text-secondary);
}
.admin-sidebar-link.is-active .count {
  background: rgba(255, 255, 255, 0.18);
  color: var(--color-text-inverse);
}

.admin-sidebar-footer {
  flex: 0 0 auto;
  padding: var(--space-3);
  border-top: 1px solid var(--color-border-subtle);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.admin-sidebar-user {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  min-width: 0;
}

.admin-sidebar-user__info {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
  flex: 1 1 auto;
  min-width: 0;
}

.admin-sidebar-user__info .username {
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  font-size: var(--text-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
  min-width: 0;
}

.admin-sidebar-user__info .role {
  flex: 0 0 auto;
}

.admin-sidebar-user__logout {
  flex: 0 0 auto;
  margin: 0;
}

.admin-sidebar-user__logout .admin-sidebar-link {
  width: auto;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  gap: var(--space-2);
}

/* Narrow sidebar: stack user info above logout button so both stay usable. */
@media (max-width: 480px) {
  .admin-sidebar-user {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
  }
  .admin-sidebar-user__logout .admin-sidebar-link {
    justify-content: center;
    text-align: center;
  }
}
.admin-sidebar-user__info .role {
  display: inline-block;
  width: max-content;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
}
.admin-sidebar-user__info .role-owner {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #92400e;
}
.admin-sidebar-user__info .role-admin {
  background: var(--color-info-light);
  color: #1e40af;
}
.admin-sidebar-user__info .role-editor {
  background: var(--color-success-light);
  color: #166534;
}
.admin-sidebar-user__info .role-viewer {
  background: var(--color-bg-subtle);
  color: var(--color-text-muted);
}

/* Metrics grid (system info page) */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.metric-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  box-shadow: var(--shadow-xs);
}
.metric-card .label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}
.metric-card .value {
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
}
.metric-card .sub {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.metric-card .bar {
  height: 6px;
  background: var(--color-bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: var(--space-2);
}
.metric-card .bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-primary-light));
  border-radius: var(--radius-full);
  transition: width var(--duration-base) var(--ease-out);
}
.metric-card.warn .bar-fill {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
}
.metric-card.danger .bar-fill {
  background: linear-gradient(90deg, #dc2626, #f87171);
}

/* Timeseries chart (system info) */
.timeseries {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 80px;
  padding: var(--space-3);
  background: var(--color-bg-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.timeseries .bar {
  flex: 1;
  background: linear-gradient(180deg, var(--color-primary), var(--color-primary-light));
  border-radius: 1px;
  min-height: 2px;
  opacity: 0.85;
  transition: opacity var(--duration-fast) var(--ease-out);
}
.timeseries .bar:hover { opacity: 1; }
.timeseries-empty {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
  padding: var(--space-4);
}

/* Badges for entities in users list / audit log */
.role-badge {
  display: inline-block;
  padding: 1px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.role-badge.role-owner { background: #fef3c7; color: #92400e; }
.role-badge.role-admin { background: var(--color-info-light); color: #1e40af; }
.role-badge.role-editor { background: var(--color-success-light); color: #166534; }
.role-badge.role-viewer { background: var(--color-bg-subtle); color: var(--color-text-muted); }
.status-badge {
  display: inline-block;
  padding: 1px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.status-badge.status-active { background: var(--color-success-light); color: #166534; }
.status-badge.status-disabled { background: var(--color-bg-subtle); color: var(--color-text-muted); }

/* Status indicators (audit log action chip) */
.action-chip {
  display: inline-block;
  padding: 1px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  background: var(--color-bg-subtle);
  color: var(--color-text-secondary);
}
.action-chip.action-create { background: var(--color-success-light); color: #166534; }
.action-chip.action-update { background: var(--color-info-light); color: #1e40af; }
.action-chip.action-delete { background: var(--color-danger-light); color: #991b1b; }
.action-chip.action-archive { background: var(--color-warning-light); color: #92400e; }
.action-chip.action-restore { background: var(--color-info-light); color: #1e40af; }
.action-chip.action-login { background: var(--color-success-light); color: #166534; }
.action-chip.action-logout { background: var(--color-bg-subtle); color: var(--color-text-muted); }
.action-chip.action-login_failed { background: var(--color-danger-light); color: #991b1b; }
.action-chip.action-lockout { background: var(--color-danger-light); color: #991b1b; }
.action-chip.action-preview { background: var(--color-info-light); color: #1e40af; }
.action-chip.action-export { background: var(--color-bg-subtle); color: var(--color-text-secondary); }

/* Mobile toggle (only visible < 768px) */
.admin-sidebar-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
}

/* ==========================================================================
   3. Content primitives
   ========================================================================== */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}
.page-header h1 {
  margin: 0;
  font-size: var(--text-3xl);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.015em;
  color: var(--color-text);
}
.page-header .subtitle {
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
  font-size: var(--text-base);
}
.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border-subtle);
}
.card-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  margin: 0;
  color: var(--color-text);
}
.card-body {
  padding: var(--space-6);
}
.card-footer {
  padding: var(--space-4) var(--space-6);
  background: var(--color-bg-subtle);
  border-top: 1px solid var(--color-border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}

.section + .section { margin-top: var(--space-8); }

/* ==========================================================================
   4. Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: 38px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-family: inherit;
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition:
    background var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
  text-decoration: none;
  line-height: 1;
}
.btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}
.btn:active { transform: translateY(1px); }
.btn svg { flex: 0 0 16px; width: 16px; height: 16px; }

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: var(--color-text-inverse);
  border-color: transparent;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { box-shadow: var(--shadow-md); filter: brightness(1.05); }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}
.btn-secondary:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-text-subtle);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--color-bg-subtle);
  color: var(--color-text);
}

.btn-danger {
  background: var(--color-danger);
  color: var(--color-text-inverse);
  border-color: var(--color-danger);
}
.btn-danger:hover { filter: brightness(1.05); }

.btn-sm { height: 30px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.btn-lg { height: 44px; padding: 0 var(--space-5); font-size: var(--text-base); }

.btn-block { width: 100%; }

.btn.is-loading { opacity: 0.7; pointer-events: none; }

.btn-icon {
  width: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   5. Forms
   ========================================================================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-5);
}
.form-grid > .form-group-full { grid-column: 1 / -1; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}
.form-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text);
}
.form-label .required { color: var(--color-danger); margin-left: 2px; }
.form-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
  line-height: 1.5;
}
.form-hint code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  color: var(--color-text-secondary);
}
.form-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
  margin-top: 2px;
  min-height: 0;
}
.form-error:not(:empty) { margin-top: var(--space-1); }

.input,
.select,
.textarea {
  width: 100%;
  padding: 0 var(--space-3);
  height: 38px;
  font-size: var(--text-sm);
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  transition:
    border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out),
    background var(--duration-fast) var(--ease-out);
}
.textarea {
  height: auto;
  min-height: 120px;
  padding: var(--space-3);
  line-height: var(--leading-normal);
  resize: vertical;
}
.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--color-text-subtle);
}
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--color-focus);
  box-shadow: var(--shadow-focus);
}
.input::placeholder,
.textarea::placeholder {
  color: var(--color-text-subtle);
}
.input:disabled,
.select:disabled,
.textarea:disabled {
  background: var(--color-surface-sunken);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.input-with-counter {
  position: relative;
}
.input-with-counter .counter {
  position: absolute;
  right: var(--space-3);
  bottom: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  background: var(--color-surface);
  padding: 0 var(--space-1);
  pointer-events: none;
}
.input-with-counter .counter.is-warning { color: var(--color-warning); }
.input-with-counter .counter.is-danger { color: var(--color-danger); font-weight: var(--weight-semibold); }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8.5L1.5 4h9z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: var(--space-8);
}

.textarea-code {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  background: var(--color-bg-subtle);
  min-height: 180px;
}

/* Checkbox + toggle */
.checkbox {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--space-3);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--color-text);
  user-select: none;
}
.checkbox input { position: absolute; opacity: 0; pointer-events: none; }
.checkbox .checkbox-box {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-xs);
  border: 1.5px solid var(--color-border-strong);
  background: var(--color-surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration-fast) var(--ease-out);
  margin-top: 2px;
}
.checkbox .checkbox-box::after {
  content: '';
  width: 10px;
  height: 10px;
  background: var(--color-primary);
  border-radius: 1px;
  transform: scale(0);
  transition: transform var(--duration-fast) var(--ease-out);
}
.checkbox input:checked + .checkbox-box {
  border-color: var(--color-primary);
  background: var(--color-primary);
}
.checkbox input:checked + .checkbox-box::after {
  background: var(--color-text-inverse);
  transform: scale(1);
}
.checkbox input:focus-visible + .checkbox-box {
  box-shadow: var(--shadow-focus);
}
.checkbox .checkbox-text { line-height: 1.5; }
.checkbox .checkbox-text .hint {
  display: block;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  margin-top: 2px;
}

/* Slug editor */
.slug-input {
  display: flex;
  align-items: center;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  overflow: hidden;
  transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
.slug-input:focus-within {
  border-color: var(--color-focus);
  box-shadow: var(--shadow-focus);
}
.slug-prefix {
  padding: 0 var(--space-3);
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background: var(--color-bg-subtle);
  border-right: 1px solid var(--color-border);
  height: 36px;
  display: inline-flex;
  align-items: center;
}
.slug-input input {
  flex: 1 1 auto;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 0 var(--space-3);
  height: 36px;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-text);
  min-width: 0;
}

/* ==========================================================================
   6. Tables
   ========================================================================== */
.data-table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.data-table th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  background: var(--color-bg-subtle);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.data-table td {
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border-subtle);
  color: var(--color-text);
  vertical-align: middle;
}
.data-table tbody tr {
  transition: background var(--duration-fast) var(--ease-out);
}
.data-table tbody tr:hover { background: var(--color-surface-hover); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table td a { color: var(--color-text); font-weight: var(--weight-medium); }
.data-table td a:hover { color: var(--color-primary); text-decoration: underline; }
.data-table .col-actions { text-align: right; white-space: nowrap; }
.data-table .col-narrow { width: 1%; white-space: nowrap; }
.data-table-empty {
  padding: var(--space-12) var(--space-6);
  text-align: center;
  color: var(--color-text-muted);
}

/* ==========================================================================
   7. Badges + alerts
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  background: var(--color-bg-subtle);
  color: var(--color-text-secondary);
  white-space: nowrap;
  line-height: 1.4;
}
.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.65;
  flex: 0 0 6px;
}
.badge-pending { background: var(--color-warning-light); color: #92400e; }
.badge-contacted { background: var(--color-info-light); color: #1e40af; }
.badge-won { background: var(--color-success-light); color: #166534; }
.badge-lost { background: var(--color-danger-light); color: #991b1b; }
.badge-new {
  background: var(--color-warning);
  color: var(--color-text-inverse);
  margin-left: var(--space-2);
  padding: 1px 7px;
}
.badge-new::before { display: none; }
.badge-published { background: var(--color-success-light); color: #166534; }
.badge-draft { background: var(--color-bg-subtle); color: var(--color-text-muted); }

.alert {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid;
  font-size: var(--text-sm);
  align-items: flex-start;
  line-height: 1.5;
}
.alert-icon {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  margin-top: 1px;
}
.alert-body { flex: 1 1 auto; min-width: 0; }
.alert-body strong { display: block; font-weight: var(--weight-semibold); }
.alert-body p { margin: 2px 0 0; }

.alert-success { background: var(--color-success-light); border-color: #bbf7d0; color: #166534; }
.alert-success .alert-icon { background: var(--color-success); color: var(--color-text-inverse); }
.alert-error   { background: var(--color-danger-light);  border-color: #fecaca; color: #991b1b; }
.alert-error .alert-icon   { background: var(--color-danger);  color: var(--color-text-inverse); }
.alert-warning { background: var(--color-warning-light); border-color: #fde68a; color: #92400e; }
.alert-warning .alert-icon { background: var(--color-warning); color: var(--color-text-inverse); }
.alert-info    { background: var(--color-info-light);    border-color: #bfdbfe; color: #1e40af; }
.alert-info .alert-icon    { background: var(--color-info);    color: var(--color-text-inverse); }

/* Toast — for save confirmation etc. */
.toast {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  z-index: 100;
  background: var(--color-text);
  color: var(--color-text-inverse);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  opacity: 0;
  transform: translateY(-8px);
  animation: toast-in var(--duration-slow) var(--ease-out) forwards;
}
@keyframes toast-in {
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   8. Dashboard
   ========================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--duration-base) var(--ease-out), transform var(--duration-base) var(--ease-out);
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--stat-accent, var(--color-primary));
}
.stat-card.is-warning { --stat-accent: var(--color-warning); }
.stat-card.is-info    { --stat-accent: var(--color-info); }
.stat-card.is-success { --stat-accent: var(--color-success); }
.stat-card.is-accent  { --stat-accent: var(--color-accent); }

.stat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.stat-head .icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-subtle);
  color: var(--stat-accent, var(--color-primary));
  font-size: 14px;
}
.stat-value {
  font-size: var(--text-4xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.025em;
  color: var(--color-text);
  line-height: 1;
}
.stat-trend {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.stat-trend .delta {
  font-weight: var(--weight-semibold);
  color: var(--color-success);
}
.stat-trend .delta.is-down { color: var(--color-danger); }

.empty-state {
  padding: var(--space-12) var(--space-6);
  text-align: center;
  background: var(--color-surface);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  color: var(--color-text-muted);
}
.empty-state .icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--color-bg-subtle);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: var(--space-3);
}
.empty-state h3 {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  margin: 0 0 var(--space-1);
  color: var(--color-text);
}
.empty-state p { margin: 0 0 var(--space-4); }

/* ==========================================================================
   9. Editor — product / page edit
   ========================================================================== */
.editor-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: var(--space-6);
  align-items: start;
}
@media (max-width: 1024px) { .editor-shell { grid-template-columns: 1fr; } }

.editor-main {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.editor-aside {
  position: sticky;
  top: calc(var(--header-height) + var(--space-4));
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.editor-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.editor-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border-subtle);
  background: var(--color-bg-subtle);
}
.editor-section-header h2 {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  margin: 0;
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.editor-section-header h2 .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
}
.editor-section-body {
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.json-editor {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.json-editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
}
.json-editor-toolbar .label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-family: var(--font-mono);
}
.json-validation {
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.json-validation.is-valid { color: var(--color-success); }
.json-validation.is-invalid { color: var(--color-danger); font-weight: var(--weight-medium); }
.json-validation .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

/* Sticky save bar */
.editor-actions {
  position: sticky;
  bottom: var(--space-4);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.editor-actions .status {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.editor-actions .status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success);
}

/* ==========================================================================
   10. Detail / metadata
   ========================================================================== */
.detail-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--space-6);
}
.detail-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border-subtle);
}
.detail-card-title {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.detail-card-title h2 {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  margin: 0;
  color: var(--color-text);
}
.detail-card-title .meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
.detail-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: var(--space-4) var(--space-6);
  padding: var(--space-5) var(--space-6);
}
.detail-label {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}
.detail-value {
  font-size: var(--text-sm);
  color: var(--color-text);
  word-break: break-word;
}

.message-body {
  background: var(--color-bg-subtle);
  padding: var(--space-5);
  border-radius: var(--radius-md);
  white-space: pre-wrap;
  line-height: 1.7;
  font-size: var(--text-sm);
  color: var(--color-text);
  border-left: 3px solid var(--color-primary);
}

.metadata-toggle {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  width: 100%;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  transition: background var(--duration-fast) var(--ease-out);
}
.metadata-toggle:hover { background: var(--color-surface-hover); }
.metadata-toggle[open] { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.metadata-toggle summary { list-style: none; cursor: pointer; flex: 1; }
.metadata-toggle summary::-webkit-details-marker { display: none; }
.metadata-toggle .chevron {
  margin-left: auto;
  transition: transform var(--duration-fast) var(--ease-out);
}
.metadata-toggle[open] .chevron { transform: rotate(180deg); }
.metadata-toggle + .metadata-body {
  border: 1px solid var(--color-border);
  border-top: 0;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  padding: var(--space-4);
  background: var(--color-surface);
  font-size: var(--text-sm);
  font-family: var(--font-mono);
  color: var(--color-text-secondary);
}
.metadata-toggle + .metadata-body dl { margin: 0; display: grid; grid-template-columns: 140px 1fr; gap: var(--space-2) var(--space-4); }
.metadata-toggle + .metadata-body dt { color: var(--color-text-muted); }

/* Filters bar */
.filters-bar {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}
.filters-bar .search {
  flex: 1 1 280px;
  position: relative;
}
.filters-bar .search svg {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--color-text-subtle);
}
.filters-bar .search input {
  width: 100%;
  height: 38px;
  padding: 0 var(--space-3) 0 36px;
  font-size: var(--text-sm);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-family: inherit;
  color: var(--color-text);
  transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
.filters-bar .search input:focus {
  outline: none;
  border-color: var(--color-focus);
  box-shadow: var(--shadow-focus);
}
.filters-bar .select-wrap { min-width: 140px; }
.filters-bar select {
  width: 100%;
  height: 38px;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--color-bg-subtle);
  border-top: 1px solid var(--color-border-subtle);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}
.pagination .pages {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Legacy helpers kept for backward compatibility */
.text-muted { color: var(--color-text-muted); font-weight: inherit; font-size: inherit; }
.inline-form { display: inline; margin: 0; }
.btn-link {
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: underline;
}

/* ==========================================================================
   11. Login (two-pane)
   ========================================================================== */
.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
  background: var(--color-bg);
}
.login-aside {
  display: none;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.08), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(168, 197, 194, 0.18), transparent 45%),
    linear-gradient(135deg, #1a3a5f 0%, #2d5d5b 55%, #3a7d7b 100%);
  color: #fff;
}
.login-aside-inner {
  position: relative;
  z-index: 1;
  height: 100%;
  padding: var(--space-16) var(--space-12);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--space-8);
  max-width: 520px;
  margin: 0 auto;
}
.login-aside::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at 50% 50%, black 30%, transparent 80%);
  -webkit-mask-image: radial-gradient(circle at 50% 50%, black 30%, transparent 80%);
}
.brand-mark { display: flex; align-items: center; gap: var(--space-4); }
.brand-name { font-size: var(--text-xl); font-weight: var(--weight-bold); letter-spacing: 0.05em; }
.quote-text {
  font-size: clamp(1.5rem, 2.5vw, 2rem);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  margin: 0 0 var(--space-2);
  letter-spacing: 0.01em;
}
.quote-text::before { content: '“'; margin-right: 0.1em; opacity: 0.6; }
.quote-text::after  { content: '”'; margin-left: 0.1em; opacity: 0.6; }
.quote-meta {
  margin: 0;
  font-size: var(--text-sm);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.7;
}
.aside-features { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--space-4); }
.aside-features li { display: flex; align-items: center; gap: var(--space-3); font-size: var(--text-base); opacity: 0.92; }
.aside-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-md);
}
.aside-footer { margin: 0; font-size: var(--text-xs); letter-spacing: 0.05em; opacity: 0.55; }

.login-main {
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-12) var(--space-4);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-12);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--color-border);
}
.login-header { margin-bottom: var(--space-8); }
.login-header h1 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  color: var(--color-text);
  letter-spacing: -0.02em;
}
.login-subtitle { margin: 0; color: var(--color-text-muted); font-size: var(--text-base); }

.login-form { display: flex; flex-direction: column; gap: var(--space-5); }
.login-form .form-label { font-weight: var(--weight-semibold); font-size: var(--text-sm); color: var(--color-text); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-icon {
  position: absolute; left: 14px;
  color: var(--color-text-muted);
  pointer-events: none;
  transition: color var(--duration-fast) var(--ease-out);
}
.login-form .input {
  padding-left: 42px;
}
.login-form .input:focus ~ .input-icon,
.login-form .input-wrap:focus-within .input-icon {
  color: var(--color-primary);
}
.login-submit {
  height: 48px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
  border: none;
  color: #fff;
  margin-top: var(--space-2);
  box-shadow: 0 6px 16px rgba(30, 58, 95, 0.2);
}
.login-submit:hover {
  filter: brightness(1.06);
  box-shadow: 0 8px 22px rgba(30, 58, 95, 0.28);
  transform: translateY(-1px);
}
.login-submit:active { transform: translateY(0); }
.login-submit:focus-visible { outline: none; box-shadow: var(--shadow-focus), 0 6px 16px rgba(30, 58, 95, 0.2); }

.login-footer { text-align: center; margin: var(--space-8) 0 0; font-size: var(--text-sm); }
.login-footer a {
  display: inline-flex; align-items: center; gap: var(--space-2);
  color: var(--color-text-muted);
  text-decoration: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  transition: color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out);
}
.login-footer a:hover { color: var(--color-primary); background: var(--color-bg-subtle); }

@media (min-width: 960px) {
  .login-shell { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
  .login-aside { display: block; }
  .login-main { padding: var(--space-16) var(--space-12); }
  .login-card { padding: var(--space-16); max-width: 460px; }
}
@media (max-width: 480px) {
  .login-card { padding: var(--space-6); box-shadow: var(--shadow-md); }
  .login-header h1 { font-size: var(--text-2xl); }
}

/* ==========================================================================
   12. Tabs
   ========================================================================== */

/**
 * Tabs used by `/admin/config`. Each tab is a `<button role="tab">`
 * inside an element with `[role="tablist"]`. The corresponding panel
 * is a sibling with `role="tabpanel"` and a unique `id`. The JS in
 * `src/public/js/admin.ts` toggles `is-active` + `hidden` + ARIA
 * attributes on click; this stylesheet only paints the result.
 *
 * Active-state visual cue: a 2-px accent underline + bold text. The
 * underline is animated by a `::after` element with a CSS
 * `transform: scaleX` transition so the indicator slides between
 * tabs when the user clicks (or the JS calls `.activate(tabId)`).
 *
 * Mobile: the tab bar becomes a horizontally-scrollable row with
 * each button auto-sizing to its label — no overflow ellipsis, no
 * clipped text. The active border moves to the bottom edge.
 */
.admin-tabs {
  position: relative;
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: var(--space-1);
  margin: 0 0 var(--space-5);
  padding: 0;
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.admin-tabs::-webkit-scrollbar { height: 4px; }
.admin-tabs::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-pill);
}

.admin-tab {
  /* Reset native button styles so the tab reads as a label, not a button. */
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 0;
  margin: 0;
  padding: var(--space-3) var(--space-4);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px; /* overlap the tab-bar border when active */
  transition: color var(--duration-fast, 120ms) var(--ease-out),
              border-color var(--duration-fast, 120ms) var(--ease-out),
              background var(--duration-fast, 120ms) var(--ease-out);
  position: relative;
  border-radius: 0;
}
.admin-tab:hover {
  color: var(--color-text);
  background: var(--color-bg-subtle);
}
.admin-tab:focus-visible {
  outline: 2px solid var(--color-accent, var(--color-primary));
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}
.admin-tab.is-active {
  color: var(--color-accent, var(--color-primary-dark));
  font-weight: var(--weight-semibold);
  border-bottom-color: var(--color-accent, var(--color-primary));
}
.admin-tab__icon {
  display: inline-flex;
  align-items: center;
  font-size: 14px;
  line-height: 1;
}
.admin-tab__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: var(--weight-semibold);
  background: var(--color-bg-subtle);
  color: var(--color-text-muted);
  border-radius: var(--radius-pill);
  margin-left: var(--space-1);
}
.admin-tab.is-active .admin-tab__count {
  background: var(--color-accent-light, var(--color-primary-light, #dbeafe));
  color: var(--color-accent, var(--color-primary-dark));
}

/* The animated underline. We use a `::after` instead of
   `border-bottom-color` transition because the latter doesn't
   transition (it snaps between two discrete colors). The
   `transform-origin: left` + `transform: scaleX(0→1)` gives a
   "slide" effect when the JS swaps `is-active` between tabs. */
.admin-tab::after {
  content: "";
  position: absolute;
  left: var(--space-3);
  right: var(--space-3);
  bottom: -1px;
  height: 2px;
  background: var(--color-accent, var(--color-primary));
  border-radius: 2px;
  transform: scaleX(0);
  transform-origin: center;
  transition: transform var(--duration-base, 200ms) var(--ease-out);
}
.admin-tab.is-active::after { transform: scaleX(1); }

/* Tab panels. Only the active panel is shown; we toggle the
   native `hidden` attribute (for screen readers + no-JS) and the
   JS adds `admin-tab-panel--shown` to retrigger the entrance
   animation on every switch. */
.admin-tab-panel[hidden] { display: none; }
.admin-tab-panel.admin-tab-panel--shown {
  animation: admin-tab-panel-in 220ms var(--ease-out) both;
}
@keyframes admin-tab-panel-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Subtle card wrapper for each tab so the active content feels
   distinct. The brand tab uses its own wrapper; settings tab and
   backups tab reuse this for visual consistency. */
.admin-tab-panel > .data-section {
  margin-bottom: var(--space-6);
}
.admin-tab-panel > .data-section:last-child {
  margin-bottom: 0;
}

/* Mobile: shrink tab padding so 4 tabs fit on a 360px viewport
   without horizontal scroll, and the icon+label stays readable. */
@media (max-width: 768px) {
  .admin-tab {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
  }
  .admin-tab__icon { font-size: 13px; }
}
@media (max-width: 480px) {
  .admin-tabs {
    margin-left: calc(-1 * var(--space-4, 16px));
    margin-right: calc(-1 * var(--space-4, 16px));
    padding-left: var(--space-4, 16px);
    padding-right: var(--space-4, 16px);
  }
  .admin-tab { padding: var(--space-2) var(--space-2); }
}

/* Respect users who prefer reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .admin-tab::after,
  .admin-tab,
  .admin-tab-panel { transition: none; animation: none; }
}

/* ==========================================================================
   12. Responsive
   ========================================================================== */
@media (max-width: 1024px) {
  .admin-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "main";
  }
  .admin-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform var(--duration-base) var(--ease-out);
    box-shadow: var(--shadow-xl);
  }
  .admin-sidebar.is-open { transform: translateX(0); }
  .admin-sidebar-toggle { display: inline-flex; }
  .admin-sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 29;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-base) var(--ease-out);
  }
  .admin-sidebar-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
  }
  .stat-value { font-size: var(--text-3xl); }
}

@media (max-width: 768px) {
  .admin-header { padding: 0 var(--space-4); }
  .admin-main { padding: var(--space-5) var(--space-4) var(--space-10); }
  .admin-user-name { display: none; }
  .page-header { flex-direction: column; align-items: stretch; }
  .filters-bar { flex-direction: column; }
  .filters-bar .search { flex: 1 1 auto; }
}

/* ==========================================================================
   13. AI Fill Panel
   ========================================================================== */

.ai-fill-panel {
  margin-bottom: var(--space-6);
  padding: var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius-lg);
}

.ai-fill-header h3 {
  margin: 0 0 var(--space-1);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
}

.ai-fill-header p {
  margin: 0 0 var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
}

.ai-fill-panel .textarea {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: var(--space-3);
}

.ai-fill-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.ai-fill-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.ai-fill-hint.is-error {
  color: var(--color-danger);
}

.ai-fill-hint.is-success {
  color: var(--color-success);
}

.ai-fill-fields-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* ---- AI Progress ---- */

.ai-progress {
  margin-top: var(--space-4);
  padding: var(--space-4);
  background: var(--color-bg-subtle);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-subtle);
}

.ai-progress-bar-track {
  height: 6px;
  background: var(--color-border-subtle);
  border-radius: 3px;
  overflow: hidden;
}

.ai-progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--color-accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.ai-progress-bar-fill.is-error {
  background: var(--color-danger);
}

.ai-progress-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  flex-wrap: wrap;
}

.ai-step {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  transition: color 0.3s ease;
}

.ai-step.is-active {
  color: var(--color-accent);
  font-weight: 600;
}

.ai-step.is-done {
  color: var(--color-success);
}

.ai-step-icon {
  font-size: var(--text-sm);
  line-height: 1;
  min-width: 1em;
  text-align: center;
}

.ai-step-arrow {
  color: var(--color-border);
  font-size: var(--text-xs);
}

.ai-progress-message {
  margin-top: var(--space-3);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  min-height: 1.4em;
  transition: color 0.3s ease;
}

.ai-progress-message.is-success {
  color: var(--color-success);
  font-weight: 500;
}

.ai-progress-message.is-error {
  color: var(--color-danger);
  font-weight: 500;
}

@media (prefers-reduced-motion: reduce) {
  .ai-progress-bar-fill,
  .ai-step,
  .ai-progress-message {
    transition: none;
  }
}