/* ReportGenAI — App workspace (Material 3 + HIG inspired) */

.app-body {
  display: flex;
  min-height: 100vh;
  background: var(--ai-mesh, #030014);
  background-attachment: fixed;
}

/* ── Sidebar (Jakob's Law: familiar nav pattern) ── */
.app-sidebar {
  width: 272px;
  flex-shrink: 0;
  background: #0f1219;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 50;
  transition: width 0.25s ease, padding 0.25s ease;
}

.app-sidebar.collapsed {
  width: 72px;
  padding: 0.75rem 0.5rem;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.app-sidebar.collapsed .sidebar-top {
  flex-direction: column;
}

.sidebar-toggle {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: #94a3b8;
  cursor: pointer;
  font-size: 0.75rem;
  display: grid;
  place-items: center;
  transition: all 0.2s;
}

.sidebar-toggle:hover {
  background: rgba(99, 102, 241, 0.15);
  color: #fff;
  border-color: rgba(99, 102, 241, 0.4);
}

.app-sidebar.collapsed .sidebar-toggle {
  transform: rotate(180deg);
}

.app-sidebar.collapsed .sidebar-logo-text,
.app-sidebar.collapsed .nav-label,
.app-sidebar.collapsed .user-info {
  display: none;
}

.app-sidebar.collapsed .sidebar-logo {
  justify-content: center;
  padding: 0.5rem;
}

.app-sidebar.collapsed .sidebar-nav a {
  justify-content: center;
  padding: 0.875rem;
}

.app-sidebar.collapsed .user-chip {
  justify-content: center;
  padding: 0.5rem;
}

.app-sidebar.collapsed .sidebar-footer .btn {
  font-size: 0;
  min-height: 44px;
}

.app-sidebar.collapsed .sidebar-footer .btn::after {
  content: '⎋';
  font-size: 1rem;
}

body.sidebar-collapsed .app-main {
  margin-left: 72px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  font-size: 1.0625rem;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  border-radius: 12px;
  transition: background 0.2s;
}

.sidebar-logo:hover { background: rgba(255, 255, 255, 0.04); }

.sidebar-nav { flex: 1; padding: 0.5rem 0; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1rem;
  min-height: 48px;
  border-radius: 12px;
  color: #94a3b8;
  font-size: 0.9375rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  transition: all 0.2s;
}

.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #e2e8f0;
}

.sidebar-nav a.active {
  background: rgba(99, 102, 241, 0.18);
  color: #fff;
  font-weight: 600;
}

.nav-icon {
  width: 22px;
  text-align: center;
  font-size: 1.125rem;
  opacity: 0.9;
}

.sidebar-footer {
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  margin-bottom: 0.75rem;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.9375rem;
  color: #fff;
  flex-shrink: 0;
}

.user-name { font-size: 0.875rem; font-weight: 600; color: #f1f5f9; }
.user-email { font-size: 0.75rem; color: #64748b; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }

/* ── Main area ── */
.app-main {
  flex: 1;
  margin-left: 272px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.25s ease;
}

.app-header {
  padding: 1.5rem 2rem 0;
  flex-shrink: 0;
}

.app-header h1 {
  margin: 0;
  font-size: 1.625rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #f8fafc;
}

.app-header p {
  margin: 0.375rem 0 0;
  color: #64748b;
  font-size: 0.9375rem;
}

/* Step progress (Recognition over Recall) */
.workflow-steps {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 1.25rem 2rem;
  flex-shrink: 0;
  overflow-x: auto;
}

.step {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-shrink: 0;
}

.step-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8125rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.06);
  color: #64748b;
  border: 2px solid rgba(255, 255, 255, 0.08);
  transition: all 0.3s;
}

.step.active .step-num {
  background: #6366f1;
  color: #fff;
  border-color: #6366f1;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.25);
}

.step.done .step-num {
  background: #10b981;
  color: #fff;
  border-color: #10b981;
}

.step-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #64748b;
}

