/*
 * Market window (src/ui/modals/modal-market.js), laid out like the OTClient market of the screenshots m1-m7:
 * Market Offers / My Offers, the Browse panel on the left, Offers / NPCs / Details / Statistics on the right and the
 * Create New Offer row under them. It is fixed to the page (outside the game screen, which clips), with the z-index of
 * every modal (modal.css .modal: 30000), so the creature labels (#text-wrapper, 101) stay under it.
 */

#market-modal.market-window {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 830px;
  height: 572px;
  max-width: calc(100vw - 8px);
  max-height: calc(100vh - 8px);
  box-sizing: border-box;
  flex-direction: column;
  background-image: url("/png/bg3.png");
  border: 1px solid black;
  box-shadow: 0 0 12px 0 black;
  color: #d8d8d8;
  font-size: 11px;
  user-select: none;
}

/* MarketModal.show opens it as a flex column (the modal manager hides it with display none) */
#market-modal.market-dragged {
  transform: none;
}

#market-modal button {
  margin: 0;
  padding: 2px 8px;
  border-radius: 2px;
  font-size: 10px;
}

#market-modal input,
#market-modal select {
  box-sizing: border-box;
  height: 20px;
  padding: 1px 4px;
  color: white;
  background: #111317;
  background-image: none;
  border: 1px solid #3a3f47;
  font-family: Verdana, "Sans-Serif";
  font-size: 11px;
  font-weight: bold;
}

#market-modal input:disabled,
#market-modal select:disabled {
  color: #6f6f6f;
  border-color: #2a2d33;
}

#market-modal input[type="checkbox"] {
  height: auto;
  width: auto;
  margin: 0 4px 0 0;
  vertical-align: middle;
}

.market-titlebar {
  position: relative;
  height: 18px;
  line-height: 18px;
  flex: 0 0 auto;
  text-align: center;
  color: #b8b8b8;
  background-image: url("/png/bg4.png");
  cursor: grab;
}

.market-titlebar .market-close-x {
  position: absolute;
  right: 2px;
  top: 1px;
  width: 16px;
  height: 16px;
  padding: 0;
  line-height: 14px;
  font-size: 9px;
}

.market-content {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 6px 8px 6px 8px;
}

.market-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex: 0 0 auto;
}

.market-balance {
  padding: 0 4px 4px 0;
  color: #d8d8d8;
}

.market-balance span {
  color: #f0e040;
}

.market-tabs {
  display: flex;
  gap: 2px;
}

#market-modal .market-tab {
  min-width: 90px;
  padding: 4px 14px;
  font-size: 11px;
  color: #c8c8c8;
  background: #101114;
  background-image: none;
  border: 1px solid #2c2f35;
  border-bottom: none;
  border-radius: 0;
}

#market-modal .market-tab:hover {
  color: white;
  border-color: #6c6c6c;
}

#market-modal .market-tab.selected {
  color: white;
  background: #222833;
}

.market-page {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid black;
  background: #1a1c20;
}

.market-page[hidden] {
  display: none;
}

/* ------------------------------------------------------------------ Browse */

.market-browse {
  flex: 0 0 176px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 3px;
  background: #16181c;
  border: 1px solid #0c0d0f;
}

.market-panel-title {
  text-align: center;
  padding: 2px 0;
  background: #101114;
  border: 1px solid #2c2f35;
}

#market-category {
  width: 100%;
}

.market-filter-row {
  display: flex;
  gap: 3px;
}

.market-filter-row select {
  flex: 1 1 auto;
  min-width: 0;
}

#market-modal .market-toggle {
  color: #9a9a9a;
}

#market-modal .market-toggle.active {
  color: white;
  border-color: #c9c9c9;
  background-image: url("/png/bg2.png");
}

#market-modal .market-wide {
  width: 100%;
}

.market-items {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(4, 36px);
  grid-auto-rows: 36px;
  gap: 5px;
  align-content: start;
  justify-content: center;
  padding: 4px 0;
  background: #0f1012;
  border: 1px solid #000;
  scrollbar-width: thin;
}

.market-item {
  position: relative;
  box-sizing: border-box;
  width: 36px;
  height: 36px;
  padding: 1px;
  background-image: url("/png/item.png");
  background-size: cover;
  border: 1px solid #000;
  cursor: pointer;
}

