/* Research Paper Watcher — dashboard styles.
   Light/dark are both explicit so the page never borrows a host background. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --border: #e3e6ea;
  --border-strong: #cdd3da;
  --text: #14181d;
  --text-dim: #5b6472;
  --text-faint: #8a94a2;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --high: #b42318;
  --high-soft: #fdecea;
  --medium: #b54708;
  --medium-soft: #fdf0e3;
  --low: #475467;
  --low-soft: #eef0f3;
  --ok: #067647;
  --ok-soft: #e6f4ed;
  --warn: #b54708;
  --danger: #b42318;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .04);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Malgun Gothic",
          "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

:root[data-theme="dark"],
:root:not([data-theme="light"]) {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1b2129;
    --border: #262d36;
    --border-strong: #38404a;
    --text: #e6edf3;
    --text-dim: #9aa5b1;
    --text-faint: #6e7a89;
    --accent: #4f92f7;
    --accent-soft: #16243d;
    --high: #ff8a80;
    --high-soft: #3a1c1a;
    --medium: #f0b46a;
    --medium-soft: #362718;
    --low: #9aa5b1;
    --low-soft: #21272f;
    --ok: #56d39a;
    --ok-soft: #14291f;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1b2129;
  --border: #262d36;
  --border-strong: #38404a;
  --text: #e6edf3;
  --text-dim: #9aa5b1;
  --text-faint: #6e7a89;
  --accent: #4f92f7;
  --accent-soft: #16243d;
  --high: #ff8a80;
  --high-soft: #3a1c1a;
  --medium: #f0b46a;
  --medium-soft: #362718;
  --low: #9aa5b1;
  --low-soft: #21272f;
  --ok: #56d39a;
  --ok-soft: #14291f;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* The browser's own `[hidden] { display: none }` has the same specificity as a
   class selector, so any author rule setting `display` silently defeats it.
   .modal-backdrop and .save-bar both set `display: flex`, which left the modal
   overlay permanently covering the page with no way to dismiss it. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ---------------- top bar ---------------- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding-top: 14px; padding-bottom: 12px;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok); flex: none;
  box-shadow: 0 0 0 3px var(--ok-soft);
}
.brand-name { font-weight: 680; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--text-faint); }
.topbar-actions { display: flex; gap: 8px; flex: none; }

.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-dim); font: inherit; font-weight: 550;
  padding: 9px 13px; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.pill {
  display: inline-block; margin-left: 5px; padding: 1px 6px;
  background: var(--low-soft); color: var(--text-dim);
  border-radius: 20px; font-size: 11px; font-weight: 600;
}

/* ---------------- panels ---------------- */

.panel { display: none; padding: 22px 0 60px; }
.panel.active { display: block; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  margin-bottom: 16px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 14px; font-weight: 650; letter-spacing: -.01em; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.hint { font-size: 12.5px; color: var(--text-dim); margin: -4px 0 14px; }

/* ---------------- stats ---------------- */

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.stat-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); font-weight: 620;
}
.stat-value { font-size: 26px; font-weight: 640; line-height: 1.15; margin-top: 5px; letter-spacing: -.02em; }
.stat-note { font-size: 11.5px; color: var(--text-dim); margin-top: 3px; }
.stat-value.accent { color: var(--accent); }
.stat-value.high { color: var(--high); }

/* ---------------- bars ---------------- */

.bars { display: flex; flex-direction: column; gap: 11px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 210px) 1fr auto; gap: 12px; align-items: center; }
.bar-label { font-size: 12.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: var(--low-soft); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s ease; }
.bar-value { font-size: 12.5px; font-weight: 620; font-variant-numeric: tabular-nums; min-width: 40px; text-align: right; }

