:root {
  --ink: #101721;
  --muted: #637083;
  --soft: #edf3f7;
  --line: #d8e2ea;
  --panel: #ffffff;
  --nav: #07111d;
  --nav-2: #0d1b2a;
  --cyan: #00aee8;
  --cyan-2: #e7f8fd;
  --green: #29b56d;
  --green-bg: #e7f8ee;
  --orange: #f39b31;
  --orange-bg: #fff4e5;
  --red: #e44b55;
  --red-bg: #fff0f1;
  --shadow: 0 18px 50px rgba(15, 31, 47, .08);
  --radius: 8px;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: #f6f9fb;
}

button, input, select, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  background: linear-gradient(180deg, var(--nav), var(--nav-2));
  color: #fff;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 10px;
}

.brand strong {
  display: block;
  font-size: 21px;
  letter-spacing: 0;
}

.brand span {
  display: block;
  color: #9fb0c3;
  font-size: 12px;
  margin-top: 3px;
}

.brand-mark {
  width: 40px;
  height: 44px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  color: var(--cyan);
  font-weight: 900;
  line-height: .84;
}

.mark-h {
  font-size: 34px;
  border-right: 2px solid var(--cyan);
}

.mark-box {
  font-size: 11px;
  padding-left: 5px;
}

.nav {
  display: grid;
  gap: 5px;
}

.nav-item {
  width: 100%;
  border: 0;
  color: #d9e5ef;
  background: transparent;
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius);
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 14px;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(0, 174, 232, .13);
  color: #fff;
}

.sidebar-block {
  margin-top: auto;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.05);
  border-radius: var(--radius);
  padding: 16px;
}

.sidebar-block p {
  margin: 0 0 12px;
  color: #b8c8d8;
  text-transform: uppercase;
  font-size: 12px;
}

.sidebar-block dl {
  margin: 0;
  display: grid;
  gap: 9px;
}

.sidebar-block div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.sidebar-block dt {
  color: #dce7f0;
  font-size: 13px;
}

.sidebar-block dd {
  margin: 0;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
}

.report-btn {
  width: 100%;
  margin-top: 14px;
  min-height: 36px;
  border: 1px solid rgba(0, 174, 232, .35);
  border-radius: var(--radius);
  background: rgba(0, 174, 232, .12);
  color: #e8f8ff;
  font-weight: 800;
  font-size: 13px;
}

.version {
  color: #90a5b8;
  padding: 0 8px;
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 74px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 14px 22px;
}

.search-shell {
  height: 44px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid #cfdbe4;
  border-radius: var(--radius);
  padding: 0 12px;
  background: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.02);
}

.search-shell input {
  border: 0;
  outline: 0;
  min-width: 0;
  font-size: 15px;
}

.search-shell button {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: #e8eef3;
  color: #526273;
}

.primary-btn {
  border: 0;
  background: var(--cyan);
  color: #fff;
  font-weight: 700;
  border-radius: var(--radius);
  min-height: 42px;
  padding: 0 18px;
  box-shadow: 0 9px 20px rgba(0,174,232,.22);
}

.wide {
  width: 100%;
}

.ghost-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: #344256;
  border-radius: var(--radius);
  min-height: 36px;
  padding: 0 12px;
}

.user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user strong,
.user span {
  display: block;
  font-size: 13px;
}

.user span {
  color: var(--muted);
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #eaf1f6;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.content-grid {
  min-height: calc(100vh - 74px);
  display: grid;
  grid-template-columns: 350px minmax(0, 1fr) 300px;
  min-width: 0;
}

.results-panel,
.detail-panel,
.ingest-panel {
  min-width: 0;
  background: var(--panel);
}

.results-panel {
  border-right: 1px solid var(--line);
}

.ingest-panel {
  border-left: 1px solid var(--line);
  padding: 22px 18px;
}

.tabs,
.detail-tabs,
.source-tabs {
  display: flex;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.tabs {
  padding: 0 16px;
}

.tab,
.detail-tab,
.source-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  min-height: 46px;
  border-bottom: 2px solid transparent;
}