.market-item canvas {
  display: block;
  width: 32px;
  height: 32px;
}

.market-item:hover {
  border-color: #8a8a8a;
}

.market-item.selected {
  border-color: #f0f0f0;
}

.market-item .market-count {
  position: absolute;
  right: 1px;
  bottom: 0;
  font-size: 10px;
  color: white;
  pointer-events: none;
}

.market-empty {
  grid-column: 1 / -1;
  padding: 6px;
  text-align: center;
  color: #8d8d8d;
}

.market-find {
  display: flex;
  align-items: center;
  gap: 3px;
}

.market-find input {
  flex: 1 1 auto;
  min-width: 0;
}

/* ------------------------------------------------------------------ Offers / NPCs / Details / Statistics */

.market-detail {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.market-detail-tabs {
  justify-content: flex-end;
}

#market-modal .market-detail-tabs .market-tab {
  min-width: 0;
  padding: 3px 10px;
}

#market-modal .market-detail-tabs .market-tab:last-child {
  min-width: 150px;
}

.market-detail-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 4px 8px 4px 8px;
  background: #222833;
  border: 1px solid #0c0d0f;
  overflow-y: auto;
}

.market-selected {
  flex: 0 0 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 4px;
}

.market-selected canvas {
  width: 32px;
  height: 32px;
}

.market-detail-page {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.market-detail-page[hidden],
.market-mine-panel[hidden] {
  display: none;
}

.market-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 3px 0 2px 0;
  font-weight: bold;
}

.market-section-title button {
  min-width: 78px;
}

.market-table {
  flex: 1 1 0;
  min-height: 66px;
  display: flex;
  flex-direction: column;
  background: #1c212a;
  border: 1px solid #191f27;
}

.market-table-head,
.market-row {
  display: grid;
  grid-template-columns: var(--market-columns);
  column-gap: 2px;
}

.market-table-head {
  flex: 0 0 auto;
  background: #0f1114;
  border-bottom: 1px solid black;
}

.market-table-head > div {
  padding: 2px 4px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: #15181d;
  border: 1px solid #262a31;
}

.market-table-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}

.market-row {
  cursor: pointer;
}

.market-row > div {
  padding: 1px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.market-row:nth-child(even) {
  background: #1d232c;
}

.market-row:hover {
  background: #2b3340;
}

.market-row.selected {
  background: #45506a;
  color: white;
}

.market-row.market-own {
  color: #9fd08f;
}

.market-table-empty {
  padding: 4px 6px;
  color: #9a9a9a;
}

.market-npcs {
  flex-direction: row;
  gap: 10px;
}

.market-npc-column {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.market-npc-list {
  flex: 1 1 auto;
  min-height: 80px;
  overflow-y: auto;
  background: #1c212a;
  border: 1px solid #191f27;
  scrollbar-width: thin;
}

.market-npc-entry {
  padding: 2px 6px;
}

.market-npc-entry:nth-child(even) {
  background: #1d232c;
}

.market-npc-price {
  color: #b9b9b9;
}

.market-npc-price::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 4px;
  background-image: url("/png/gc.png");
}

.market-npc-residence {
  color: #7c7a7a;
}

.market-nowhere {
  padding: 6px;
  text-align: center;
  color: #9a9a9a;
}

.market-details,
.market-statistics {
  display: grid;
  grid-template-columns: 130px 1fr;
  row-gap: 2px;
  padding: 4px 6px;
  background: #1c212a;
  border: 1px solid #191f27;
  overflow-y: auto;
}

.market-details {
  flex: 1 1 auto;
  min-height: 0;
}

.market-statistics {
  flex: 1 1 0;
  min-height: 60px;
  align-content: start;
}

.market-details > .market-label,
.market-statistics > .market-label {
  color: #b0b0b0;
}

.market-details > .market-value {
  white-space: pre-wrap;
}

.market-statistics > .market-nodata {
  grid-column: 1 / -1;
  color: #d8d8d8;
}

/* ------------------------------------------------------------------ Create New Offer */

.market-create {
  flex: 0 0 auto;
  padding: 3px 4px 2px 4px;
  background: #1b1f26;
  border: 1px solid #0c0d0f;
  border-top: none;
}

.market-create-title {
  margin-bottom: 2px;
}

.market-create-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 5px 8px;
}

