@import url("/layout-module/css/home.css");

.page {
  width: min(1000px, calc(100vw - 32px));
}

.version-badge {
  position: fixed;
  top: 18px;
  right: 18px;
  left: auto;
  inset: auto 18px auto auto;
  z-index: 1000;
}

.top-menu {
  position: absolute;
  top: 24px;
  right: 170px;
  z-index: 2;
}

.settings-control,
.help-control {
  position: relative;
  display: inline-flex;
}

.settings-icon-button {
  border: 0;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

button.settings-icon-button {
  width: 28px;
  min-width: 0;
  min-height: 22px;
  padding: 0;
  color: var(--ink);
}

.settings-menu,
.help-menu {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  z-index: 20;
  display: none;
  min-width: 270px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 30px rgba(28, 37, 43, 0.18);
}

.settings-menu {
  min-width: 270px;
}

.help-menu {
  width: min(340px, calc(100vw - 32px));
}

.settings-control.open .settings-menu {
  display: grid;
  gap: 5px;
}

.help-control.open .help-menu {
  display: grid;
  gap: 8px;
}

.help-menu p {
  margin: 0;
  line-height: 1.35;
}

.help-menu kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(28, 37, 43, 0.08);
  font: inherit;
  font-weight: 800;
}

.settings-block-title {
  margin-top: 4px;
  padding: 5px 6px 2px;
  color: rgba(28, 37, 43, 0.68);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

.settings-block-title:first-child {
  margin-top: 0;
}

.settings-menu-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 4px 6px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 700;
  white-space: nowrap;
}

.settings-menu-row input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

h1 {
  margin: 0 0 8px;
}

.subtitle {
  margin: 0 0 20px;
}

.keyword-form {
  display: grid;
  gap: 12px;
  padding-top: 8px;
}

.keyword-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: end;
}

select,
input,
textarea,
button {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}

select,
input,
button {
  min-height: 30px;
  padding: 0 10px;
}

textarea {
  min-height: 150px;
  padding: 10px;
  resize: vertical;
}

button {
  width: max-content;
  min-width: 140px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
}

.toggle-row {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.toggle-row input {
  width: auto;
}

.keyword-goal-decision,
.header-unknown-analysis,
.keyword-entry {
  display: grid;
  gap: 12px;
  margin: 18px 0 20px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.66);
}

.keyword-goal-decision,
.keyword-entry {
  border-left: 5px solid rgba(41, 87, 138, 0.88);
}

.header-unknown-analysis {
  border-left: 5px solid rgba(95, 85, 35, 0.88);
}

.keyword-goal-decision > summary,
.header-unknown-analysis > summary,
.keyword-entry > summary {
  cursor: pointer;
  list-style: none;
}

.keyword-goal-decision > summary::-webkit-details-marker,
.header-unknown-analysis > summary::-webkit-details-marker,
.keyword-entry > summary::-webkit-details-marker {
  display: none;
}

.keyword-goal-decision > summary::before,
.header-unknown-analysis > summary::before,
.keyword-entry > summary::before {
  content: "▾";
  margin-right: 2px;
  color: #5f5523;
  font-weight: 900;
}

.keyword-goal-decision:not([open]) > summary::before,
.header-unknown-analysis:not([open]) > summary::before,
.keyword-entry:not([open]) > summary::before {
  content: "▸";
}

.keyword-goal-decision:not([open]),
.header-unknown-analysis:not([open]),
.keyword-entry:not([open]) {
  gap: 0;
}

.header-unknown-analysis p,
.goal-summary p {
  margin: 0;
}

.keyword-entry label {
  gap: 8px;
  font-size: 0.9rem;
}

.keyword-entry textarea {
  min-height: 110px;
}

.keyword-entry .goal-head {
  justify-content: center;
  position: relative;
  padding-right: 96px;
  padding-left: 96px;
}

.keyword-entry .goal-head::before {
  position: absolute;
  left: 0;
}

.keyword-entry .goal-head h2 {
  text-align: center;
}

.keyword-entry .goal-head .goal-status {
  position: absolute;
  right: 0;
}

.keyword-goal-decision.deferred {
  border-left-color: rgba(143, 29, 29, 0.88);
}

