:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #d9dde3;
  --text: #1c1f24;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --ok: #16a34a;
  --warn: #b45309;
  --err: #b91c1c;
  --code-bg: #0f172a;
  --code-fg: #e2e8f0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header h1 { margin: 0; font-size: 18px; }
header nav { display: flex; gap: 16px; align-items: center; }
header nav a { color: var(--accent); text-decoration: none; }
header nav a:hover { text-decoration: underline; }

.badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}
.badge-loading { background: #fef3c7; color: var(--warn); }
.badge-ready   { background: #dcfce7; color: var(--ok); }
.badge-error   { background: #fee2e2; color: var(--err); }

main {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  padding: 16px 20px;
  align-items: start;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}

.file-picker {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.file-picker span { font-weight: 600; }

.filelist {
  font-size: 12px;
  color: var(--muted);
  min-height: 16px;
}
.filelist ul { margin: 4px 0 0; padding-left: 18px; }

.endpoint-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin: 4px 0 0;
}
.endpoint-tabs button {
  background: transparent;
  border: 0;
  padding: 8px 14px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.endpoint-tabs button.active {
  border-bottom-color: var(--accent);
  color: var(--accent);
}
.endpoint-tabs button:hover:not(.active) { color: var(--text); }

fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
fieldset legend { font-weight: 600; padding: 0 4px; }
fieldset label { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
fieldset input[type=number], fieldset select {
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  min-width: 140px;
}

button#run {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 10px 14px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}
button#run:hover:not(:disabled) { background: var(--accent-hover); }
button#run:disabled { opacity: 0.6; cursor: not-allowed; }

.status { font-size: 12px; color: var(--muted); }
.status.err { color: var(--err); }
.status.ok  { color: var(--ok); }

.results {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  min-height: 400px;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: #f9fafb;
}
.tabs button {
  background: transparent;
  border: 0;
  padding: 10px 16px;
  cursor: pointer;
  font: inherit;
  border-bottom: 2px solid transparent;
}
.tabs button.active {
  border-bottom-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.tab-panel { padding: 16px 20px; margin: 0; }

pre#tab-raw {
  background: var(--code-bg);
  color: var(--code-fg);
  overflow: auto;
  max-height: 78vh;
  font: 12px/1.5 "SF Mono", Menlo, Consolas, monospace;
  border-radius: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

#tab-debug { max-height: 78vh; overflow: auto; }
#tab-debug .file-block { border-top: 1px dashed var(--border); padding-top: 12px; margin-top: 12px; }
#tab-debug .file-block:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
#tab-debug h2 { font-size: 16px; margin: 0 0 8px; color: var(--muted); }

.overlay-page {
  margin: 12px 0 20px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fafbfc;
  overflow: hidden;
}
.overlay-page img {
  display: block;
  width: 100%;
  height: auto;
}
.overlay-page figcaption {
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: #fff;
}

#tab-rendered { max-height: 78vh; overflow: auto; }
#tab-rendered .file-block { border-top: 1px dashed var(--border); padding-top: 12px; margin-top: 12px; }
#tab-rendered .file-block:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
#tab-rendered h2 { font-size: 16px; margin: 0 0 8px; color: var(--muted); }
#tab-rendered .meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}

#tab-rendered .page-text {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font: 13px/1.5 "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap;
  max-height: 300px;
  overflow: auto;
}
#tab-rendered .page-text summary { cursor: pointer; font-weight: 600; color: var(--text); }

#tab-rendered table { border-collapse: collapse; margin: 8px 0; }
#tab-rendered th, #tab-rendered td { border: 1px solid var(--border); padding: 4px 8px; }
#tab-rendered th { background: #f3f4f6; }

.download-link {
  display: inline-block;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  text-decoration: none;
  margin-top: 8px;
  margin-bottom: 12px;
}
.download-link:hover { background: var(--accent-hover); }

/* Word-accounting badge + drops table (parse endpoint). */
.word-accounting {
  margin: 4px 0 12px;
  padding: 8px 10px;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}
.word-accounting-badge {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.wa-pill {
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}
.wa-pill.ok      { background: #dcfce7; color: var(--ok); }
.wa-pill.warn    { background: #fef3c7; color: var(--warn); }
.wa-pill.err     { background: #fee2e2; color: var(--err); }
.wa-pill.neutral { background: #e5e7eb; color: var(--muted); }
.wa-counts { color: var(--muted); font-family: "SF Mono", Menlo, Consolas, monospace; }
.wa-intent-counts { color: var(--muted); }
.wa-drops { color: var(--muted); }

.intent-pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.intent-pill.ok  { background: #dcfce7; color: var(--ok); }
.intent-pill.err { background: #fee2e2; color: var(--err); }
.drops-table tr.drop-unintentional { background: #fff1f1; }

.drops-details { margin-top: 8px; }
.drops-details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  padding: 4px 0;
}
.drops-page-heading {
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 4px;
}
.drops-table {
  width: 100%;
  border-collapse: collapse;
  font: 12px/1.4 "SF Mono", Menlo, Consolas, monospace;
  margin: 4px 0 12px;
}
.drops-table th, .drops-table td {
  border: 1px solid var(--border);
  padding: 3px 6px;
  text-align: left;
}
.drops-table th { background: #f3f4f6; font-weight: 600; }
.drops-table td.drops-text { max-width: 300px; word-break: break-word; }