.market-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 10px;
}

.market-field select,
.market-field input {
  width: 92px;
}

.market-amount {
  display: flex;
  align-items: center;
  gap: 1px;
}

.market-amount input {
  width: 58px !important;
}

#market-modal .market-amount button {
  padding: 1px 3px;
  font-size: 9px;
}

.market-create-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  margin-left: auto;
}

.market-anonymous {
  font-size: 10px;
  white-space: nowrap;
}

#market-create-offer {
  min-width: 98px;
  padding: 4px 8px;
}

#market-fee {
  font-size: 10px;
}

/* ------------------------------------------------------------------ My Offers */

.market-page-mine {
  flex-direction: column;
}

.market-mine-tabs .market-tab {
  flex: 1 1 0;
}

.market-mine-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 4px 8px 6px 8px;
  background: #222833;
  border: 1px solid #0c0d0f;
}

.market-history {
  margin-top: 4px;
}

/* ------------------------------------------------------------------ bottom row and dialogs */

.market-bottom {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
}

.market-bottom button {
  min-width: 110px;
}

.market-dialog-backdrop {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}

.market-dialog-backdrop[hidden] {
  display: none;
}

.market-dialog {
  width: 320px;
  max-width: calc(100% - 20px);
  background-image: url("/png/bg3.png");
  border: 1px solid black;
  box-shadow: 0 0 10px 0 black;
}

.market-dialog-title {
  height: 18px;
  line-height: 18px;
  text-align: center;
  background-image: url("/png/bg4.png");
  color: #d0d0d0;
}

.market-dialog-body {
  padding: 10px 12px 6px 12px;
  white-space: pre-line;
  line-height: 15px;
}

.market-dialog-amount {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0 12px 6px 12px;
}

.market-dialog-amount[hidden] {
  display: none;
}

/* The slider of slider.css (the generic #market-modal input rule would hide its track) */
#market-modal input.slider {
  width: 100%;
  height: 12px;
  padding: 0;
  border: 1px solid black;
  background: url("/png/bg3.png");
}

#market-dialog-summary {
  text-align: center;
  line-height: 15px;
  white-space: pre-line;
}

.market-dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding: 4px 10px 8px 10px;
}

.market-dialog-buttons button {
  min-width: 64px;
}

/* ------------------------------------------------------------------ small screens and phones */

@media screen and (max-width: 860px), screen and (max-height: 600px) {

  #market-modal.market-window,
  #market-modal.market-window.market-dragged {
    left: 0 !important;
    top: 0 !important;
    transform: none;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border: none;
  }

  .market-titlebar {
    height: 24px;
    line-height: 24px;
    cursor: default;
  }

  .market-titlebar .market-close-x {
    width: 22px;
    height: 22px;
    font-size: 12px;
  }

  .market-content {
    padding: 4px;
    overflow-y: auto;
  }

  .market-browse {
    flex-basis: 158px;
  }

  .market-items {
    grid-template-columns: repeat(3, 36px);
    min-height: 90px;
  }

  #market-modal .market-tab {
    min-width: 0;
    padding: 5px 8px;
  }

  #market-modal .market-detail-tabs .market-tab:last-child {
    min-width: 0;
  }

  .market-field select,
  .market-field input {
    width: 78px;
  }

  /* A short (landscape) screen: the page takes what is left and its lists scroll, the bottom buttons stay visible */
  .market-page {
    min-height: 0;
  }

  .market-selected {
    flex-basis: 30px;
  }

  .market-table {
    min-height: 54px;
  }

}

@media screen and (max-width: 600px) {

  .market-page:not([hidden]) {
    flex: 0 0 auto;
    flex-direction: column;
  }

  .market-browse {
    flex: 0 0 auto;
  }

  .market-items {
    flex: 0 0 132px;
    grid-template-columns: repeat(auto-fill, 36px);
  }

  .market-detail {
    min-height: 420px;
  }

  .market-npcs {
    flex-direction: column;
  }

  .market-create-actions {
    margin-left: 0;
  }

}
