* { box-sizing: border-box; }
html { height: 100%; }
body {
  font-family: -apple-system, Segoe UI, Roboto, sans-serif;
  margin: 0;
  background: #f4f4f4;
  color: #1a1a1a;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.banner {
  background: #c0392b;
  color: #fff;
  font-weight: bold;
  text-align: center;
  padding: 14px;
  font-size: 1.1em;
  letter-spacing: .02em;
  flex: 0 0 auto;
}
.app-body {
  flex: 1 1 auto;
  display: flex;
  overflow: hidden;
  min-height: 0;
}
.side-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #2c2c2c;
  padding: 1em 0;
  flex: 0 0 190px;
  overflow-y: auto;
}
.tab-btn { white-space: nowrap; }
.tab-btn {
  background: none;
  border: none;
  color: #ccc;
  padding: 12px 18px;
  cursor: pointer;
  font-size: .95em;
  text-align: left;
  width: 100%;
}
.tab-btn.active { color: #fff; border-left: 3px solid #c0392b; background: rgba(255,255,255,0.06); font-weight: bold; }
main { padding: 1.5em; max-width: none; margin: 0; flex: 1 1 auto; overflow-y: auto; min-height: 0; }
.muted { color: #777; font-style: italic; }
.status-bar {
  flex: 0 0 auto;
  background: #1a1a1a;
  color: #ddd;
  display: flex;
  align-items: center;
  padding: 0 1em;
  height: 36px;
  font-size: .9em;
}
.status-bar.offline { background: #c0392b; color: #fff; }

.subtabs { display: flex; gap: .4em; margin: .6em 0; }
.subtab-btn { padding: .3em .9em; cursor: pointer; }
.subtab-btn.active { font-weight: bold; border-bottom: 3px solid #2c6fbb; }
.subpanel { display: none; }
.subpanel.active { display: block; }
.tabpanel { display: none; }
.tabpanel.active { display: block; }

.dropgrid { display: grid; grid-template-columns: 1fr; gap: 1em; margin: 1em 0; max-width: 520px; }
.dropzone {
  border: 2px dashed #999;
  border-radius: 8px;
  padding: 2em 1em;
  text-align: center;
  background: #fff;
  cursor: pointer;
}
.dropzone.dragover { border-color: #c0392b; background: #fdecea; }

button {
  padding: 8px 14px;
  border: 1px solid #888;
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
}
button:hover { background: #eee; }
button.danger { border-color: #c0392b; color: #c0392b; }
button:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: .6em; margin: 1em 0; flex-wrap: wrap; }
.note { color: #555; font-size: .9em; }

table { width: 100%; border-collapse: collapse; background: #fff; }
table th, table td { border: 1px solid #ddd; padding: 6px 10px; text-align: left; font-size: .92em; }
table th { background: #eee; }

.review-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 300px; gap: 1em; height: 60vh; }
.ner-panel { margin-top: 1em; background: #fff; border: 1px solid #ddd; border-radius: 6px; padding: 0.5em 1em; }
.ner-panel summary { cursor: pointer; font-weight: bold; }
.ner-panel ul { list-style: none; padding: 0; margin: 0.5em 0 0 0; }
.ner-panel li { display: flex; justify-content: space-between; align-items: center; padding: 0.3em 0; border-bottom: 1px solid #eee; }
.pane { background: #fff; border: 1px solid #ddd; border-radius: 6px; overflow-y: auto; padding: 1em; position: relative; }
.page-nav {
  position: sticky;
  top: -1em;
  margin: -1em -1em 1em -1em;
  padding: 1em;
  background: #fff;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #eee;
}
.page-image-wrap { position: relative; }
.page-image { max-width: 100%; display: block; }
.page-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.dropzone.processing { opacity: 0.6; pointer-events: none; }
.processing-note { font-style: italic; }
.page-image-placeholder {
  background: repeating-linear-gradient(45deg, #ccc, #ccc 10px, #bbb 10px, #bbb 20px);
  height: 50vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
  font-weight: bold;
}
.page-image-placeholder[hidden] { display: none; }
.entity-boxes { position: absolute; top: 0; left: 0; right: 0; bottom: 0; pointer-events: none; }
.entity-boxes .box { position: absolute; border: 2px solid #e67e22; background: rgba(230,126,34,.15); }

.editor { line-height: 1.8; }
.token {
  background: #fdebd0;
  border-bottom: 2px solid #e67e22;
  border-radius: 3px;
  padding: 0 2px;
  cursor: pointer;
  position: relative;
}
.token[data-original=""]:hover::after { display: none; }
.token:hover::after {
  content: attr(data-original);
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 20;
  white-space: nowrap;
  pointer-events: none;
  background: #333;
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: .8em;
  margin-left: 4px;
}
.pane-tools h3 { margin-top: 0; }
#mask-popup {
  background: #f9f9f9;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 1em;
}
#mask-popup select, #mask-popup input { display: block; width: 100%; margin: .4em 0; }
#mask-popup button:disabled, #mask-popup select:disabled { opacity: .5; cursor: not-allowed; }
.mask-selected-label { font-style: italic; color: #555; margin: 0 0 .6em 0; word-break: break-word; }

#ner-list { list-style: none; padding: 0; max-height: 220px; overflow-y: auto; }
.ner-toolbar {
  display: flex;
  align-items: center;
  gap: 1em;
  margin-bottom: 0.5em;
}
.ner-controls select {
  margin: 0 0.3em;
}
#ner-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5em;
  flex-wrap: wrap;
  padding: 0.3em 0;
}
#ner-list li { display: flex; justify-content: space-between; align-items: center; padding: .4em 0; border-bottom: 1px solid #eee; }
#ner-list button { padding: 2px 8px; font-size: .8em; }

textarea { width: 100%; min-height: 120px; font-family: inherit; padding: .6em; }

@keyframes token-flash-fade { from { background: #ffe58a; } to { background: transparent; } }
.token-flash { animation: token-flash-fade 1.6s ease-out; }

#piece-table th, #piece-table td, #entity-table th, #entity-table td { font-size: 1.1em; padding: 9px 12px; }

#entity-table th[data-sort] { cursor: pointer; user-select: none; }
#entity-table th.sort-asc::after { content: " ▲"; }
#entity-table th.sort-desc::after { content: " ▼"; }

.status-bar.busy { background: #1f4e79; color: #fff; }
.status-bar.busy #status-text::before {
  content: ""; display: inline-block; width: .8em; height: .8em; margin-right: .6em;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%;
  vertical-align: -.1em; animation: sbspin .9s linear infinite;
}
@keyframes sbspin { to { transform: rotate(360deg); } }

.ner-text { cursor: pointer; text-decoration: underline dotted; }
mark.ner-hit { background: #ffe58a; color: inherit; padding: 0 1px; border-radius: 2px; }
mark.ner-hit-active { background: #ff9f43; outline: 2px solid #ff9f43; }

.ocr-bar{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr) 300px;gap:1em;margin-bottom:8px}
.ocr-bar .ocr-buttons{grid-column:2}
.ocr-bar button[hidden]{display:none}
.modal-back{position:fixed;inset:0;background:rgba(0,0,0,.4);display:flex;align-items:center;justify-content:center;z-index:1000}
.modal-box{background:#fff;color:#000;padding:18px;border-radius:8px;max-width:460px}
.modal-box .modal-actions{margin-top:12px;display:flex;gap:8px;flex-wrap:wrap}
.ocr-edit[hidden],#pseudo-editor[hidden]{display:none}
.ocr-edit textarea{width:100%;min-height:50vh;font-family:inherit;box-sizing:border-box}
.ocr-actions{margin-top:6px}

.filtered-out { display: none !important; }
#ner-filter, #entity-filter { padding: 2px 6px; margin-left: .5em; }

.help { max-width: 60em; line-height: 1.5; }
.help h3 { margin-top: 1.4em; }
.help code { background: #eee; padding: 1px 5px; border-radius: 3px; }

.processing-note::before {
  content: ""; display: inline-block; width: 1em; height: 1em; margin-right: .5em;
  border: 3px solid rgba(31,78,121,.25); border-top-color: #1f4e79; border-radius: 50%;
  vertical-align: -.2em; animation: sbspin .9s linear infinite;
}

.session-picker { display: flex; gap: .3em; margin-bottom: .8em; }
.session-picker select { flex: 1; min-width: 0; }

/* ph2ui: user bar, sessions panel, user form */
.user-bar { display: flex; gap: .3em; align-items: center; margin-bottom: .6em; }
.user-bar .user-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: bold; }
.side-panel { margin-top: 1em; font-size: .9em; }
.side-panel summary { cursor: pointer; font-weight: bold; }
.sess-list { list-style: none; margin: .4em 0; padding: 0; }
.sess-list li { display: flex; gap: .2em; margin-bottom: .2em; }
.sess-list li.current .sess-open { font-weight: bold; text-decoration: underline; }
.sess-list .sess-open { flex: 1; min-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; }
.user-form label { display: block; margin: .3em 0; }
.user-form input { width: 100%; box-sizing: border-box; }
.user-msg { margin: .4em 0 0; }
.user-msg.ok { color: #1a7f37; }
.user-msg.err { color: #c62828; }

html { color-scheme: light; }
select, option, input, textarea { background: #fff; color: #1a1a1a; }
option { background: #fff; color: #1a1a1a; }

.side-menu .user-bar, .side-menu .side-panel, .side-menu .user-name, .side-menu label, .side-menu summary { color: #eee; }
.side-menu .user-msg.ok { color: #6fdc8c; }
.side-menu .user-msg.err { color: #ff8a80; }
.side-menu .side-panel { padding: 0 12px; }
.side-menu .user-bar { padding: 0 12px; }
.side-menu .session-picker { padding: 0 12px; }

.side-menu .user-bar { flex-direction: column; align-items: stretch; gap: .4em; }
.side-menu .user-bar .user-name { flex: none; white-space: normal; overflow: visible; word-break: break-all; }
