/* ============================================================
   ProVision Voice AI — Configuration Page Styles
   Designed to work inside a GHL iframe.
   No framework dependencies — vanilla CSS.
   ============================================================ */

:root {
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #eff6ff;
  --color-secondary: #059669;
  --color-secondary-hover: #047857;
  --color-danger: #dc2626;
  --color-warning: #f59e0b;
  --color-text: #1f2937;
  --color-text-light: #6b7280;
  --color-border: #e5e7eb;
  --color-bg: #f9fafb;
  --color-white: #ffffff;
  --color-success-bg: #ecfdf5;
  --color-error-bg: #fef2f2;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
  --transition: 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  padding-bottom: 80px; /* space for sticky action bar */
}

/* ---- Header ---- */
.app-header {
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 900px;
  margin: 0 auto;
}

.header-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--color-text);
}

/* ---- Status Badge ---- */
.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--color-text-light);
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--color-bg);
}

.status-badge.status-updating {
  background: #fef3c7;
  color: #92400e;
}

.status-badge.status-complete {
  background: var(--color-success-bg);
  color: #065f46;
}

.status-badge.status-error {
  background: var(--color-error-bg);
  color: var(--color-danger);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-light);
}

.status-badge.status-updating .status-dot { background: var(--color-warning); }
.status-badge.status-complete .status-dot { background: var(--color-secondary); }
.status-badge.status-error .status-dot { background: var(--color-danger); }

/* ---- Main Content ---- */
.app-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px;
}

/* ---- Loading Overlay ---- */
.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 0;
  color: var(--color-text-light);
  gap: 16px;
}

.loading-overlay.hidden { display: none; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- Error Banner ---- */
.error-banner {
  background: var(--color-error-bg);
  border: 1px solid #fecaca;
  color: var(--color-danger);
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.error-banner.hidden { display: none; }

.error-dismiss {
  background: none;
  border: none;
  color: var(--color-danger);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}

/* ---- Config Sections (Accordion) ---- */
.config-section {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.section-header:hover {
  background: var(--color-bg);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-icon {
  font-size: 18px;
}

.section-title h2 {
  font-size: 15px;
  font-weight: 600;
}

.section-header .chevron {
  font-size: 12px;
  color: var(--color-text-light);
  transition: transform var(--transition);
}

.section-header .chevron.collapsed {
  transform: rotate(-90deg);
}

/* Master Toggle in Section Header */
.section-header .master-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  margin-right: 12px;
}

.section-body {
  padding: 0 20px 20px;
  display: none;
}

.section-body.expanded {
  display: block;
}

/* ---- Categories Heading ---- */
.categories-heading {
  font-size: 16px;
  font-weight: 600;
  margin-top: 28px;
  margin-bottom: 4px;
}

.categories-subheading {
  font-size: 13px;
  color: var(--color-text-light);
  margin-bottom: 16px;
}

/* ---- Toggle Switch ---- */
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 24px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--color-white);
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: var(--shadow-sm);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--color-primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.toggle-switch input:disabled + .toggle-slider {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---- Checkbox Tree ---- */
.product-tree {
  padding-left: 0;
  list-style: none;
}

.product-tree .product-item {
  padding: 6px 0;
}

.product-tree .product-item label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
}

.product-tree .product-item label:hover {
  color: var(--color-primary);
}

.product-tree .product-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
  cursor: pointer;
  flex-shrink: 0;
}

.product-tree .product-item input[type="checkbox"]:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.product-children {
  padding-left: 28px;
  list-style: none;
}

.securities-badge {
  font-size: 10px;
  background: #fef3c7;
  color: #92400e;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 500;
  white-space: nowrap;
}

/* ---- Field Groups (Company Info) ---- */
.field-group {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}

.field-group legend {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-light);
  padding: 0 6px;
}

.field-row {
  display: flex;
  gap: 16px;
  margin-top: 12px;
}

.field {
  flex: 1;
}

.field.full-width {
  flex: 1 1 100%;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--color-text);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-white);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.field textarea {
  resize: vertical;
  min-height: 60px;
}

/* ---- Sticky Action Bar ---- */
.action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-white);
  border-top: 1px solid var(--color-border);
  padding: 12px 24px;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
  z-index: 100;
}

.action-bar-content {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.action-left {
  flex: 1;
}

.action-buttons {
  display: flex;
  gap: 10px;
}

/* ---- Buttons ---- */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-white);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  box-shadow: var(--shadow);
}

.btn-secondary {
  background: var(--color-secondary);
  color: var(--color-white);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-secondary-hover);
  box-shadow: var(--shadow);
}

/* ---- Update Status Indicator ---- */
.update-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--color-text-light);
}

.update-status.hidden { display: none; }

.mini-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text);
  color: var(--color-white);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  transition: opacity 0.3s ease;
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
}

.toast.toast-success { background: #065f46; }
.toast.toast-error { background: var(--color-danger); }

/* ---- Utility ---- */
.hidden { display: none !important; }

/* ---- Target Subaccount ---- */
.section-header-static {
  cursor: default;
}

.field-action {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.subaccount-status {
  margin-top: 8px;
  padding: 6px 10px;
  background: #e8f5e9;
  color: #2e7d32;
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: monospace;
}

/* ---- Responsive (within iframe) ---- */
@media (max-width: 600px) {
  .app-main { padding: 16px; }
  .field-row { flex-direction: column; gap: 0; }
  .action-buttons { flex-direction: column; gap: 6px; }
  .btn { width: 100%; text-align: center; }
  .header-content { flex-direction: column; gap: 8px; align-items: flex-start; }
}
