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

:root {
  --bg:      #0f1117;
  --bg2:     #181c27;
  --bg3:     #1e2333;
  --border:  #2a3050;
  --border2: #3a4060;
  --text1:   #e8eaf0;
  --text2:   #9aa0b8;
  --text3:   #5a6080;
  --accent:  #5b8def;
  --green:   #3ecf8e;
  --red:     #f06565;
  --yellow:  #f5c842;
  --purple:  #9b7fe8;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:     #f4f6fb;
    --bg2:    #ffffff;
    --bg3:    #eef0f7;
    --border: #d8dce8;
    --border2:#c0c6d8;
    --text1:  #1a1e2e;
    --text2:  #4a5070;
    --text3:  #8890aa;
  }
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text1);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── LOGIN ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 360px;
}

.login-logo {
  display: block;
  height: 36px;
  width: auto;
  margin-bottom: 12px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}

.login-sub {
  color: var(--text3);
  font-size: 12px;
  margin-bottom: 28px;
}

.login-box input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text1);
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 12px;
  outline: none;
}

.login-box input:focus { border-color: var(--accent); }

.login-box button {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.login-box button:hover { opacity: 0.9; }

.login-error {
  color: var(--red);
  font-size: 12px;
  margin-top: 8px;
  display: none;
}

/* ── LAYOUT ── */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.sidebar-logo {
  display: block;
  height: 28px;
  width: auto;
  margin-bottom: 8px;
}

.sidebar-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.08em;
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sidebar-title span {
  display: block;
  font-size: 10px;
  color: var(--text3);
  font-weight: 400;
  letter-spacing: 0;
  margin-top: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  border-left: 2px solid transparent;
  transition: all 0.15s;
  user-select: none;
}

.nav-item:hover { color: var(--text1); background: var(--bg3); }
.nav-item.active { color: var(--text1); border-left-color: var(--accent); background: var(--bg3); }

.sidebar-nav-divider { height: 1px; background: var(--border); margin: 8px 12px; }
.nav-item-external { color: var(--text3); border-left-color: transparent; text-decoration: none; }
.nav-item-external:hover { color: var(--text1); }
.nav-external-icon { margin-left: auto; opacity: 0.5; flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px 0;
  border-top: 1px solid var(--border);
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text3);
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
  font-family: inherit;
  width: 100%;
}
.btn-logout:hover { border-color: var(--red); color: var(--red); }

.main { flex: 1; overflow-y: auto; }

/* ── TOPBAR ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-sub { font-size: 12px; color: var(--text3); margin-top: 1px; }

/* ── STATS ROW ── */
.stats-row {
  display: flex;
  gap: 12px;
  padding: 20px 28px 0;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 20px;
  flex: 1;
}

.stat-num { font-size: 24px; font-weight: 700; }
.stat-label { font-size: 11px; color: var(--text3); margin-top: 2px; }
.stat-num.green { color: var(--green); }
.stat-num.red   { color: var(--red); }
.stat-num.yellow { color: var(--yellow); }
.stat-num.accent { color: var(--accent); }

/* ── FILE TABLE ── */
.table-wrap {
  padding: 20px 28px;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.table-title { font-size: 13px; font-weight: 600; }

.filter-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}

.filter-wrap select, .filter-wrap input {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text1);
  font-size: 12px;
  padding: 6px 10px;
  font-family: inherit;
  outline: none;
}
.filter-wrap select:focus, .filter-wrap input:focus { border-color: var(--accent); }

.file-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.file-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}

.file-table td {
  padding: 10px 14px;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text2);
  vertical-align: middle;
}

.file-table tr:last-child td { border-bottom: none; }
.file-table tr:hover td { background: var(--bg3); }

.file-name { color: var(--text1); font-weight: 500; font-size: 13px; }
.file-folder { color: var(--text3); font-size: 11px; margin-top: 2px; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
}

.status-badge.extracted      { background: rgba(62,207,142,0.12);  color: var(--green); }
.status-badge.error          { background: rgba(240,101,101,0.12); color: var(--red); }
.status-badge.processed      { background: rgba(91,141,239,0.12);  color: var(--accent); }
.status-badge.pending        { background: rgba(245,200,66,0.12);  color: var(--yellow); }
.status-badge.classified     { background: rgba(155,127,232,0.15); color: var(--purple); }
.status-badge.article        { background: rgba(245,200,66,0.10);  color: #b89a30; }
.status-badge.classify_error { background: rgba(240,101,101,0.12); color: var(--red); }

.label-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  text-transform: capitalize;
}
.label-badge.fiction     { background: rgba(91,141,239,0.15);  color: var(--accent); }
.label-badge.nonfiction  { background: rgba(62,207,142,0.12);  color: var(--green); }
.label-badge.article     { background: rgba(245,200,66,0.10);  color: #b89a30; }
.label-badge.mixed       { background: rgba(245,200,66,0.12);  color: var(--yellow); }
.label-badge.noise       { background: rgba(90,96,128,0.15);   color: var(--text3); }
.label-badge.unknown     { background: rgba(155,127,232,0.15); color: var(--purple); }

.stat-num.purple { color: var(--purple); }

.action-btns { display: flex; gap: 6px; justify-content: flex-end; }

.btn-action {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text2);
  font-size: 11px;
  padding: 4px 10px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.btn-action:hover  { border-color: var(--accent); color: var(--accent); }
.btn-delete:hover  { border-color: var(--red); color: var(--red); }
.btn-update:hover  { border-color: var(--yellow); color: var(--yellow); }

.paging {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--border);
}

