:root {
  --ink: #17182a;
  --muted: #687482;
  --line: #dce5ea;
  --soft: #f3f8fa;
  --panel: #ffffff;
  --teal: #0aa0b8;
  --teal-dark: #006477;
  --blue: #1c6ee8;
  --green: #16a37d;
  --amber: #e89323;
  --red: #d85a5a;
  --shadow: 0 18px 46px rgba(26, 37, 52, .12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: #f7fafc;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  line-height: 1.42;
}

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

button {
  cursor: pointer;
}

img {
  display: block;
  max-width: 100%;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
}

.side-rail {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 12px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(14px);
}

.brand-mark {
  display: grid;
  justify-items: center;
  gap: 7px;
  color: var(--teal-dark);
  font-weight: 850;
  text-decoration: none;
}

.brand-mark img {
  width: 42px;
  height: 42px;
  border-radius: 13px;
}

.brand-mark span {
  font-size: 12px;
}

.rail-nav {
  display: grid;
  gap: 10px;
  margin-top: 30px;
}

.rail-button {
  min-height: 74px;
  display: grid;
  place-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 18px;
  background: transparent;
  color: #506070;
  font-size: 12px;
  font-weight: 800;
}

.rail-button img {
  width: 24px;
  height: 24px;
}

.rail-button.active,
.rail-button:hover {
  border-color: rgba(10, 160, 184, .24);
  background: #fff;
  color: var(--teal-dark);
  box-shadow: 0 10px 30px rgba(10, 160, 184, .12);
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.top-bar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.kicker {
  margin: 0 0 5px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1;
}

h2 {
  margin: 0;
  font-size: 23px;
  line-height: 1.12;
}

h3 {
  margin: 0;
  font-size: 17px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: min(760px, 60vw);
}

.search-box {
  flex: 1;
  min-width: 240px;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.search-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.search-box input,
.field input,
.field select,
.field textarea {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 430px);
  gap: 18px;
  align-items: start;
}

.main-column,
.detail-column {
  min-width: 0;
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-card,
.profile-form,
.empty-detail,
.detail-panel,
.halo-status {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 12px 34px rgba(26, 37, 52, .07);
}

.summary-card {
  min-height: 112px;
  padding: 17px;
}

.summary-card span,
.summary-card small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.summary-card strong {
  display: block;
  margin: 9px 0 4px;
  color: var(--teal-dark);
  font-size: 32px;
  line-height: 1;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin: 22px 0 12px;
}

.listing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 13px;
}

.listing-grid.compact {
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}

.listing-card,
.order-row {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  overflow: hidden;
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}

.listing-card {
  min-height: 266px;
  display: grid;
  grid-template-rows: 134px 1fr;
  text-align: left;
}

.listing-card:hover,
.order-row:hover,
.listing-card.selected,
.order-row.selected {
  transform: translateY(-1px);
  border-color: rgba(10, 160, 184, .46);
  box-shadow: var(--shadow);
}

.listing-photo {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #dff8fc, #fff7e9);
}

.listing-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.listing-photo .photo-fallback,
.detail-photo .photo-fallback {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--teal-dark);
  font-size: 34px;
  font-weight: 900;
}

.listing-body {
  min-width: 0;
  padding: 14px;
}

.listing-body h3 {
  display: -webkit-box;
  min-height: 44px;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.listing-body p {
  display: -webkit-box;
  margin: 7px 0 10px;
  min-height: 38px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.price-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.price-line strong {
  color: var(--teal-dark);
  font-size: 18px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef6f8;
  color: #536371;
  font-size: 12px;
  font-weight: 800;
}

.list-stack {
  display: grid;
  gap: 10px;
}

.order-row {
  width: 100%;
  min-height: 86px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px;
  text-align: left;
}

.order-row p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.order-total {
  display: grid;
  justify-items: end;
  align-content: center;
  gap: 6px;
}

.order-total strong {
  font-size: 18px;
  color: var(--teal-dark);
}

.form-actions {
  display: flex;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
}

.market-hero {
  display: block;
  margin-bottom: 18px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

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

.market-layout {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 20px;
}

.market-categories {
  position: sticky;
  top: 24px;
  align-self: start;
  padding-right: 16px;
  border-right: 1px solid var(--line);
}

.market-categories h3 {
  margin-bottom: 12px;
  font-size: 15px;
}

#marketCategoryList {
  display: grid;
  gap: 4px;
}

.category-button {
  width: 100%;
  min-height: 30px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 5px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #253341;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
}

.category-button span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-button strong {
  color: var(--muted);
  font-size: 12px;
}

.category-button.active,
.category-button:hover {
  background: #eaf7fa;
  color: var(--teal-dark);
}

.market-shelves {
  min-width: 0;
  display: grid;
  gap: 24px;
}

.market-shelf {
  min-width: 0;
}

.shelf-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.shelf-head h2 {
  font-size: 24px;
}

.shelf-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.shelf-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.shelf-track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(190px, 220px);
  gap: 16px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  padding: 4px 6px 14px 2px;
  scroll-snap-type: inline proximity;
}

.shelf-track::-webkit-scrollbar {
  height: 9px;
}

.shelf-track::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #cfdce2;
}

.shelf-card {
  position: relative;
  min-height: 286px;
  display: grid;
  grid-template-rows: 138px minmax(0, 1fr);
  gap: 9px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  scroll-snap-align: start;
}

.shelf-card:hover,
.shelf-card.selected {
  border-color: rgba(10, 160, 184, .36);
  background: #fff;
  box-shadow: 0 14px 32px rgba(26, 37, 52, .10);
}

.rank-flag {
  position: absolute;
  z-index: 2;
  top: 8px;
  left: 8px;
  min-width: 34px;
  min-height: 24px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  border-radius: 6px 6px 10px 6px;
  background: var(--teal-dark);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.shelf-photo {
  height: 138px;
  overflow: hidden;
  border-radius: 14px;
  background: #f2f7f9;
}

.shelf-photo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 8px;
  mix-blend-mode: multiply;
}

.shelf-photo .photo-fallback {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--teal-dark);
  font-size: 34px;
  font-weight: 900;
}

