/*
 * CK3 DNA Manager — dark, warm parchment-and-gold theme.
 * CSS translation of resources/theme.qss.
 */

:root {
  --bg: #14110d;
  --sidebar: #17130e;
  --surface: #1d1812;
  --surface-2: #191510;
  --surface-3: #241e17;
  --border: #2e271d;
  --border-strong: #362d21;
  --border-soft: #251f17;
  --gold: #e8c766;
  --gold-strong: #d8b84a;
  --gold-dim: #8a7130;
  --text: #e8dfcf;
  --text-bright: #f2e7d1;
  --muted: #a99d88;
  --dim: #7f7464;
  --faint: #6c6152;
  --danger: #e07b6a;
  --ok: #8fc98a;
  --warning: #e3b74d;
  --selection: #6f5a1f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Noto Sans", sans-serif;
  font-size: 13px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Menu bar */

.menubar {
  display: flex;
  align-items: center;
  height: 30px;
  flex: 0 0 30px;
  padding: 0 4px;
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 20;
}

.menu {
  position: relative;
}

.menu-button {
  background: transparent;
  border: 0;
  border-radius: 4px;
  padding: 5px 10px;
  color: #c9bda6;
}

.menu-button:hover,
.menu.open .menu-button {
  background: #2a2318;
  color: #f0e4cc;
}

.menu-popup {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 250px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid #3a3025;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  z-index: 30;
}

.menu.open .menu-popup {
  display: block;
}

.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: 100%;
  padding: 6px 22px 6px 24px;
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: #e3dac8;
  text-align: left;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: #3a2f18;
  color: #f6ecd6;
  outline: none;
}

.menu-item:disabled {
  color: var(--faint);
}

.menu-item .shortcut {
  color: var(--dim);
  font-size: 11px;
}

.menu-separator {
  height: 1px;
  margin: 5px 8px;
  background: #322a1f;
}

/* Workspace */

.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  flex: 0 0 334px;
  width: 334px;
  min-height: 0;
  padding: 16px 18px 16px 16px;
  gap: 10px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}

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

.brand-icon {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.brand {
  color: var(--gold);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

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

.field-label {
  color: #9c8f79;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.7px;
  text-transform: uppercase;
}

.input,
select.input,
textarea.input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 8px;
  color: #ece3d2;
  outline: none;
}

select.input {
  appearance: none;
  padding-right: 28px;
  background-image: url("./assets/icons/chevron.svg");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 10px 8px;
}

.input:focus {
  background: #211b14;
  border-color: var(--gold-dim);
}

.input:disabled {
  color: var(--faint);
  background: #181410;
  border-color: #2a231a;
}

input[type="search"]::-webkit-search-cancel-button {
  filter: invert(0.7);
}

.sort-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sort-row .input {
  flex: 1;
  min-width: 0;
}

/* Entry list */

.entry-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0 -5px;
  padding: 0 5px;
}

.entry-item {
  position: relative;
  display: flex;
  gap: 12px;
  height: 82px;
  padding: 10px;
  margin-bottom: 2px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  overflow: hidden;
}

.entry-item:hover {
  background: #221d16;
}

.entry-item.selected {
  background: #2c251a;
  border-color: #7d6726;
}

.entry-item.selected::before {
  content: "";
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 0;
  width: 3px;
  background: var(--gold-strong);
}

.entry-thumb {
  flex: 0 0 48px;
  width: 48px;
  height: 60px;
  border-radius: 5px;
  border: 1px solid #3a3025;
  background: #0f0d0a;
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #5b5040;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.5px;
  overflow: hidden;
}

.entry-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.entry-main {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-right: 18px;
}

.entry-name {
  color: var(--text);
  font-size: 13.4px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.entry-item.selected .entry-name {
  color: #f4ead3;
}

.entry-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-date {
  margin-top: auto;
  color: var(--dim);
  font-size: 11px;
}

.entry-star {
  position: absolute;
  top: 6px;
  right: 8px;
  color: var(--gold-strong);
  font-size: 14px;
}

.empty-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px 24px;
  text-align: center;
}

.empty-title {
  color: #cdbfa6;
  font-size: 15px;
  font-weight: 600;
}

.empty-hint {
  color: var(--muted);
  font-size: 12px;
}

.divider {
  height: 1px;
  background: var(--border);
}

.button-row {
  display: flex;
  gap: 8px;
}

.button-row .btn {
  flex: 1;
}

.quick-convert {
  width: 100%;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 32px;
  padding: 6px 12px;
  background: var(--surface-3);
  border: 1px solid #3a3125;
  border-radius: 6px;
  color: #e6dcc9;
  white-space: nowrap;
}

.btn:hover {
  background: #2d261c;
  border-color: #57492f;
}

.btn:active {
  background: #1f1a14;
}

.btn:disabled {
  color: var(--faint);
  background: #1a1611;
  border-color: #2a231a;
  cursor: default;
}

.btn.primary {
  background: var(--gold-dim);
  border-color: #b5952f;
  color: #1b150a;
  font-weight: 700;
}