.page-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text2);
  font-size: 12px;
  padding: 5px 12px;
  cursor: pointer;
  font-family: inherit;
}
.page-btn:hover:not([disabled]) { border-color: var(--accent); color: var(--accent); }
.page-btn[disabled] { opacity: 0.35; cursor: not-allowed; }
.page-info { font-size: 12px; color: var(--text3); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text3);
}
.empty-state p { margin-top: 8px; font-size: 12px; }

/* ── RAW VIEWER MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 780px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h3 { font-size: 14px; font-weight: 600; }
.modal-meta { font-size: 11px; color: var(--text3); margin-top: 2px; }

.btn-close {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
.btn-close:hover { color: var(--text1); }

.modal-body {
  overflow-y: auto;
  padding: 20px;
  flex: 1;
}

.raw-text {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text2);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── STORY IDEA CARDS (modal) ── */
.story-idea-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.story-idea-num   { font-size: 10px; color: var(--text3); margin-bottom: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.story-idea-title { font-size: 13px; font-weight: 600; color: var(--text1); margin-bottom: 6px; }
.story-idea-text  { font-size: 12px; color: var(--text2); line-height: 1.6; white-space: pre-wrap; word-break: break-word; }

/* ── STORY LIST (classified view) ── */
.story-list { display: flex; flex-direction: column; }

.story-list-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.story-list-item:last-child { border-bottom: none; }

.story-list-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.story-list-num    { font-size: 11px; color: var(--text3); font-weight: 600; min-width: 28px; }
.story-list-source { font-size: 11px; color: var(--text3); margin-left: 4px; }
.story-list-title  { font-size: 14px; font-weight: 600; color: var(--text1); margin-bottom: 5px; }
.story-list-preview {
  font-size: 12px;
  color: var(--text2);
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.btn-expand {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
  padding: 4px 0 0;
  font-family: inherit;
}
.btn-expand:hover { text-decoration: underline; }

/* ── MULTISELECT DROPDOWN ── */
.multiselect-wrap { position: relative; }

.multiselect-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text1);
  font-size: 12px;
  padding: 6px 10px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.multiselect-btn:hover { border-color: var(--accent); }

.multiselect-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 0;
  z-index: 50;
  min-width: 160px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.multiselect-dropdown.open { display: block; }

.ms-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  font-size: 12px;
  color: var(--text2);
  cursor: pointer;
  text-transform: capitalize;
}
.ms-option:hover { background: var(--bg3); color: var(--text1); }
.ms-option input[type=checkbox] { accent-color: var(--accent); cursor: pointer; }

.ms-actions {
  display: flex;
  gap: 6px;
  padding: 7px 14px 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.ms-actions button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text3);
  font-size: 11px;
  padding: 2px 8px;
  cursor: pointer;
  font-family: inherit;
}
.ms-actions button:hover { border-color: var(--accent); color: var(--accent); }

.btn-edit-type {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text3);
  font-size: 10px;
  padding: 2px 7px;
  cursor: pointer;
  font-family: inherit;
  margin-left: 4px;
}
.btn-edit-type:hover { border-color: var(--accent); color: var(--accent); }

.btn-raw {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text3);
  font-size: 10px;
  padding: 2px 7px;
  cursor: pointer;
  font-family: inherit;
  margin-left: 4px;
}
.btn-raw:hover { border-color: var(--purple); color: var(--purple); }

.inline-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text1);
  font-size: 11px;
  padding: 3px 6px;
  font-family: inherit;
  outline: none;
}

#[id$="-form"] { display: inline-flex; align-items: center; gap: 5px; }

.btn-save-type {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
  font-family: inherit;
}
.btn-cancel-type {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text3);
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
  font-family: inherit;
}

/* ── COMMAND BOX ── */
.command-box {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin: 20px 28px 0;
  font-size: 12px;
}

.command-box h4 { font-size: 12px; font-weight: 600; margin-bottom: 8px; color: var(--text2); }

.cmd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  color: var(--green);
  display: block;
  margin-bottom: 6px;
}

/* ── DUPLICATES VIEW ── */
.dup-cluster {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 0 28px 16px;
  overflow: hidden;
}

.dup-cluster-header {
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.dup-cluster-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dup-cluster-count {
  font-size: 11px;
  color: var(--text3);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 8px;
}

.dup-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.dup-item:last-child { border-bottom: none; }

.dup-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.dup-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text1);
  margin-bottom: 3px;
}

.dup-item-preview {
  font-size: 12px;
  color: var(--text3);
  line-height: 1.5;
}

/* ── VERDICT BADGES ── */
.verdict-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.3px;
}
.verdict-badge.duplicate  { background: rgba(239,68,68,0.12); color: #ef4444; }
.verdict-badge.mixed      { background: rgba(245,158,11,0.12); color: #f59e0b; }
.verdict-badge.different  { background: rgba(34,197,94,0.12); color: #22c55e; }
.verdict-badge.unverified { background: var(--bg3); color: var(--text3); }

.dup-reason {
  font-size: 11px;
  color: var(--text3);
  font-style: italic;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-status {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 8px;
}
.item-status.canonical  { background: rgba(34,197,94,0.12); color: #22c55e; }
.item-status.duplicate  { background: rgba(239,68,68,0.12); color: #ef4444; }
.item-status.variant    { background: rgba(245,158,11,0.12); color: #f59e0b; }
.item-status.different  { background: rgba(99,102,241,0.12); color: #6366f1; }
.item-status.unclear    { background: var(--bg3); color: var(--text3); }