.shelf-info {
  min-width: 0;
  padding: 0 6px 8px;
}

.shelf-info h3 {
  display: -webkit-box;
  min-height: 40px;
  overflow: hidden;
  color: #155a86;
  font-size: 14px;
  font-weight: 750;
  line-height: 1.35;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.shelf-info p {
  display: -webkit-box;
  margin: 6px 0;
  min-height: 32px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.shelf-signals {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 22px;
  margin: 6px 0;
}

.shelf-signals span {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: #eef6f8;
  color: #55707a;
  font-size: 11px;
  font-weight: 800;
}

.shelf-info strong {
  color: #b04400;
  font-size: 16px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: #516171;
  font-size: 13px;
  font-weight: 800;
}

.field input,
.field select,
.field textarea {
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.field textarea {
  min-height: 110px;
  padding: 13px 14px;
  resize: vertical;
}

.field.wide {
  grid-column: 1 / -1;
}

.primary-button,
.ghost-button,
.text-button {
  min-height: 44px;
  border-radius: 999px;
  font-weight: 850;
}

.primary-button {
  padding: 0 18px;
  border: 0;
  background: var(--teal);
  color: #fff;
  box-shadow: 0 12px 28px rgba(10, 160, 184, .20);
}

.primary-button.full {
  width: 100%;
}

.primary-button:disabled {
  background: #a7c5cd;
  box-shadow: none;
  cursor: default;
}

.ghost-button {
  padding: 0 15px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--teal-dark);
  padding: 0 8px;
}

.halo-status {
  padding: 15px;
  margin-bottom: 12px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.status-tile {
  min-height: 74px;
  padding: 12px;
  border: 1px solid #e4edf1;
  border-radius: 16px;
  background: #f8fbfc;
}

.status-tile span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-tile strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
}

.profile-form {
  padding: 18px;
}

.profile-card-large {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 18px;
}

.avatar-large {
  width: 78px;
  height: 78px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  background: linear-gradient(135deg, #0aa0b8, #16c799);
  color: #fff;
  font-size: 32px;
  font-weight: 900;
}

.profile-card-large p {
  margin: 6px 0 0;
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
}

.detail-column {
  position: sticky;
  top: 24px;
}

.empty-detail,
.detail-panel {
  min-height: calc(100vh - 48px);
}

.empty-detail {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  padding: 30px;
  text-align: center;
}

.empty-detail img {
  width: 82px;
  height: 82px;
  border-radius: 24px;
}

.empty-detail p {
  max-width: 280px;
  color: var(--muted);
}

.detail-panel {
  padding: 16px;
}

.hidden {
  display: none !important;
}

.detail-photo {
  height: 240px;
  overflow: hidden;
  border-radius: 18px;
  background: linear-gradient(135deg, #dff8fc, #fff4df);
}

.detail-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-title {
  margin: 16px 0 8px;
}

.detail-copy {
  color: var(--muted);
  white-space: pre-wrap;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.purchase-room {
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto;
  min-height: calc(100vh - 80px);
}

.room-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.room-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.room-timeline {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  padding: 14px 2px;
}

.room-message {
  padding: 13px;
  border: 1px solid #e1ebef;
  border-radius: 18px;
  background: #fff;
}

.room-message.system {
  background: #f4fbfd;
  border-color: rgba(10, 160, 184, .22);
}

.room-message strong {
  display: block;
  margin-bottom: 4px;
}

.room-message p {
  margin: 0;
  color: #536371;
  font-size: 14px;
}

.room-actions {
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

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

.action-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid #e1ebef;
  border-radius: 16px;
  background: #f8fbfc;
}

.action-form .primary-button {
  grid-column: 1 / -1;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(246, 250, 252, .92);
  backdrop-filter: blur(20px);
}

.auth-card {
  width: min(440px, 100%);
  display: grid;
  gap: 13px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: #fff;
  box-shadow: var(--shadow);
}

.auth-card img {
  width: 66px;
  height: 66px;
  border-radius: 20px;
}

.auth-card h1 {
  font-size: 38px;
}

.advanced-box {
  border: 1px solid #e2ebef;
  border-radius: 16px;
  padding: 12px;
  color: var(--muted);
}

.advanced-box summary {
  color: var(--ink);
  font-weight: 850;
  cursor: pointer;
}

.advanced-box .field {
  margin-top: 12px;
}

.auth-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-weight: 750;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 60;
  max-width: min(520px, calc(100vw - 32px));
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  padding: 13px 17px;
  border-radius: 999px;
  background: #102f37;
  color: #fff;
  font-weight: 800;
  box-shadow: var(--shadow);
  transition: opacity .16s ease, transform .16s ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.empty-state {
  min-height: 130px;
  display: grid;
  place-items: center;
  padding: 20px;
  border: 1px dashed #cbd9df;
  border-radius: 18px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1180px) {
  .content-grid {
    grid-template-columns: 1fr;
  }

  .detail-column {
    position: static;
  }

  .empty-detail,
  .detail-panel {
    min-height: 520px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding-bottom: 84px;
  }

  .side-rail {
    position: fixed;
    z-index: 30;
    left: 12px;
    right: 12px;
    bottom: 10px;
    top: auto;
    height: 68px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: var(--shadow);
  }

  .brand-mark span {
    display: none;
  }

  .brand-mark img {
    width: 38px;
    height: 38px;
  }

  .rail-nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-top: 0;
    gap: 4px;
  }

  .rail-button {
    min-height: 50px;
    border-radius: 16px;
    font-size: 11px;
  }

  .rail-button img {
    width: 20px;
    height: 20px;
  }

  .workspace {
    padding: 16px;
  }

  .top-bar,
  .top-actions,
  .market-toolbar,
  .section-head {
    align-items: stretch;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .market-layout {
    grid-template-columns: 1fr;
  }

  .market-categories {
    position: static;
    padding-right: 0;
    border-right: 0;
  }

  #marketCategoryList {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    padding-bottom: 6px;
  }

  .category-button {
    min-width: 132px;
  }

  .shelf-track {
    grid-auto-columns: minmax(154px, 172px);
    gap: 12px;
  }

  .top-actions {
    min-width: 0;
  }

  .search-box {
    min-width: 0;
  }

  .summary-strip,
  .form-grid,
  .status-grid,
  .action-form {
    grid-template-columns: 1fr;
  }

  .listing-grid,
  .listing-grid.compact {
    grid-template-columns: 1fr;
  }
}