.btn.primary:hover {
  background: #a2853b;
  border-color: #d2ad3b;
}

.btn.primary:disabled {
  background: #3a3018;
  border-color: #4b3d1e;
  color: #8a7a51;
}

.btn.danger {
  color: #e0917f;
  border-color: #4a2b23;
}

.btn.danger:hover {
  background: #3a201b;
  border-color: #6b3a2e;
}

.btn.small {
  min-height: 28px;
  padding: 4px 9px;
  font-size: 12px;
}

.btn .icon {
  width: 16px;
  height: 16px;
}

.language-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.language-row .input {
  flex: 1;
  min-width: 0;
}

/* Main area */

.main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 30px;
  text-align: center;
}

.welcome-icon {
  width: 112px;
  height: 112px;
  object-fit: contain;
}

.welcome-title {
  max-width: 560px;
  color: #efe4cf;
  font-size: 24px;
  font-weight: 700;
}

.welcome-hint {
  max-width: 560px;
  color: var(--muted);
}

.welcome-buttons {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.detail-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: var(--text-bright);
  font-size: 24px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.favorite {
  flex: 0 0 38px;
  width: 38px;
  height: 34px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--gold-strong);
  font-size: 20px;
}

.favorite:hover {
  background: #2a2318;
  border-color: #4a3d22;
}

.favorite.checked {
  color: #f0c94e;
}

.tabs {
  display: flex;
  padding: 0 22px;
  background: var(--bg);
}

.tab {
  padding: 9px 20px;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: #9c8f79;
  font-weight: 600;
}

.tab:hover {
  color: #d8cbb2;
}

.tab.active {
  color: var(--gold);
  border-bottom-color: var(--gold-strong);
}

.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Overview */

.overview-scroll {
  flex: 1;
  overflow-y: auto;
}

.overview-content {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  padding: 16px 22px 22px;
}

.portrait-column {
  flex: 0 0 330px;
  width: 330px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.portrait {
  position: relative;
  height: clamp(360px, 52vh, 560px);
  background: #100d0a;
  border: 1px solid #3a3025;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.portrait img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.portrait-placeholder {
  position: absolute;
  inset: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1.6px dashed #3b3227;
  border-radius: 8px;
  color: #b6a98f;
  font-weight: 700;
  text-align: center;
  padding: 24px;
  white-space: pre-line;
}

.portrait.drag-active .portrait-placeholder {
  border-color: var(--gold-strong);
}

.portrait-format-hint {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  color: #6d6252;
  font-size: 11px;
  text-align: center;
}

.portrait-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.name-input {
  font-size: 14px;
  font-weight: 600;
  padding: 8px 10px;
}

.notes {
  min-height: 82px;
  max-height: 120px;
  resize: vertical;
}

.meta {
  font-size: 13px;
  line-height: 1.5;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.actions .btn {
  min-height: 34px;
}

.code-tabs {
  display: flex;
  flex-direction: column;
  min-height: 210px;
  margin-top: 4px;
}

.code-tab-headers {
  display: flex;
  align-items: center;
  gap: 2px;
  border-bottom: 1px solid var(--border);
}

.code-tab {
  padding: 8px 16px;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: #9c8f79;
  font-weight: 600;
}

.code-tab.active {
  color: var(--gold);
  border-bottom-color: var(--gold-strong);
}

.code-tab-headers .btn {
  margin-left: auto;
  margin-bottom: 4px;
}

.code {
  flex: 1;
  min-height: 180px;
  margin-top: 6px;
  font-family: "Cascadia Mono", "Consolas", "DejaVu Sans Mono", monospace;
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-all;
  overflow-x: hidden;
  overflow-y: auto;
  resize: vertical;
}

/* Gene editor */

.gene-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px 8px;
}

.gene-toolbar .input:first-child {
  flex: 1;
  min-width: 220px;
}

.gene-toolbar select.input {
  flex: 0 0 180px;
  width: 180px;
}

.legend {
  padding: 0 18px 8px;
  font-size: 12px;
}

.gene-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 4px 14px 14px;
}

.gene-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gene-section {
  margin-top: 10px;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: #1b1711;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #c8b58c;
  font-weight: 700;
  text-align: left;
}

.section-header:hover {
  background: #241e16;
  border-color: #4a3d22;
}

.section-arrow {
  width: 10px;
  color: var(--gold-strong);
}

.section-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 0 10px;
}

.gene-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
}

.gene-row:hover {
  background: var(--surface);
  border-color: #332b20;
}

.gene-label {
  flex: 0 0 210px;
  width: 210px;
  min-width: 0;
}