.tab.active,
.detail-tab.active,
.source-tab.active {
  color: var(--ink);
  border-bottom-color: var(--cyan);
}

.tab span {
  color: var(--cyan);
  margin-left: 4px;
}

.filters {
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.filters select,
.field input,
.field select,
.note-form textarea {
  width: 100%;
  border: 1px solid #cfdbe4;
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

.filters select {
  min-height: 36px;
  padding: 0 10px;
  font-size: 13px;
}

.quick-searches {
  padding: 0 16px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.quick-searches button {
  border: 1px solid var(--line);
  background: #fff;
  color: #344256;
  border-radius: 6px;
  min-height: 30px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 800;
}

.quick-searches button:hover {
  border-color: var(--cyan);
  color: #007eaa;
}

mark {
  background: #fff0a8;
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

.result-list {
  height: calc(100vh - 223px);
  overflow: auto;
  padding: 0 10px 18px;
}

.result-card {
  width: 100%;
  border: 1px solid transparent;
  background: #fff;
  border-bottom-color: var(--line);
  text-align: left;
  padding: 16px 14px;
  display: grid;
  gap: 8px;
}

.result-card:hover,
.result-card.active {
  border-color: var(--cyan);
  border-radius: var(--radius);
  background: linear-gradient(90deg, #fff, #f5fcff);
}

.result-card h3 {
  margin: 0;
  font-size: 15px;
}

.result-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.meta-row,
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.chip {
  background: #edf3f7;
  color: #536274;
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 12px;
  font-weight: 700;
}

.muted-text {
  color: var(--muted);
  font-size: 13px;
}

.status-pill {
  justify-self: end;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-worked {
  color: #16864d;
  background: var(--green-bg);
  border: 1px solid #bde8cf;
}

.status-review {
  color: #b26709;
  background: var(--orange-bg);
  border: 1px solid #ffd69b;
}

.status-reference {
  color: #226b98;
  background: var(--cyan-2);
  border: 1px solid #b9e9f7;
}

.detail-panel {
  padding: 22px 24px;
  overflow: auto;
}

.detail-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 14px;
}

.detail-head > div {
  min-width: 0;
}

.detail-head h1 {
  margin: 0 0 6px;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.detail-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.tag-row {
  margin: 18px 0 14px;
}

.solution-body {
  padding-top: 20px;
}

.section-block {
  border-bottom: 1px solid var(--line);
  padding: 0 0 22px;
  margin-bottom: 22px;
}

.section-block h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.section-block p,
.section-block li {
  color: #344256;
  line-height: 1.55;
  font-size: 14px;
}

.section-block ol,
.section-block ul {
  margin: 0;
  padding-left: 22px;
}

.data-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.data-table {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table h3 {
  margin: 0;
  padding: 12px;
  background: #f6f9fb;
  font-size: 14px;
}

.data-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table td,
.data-table th {
  border-top: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  background: #fbfdfe;
}

.source-link {
  display: block;
  color: #007eaa;
  text-decoration: none;
  margin: 8px 0;
  overflow-wrap: anywhere;
}

.decision-bar {
  position: sticky;
  bottom: -22px;
  margin: 24px -26px -22px;
  padding: 14px 26px;
  background: rgba(255,255,255,.96);
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.decision-bar span {
  color: var(--muted);
  font-size: 13px;
  margin-right: auto;
}

.worked,
.failed,
.partial {
  border-radius: var(--radius);
  min-height: 36px;
  padding: 0 12px;
  font-weight: 800;
}

.worked {
  border: 1px solid #bde8cf;
  background: var(--green-bg);
  color: #16864d;
}

.failed {
  border: 1px solid #ffc3c8;
  background: var(--red-bg);
  color: var(--red);
}

.partial {
  border: 1px solid #ffd69b;
  background: var(--orange-bg);
  color: #a75f00;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.panel-head h2,
.parse-box h3,
.history h3 {
  margin: 0;
  font-size: 16px;
}

.info-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
  font-size: 12px;
}

.source-tabs {
  margin-bottom: 18px;
}

.field {
  display: grid;
  gap: 7px;
  margin: 0 0 14px;
}

.field span {
  color: #344256;
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select {
  min-height: 42px;
  padding: 0 11px;
}

.field textarea {
  width: 100%;
  border: 1px solid #cfdbe4;
  border-radius: var(--radius);
  padding: 11px;
  resize: vertical;
  line-height: 1.45;
}

.source-text-field {
  display: none;
}

.source-text-field.visible {
  display: grid;
}

.parse-box {
  margin-top: 28px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.parse-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.parse-head span {
  color: #226b98;
  background: var(--cyan-2);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
}

#parseSteps {
  margin: 14px 0;
  padding-left: 20px;
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

#parseSteps li.done {
  color: var(--green);
  font-weight: 700;
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: #e8eef3;
  overflow: hidden;
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--cyan);
  transition: width .3s ease;
}

.history {
  margin-top: 32px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 10px;
  background: #fbfdfe;
}

.history-item strong {
  display: block;
  font-size: 13px;
}

.history-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(7,17,29,.38);
}

.note-form,
.review-form,
.report-form {
  width: min(520px, calc(100vw - 32px));
  padding: 22px;
}

.report-form,
.card-form {
  width: min(860px, calc(100vw - 32px));
}

.note-form h2,
.review-form h2,
.report-form h2,
.card-form h2 {
  margin: 0 0 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.review-form p,
.report-form p {
  margin: -6px 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.report-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

#reportText {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.45;
  background: #fbfdfe;
}

.note-form textarea {
  padding: 12px;
  resize: vertical;
}

.review-form textarea {
  padding: 12px;
  resize: vertical;
}

.review-list {
  display: grid;
  gap: 10px;
}

.review-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfe;
  padding: 12px;
}

.review-item strong {
  display: block;
  font-size: 14px;
}

.review-item p {
  margin: 8px 0;
  color: #344256;
}

.review-item dl {
  margin: 0;
  display: grid;
  gap: 6px;
  font-size: 13px;
}

.review-item dl div {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 10px;
}

.review-item dt {
  color: var(--muted);
  font-weight: 700;
}

.review-item dd {
  margin: 0;
}

.dialog-actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 1200px) {
  .app {
    grid-template-columns: 76px 1fr;
  }

  .brand div:last-child,
  .nav-item span,
  .sidebar-block,
  .version {
    display: none;
  }

  .content-grid {
    grid-template-columns: 340px 1fr;
  }

  .ingest-panel {
    display: none;
  }
}

@media (max-width: 820px) {
  body,
  .workspace,
  .content-grid,
  .results-panel,
  .detail-panel {
    max-width: 100vw;
    overflow-x: hidden;
  }

  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .topbar {
    grid-template-columns: 1fr;
    height: auto;
  }

  .topbar .primary-btn {
    width: 100%;
  }

  .user {
    display: none;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .results-panel {
    border-right: 0;
  }

  .result-list {
    height: auto;
    max-height: 46vh;
  }

  .detail-panel {
    padding: 18px;
  }

  .detail-head {
    grid-template-columns: auto 1fr;
    align-items: start;
  }

  .detail-head .status-pill {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .detail-head h1 {
    max-width: calc(100vw - 106px);
    font-size: 20px;
  }

  .section-block p,
  .section-block li {
    max-width: calc(100vw - 36px);
    overflow-wrap: anywhere;
  }

  .detail-tabs,
  .tabs {
    max-width: calc(100vw - 36px);
    overflow-x: auto;
    scrollbar-width: none;
  }

  .detail-tabs::-webkit-scrollbar,
  .tabs::-webkit-scrollbar {
    display: none;
  }

  .detail-tab,
  .tab {
    flex: 0 0 auto;
  }

  .data-grid {
    grid-template-columns: 1fr;
  }

  .decision-bar {
    margin-inline: -18px;
    padding-inline: 18px;
  }
}
