:root {
  --bg: #0f1419;
  --surface: #1a1f26;
  --border: #2d3640;
  --text: #e7e9ea;
  --muted: #8b98a5;
  --accent: #2dd4bf;
  --accent-dim: rgba(45, 212, 191, 0.15);
  --yellow: #f5a623;
  --success: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --radius: 12px;
  --font: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
  gap: 0.75rem;
}
.logo-row { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.logo-icon { width: 32px; height: 32px; color: var(--yellow); flex-shrink: 0; }
.brand-title { font-size: 1.25rem; font-weight: 700; letter-spacing: 0.02em; color: var(--text); margin: 0; }
.brand-tagline { font-size: 0.7rem; color: var(--muted); margin: 0.15rem 0 0 0; letter-spacing: 0.04em; max-width: 420px; }

/* Container & sections */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 2.5rem 2rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}
.section-title { font-size: 1.5rem; font-weight: 700; color: var(--text); margin: 0 0 0.35rem 0; text-align: center; }
.section-sub { font-size: 0.9rem; color: var(--muted); margin: 0 0 1.5rem 0; text-align: center; }

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  margin-bottom: 2rem;
  min-height: 140px;
  -webkit-tap-highlight-color: transparent;
}
.drop-zone:hover, .drop-zone.dragover { background: var(--accent-dim); border-color: #5eead4; }
.drop-zone input[type="file"] { display: none; }
.drop-zone .folder-icon { width: 64px; height: 64px; margin: 0 auto 1rem; color: var(--yellow); }
.drop-zone .drop-title { font-size: 1rem; font-weight: 600; color: var(--text); margin: 0 0 0.25rem 0; }
.drop-zone .drop-hint { font-size: 0.8rem; color: var(--muted); margin: 0; }

/* Separator */
.separator {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 2rem 0 1.5rem 0;
}
.separator::before, .separator::after {
  content: '';
  flex: 1;
  min-width: 0;
  height: 1px;
  background: var(--border);
}
.separator span { font-size: 0.75rem; color: var(--muted); letter-spacing: 0.05em; white-space: nowrap; }

/* Industry grid */
.industry-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}
.industry-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1.25rem 1rem;
  min-height: 100px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.industry-btn:hover { border-color: var(--accent); background: var(--accent-dim); }
.industry-btn.selected { border-color: var(--accent); background: var(--accent-dim); }
.industry-btn .icon { width: 40px; height: 40px; flex-shrink: 0; }

/* Buttons & actions */
.next-row { margin-top: 2rem; text-align: center; }
.btn {
  padding: 0.65rem 1.5rem;
  min-height: 44px;
  border-radius: 8px;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  background: var(--accent);
  color: #0f1419;
  transition: background 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: #5eead4; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Preview table */
.preview-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: 0.75rem; }
.preview-table { width: 100%; min-width: 320px; border-collapse: collapse; font-size: 0.8rem; }
.preview-table th, .preview-table td { padding: 0.45rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); }
.preview-table th { color: var(--muted); font-weight: 500; }