.gene-name {
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gene-key {
  color: var(--dim);
  font-size: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.allele-tag {
  flex: 0 0 22px;
  width: 22px;
  color: #8e8069;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}

.gene-row select.input {
  flex: 1;
  min-width: 0;
}

.gene-row .number {
  flex: 0 0 64px;
  width: 64px;
  text-align: center;
  padding-left: 2px;
  padding-right: 2px;
}

.gene-row .number::-webkit-inner-spin-button,
.gene-row .number::-webkit-outer-spin-button {
  opacity: 0.35;
}

.color-values {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.extra-hint {
  padding: 0 4px 6px;
  color: var(--muted);
  font-size: 12px;
}

.extra-option {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  color: #cdbfa6;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.no-matches {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.editor-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
}

.dirty {
  flex: 1;
  color: #8e8069;
  font-size: 11px;
}

.dirty.is-dirty {
  color: var(--warning);
  font-weight: 600;
}

/* Status bar */

.statusbar {
  display: flex;
  align-items: center;
  height: 24px;
  flex: 0 0 24px;
  padding: 0 10px;
  background: var(--sidebar);
  border-top: 1px solid var(--border);
  color: #9c8f79;
  font-size: 12px;
}

/* Dialogs */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.62);
}

.dialog {
  display: flex;
  flex-direction: column;
  background: #1a1611;
  border: 1px solid #3a3025;
  border-radius: 10px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  max-width: 95vw;
  max-height: 92vh;
}

.dialog-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px 10px;
}

.dialog-title {
  flex: 1;
  margin: 0;
  color: var(--text-bright);
  font-size: 18px;
  font-weight: 700;
}

.dialog-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 20px 16px;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 20px 16px;
}

.dialog p {
  margin: 0 0 12px;
  color: var(--muted);
}

.add-dialog {
  width: 960px;
  height: 620px;
  min-width: 900px;
  min-height: 580px;
}

.add-body {
  display: flex;
  gap: 20px;
  min-height: 0;
  flex: 1;
  padding: 0 20px;
}

.add-left {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.add-right {
  flex: 0 0 300px;
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.add-dna {
  flex: 1;
  min-height: 300px;
  font-family: "Cascadia Mono", "Consolas", "DejaVu Sans Mono", monospace;
  font-size: 12px;
  resize: none;
}

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

.format-row select {
  width: 190px;
  flex: 0 0 190px;
}

.status-message {
  min-height: 40px;
  color: var(--muted);
  font-size: 12px;
  white-space: pre-line;
}

.status-message.ok {
  color: var(--ok);
}

.status-message.warning {
  color: var(--warning);
}

.status-message.error {
  color: var(--danger);
}

.add-portrait {
  flex: 1;
  min-height: 300px;
  height: auto;
}

.add-image-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-dialog {
  width: 940px;
  height: 640px;
  min-width: 760px;
  min-height: 560px;
}

.quick-body {
  display: flex;
  flex: 1;
  gap: 20px;
  min-height: 0;
  padding: 0 20px;
}

.quick-input-column,
.quick-output-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quick-input {
  flex: 1;
  min-height: 220px;
  font-family: "Cascadia Mono", "Consolas", "DejaVu Sans Mono", monospace;
  font-size: 12px;
  resize: none;
}

.quick-output-block {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.quick-output-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.quick-output-header .field-label {
  flex: 1;
}

.quick-output {
  flex: 1;
  min-height: 120px;
  font-family: "Cascadia Mono", "Consolas", "DejaVu Sans Mono", monospace;
  font-size: 12px;
  resize: none;
}

.about-dialog {
  width: 600px;
  min-width: 560px;
  height: 400px;
}

.about-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 22px 26px 10px;
}

.about-icon {
  width: 72px;
  height: 72px;
}

.about-title {
  color: var(--gold);
  font-size: 20px;
  font-weight: 700;
}

.about-tagline {
  color: #cdbfa6;
  font-size: 13px;
  font-style: italic;
}

.about-text {
  color: var(--muted);
}

.about-links {
  color: var(--muted);
  line-height: 1.8;
}

.about-links a {
  color: var(--gold-strong);
  text-decoration: none;
}

.about-links a:hover {
  text-decoration: underline;
}

.storage-dialog {
  width: 560px;
}

.storage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid #2a231a;
}

.storage-row:last-child {
  border-bottom: 0;
}

/* Scrollbars */

* {
  scrollbar-color: #3a3125 transparent;
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: #3a3125;
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: #57492f;
  background-clip: content-box;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

/* Responsive fallback */

@media (max-width: 1100px) {
  .sidebar {
    flex-basis: 290px;
    width: 290px;
  }

  .portrait-column {
    flex-basis: 280px;
    width: 280px;
  }

  .gene-label {
    flex-basis: 170px;
    width: 170px;
  }
}

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

  .sidebar {
    flex: 0 0 auto;
    width: 100%;
    max-height: 45vh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .overview-content {
    flex-direction: column;
  }

  .portrait-column {
    flex-basis: auto;
    width: 100%;
  }

  .portrait {
    height: 360px;
  }

  .add-dialog {
    width: 95vw;
    min-width: 0;
    height: 90vh;
  }

  .add-body {
    flex-direction: column;
    overflow-y: auto;
  }

  .add-right {
    flex-basis: auto;
    width: 100%;
  }

  .quick-dialog {
    width: 95vw;
    min-width: 0;
    height: 90vh;
  }

  .quick-body {
    flex-direction: column;
    overflow-y: auto;
  }

  .quick-input {
    min-height: 200px;
  }
}