.year-chart { display: flex; align-items: flex-end; gap: 2px; height: 130px; }
.year-bar { flex: 1; min-width: 4px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.year-bar i { display: block; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; opacity: .85; }
.year-bar span { font-size: 9px; color: var(--text-faint); text-align: center; margin-top: 3px;
  writing-mode: vertical-rl; transform: rotate(180deg); height: 26px; }

/* ---------------- filters ---------------- */

.filters { padding-bottom: 14px; }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-row.secondary { margin-top: 8px; }
.filter-row #q { flex: 1 1 260px; }
.filter-summary { font-size: 12px; color: var(--text-faint); margin-top: 10px; }

input, select, textarea {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 7px;
  padding: 7px 10px; font: inherit; font-size: 13px; min-width: 0;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
input[type="number"] { width: 108px; }
select { cursor: pointer; }

button {
  font: inherit; font-size: 13px; font-weight: 550;
  border-radius: 7px; padding: 7px 13px; cursor: pointer;
  border: 1px solid transparent; transition: background .12s, border-color .12s;
}
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
button.secondary:hover { border-color: var(--accent); color: var(--accent); }
button.ghost { background: transparent; color: var(--text-dim); border-color: var(--border); }
button.ghost:hover { color: var(--text); border-color: var(--border-strong); }
button.danger { background: transparent; color: var(--danger); border-color: var(--border); }
button.danger:hover { border-color: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.linklike {
  background: none; border: none; padding: 0; color: var(--accent);
  text-decoration: underline; cursor: pointer; font-weight: 550;
}

/* ---------------- paper list ---------------- */

.paper-list { display: flex; flex-direction: column; gap: 10px; }
.paper {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 17px; box-shadow: var(--shadow);
}
.paper-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 7px; }
.grade {
  font-size: 10.5px; font-weight: 700; letter-spacing: .05em;
  padding: 2px 7px; border-radius: 4px;
}
.grade.HIGH { background: var(--high-soft); color: var(--high); }
.grade.MEDIUM { background: var(--medium-soft); color: var(--medium); }
.grade.LOW { background: var(--low-soft); color: var(--low); }
.score { font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--text-dim); }
.tag {
  font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent); font-weight: 550;
}
.tag.muted { background: var(--low-soft); color: var(--text-dim); }
.paper-title { font-size: 15px; font-weight: 620; line-height: 1.4; margin: 0 0 6px; letter-spacing: -.01em; }
.paper-title a { color: var(--text); text-decoration: none; }
.paper-title a:hover { color: var(--accent); text-decoration: underline; }
.paper-meta { font-size: 12.5px; color: var(--text-dim); line-height: 1.7; }
.paper-meta strong { color: var(--text); font-weight: 600; }
.paper-abstract {
  font-size: 12.5px; color: var(--text-dim); margin-top: 9px;
  padding-top: 9px; border-top: 1px dashed var(--border);
}
.paper-links { margin-top: 9px; display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; }
.paper-links a { color: var(--accent); text-decoration: none; }
.paper-links a:hover { text-decoration: underline; }
.load-more-wrap { text-align: center; margin-top: 16px; }

.recent-list { display: flex; flex-direction: column; gap: 9px; }
.recent-item { display: flex; gap: 10px; align-items: baseline; font-size: 13px; }
.recent-item a { color: var(--text); text-decoration: none; flex: 1; }
.recent-item a:hover { color: var(--accent); }
.recent-date { font-size: 11.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; flex: none; }

/* ---------------- keyword editor ---------------- */

.notice { border-left: 3px solid var(--accent); }
.token-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.token-row input { flex: 1 1 320px; font-family: var(--mono); font-size: 12px; }
.status { font-size: 12.5px; margin-top: 9px; }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }
.status.warn { color: var(--warn); }

.group-block, .track-block {
  border: 1px solid var(--border); border-radius: 9px;
  padding: 14px 15px; margin-bottom: 11px; background: var(--surface-2);
}
.group-head, .track-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 10px;
}
.group-title { font-weight: 640; font-size: 13.5px; }
.group-id { font-family: var(--mono); font-size: 11px; color: var(--text-faint); margin-left: 7px; }
.group-used { font-size: 11.5px; color: var(--text-faint); }