.goal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.goal-head h2 {
  margin: 0;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.goal-status {
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(41, 87, 138, 0.16);
  color: #173d6c;
  font-size: 0.8rem;
  font-weight: 700;
}

.goal-status.deferred {
  background: rgba(143, 29, 29, 0.14);
  color: #8f1d1d;
}

.goal-summary {
  display: grid;
  gap: 4px;
}

.goal-known {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.goal-pill {
  display: inline-flex;
  gap: 5px;
  padding: 4px 7px;
  border-radius: 8px;
  background: rgba(28, 37, 43, 0.08);
  font-size: 0.84rem;
}

.goal-signal-table {
  font-size: 0.86rem;
}

.keyword-results,
.keyword-pdf-view {
  margin-top: 24px;
}

.pdf-page-card {
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.76);
}

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.page-head h2 {
  margin: 0;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.page-note {
  font-size: 0.92rem;
  color: #8b2f15;
}

.pdf-stage {
  position: relative;
  width: 100%;
}

.pdf-image {
  width: 100%;
  display: block;
  border-radius: 14px;
  border: 1px solid rgba(28, 37, 43, 0.08);
  box-shadow: 0 18px 35px rgba(28, 37, 43, 0.12);
}

.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.overlay-box {
  position: absolute;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
  pointer-events: auto;
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease, background-color 120ms ease;
}

.overlay-box:hover {
  z-index: 4;
  transform: scale(1.01);
  filter: saturate(1.18) brightness(1.06);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.72), 0 0 0 3px rgba(18, 24, 28, 0.18);
}

.overlay-label {
  position: absolute;
  top: -2px;
  left: -2px;
  transform: translateY(-100%);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 3px 7px;
  border-radius: 8px 8px 8px 0;
  color: #fff;
  font-size: 0.76rem;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
}

.overlay-box.keyword-match {
  border: 3px solid rgba(196, 45, 78, 0.96);
  background: rgba(255, 121, 153, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.48), 0 0 0 2px rgba(196, 45, 78, 0.18);
  z-index: 10;
}

.overlay-box.keyword-match .overlay-label {
  background: rgba(196, 45, 78, 0.96);
}

.overlay-box.header-analysis {
  z-index: 8;
  pointer-events: auto;
}

.overlay-box.header-analysis.unknown {
  border: 2px dashed rgba(84, 91, 103, 0.92);
  background: rgba(84, 91, 103, 0.12);
  cursor: pointer;
}

.overlay-box.header-analysis.unknown .overlay-label {
  background: rgba(84, 91, 103, 0.96);
}

.overlay-box.header-analysis.candidate {
  border: 3px solid rgba(95, 85, 35, 0.96);
  background: rgba(234, 179, 8, 0.18);
}

.overlay-box.header-analysis.candidate .overlay-label {
  background: rgba(95, 85, 35, 0.96);
}

.overlay-box.header-analysis.found {
  border: 3px solid rgba(21, 128, 61, 0.96);
  background: rgba(74, 222, 128, 0.18);
}

.overlay-box.header-analysis.found .overlay-label {
  background: rgba(21, 128, 61, 0.96);
}

.overlay-box:not(.keyword-match) {
  border: 2px solid rgba(41, 87, 138, 0.72);
  background: rgba(41, 87, 138, 0.08);
}

.overlay-box:not(.keyword-match) .overlay-label {
  background: rgba(41, 87, 138, 0.92);
}

.overlay-box.region {
  border-color: rgba(114, 64, 7, 0.85);
  background: rgba(255, 208, 122, 0.14);
  z-index: 1;
  pointer-events: none;
}

.overlay-box.region.sender-address {
  border-color: rgba(21, 128, 61, 0.96);
  background: rgba(74, 222, 128, 0.16);
}

.overlay-box.region.sender-address .overlay-label {
  background: rgba(21, 128, 61, 0.96);
}

.overlay-box.region.recipient-address {
  border-color: rgba(14, 116, 144, 0.96);
  background: rgba(34, 211, 238, 0.16);
}

.overlay-box.region.recipient-address .overlay-label {
  background: rgba(14, 116, 144, 0.96);
}

.overlay-box.token {
  border-color: rgba(78, 110, 94, 0.92);
  background: rgba(78, 110, 94, 0.14);
}

.overlay-box.candidate,
.overlay-box.table-structure {
  border-color: rgba(184, 92, 56, 0.92);
  background: rgba(184, 92, 56, 0.10);
}

.overlay-line {
  position: absolute;
  opacity: 0.88;
}

.overlay-line.vertical {
  width: 2px;
  background: rgba(41, 87, 138, 0.92);
}

.overlay-line.horizontal {
  height: 2px;
  background: rgba(41, 87, 138, 0.92);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

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

th {
  background: rgba(28, 37, 43, 0.08);
}

.keyword-hit {
  display: inline-flex;
  gap: 5px;
  margin: 0 6px 6px 0;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(184, 92, 56, 0.16);
}

.ocr-token-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.ocr-token-chip {
  display: inline-flex;
  padding: 3px 7px;
  border: 1px solid rgba(95, 85, 35, 0.26);
  border-radius: 6px;
  background: rgba(95, 85, 35, 0.1);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.25;
}

.ocr-token-chip.found {
  border-color: rgba(21, 128, 61, 0.42);
  background: rgba(74, 222, 128, 0.22);
  color: #14532d;
  font-weight: 700;
}

.analysis-status {
  display: inline-flex;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(84, 91, 103, 0.14);
  font-weight: 700;
}

.analysis-status.candidate {
  background: rgba(234, 179, 8, 0.22);
  color: #5f5523;
}

.analysis-status.found {
  background: rgba(74, 222, 128, 0.22);
  color: #14532d;
}

.header-row-status-cell {
  cursor: pointer;
}

.header-row-status-cell:hover .analysis-status {
  box-shadow: 0 0 0 2px rgba(41, 87, 138, 0.18);
}

.keyword-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(28, 37, 43, 0.26);
}

.keyword-modal-backdrop.open {
  display: flex;
}

.keyword-modal {
  position: relative;
  display: grid;
  gap: 12px;
  width: min(420px, calc(100vw - 32px));
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 24px 60px rgba(28, 37, 43, 0.24);
}

.keyword-modal h2 {
  margin: 0;
  padding-right: 32px;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.keyword-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  min-width: 0;
  min-height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(28, 37, 43, 0.06);
  color: var(--ink);
}

.keyword-modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.keyword-modal-actions button {
  width: auto;
  min-width: 128px;
}

.keyword-modal-actions .danger {
  border-color: rgba(143, 29, 29, 0.32);
  background: rgba(143, 29, 29, 0.1);
  color: #8f1d1d;
}

.keyword-modal-message {
  min-height: 18px;
  margin: 0;
  color: #8f1d1d;
  font-size: 0.88rem;
  font-weight: 700;
}

.keyword-modal-message.success {
  color: #14532d;
}

.keyword-status-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 16px;
  border-top: 1px solid rgba(28, 37, 43, 0.16);
  background: rgba(255, 255, 255, 0.96);
  color: rgba(28, 37, 43, 0.74);
  font-size: 0.88rem;
  font-weight: 700;
  box-shadow: 0 -8px 24px rgba(28, 37, 43, 0.08);
}