.step.active .step-label { color: #e2e8f0; }
.step.done .step-label { color: #94a3b8; }

.step-connector {
  width: 48px;
  height: 2px;
  background: rgba(255, 255, 255, 0.08);
  margin: 0 0.75rem;
  flex-shrink: 0;
}

.step-connector.done { background: #10b981; }

/* Split layout (Law of Proximity) */
.workspace-split {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 0;
  flex: 1;
  min-height: 0;
  padding: 0 2rem 2rem;
}

.config-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-right: 1.25rem;
  overflow-y: auto;
  max-height: calc(100vh - 180px);
}

.canvas-column {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 180px);
  background: #f1f5f9;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.canvas-column.canvas-dark {
  background: #0a0d14;
  border-color: rgba(255, 255, 255, 0.06);
}

.canvas-column.canvas-dark .canvas-header {
  background: #0f1219;
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.canvas-column.canvas-dark .canvas-header h2 { color: #e2e8f0; }

.canvas-column.canvas-dark .canvas-body {
  background: #0a0d14;
}

.canvas-column.is-fullscreen {
  border-radius: 0;
  min-height: 100vh;
}

.canvas-column:fullscreen,
.canvas-column:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
  background: #f1f5f9;
}

.workspace-split.focus-mode {
  grid-template-columns: 1fr;
}

.workspace-split.focus-mode .config-column {
  display: none;
}

.workspace-split.focus-mode .canvas-column {
  min-height: calc(100vh - 140px);
}

.canvas-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.canvas-header h2 {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  color: #334155;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.canvas-status {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  background: #f1f5f9;
  color: #64748b;
}

.canvas-status.ready { background: #ecfdf5; color: #059669; }
.canvas-status.loading { background: #eef2ff; color: #6366f1; }

.canvas-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

#exportPdf {
  min-height: 36px;
  font-weight: 700;
}

.canvas-body {
  flex: 1;
  overflow-y: auto;
  background: #f1f5f9;
}

/* Panels in config column */
.panel {
  background: #141820;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 14px;
  padding: 1.25rem;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  margin: 0 0 1rem;
}

.panel-title-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(99, 102, 241, 0.15);
  display: grid;
  place-items: center;
  font-size: 0.875rem;
}

/* Upload zone (Fitts's Law: large target) */
.upload-zone {
  border: 2px dashed rgba(99, 102, 241, 0.35);
  border-radius: 14px;
  padding: 1.75rem 1.25rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s;
  background: rgba(99, 102, 241, 0.04);
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.upload-zone:hover,
.upload-zone.dragover,
.upload-zone.has-file {
  border-color: #6366f1;
  background: rgba(99, 102, 241, 0.1);
}

.upload-zone.has-file {
  border-style: solid;
}

.upload-zone input { display: none; }

.upload-icon-wrap {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: rgba(99, 102, 241, 0.15);
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
}

.upload-zone p {
  margin: 0;
  color: #cbd5e1;
  font-size: 0.875rem;
  font-weight: 500;
}

.upload-zone .hint {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 0.375rem;
}

.upload-success {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: rgba(16, 185, 129, 0.12);
  border-radius: 8px;
  font-size: 0.8125rem;
  color: #6ee7b7;
  font-weight: 600;
}

.upload-success.hidden { display: none; }

/* Data preview table */
.data-preview-wrap {
  margin-top: 1rem;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.data-preview-header {
  padding: 0.5rem 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
}

.data-preview {
  overflow-x: auto;
  max-height: 160px;
  font-size: 0.75rem;
}

.data-preview table {
  width: 100%;
  border-collapse: collapse;
  min-width: 500px;
}

.data-preview th {
  position: sticky;
  top: 0;
  padding: 0.5rem 0.625rem;
  background: #1a1f2e;
  color: #94a3b8;
  font-weight: 600;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  white-space: nowrap;
}

.data-preview td {
  padding: 0.4375rem 0.625rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: #cbd5e1;
  white-space: nowrap;
}

.data-preview tr:hover td { background: rgba(255, 255, 255, 0.02); }

/* Forms */
.form-group { margin-bottom: 1rem; }

.form-group:last-child { margin-bottom: 0; }

.form-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #94a3b8;
  margin-bottom: 0.4375rem;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.75rem 0.875rem;
  min-height: 44px;
  background: #0a0d14;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: #f1f5f9;
  font-size: 0.9375rem;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.form-textarea {
  min-height: 88px;
  resize: vertical;
}

/* Engine selector (Hick's Law: 2 clear choices) */
.engine-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.engine-tab {
  padding: 0.875rem 0.75rem;
  min-height: 56px;
  background: #0a0d14;
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  color: #94a3b8;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  font-family: inherit;
}

.engine-tab:hover { border-color: rgba(99, 102, 241, 0.4); color: #e2e8f0; }

.engine-tab.active {
  background: rgba(99, 102, 241, 0.12);
  border-color: #6366f1;
  color: #fff;
}

.engine-tab .badge {
  display: block;
  font-size: 0.625rem;
  font-weight: 700;
  color: #10b981;
  margin-top: 0.25rem;
  letter-spacing: 0.03em;
}

.engine-tab[data-engine="ai"] .badge { color: #a5b4fc; }

/* Primary CTA (Fitts's Law) */
#generateBtn {
  min-height: 52px;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 12px;
  letter-spacing: 0.01em;
}

#generateBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.generate-hint {
  text-align: center;
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 0.75rem;
  line-height: 1.5;
}

/* Empty state (Aesthetic-Usability + high contrast) */
.dashboard-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 480px;
  padding: 3rem 2rem;
  text-align: center;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
}

.dashboard-empty-icon {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  background: linear-gradient(135deg, #eef2ff, #e0e7ff);
  display: grid;
  place-items: center;
  font-size: 2.25rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 8px 32px rgba(99, 102, 241, 0.15);
}

.dashboard-empty h3 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: #1e293b;
}

.dashboard-empty p {
  margin: 0;
  font-size: 0.9375rem;
  color: #64748b;
  max-width: 360px;
  line-height: 1.6;
}

.dashboard-empty-steps {
  display: flex;
  gap: 1.5rem;
  margin-top: 2rem;
  flex-wrap: wrap;
  justify-content: center;
}

.dashboard-empty-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  max-width: 120px;
}

.dashboard-empty-step span:first-child {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #e2e8f0;
  display: grid;
  place-items: center;
  font-size: 0.875rem;
  font-weight: 700;
  color: #6366f1;
}

.dashboard-empty-step span:last-child {
  font-size: 0.75rem;
  color: #64748b;
  font-weight: 500;
}

.btn-empty-cta {
  margin-top: 1.5rem;
  min-height: 44px;
  padding: 0 1.5rem;
}

.report-output {
  min-height: 0;
  padding: 0;
  background: transparent;
  border: none;
  white-space: normal;
}

.report-output.has-dashboard { display: block; }

/* Buttons */
.btn-sm {
  min-height: 36px;
  padding: 0.5rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 600;
}

.btn-ghost {
  min-height: 36px;
}

/* Reports list */
.reports-list { display: flex; flex-direction: column; gap: 0.75rem; }

.report-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  min-height: 64px;
  background: #141820;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.report-item:hover {
  border-color: rgba(99, 102, 241, 0.4);
  background: rgba(99, 102, 241, 0.06);
}

.report-item-title { font-weight: 600; font-size: 0.9375rem; color: #f1f5f9; }
.report-item-meta { font-size: 0.75rem; color: #64748b; margin-top: 0.25rem; }

.status-badge {
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.3125rem 0.625rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-badge.completed { background: rgba(16, 185, 129, 0.15); color: #6ee7b7; }

/* Auth */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 15, 0.94);
  backdrop-filter: blur(16px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-overlay.hidden { display: none; }

.auth-modal {
  width: 100%;
  max-width: 420px;
  background: #141820;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 2.5rem;
  box-shadow: 0 32px 64px rgba(0, 0, 0, 0.5);
}

.auth-modal h2 { margin: 0 0 0.5rem; font-size: 1.5rem; color: #f8fafc; }
.auth-modal .subtitle { color: #64748b; margin: 0 0 1.5rem; font-size: 0.9375rem; }

.auth-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }

.auth-tab {
  flex: 1;
  min-height: 44px;
  padding: 0.625rem;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: #94a3b8;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.auth-tab.active {
  background: rgba(99, 102, 241, 0.15);
  border-color: #6366f1;
  color: #fff;
}

.alert {
  padding: 0.875rem 1rem;
  border-radius: 10px;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.alert-error { background: rgba(239, 68, 68, 0.12); color: #fca5a5; }
.alert-success { background: rgba(16, 185, 129, 0.12); color: #6ee7b7; }
.alert-info { background: rgba(99, 102, 241, 0.12); color: #a5b4fc; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-backdrop.open { display: flex; }

.modal {
  width: 100%;
  max-width: 480px;
  background: #141820;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 1.75rem;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.modal-header h3 { margin: 0; font-size: 1.125rem; color: #f1f5f9; }

.modal-close {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.05);
  border: none;
  border-radius: 8px;
  color: #94a3b8;
  font-size: 1.25rem;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.modal-close:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }

.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: #6366f1;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.generating-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  gap: 1rem;
  color: #64748b;
  background: #f8fafc;
}

.generating-overlay .loading-spinner {
  width: 44px;
  height: 44px;
  border-width: 3px;
  border-color: #e2e8f0;
  border-top-color: #6366f1;
}

.widget-edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.hint { font-size: 0.8125rem; color: #64748b; }
.hidden { display: none !important; }

/* Mobile sidebar toggle */
.mobile-nav-toggle {
  display: none;
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: #6366f1;
  color: #fff;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 60;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.45);
}

/* Responsive */
@media (max-width: 1100px) {
  .workspace-split {
    grid-template-columns: 1fr;
  }

  .config-column {
    max-height: none;
    padding-right: 0;
  }

  .canvas-column {
    min-height: 520px;
  }
}

@media (max-width: 768px) {
  .app-sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
  }

  .app-sidebar.open { transform: translateX(0); }

  .app-main { margin-left: 0; }

  .app-header,
  .workflow-steps,
  .workspace-split {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .mobile-nav-toggle { display: grid; place-items: center; }

  .step-label { display: none; }

  .step-connector { width: 24px; }
}

/* Focus visible (Accessibility) */
:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
}

.plan-badge-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.plan-badge {
  font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.3125rem 0.625rem; border-radius: 9999px;
  background: rgba(99, 102, 241, 0.15); color: #a5b4fc;
}
.plan-badge.pro { background: rgba(16, 185, 129, 0.15); color: #6ee7b7; }
.plan-badge-hint { font-size: 0.8125rem; color: #64748b; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
