*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --good: #0d9488;
  --good-bg: #f0fdfa;
  --good-light: #ccfbf1;
  --risky: #d97706;
  --risky-bg: #fffbeb;
  --risky-light: #fef3c7;
  --bad: #dc2626;
  --bad-bg: #fef2f2;
  --bad-light: #fee2e2;
  --primary: #2563eb;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --radius: 12px;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 32px;
}

.header-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.logo-icon {
  width: 32px;
  height: 32px;
  color: var(--primary);
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 700;
}

.header-sub {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Upload */
.upload-section {
  margin-bottom: 28px;
}

.upload-zone {
  background: var(--card);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: #f8faff;
}

.upload-icon {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.upload-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.upload-hint {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  font-size: inherit;
  text-decoration: underline;
}

.upload-note {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.upload-progress {
  background: var(--card);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  box-shadow: var(--shadow);
}

.upload-progress p {
  margin-top: 16px;
  color: var(--text-muted);
}

.hidden { display: none !important; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Report Card */
.report-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}

.report-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.report-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.report-meta .filename {
  font-weight: 600;
  font-size: 1.05rem;
}

.report-meta .details {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}

.btn-icon:hover {
  background: var(--bad-light);
  color: var(--bad);
}

.btn-icon.stop-btn:hover {
  background: var(--risky-light);
  color: var(--risky);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

/* Processing bar */
.processing-bar {
  padding: 12px 24px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.processing-bar p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.progress-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width .4s ease;
}

/* Category rows */
.category {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.category:last-of-type {
  border-bottom: none;
}

.category.good { background: var(--good-bg); }
.category.risky { background: var(--risky-bg); }
.category.bad { background: var(--bad-bg); }

/* Circular progress */
.ring-wrap {
  position: relative;
  width: 72px;
  height: 72px;
  flex-shrink: 0;
}

.ring-wrap svg {
  width: 72px;
  height: 72px;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: rgba(0,0,0,.08);
  stroke-width: 5;
}

.ring-fill {
  fill: none;
  stroke-width: 5;
  stroke-linecap: round;
  transition: stroke-dashoffset .6s ease;
}

.category.good .ring-fill { stroke: var(--good); }
.category.risky .ring-fill { stroke: var(--risky); }
.category.bad .ring-fill { stroke: var(--bad); }

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring-center svg {
  width: 28px;
  height: 28px;
  transform: none;
}

.category.good .ring-center svg { color: var(--good); }
.category.risky .ring-center svg { color: var(--risky); }
.category.bad .ring-center svg { color: var(--bad); }

.category-info {
  flex: 1;
  min-width: 0;
}

.category-label {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 2px;
}

.category.good .category-label { color: var(--good); }
.category.risky .category-label { color: var(--risky); }
.category.bad .category-label { color: var(--bad); }

.category-stats {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
}

.category-stats .count {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 6px;
}

.category-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Download button */
.download-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: calc(100% - 48px);
  margin: 16px 24px 20px;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}

.download-btn:hover:not(:disabled) {
  background: #1d4ed8;
}

.download-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.download-btn svg {
  width: 20px;
  height: 20px;
}

.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Login */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
}

.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.login-brand h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.login-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 28px;
}

.login-form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 16px;
  color: var(--text);
}

.login-form input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}

.login-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.login-btn {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}

.login-btn:hover:not(:disabled) {
  background: #1d4ed8;
}

.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-error {
  color: var(--bad);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.login-note {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 20px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 18px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
}

.credits-badge {
  background: #eff6ff;
  color: var(--primary);
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.btn-logout:hover {
  background: var(--bad-light);
  border-color: var(--bad);
  color: var(--bad);
}

/* Admin panel */
.admin-panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.admin-panel h3 {
  font-size: 0.95rem;
  margin-bottom: 12px;
}

.admin-row {
  display: flex;
  gap: 8px;
}

.admin-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
}

.admin-row button {
  padding: 10px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.admin-msg {
  font-size: 0.85rem;
  margin-top: 8px;
  color: var(--good);
}

.processing-bar.paused {
  background: var(--risky-bg);
}

.processing-bar.paused p {
  color: var(--risky);
}

.credits-used-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0 24px 12px;
}

/* Live stats */
.live-stats {
  margin-top: 12px;
}

.live-stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.live-stat {
  font-size: 0.82rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--border);
}

.live-stat.good { color: var(--good); border-color: var(--good-light); background: var(--good-bg); }
.live-stat.risky { color: var(--risky); border-color: var(--risky-light); background: var(--risky-bg); }
.live-stat.bad { color: var(--bad); border-color: var(--bad-light); background: var(--bad-bg); }
.live-stat.muted { color: var(--text-muted); background: #f8fafc; }

.live-feed {
  margin-top: 12px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.live-feed.empty {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.live-feed-row {
  display: grid;
  grid-template-columns: 56px 1fr 1.2fr;
  gap: 8px;
  padding: 8px 12px;
  font-size: 0.78rem;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.live-feed-row:last-child { border-bottom: none; }
.live-feed-row.good { background: var(--good-bg); }
.live-feed-row.risky { background: var(--risky-bg); }
.live-feed-row.bad { background: var(--bad-bg); }

.live-feed-status {
  font-weight: 700;
  font-size: 0.7rem;
}

.live-feed-row.good .live-feed-status { color: var(--good); }
.live-feed-row.risky .live-feed-status { color: var(--risky); }
.live-feed-row.bad .live-feed-status { color: var(--bad); }

.live-feed-email {
  font-family: ui-monospace, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-feed-reason {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .live-feed-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}