.keyword-status-bar.success {
  color: #14532d;
}

.keyword-status-bar.error {
  color: #8f1d1d;
}

.keyword-direction-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.keyword-direction-row span {
  flex: 0 0 100%;
  font-weight: 700;
}

.keyword-direction-row label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: auto;
  font-weight: 400;
}

.keyword-direction-row input {
  width: auto;
  min-height: 0;
}

.keyword-pool-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.keyword-pool-fields label,
.keyword-pool-fields select,
.header-row-modal-table input,
.header-row-modal-table td {
  min-width: 0;
}

.keyword-new-value {
  display: none;
  margin-top: 4px;
}

.keyword-new-value.open {
  display: block;
}

.header-row-modal {
  width: min(760px, calc(100vw - 40px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  will-change: transform;
}

.header-row-modal-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -16px -16px 4px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  background: rgba(28, 37, 43, 0.08);
  cursor: move;
  touch-action: none;
  user-select: none;
}

.header-row-modal-bar h2 {
  margin: 0;
  padding-right: 0;
}

.header-row-modal-bar .keyword-modal-close {
  position: static;
  flex: 0 0 auto;
}

.header-row-modal-table td {
  overflow-wrap: anywhere;
}

.header-row-modal-table th {
  width: 30%;
}

.empty-state,
.muted {
  color: rgba(28, 37, 43, 0.66);
}

.error {
  color: #8f1d1d;
  font-weight: 700;
}

@media (max-width: 720px) {
  .page {
    width: calc(100vw - 20px);
    margin: 10px auto;
    padding: 16px;
  }

  .version-badge {
    top: 12px;
    right: 12px;
    inset: auto 12px auto auto;
  }

  .top-menu {
    position: static;
    margin-bottom: 12px;
    width: max-content;
  }

  .keyword-grid,
  .keyword-pool-fields {
    grid-template-columns: 1fr;
  }

  button:not(.settings-icon-button) {
    width: 100%;
  }
}