.chip-set { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; align-items: center; }
.chip-kind {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); font-weight: 620; margin-right: 4px; flex: none;
}
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 20px; padding: 3px 5px 3px 11px; font-size: 12px;
}
.chip.acronym { font-family: var(--mono); font-weight: 620; }
.chip.weak { opacity: .72; border-style: dashed; }
.chip.excluded { text-decoration: line-through; opacity: .55; }
.chip button {
  background: none; border: none; padding: 0 4px; cursor: pointer;
  color: var(--text-faint); font-size: 13px; line-height: 1; border-radius: 4px;
}
.chip button:hover { color: var(--danger); }
.chip.excluded button:hover { color: var(--ok); }
.chip-add { display: flex; gap: 5px; align-items: center; }
.chip-add input { width: 190px; font-size: 12px; padding: 4px 9px; }
.chip-add select { font-size: 12px; padding: 4px 7px; }

.track-block .track-groups { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-dim); }
.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; cursor: pointer; }
.switch input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.setting label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; font-weight: 550; }
.setting input, .setting select { width: 100%; }
.setting .desc { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }

.save-bar {
  position: sticky; bottom: 16px; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 13px 17px;
  box-shadow: 0 6px 22px rgba(16, 24, 40, .14);
}
.save-info { font-size: 13px; }
.save-detail { color: var(--text-dim); margin-left: 7px; font-size: 12px; }
.save-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------- tables ---------------- */

.table-scroll { overflow-x: auto; }
.runs-table { width: 100%; border-collapse: collapse; font-size: 12.5px; white-space: nowrap; }
.runs-table th {
  text-align: right; font-weight: 620; color: var(--text-faint);
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.runs-table th:first-child, .runs-table th:nth-child(2), .runs-table th:nth-child(3) { text-align: left; }
.runs-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  text-align: right; font-variant-numeric: tabular-nums;
}
.runs-table td:first-child, .runs-table td:nth-child(2), .runs-table td:nth-child(3) { text-align: left; }
.runs-table tbody tr:hover { background: var(--surface-2); }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 4px; font-weight: 620; }
.badge.success { background: var(--ok-soft); color: var(--ok); }
.badge.partial_success { background: var(--medium-soft); color: var(--medium); }
.badge.failed { background: var(--high-soft); color: var(--high); }

.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.kv { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--surface-2); }
.kv dt { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; font-weight: 620; }
.kv dd { margin: 4px 0 0; font-size: 13px; font-family: var(--mono); word-break: break-all; }

.steps { margin: 0; padding-left: 20px; font-size: 13px; line-height: 1.9; color: var(--text-dim); }
.steps strong { color: var(--text); }
.flow {
  font-family: var(--mono); font-size: 12px; line-height: 1.65;
  color: var(--text-dim); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 14px 16px; overflow-x: auto; margin: 0;
}

/* ---------------- modal + toast ---------------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(16, 24, 40, .5);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; width: min(820px, 100%); max-height: 84vh;
  display: flex; flex-direction: column; box-shadow: 0 18px 48px rgba(16, 24, 40, .28);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 14.5px; }
.modal-body { padding: 16px 18px; overflow: auto; }
.modal-body pre {
  font-family: var(--mono); font-size: 12px; line-height: 1.6;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px; overflow-x: auto; margin: 0;
  white-space: pre-wrap; word-break: break-word;
}
.modal-foot {
  padding: 13px 18px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
}
.modal-field { margin-bottom: 13px; }
.modal-field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; font-weight: 550; }
.modal-field input, .modal-field select { width: 100%; }
.diff-add { color: var(--ok); }
.diff-del { color: var(--danger); }

.toast-stack {
  position: fixed; right: 18px; bottom: 18px; z-index: 100;
  display: flex; flex-direction: column; gap: 9px; max-width: 380px;
}
.toast {
  background: var(--surface); border: 1px solid var(--border-strong);
  border-left-width: 3px; border-radius: 8px; padding: 11px 14px;
  font-size: 13px; box-shadow: 0 6px 20px rgba(16, 24, 40, .18);
  animation: slide-in .18s ease;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--accent); }
@keyframes slide-in { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }

.empty { text-align: center; padding: 44px 20px; color: var(--text-faint); font-size: 13.5px; }

@media (max-width: 760px) {
  .two-col { grid-template-columns: 1fr; }
  .wrap { padding: 0 14px; }
  .bar-row { grid-template-columns: minmax(90px, 140px) 1fr auto; }
  .save-bar { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
