/* ============================================================
   PatentScope — refined light/dark theme
   ============================================================ */

:root {
  /* Brand / accent */
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eaf1ff;
  --primary-contrast: #ffffff;

  /* Surfaces */
  --bg-app: #f5f6f8;
  --bg-surface: #ffffff;
  --bg-subtle: #f2f4f7;
  --bg-hover: #eef1f5;
  --bg-inset: #f8fafc;

  /* Text */
  --text-primary: #1a1d21;
  --text-secondary: #5b6470;
  --text-muted: #8b929c;

  /* Lines */
  --border: #e3e6ea;
  --border-strong: #d4d8de;

  /* Semantic match colors */
  --o: #e5484d;  --o-bg: #fdecec;  --o-fg: #c4292e;  --o-border: #f6cccd;
  --y: #e0900a;  --y-bg: #fdf3e0;  --y-fg: #b3730a;  --y-border: #f6e0b3;
  --x: #2a9d63;  --x-bg: #e9f6ef;  --x-fg: #1f7a4d;  --x-border: #c2e6d2;

  --success: #2a9d63;
  --warning: #e0900a;
  --danger: #e5484d;

  /* Effects */
  --shadow-sm: 0 1px 2px rgba(16,24,40,0.04), 0 1px 3px rgba(16,24,40,0.06);
  --shadow-md: 0 4px 12px rgba(16,24,40,0.08);
  --shadow-lg: 0 12px 32px rgba(16,24,40,0.12);
  --ring: 0 0 0 3px rgba(37,99,235,0.18);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --nav-h: 60px;
}