/* Report & summary */
.report-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-top: 1rem;
  white-space: pre-wrap;
  font-size: 0.9rem;
  line-height: 1.6;
  max-height: 65vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.summary-bar { display: flex; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.summary-item { padding: 0.45rem 0.85rem; border-radius: 6px; font-size: 0.85rem; font-weight: 600; }
.summary-item.total { background: var(--accent-dim); color: var(--accent); }
.summary-item.high { background: rgba(248,81,73,0.2); color: var(--danger); }
.summary-item.medium { background: rgba(210,153,34,0.2); color: var(--warn); }
.summary-item.low { background: rgba(63,185,80,0.2); color: var(--success); }

/* Utilities */
.error { color: var(--danger); font-size: 0.9rem; margin-top: 0.5rem; text-align: center; }
.hidden { display: none !important; }

/* Popup / toast */
.popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  pointer-events: none;
}
.popup-overlay.active { pointer-events: auto; }
.popup {
  min-width: 280px;
  max-width: 90vw;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: popIn 0.25s ease-out;
  pointer-events: auto;
  cursor: pointer;
}
.popup.success { background: rgba(63, 185, 80, 0.95); color: #0f1419; border: 1px solid var(--success); }
.popup.error { background: rgba(248, 81, 73, 0.95); color: #fff; border: 1px solid var(--danger); }
.popup .pop-icon { width: 24px; height: 24px; flex-shrink: 0; }
.popup .pop-text { flex: 1; }
@keyframes popIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; vertical-align: middle; margin-right: 0.5rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Preview / results inline overrides */
#preview.preview-section { margin-top: 2rem; }
#preview .preview-meta { font-size: 0.85rem; color: var(--muted); margin: 0 0 0.5rem 0; }
#results.results-section { margin-top: 2.5rem; }
#results .section-title-left { text-align: left; }
#results .section-title-mt { text-align: left; margin-top: 1rem; }

/* Tablet and below */
@media (max-width: 768px) {
  .header { padding: 0.875rem 1.25rem; }
  .container { padding: 1.5rem 1.25rem; }
  .section-title { font-size: 1.35rem; }
  .section-sub { font-size: 0.85rem; margin-bottom: 1.25rem; }
  .drop-zone { padding: 2rem 1.25rem; margin-bottom: 1.5rem; min-height: 120px; }
  .drop-zone .folder-icon { width: 56px; height: 56px; }
  .separator { margin: 1.5rem 0 1.25rem 0; }
  .industry-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.875rem;
  }
  .industry-btn {
    padding: 1rem 0.75rem;
    min-height: 96px;
    font-size: 0.85rem;
  }
  .industry-btn .icon { width: 36px; height: 36px; }
  .next-row { margin-top: 1.5rem; }
  .report-box { max-height: 55vh; padding: 1rem 1.25rem; font-size: 0.85rem; }
}

/* Mobile */
@media (max-width: 600px) {
  .header { padding: 0.75rem 1rem; }
  .logo-icon { width: 28px; height: 28px; }
  .brand-title { font-size: 1.1rem; }
  .brand-tagline { font-size: 0.65rem; max-width: 100%; }
  .container { padding: 1.25rem 1rem; }
  .section-title { font-size: 1.2rem; }
  .section-sub { font-size: 0.8rem; margin-bottom: 1rem; line-height: 1.4; }
  .drop-zone {
    padding: 1.5rem 1rem;
    margin-bottom: 1.25rem;
    min-height: 110px;
  }
  .drop-zone .folder-icon { width: 48px; height: 48px; margin-bottom: 0.75rem; }
  .drop-zone .drop-title { font-size: 0.95rem; }
  .drop-zone .drop-hint { font-size: 0.75rem; }
  .separator { margin: 1.25rem 0 1rem 0; }
  .separator span { font-size: 0.7rem; white-space: normal; text-align: center; }
  .industry-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  .industry-btn {
    flex-direction: row;
    justify-content: flex-start;
    padding: 1rem 1rem;
    min-height: 48px;
    font-size: 0.9rem;
    gap: 1rem;
  }
  .industry-btn .icon { width: 32px; height: 32px; }
  .next-row { margin-top: 1.25rem; }
  .btn {
    width: 100%;
    max-width: 100%;
    padding: 0.85rem 1.25rem;
    font-size: 1rem;
  }
  #preview { margin-top: 1.5rem !important; }
  #preview p { font-size: 0.8rem !important; }
  .preview-table { font-size: 0.75rem; }
  .preview-table th, .preview-table td { padding: 0.35rem 0.5rem; }
  #results { margin-top: 1.5rem !important; }
  #results .section-title { font-size: 1.1rem; }
  .summary-bar { gap: 0.5rem; margin-bottom: 0.875rem; }
  .summary-item { padding: 0.4rem 0.7rem; font-size: 0.8rem; }
  .report-box { max-height: 50vh; padding: 1rem; font-size: 0.8rem; }
}

/* Small mobile */
@media (max-width: 380px) {
  .brand-title { font-size: 1rem; }
  .brand-tagline { font-size: 0.6rem; }
  .section-title { font-size: 1.1rem; }
  .industry-btn { font-size: 0.85rem; }
}
