:root {
  --bg: #efe8dc;
  --ink: #1c1712;
  --muted: #6b6258;
  --line: #ddd3c4;
  --paper: #fffdf8;
  --paper-2: #f7f1e6;
  --gold: #9a6b2f;
  --gold-dark: #7a5222;
  --up: #0f7b4c;
  --down: #b42318;
  --shadow: 0 18px 40px rgba(40, 28, 12, 0.08);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 400px at 10% -10%, #f7e7c8 0%, transparent 55%),
    var(--bg);
}

code {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.82em;
  background: var(--paper-2);
  padding: 0.12em 0.4em;
  border-radius: 6px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 28px 24px 12px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
}

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

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #c89a4b, #7a5222);
  color: #fff8ea;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
}

.brand p,
.panel-head p,
.hint,
.meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.api-base {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 280px;
  font-size: 0.82rem;
  color: var(--muted);
}

main {
  width: 100%;
  margin: 0 auto;
  padding: 12px 24px 48px;
  display: grid;
  gap: 20px;
  min-width: 0;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  min-width: 0;
  max-width: 100%;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.panel-head h2,
dialog h3 {
  margin: 0;
  font-size: 1.15rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}

label em {
  color: var(--gold);
  font-style: normal;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 42px;
}

input:focus,
select:focus {
  outline: 2px solid #d8b56a;
  border-color: var(--gold);
}

input[readonly] {
  background: var(--paper-2);
  color: var(--muted);
}

.grid-2,
.grid-4 {
  display: grid;
  gap: 12px;
}

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

.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

.span-2 {
  grid-column: span 2;
}

.mapping {
  margin: 16px 0 8px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 8px 12px 14px;
}

.mapping summary {
  cursor: pointer;
  font-weight: 600;
  padding: 8px 0;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
}

.btn {
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
}

.btn:hover {
  background: #efe6d5;
}

.btn.primary {
  background: var(--gold);
  border-color: var(--gold-dark);
  color: #fffaf0;
}

.btn.primary:hover {
  background: var(--gold-dark);
}

.btn.danger {
  background: #fbeaea;
  border-color: #e8c4c0;
  color: var(--down);
}

.btn.danger:hover {
  background: #f4d4d0;
}

.btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

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

.toolbar input,
.toolbar select {
  min-width: 180px;
}

.table-wrap {
  overflow-x: hidden;
  overflow-y: visible;
  border: 1px solid var(--line);
  border-radius: 12px;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  vertical-align: top;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.wrap-cell code {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

th.compact,
td.compact,
th.num,
td.num {
  white-space: nowrap;
  word-break: normal;
  overflow-wrap: normal;
}

th {
  background: var(--paper-2);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

th.num,
td.num {
  text-align: right;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

tbody tr:hover {
  background: #fbf6ec;
}

.empty td {
  text-align: center;
  color: var(--muted);
  padding: 36px 12px;
}

.change.up {
  color: var(--up);
}

.change.down {
  color: var(--down);
}

.status {
  margin: 0;
  font-size: 0.9rem;
}

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

.status.err {
  color: var(--down);
}

.meta {
  margin-top: 12px;
}

.selection-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: -6px 0 14px;
  padding: 10px 12px;
  background: #f3e6c8;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.selection-bar[hidden] {
  display: none;
}

.selection-bar span {
  font-weight: 600;
  margin-right: auto;
}

th.check,
td.check {
  width: 42px;
  text-align: center;
  white-space: nowrap;
}

th.actions,
td.actions {
  width: 132px;
  white-space: nowrap;
}

th.check input,
td.check input {
  width: 18px;
  height: 18px;
  min-height: 0;
  padding: 0;
  accent-color: var(--gold-dark);
  cursor: pointer;
}

tbody tr[data-price-id] {
  cursor: pointer;
}

tbody tr.checked {
  background: #f3e6c8;
}

tbody tr.inactive {
  opacity: 0.58;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--line);
  cursor: pointer;
}

.badge.on {
  background: #e7f6ee;
  color: var(--up);
  border-color: #b7e0c8;
}

.badge.off {
  background: #fbeaea;
  color: var(--down);
  border-color: #e8c4c0;
}

.rate-inherit {
  color: var(--muted);
  font-size: 0.82rem;
}

dialog {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  background: var(--paper);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(28, 23, 18, 0.42);
}

dialog form {
  padding: 22px;
}

dialog header {
  margin-bottom: 16px;
}

dialog header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

dialog footer {
  justify-content: flex-end;
}

.sources-table .url-cell {
  min-width: 0;
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sources-table td.wrap-cell {
  max-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.25;
}

.sources-table th.compact,
.sources-table td.compact {
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-cell,
.wrap-cell {
  min-width: 0;
}

.prices-table col.col-check {
  width: 36px;
}

.prices-table col.col-id {
  width: 6%;
}

.prices-table col.col-type {
  width: 4%;
}

.prices-table col.col-source {
  width: 6%;
}

.prices-table col.col-name {
  width: 10%;
}

.prices-table col.col-num {
  width: 7%;
}

.prices-table col.col-currency {
  width: 5%;
}

.prices-table col.col-mode {
  width: 4%;
}

.prices-table col.col-adjust {
  width: 5%;
}

.prices-table col.col-rate {
  width: 6%;
}

.prices-table col.col-active {
  width: 5%;
}

.prices-table col.col-updated {
  width: 8%;
}

.prices-table col.col-actions {
  width: 118px;
}

.prices-table th,
.prices-table td {
  padding: 8px 6px;
  font-size: 0.82rem;
}

.prices-table th.wrap-cell,
.prices-table td.wrap-cell,
.prices-table .source-cell {
  max-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.25;
}

.prices-table td.wrap-cell code {
  font-size: 0.78em;
  padding: 0.08em 0.25em;
}

.sources-table col.col-name {
  width: 11%;
}

.sources-table col.col-url {
  width: 14%;
}

.sources-table col.col-type {
  width: 5%;
}

.sources-table col.col-key {
  width: 8%;
}

.sources-table col.col-mode {
  width: 5%;
}

.sources-table col.col-adjust {
  width: 6%;
}

.sources-table col.col-rate {
  width: 7%;
}

.sources-table col.col-status {
  width: 7%;
}

.sources-table col.col-fetched {
  width: 10%;
}

.sources-table col.col-actions {
  width: 168px;
}

.sources-table tr.selected {
  background: #f3e6c8;
}

.muted {
  color: #6b7280;
  font-size: 0.85em;
}

.link-prices-wrap {
  max-height: min(50vh, 420px);
  overflow: auto;
  margin: 0.75rem 0;
}

.sources-table .row-actions,
.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#sourcesStatus {
  margin-top: 12px;
}

#sourceDialog {
  width: min(640px, calc(100vw - 32px));
}

@media (max-width: 900px) {
  .topbar,
  main {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar,
  .panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  .grid-2,
  .grid-4 {
    grid-template-columns: 1fr 1fr;
  }

  .span-2 {
    grid-column: span 2;
  }
}

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

  .span-2 {
    grid-column: auto;
  }
}



.sources-table tr.source-disabled {
  opacity: 0.55;
  background: #f0ebe3;
  color: #7a7268;
}

.sources-table tr.source-disabled .badge-off {
  opacity: 1;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-on {
  background: #e4f5ea;
  color: #1f6b3a;
}

.badge-off {
  background: #f6e4e4;
  color: #8a2f2f;
}