[data-theme="dark"] {
  --primary: #5b8cff;
  --primary-dark: #4f7ff0;
  --primary-soft: #18243f;
  --primary-contrast: #0b0e14;

  --bg-app: #0d1117;
  --bg-surface: #161b22;
  --bg-subtle: #1b2230;
  --bg-hover: #222b3a;
  --bg-inset: #11161e;

  --text-primary: #e6edf3;
  --text-secondary: #9da7b3;
  --text-muted: #6e7681;

  --border: #272e3a;
  --border-strong: #333c4a;

  --o: #ff6b6f;  --o-bg: #2a1517;  --o-fg: #ff8a8d;  --o-border: #4a2326;
  --y: #f0ad2e;  --y-bg: #2a2113;  --y-fg: #ffc658;  --y-border: #4a3a1a;
  --x: #3fb87a;  --x-bg: #122a1e;  --x-fg: #5fd197;  --x-border: #1d4a33;

  --success: #3fb87a;
  --warning: #f0ad2e;
  --danger: #ff6b6f;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.4);
  --shadow-lg: 0 14px 36px rgba(0,0,0,0.5);
  --ring: 0 0 0 3px rgba(91,140,255,0.25);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

/* ============================ Navbar ============================ */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  background: color-mix(in srgb, var(--bg-surface) 85%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.navbar-inner {
  max-width: 1180px;
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.3px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  font-size: 17px;
  box-shadow: var(--shadow-sm);
}

.brand-name { background: linear-gradient(90deg, var(--text-primary), var(--text-secondary)); -webkit-background-clip: text; background-clip: text; }

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  position: relative;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover { color: var(--text-primary); background: var(--bg-hover); }

.nav-link.active { color: var(--primary); background: var(--primary-soft); font-weight: 600; }

.theme-toggle {
  margin-left: 8px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.theme-toggle:hover { background: var(--bg-hover); transform: rotate(-15deg); }

.theme-icon-light { display: none; }
.theme-icon-dark { display: inline; }
[data-theme="dark"] .theme-icon-light { display: inline; }
[data-theme="dark"] .theme-icon-dark { display: none; }

/* ============================ Layout ============================ */
.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 24px 24px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.page-head h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.page-head .subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.page-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ============================ Cards ============================ */
.card {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  transition: background 0.25s, border-color 0.25s;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================ Upload ============================ */
.upload-area {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 44px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  background: var(--bg-inset);
}

.upload-area:hover, .upload-area.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.upload-area .upload-icon {
  width: 56px;
  height: 56px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 26px;
  box-shadow: var(--shadow-sm);
}

.upload-area .upload-text { font-size: 15px; color: var(--text-primary); margin-bottom: 4px; font-weight: 500; }
.upload-area .upload-hint { font-size: 13px; color: var(--text-muted); }

.upload-area input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer;
}

/* ============================ Buttons ============================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow-md); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

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

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.05); box-shadow: var(--shadow-md); }

.btn-danger { background: var(--danger); color: #fff; }

/* ============================ File chip ============================ */
.file-name-display {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--primary-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 16px;
  color: var(--primary);
  font-size: 14px;
  font-weight: 500;
}

.file-name-display .remove-file {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

/* ============================ Flash ============================ */
.flash-messages { margin-bottom: 16px; }

.flash-message {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 14px;
}

.flash-message.error { background: var(--o-bg); color: var(--o-fg); border: 1px solid var(--o-border); }
.flash-message.success { background: var(--x-bg); color: var(--x-fg); border: 1px solid var(--x-border); }

/* ============================ Task info ============================ */
.task-info p, .result-info p { font-size: 14px; color: var(--text-secondary); margin-bottom: 6px; }
.task-info strong, .result-info strong { color: var(--text-primary); margin-right: 4px; }

/* ============================ Steps ============================ */
.steps-container { margin: 20px 0; display: flex; flex-direction: column; gap: 6px; }

.step-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid transparent;
  transition: all 0.25s;
}

.step-item .step-icon {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  font-size: 13px;
  margin-right: 12px;
  flex-shrink: 0;
  transition: all 0.25s;
}

.step-item .step-icon.pending {
  background: var(--primary); color: #fff; animation: pulse 1.5s infinite;
}
.step-item .step-icon.done { background: var(--success); color: #fff; }

.step-label { flex: 1; font-size: 14px; color: var(--text-primary); }
.step-status { font-size: 12px; color: var(--text-muted); }
.step-status.status-processing { color: var(--primary); font-weight: 600; }
.step-status.status-completed { color: var(--success); font-weight: 600; }

@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:0.45;} }

/* ============================ Progress bar ============================ */
.progress-bar-container {
  width: 100%; height: 8px;
  background: var(--bg-subtle);
  border-radius: 999px;
  overflow: hidden;
  margin: 24px 0 12px;
}

.progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  border-radius: 999px;
  transition: width 0.5s ease;
}
.progress-bar.error { background: var(--danger); }

.progress-text { text-align: center; color: var(--text-secondary); font-size: 14px; margin-bottom: 8px; }
.progress-text.text-error { color: var(--danger); font-weight: 600; }

/* ============================ Preview ============================ */
.results-preview { margin-bottom: 20px; }

.preview-card {
  background: var(--bg-inset);
  padding: 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  border-left: 3px solid var(--primary);
}
.preview-card h4 { font-size: 14px; color: var(--text-primary); margin-bottom: 8px; }
.preview-card p { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }

/* ============================ Log ============================ */
.log-content {
  background: #0b0e14;
  color: #c9d1d9;
  padding: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  max-height: 320px;
  overflow-y: auto;
  font-family: 'SFMono-Regular', 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.7;
}

.log-entry { padding: 2px 0; }
.log-time { color: #58a6ff; margin-right: 8px; }
.log-error { color: #ff7b72; }
.log-warning { color: #e3b341; }

/* ============================ Summary cards ============================ */
.summary-cards { display: flex; gap: 16px; margin-top: 20px; }

.summary-card {
  flex: 1;
  padding: 20px;
  border-radius: var(--radius-md);
  text-align: center;
  border: 1px solid var(--border);
}

.summary-card .summary-count { display: block; font-size: 34px; font-weight: 700; margin-bottom: 2px; line-height: 1.1; }
.summary-card .summary-label { font-size: 13px; font-weight: 600; }

.summary-card.match-o { background: var(--o-bg); color: var(--o-fg); border-color: var(--o-border); }
.summary-card.match-y { background: var(--y-bg); color: var(--y-fg); border-color: var(--y-border); }
.summary-card.match-x { background: var(--x-bg); color: var(--x-fg); border-color: var(--x-border); }

/* ============================ Table ============================ */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  position: sticky;
  top: var(--nav-h);
}

tbody tr { transition: background 0.12s; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

.row-match-o { background: color-mix(in srgb, var(--o-bg) 55%, transparent); }
.row-match-y { background: color-mix(in srgb, var(--y-bg) 55%, transparent); }
.row-match-x { background: color-mix(in srgb, var(--x-bg) 45%, transparent); }

/* ============================ Badges ============================ */
.match-badge {
  display: inline-block;
  min-width: 26px;
  text-align: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
}
.match-badge.match-o { background: var(--o); }
.match-badge.match-y { background: var(--y); }
.match-badge.match-x { background: var(--x); }

.patent-ref { font-size: 13px; color: var(--text-primary); line-height: 1.5; word-break: break-word; }

/* ============================ Info box ============================ */
.info-box {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  padding: 16px 20px;
  border-radius: var(--radius-sm);
}

.info-box ul { list-style: none; padding-left: 0; }
.info-box li { padding: 4px 0; color: var(--text-secondary); font-size: 14px; }
.info-box li::before { content: "▸"; color: var(--primary); margin-right: 8px; }

/* ============================ Error message ============================ */
.error-message { background: var(--o-bg); border: 1px solid var(--o-border); border-radius: var(--radius-sm); padding: 16px 20px; color: var(--o-fg); }
.error-message .error-detail { font-size: 13px; margin-top: 8px; font-family: monospace; opacity: 0.85; }

/* ============================ Status text ============================ */
.status-completed { color: var(--success); font-weight: 600; }
.status-failed { color: var(--danger); font-weight: 600; }
.status-processing { color: var(--primary); font-weight: 600; animation: pulse 1.5s infinite; }

/* ============================ No data ============================ */
.no-data { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.no-data .no-data-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.6; }
.no-data p { font-size: 15px; }

/* ============================ Action buttons ============================ */
.action-buttons { margin-top: 24px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ============================ Footer ============================ */
footer {
  text-align: center;
  padding: 28px 20px 12px;
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 12px;
}

/* ============================ Tabs ============================ */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
  margin-bottom: -1px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============================ Textarea ============================ */
.textarea {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.textarea::placeholder { color: var(--text-muted); }

/* ============================ Score ============================ */
.score-row {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 8px;
}

.score-badge {
  flex-shrink: 0;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 4px solid;
}
.score-badge .score-num { font-size: 40px; font-weight: 800; line-height: 1; }
.score-badge .score-unit { font-size: 13px; opacity: 0.7; margin-top: 2px; }

.score-good { color: var(--x); border-color: var(--x); background: var(--x-bg); }
.score-mid  { color: var(--y); border-color: var(--y); background: var(--y-bg); }
.score-bad  { color: var(--o); border-color: var(--o); background: var(--o-bg); }

.score-headline { font-size: 17px; font-weight: 700; color: var(--text-primary); }
.score-sub { font-size: 14px; color: var(--text-secondary); margin-top: 4px; }

/* ============================ Stat pills ============================ */
.stat-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.pill {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--border);
}
.pill-muted { background: var(--bg-subtle); color: var(--text-secondary); font-weight: 500; }

/* ============================ Issues ============================ */
.issue-list { display: flex; flex-direction: column; gap: 10px; }

.issue {
  border: 1px solid var(--border);
  border-left: 4px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  background: var(--bg-inset);
}
.issue-error { border-left-color: var(--o); }
.issue-warning { border-left-color: var(--y); }
.issue-info { border-left-color: var(--x); }

.issue-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.issue-cat {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-subtle);
  padding: 2px 8px;
  border-radius: 6px;
}
.issue-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.issue-loc { font-size: 12px; color: var(--text-muted); margin-left: auto; }
.issue-detail { font-size: 13px; color: var(--text-secondary); margin-top: 8px; line-height: 1.55; }

/* ============================ Responsive ============================ */
@media (max-width: 768px) {
  .navbar-inner { padding: 0 16px; }
  .brand-name { display: none; }
  .container { padding: 20px 16px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-actions { flex-wrap: wrap; }
  .summary-cards { flex-direction: column; }
  th, td { padding: 10px 12px; font-size: 13px; }
}
