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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #0b1020;
  color: #f5f5f7;
}

body {
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.6rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: radial-gradient(circle at top left, #243b6b 0, #0b1020 45%);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-left h1 {
  cursor: pointer;
}

.header-logo {
  height: 36px;
  width: auto;
  object-fit: contain;
  cursor: pointer;
}

.app-header h1 {
  margin: 0;
  font-weight: 400;
  letter-spacing: 0.04em;
  font-size: 1.15rem;
}

.app-header .subtitle {
  margin: 0;
  font-size: 0.75rem;
  color: #c4c7d1;
}

.subtitle-wrap {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.app-header .version {
  display: block;
  font-size: 0.65rem;
  color: #8a8ea0;
}

.header-partner-logo {
  display: inline-block;
  height: 24px;
  width: auto;
  opacity: 0.95;
  flex: 0 0 auto;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.header-right .insert-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #c4c7d1;
}

.header-right input[type="text"] {
  width: 9rem;
}

.header-right button {
  white-space: nowrap;
}

.settings-icon-btn {
  width: auto;
  height: auto;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  box-shadow: none;
  text-transform: none;
  letter-spacing: 0;
}

.settings-icon-btn img {
  width: 24px;
  height: 24px;
  display: block;
}

.header-right #status {
  font-size: 0.75rem;
  color: #7be87b;
}

#clearAllBtn {
  background: linear-gradient(135deg, #ff5f5f, #ff3a3a);
  color: #fff;
}

#addToBatchBtn {
  background: linear-gradient(135deg, #5aaf5a, #3a8a3a);
  color: #fff;
}

.batch-badge {
  background: #1a2a3a !important;
  color: #7ee0ff !important;
  border: 1px solid #3a4a6a !important;
}
.batch-badge:hover {
  border-color: #5a9cf5 !important;
}

/* Batch panel */
.batch-panel {
  border-bottom: 1px solid #2a2e3e;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
}
.batch-panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.batch-dl-btn {
  font-size: 0.65rem;
  color: #050711;
  background: linear-gradient(135deg, #4da3ff, #00d5ff);
  border: none;
  border-radius: 0.25rem;
  padding: 0.15rem 0.5rem;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.batch-dl-btn:hover {
  filter: brightness(1.12);
}
.batch-list {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.batch-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.3rem;
  border-radius: 0.25rem;
  font-size: 0.72rem;
}
.batch-item:hover {
  background: rgba(255, 255, 255, 0.04);
}
.batch-item-openable {
  cursor: pointer;
  border: 1px dashed rgba(126, 224, 255, 0.25);
}
.batch-item-openable:hover {
  background: rgba(126, 224, 255, 0.1);
  border-color: rgba(126, 224, 255, 0.6);
}
.batch-item-num {
  color: #5a6a8a;
  font-weight: 600;
  min-width: 1.5ch;
  text-align: right;
}
.batch-item-isbn {
  color: #ffe57f;
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 0.68rem;
}
.batch-item-title {
  flex: 1;
  color: #c4c7d1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.batch-item-openhint {
  font-size: 0.62rem;
  color: #7ee0ff;
  border: 1px solid rgba(126, 224, 255, 0.55);
  border-radius: 0.3rem;
  padding: 0.02rem 0.28rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.batch-item-remove {
  font-size: 0.7rem;
  color: #ff5f5f;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 0.3rem;
  box-shadow: none;
  opacity: 0.4;
}
.batch-item:hover .batch-item-remove {
  opacity: 1;
}
.batch-item-remove:hover {
  color: #ff9a9a;
}

.app-main {
  flex: 1;
  display: flex;
  align-items: stretch;
  padding: 1rem 1.5rem 1.25rem;
  gap: 0.75rem;
}

.record-section,
.preview-section {
  background: radial-gradient(circle at top left, #181f38 0, #080b16 55%);
  border-radius: 0.9rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.8);
  padding: 1rem 1.25rem 1.1rem;
}

.record-section {
  flex: 0 0 70%;
  min-width: 320px;
}

.preview-section {
  flex: 1 1 auto;
  min-width: 260px;
  display: flex;
  flex-direction: column;
}

.preview-section h2 {
  margin-top: 0;
  font-size: 0.95rem;
  font-weight: 500;
  color: #e1e4ed;
}

.record-preview {
  flex: 1 1 auto;
  overflow-y: auto;
  margin-top: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: 0.55rem;
  background: #050711;
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-family: "SF Mono", ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 0.78rem;
  line-height: 1.55;
  letter-spacing: 0.03em;
  word-break: break-all;
  white-space: pre-wrap;
}

.record-preview .prev-tag {
  color: #7ee0ff;
  font-weight: 600;
}

.record-preview .prev-ind {
  color: #8085a0;
}

.record-preview .prev-code {
  color: #ffe57f;
}

.record-preview .prev-val {
  color: #f5f5f7;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.5rem;
}

.field-row:nth-of-type(odd) {
  background-color: rgba(255, 255, 255, 0.02);
}

.field-008 {
  margin-bottom: 0.5rem;
}

.tag {
  flex: 0 0 auto;
  min-width: 3ch;
  text-align: right;
  margin-right: 0.4rem;
  font-family: "SF Mono", ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 0.85rem;
  font-weight: 600;
  color: #7ee0ff;
}

.insert-row {
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.insert-label {
  font-size: 0.8rem;
  color: #c4c7d1;
}

/* 008 inputs – keep them compact to match fixed positions */
.field-008 select,
.field-008 input[type="text"] {
  font-variant-numeric: tabular-nums;
}

#f008_type_of_date,
#f008_date_1,
#f008_date_2,
#f008_place,
#f008_illustrations,
#f008_target_audience,
#f008_nature_of_content,
#f008_language {
  width: 3.8rem;
}

#f008_literary_form,
#f008_index,
#f008_biography {
  width: 3rem;
}

input[type="text"],
select,
textarea.sf-textarea {
  min-width: 0;
  padding: 0.25rem 0.4rem;
  border-radius: 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(9, 12, 24, 0.85);
  color: #f5f5f7;
  font-size: 0.8rem;
}

textarea.sf-textarea {
  flex: 1 1 auto;
  min-height: 4rem;
  resize: vertical;
  font-family: inherit;
  line-height: 1.4;
}

input[type="text"]:focus,
select:focus,
textarea.sf-textarea:focus {
  outline: 2px solid #4da3ff;
  outline-offset: 1px;
  border-color: #4da3ff;
}

input[type="text"]::placeholder,
textarea.sf-textarea::placeholder {
  color: #8085a0;
}

input[title="ind1"],
input[title="ind2"] {
  width: 1.6rem;
  padding-left: 0.3rem;
  padding-right: 0.1rem;
  text-align: center;
}

button {
  cursor: pointer;
  border-radius: 999px;
  border: none;
  padding: 0.35rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  /*text-transform: uppercase;*/
  background: linear-gradient(135deg, #4da3ff, #00d5ff);
  color: #050711;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
}

button:hover {
  filter: brightness(1.08);
}

button:focus-visible {
  outline: 2px solid #ffe57f;
  outline-offset: 2px;
}

.actions {
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.field-hint {
  margin-bottom: 0.35rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.35rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-family: "SF Mono", ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 0.6rem;
  line-height: 1.35;
  white-space: pre-wrap;
  color: #9a9db0;
}

.field-hint:empty {
  display: none;
}

.field-hint strong {
  color: #c4c7d1;
  font-size: 0.62rem;
}

.hint-code {
  display: inline-block;
  min-width: 2ch;
  color: #ffe57f;
  font-weight: 600;
}

.field-hint a {
  color: #ffe57f;
  text-decoration: underline;
  text-decoration-color: rgba(255, 229, 127, 0.7);
}

.field-hint a:hover,
.field-hint a:focus-visible {
  color: #fff1b0;
  text-decoration-color: rgba(255, 241, 176, 0.9);
}

.preview-actions {
  margin-top: auto;
  justify-content: flex-start;
}

.del-btn {
  margin-left: 0.4rem;
  padding: 0.1rem 0.45rem;
  font-size: 0.85rem;
  line-height: 1;
  border-radius: 0.3rem;
  background: transparent;
  color: #ff5f5f;
  border: 1px solid rgba(255, 95, 95, 0.3);
  box-shadow: none;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.4;
  transition: opacity 0.15s;
}

.field-row:hover .del-btn {
  opacity: 1;
}

.del-btn:hover {
  background: rgba(255, 95, 95, 0.15);
  opacity: 1;
}

#status {
  font-size: 0.8rem;
  color: #c4c7d1;
}

.app-footer {
  padding: 0.5rem 1.5rem 0.9rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.75rem;
  color: #8a8fad;
  background: #050711;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.splitter {
  width: 4px;
  min-width: 4px;
  flex: 0 0 4px;
  cursor: col-resize;
  background: linear-gradient(to bottom, #3e4a7a, #151a2a);
  border-radius: 999px;
  align-self: stretch;
}

@media (max-width: 900px) {
  .app-main {
    flex-direction: column;
  }

  .splitter {
    display: none;
  }

  .preview-section {
    margin-top: 0.75rem;
  }

  .record-section {
    flex-basis: auto;
  }
}

/* ---- FAST autocomplete dropdown ---- */
.fast-dropdown {
  position: fixed;
  z-index: 1000;
  max-height: 340px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #5a9cf5 #121628;
  background: #1a1e2e;
  border: 1px solid #3a3f55;
  border-radius: 0.35rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-size: 0.8rem;
}

.fast-dropdown::-webkit-scrollbar {
  width: 10px;
}

.fast-dropdown::-webkit-scrollbar-track {
  background: #121628;
}

.fast-dropdown::-webkit-scrollbar-thumb {
  background: #5a9cf5;
  border-radius: 8px;
  border: 2px solid #121628;
}

.fast-dropdown-item {
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  color: #e0e2ea;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fast-dropdown-item:hover,
.fast-dropdown-item.selected {
  background: #2a3a5c;
  color: #fff;
}

.fast-alt {
  color: #7a7f96;
  font-size: 0.7rem;
}

/* 300$b color qualifier checkboxes */
.f300-color-label {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  margin-left: 0.4rem;
  cursor: pointer;
  user-select: none;
}
.f300-color-cb {
  accent-color: #5a9cf5;
  cursor: pointer;
  margin: 0;
}

/* Cover image section */
.cover-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid #2a2e3e;
  margin-bottom: 0.5rem;
}
.cover-images {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}
.cover-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}
.cover-item img {
  width: 150px;
  height: auto;
  border-radius: 0.25rem;
  border: 1px solid #3a3f55;
  background: #12141f;
  cursor: pointer;
}
.cover-item img:hover {
  border-color: #5a9cf5;
}
.cover-source {
  font-size: 0.6rem;
  color: #6a6e82;
  text-align: center;
}
.cover-dl-btn {
  font-size: 0.6rem;
  color: #5a9cf5;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}
.cover-dl-btn:hover {
  color: #8abcff;
}
.cover-dl-note {
  font-size: 0.6rem;
  color: #8a8ea0;
}
.cover-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  width: 100%;
}
.cover-status {
  flex: 1;
  font-size: 0.7rem;
  color: #6a6e82;
}
.cover-clear-btn {
  font-size: 0.65rem;
  color: #ff7b7b;
  background: none;
  border: 1px solid #3a3f55;
  border-radius: 0.25rem;
  padding: 0.1rem 0.5rem;
  cursor: pointer;
}
.cover-clear-btn:hover {
  background: #2a1a1a;
  border-color: #ff7b7b;
}

/* ---- Suggestions panel ---- */
.suggestions-panel {
  border-bottom: 1px solid #2a2e3e;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
}
.suggestions-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.suggestions-title-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  flex: 1;
  min-width: 0;
}
.suggestions-links {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.35rem;
}
.suggestions-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #7ee0ff;
  display: block;
}
.suggestions-status {
  font-size: 0.7rem;
  color: #6a6e82;
  line-height: 1.2;
  display: block;
  width: 100%;
}
.ai-mode-select {
  font-size: 0.62rem;
  padding: 0.12rem 0.35rem;
  background: #12182a;
  color: #c4c7d1;
  border: 1px solid #3a3f55;
  border-radius: 0.25rem;
  max-width: 9.5rem;
}
.suggestions-clear-btn {
  font-size: 0.65rem;
  color: #ff7b7b;
  background: none;
  border: 1px solid #3a3f55;
  border-radius: 0.25rem;
  padding: 0.1rem 0.5rem;
  cursor: pointer;
  box-shadow: none;
}
.suggestions-clear-btn:hover {
  background: #2a1a1a;
  border-color: #ff7b7b;
}
.bfs-link {
  font-size: 0.65rem;
  color: #5a9cf5;
  text-decoration: underline;
  white-space: nowrap;
}
.bfs-link:hover {
  color: #8abcff;
}
.suggestions-body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.sug-group {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.sug-group-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: #ffe57f;
  padding: 0.15rem 0.3rem 0;
  letter-spacing: 0.03em;
}
.sug-row {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  padding: 0.2rem 0.3rem;
  border-radius: 0.25rem;
}
.sug-row:hover {
  background: rgba(255, 255, 255, 0.04);
}
.sug-source {
  flex: 0 0 auto;
  font-size: 0.6rem;
  font-weight: 600;
  padding: 0.1rem 0.35rem;
  border-radius: 0.2rem;
  white-space: nowrap;
  letter-spacing: 0.03em;
}
.sug-source.src-ol {
  background: #1a2e1a;
  color: #7be87b;
  border: 1px solid #2a4a2a;
}
.sug-source.src-gb {
  background: #2a1e1a;
  color: #ffaf5a;
  border: 1px solid #4a3a2a;
}
.sug-source.src-bnf {
  background: #1a1a2e;
  color: #8a9fff;
  border: 1px solid #2a2a4a;
}
.sug-source.src-bbfs {
  background: #12262a;
  color: #6ee6ff;
  border: 1px solid #24434a;
}
.sug-source.src-ai {
  background: #2b1a2e;
  color: #d39cff;
  border: 1px solid #4a2a55;
}
.sug-value {
  flex: 1;
  font-size: 0.75rem;
  color: #e0e2ea;
  line-height: 1.35;
  word-break: break-word;
  white-space: pre-wrap;
  max-height: 4.5em;
  overflow-y: auto;
}
.sug-apply-btn {
  flex: 0 0 auto;
  font-size: 0.6rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 0.2rem;
  cursor: pointer;
  white-space: nowrap;
  background: linear-gradient(135deg, #4da3ff, #00d5ff);
  color: #050711;
  border: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.sug-apply-btn:hover {
  filter: brightness(1.12);
}
.sug-apply-btn.applied {
  background: #2a4a2a;
  color: #7be87b;
  cursor: default;
  pointer-events: none;
}

.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 1400;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-modal-content {
  width: min(760px, 92vw);
  background: radial-gradient(circle at top left, #181f38 0, #080b16 55%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.7rem;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.65);
  padding: 0.8rem;
}

.settings-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.6rem;
}

.settings-grid label {
  align-self: center;
  font-size: 0.72rem;
  color: #c4c7d1;
}

.settings-grid input {
  width: 100%;
}

.settings-analytics {
  grid-column: 1 / -1;
  margin-top: 0.35rem;
  border-top: 1px solid #2a2e3e;
  padding-top: 0.5rem;
}

.settings-analytics-title {
  font-size: 0.74rem;
  color: #7ee0ff;
  margin-bottom: 0.25rem;
  font-weight: 600;
}

.settings-analytics-row {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.7rem;
  color: #c4c7d1;
  margin: 0.08rem 0;
}

#settingsResetAnalyticsBtn {
  margin-top: 0.35rem;
}

.settings-actions {
  margin-top: 0.7rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}
.sug-divider {
  border: none;
  border-top: 1px solid #1a1e2e;
  margin: 0.15rem 0;
}
