:root {
  color-scheme: light;
  --ink: #1b2430;
  --muted: #667184;
  --line: #dce2e8;
  --paper: #f5f6f2;
  --white: #ffffff;
  --coral: #c75c3b;
  --coral-dark: #9e4027;
  --green: #2f7d68;
  --blue: #315f87;
  --shadow: 0 16px 44px rgba(27, 36, 48, 0.09);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 84px; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }

.market-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: clamp(16px, 3vw, 34px);
  min-height: 70px;
  padding: 10px clamp(18px, 5vw, 68px);
  border-bottom: 1px solid rgba(27, 36, 48, 0.08);
  background: rgba(245, 246, 242, 0.94);
  backdrop-filter: blur(14px);
}
.market-brand { display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.market-brand > span {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 10px;
  background: var(--ink);
  color: var(--white);
  font-size: 13px;
  font-weight: 900;
}
.market-brand strong { font-size: 15px; }
.market-brand em {
  padding: 5px 8px;
  border-radius: 999px;
  background: #f1ded7;
  color: var(--coral-dark);
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
}
.market-nav { display: flex; align-items: center; gap: 22px; }
.market-nav a, .market-nav button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}
.market-nav .lucide, .account-actions .lucide { width: 16px; height: 16px; stroke-width: 2; }
.market-nav a:hover, .market-nav button:hover { color: var(--coral); }
.unread-badge {
  position: absolute;
  top: -9px;
  right: -12px;
  min-width: 18px;
  min-height: 18px;
  padding: 2px 5px;
  border-radius: 999px;
  background: var(--coral);
  color: var(--white);
  font-size: 10px;
  line-height: 14px;
  text-align: center;
}
.account-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; }
.account-actions > span { max-width: 130px; overflow: hidden; font-size: 12px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }

.primary-button, .secondary-button, .outline-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0 17px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 900;
}
.primary-button .lucide, .secondary-button .lucide, .outline-button .lucide, .text-button .lucide { width: 16px; height: 16px; margin-right: 7px; }
.primary-button { border: 1px solid var(--coral); background: var(--coral); color: var(--white); }
.primary-button:hover { border-color: var(--coral-dark); background: var(--coral-dark); }
.secondary-button, .outline-button { border: 1px solid var(--line); background: var(--white); }
.secondary-button:hover, .outline-button:hover { border-color: var(--coral); color: var(--coral); }
.primary-button.small { min-height: 39px; padding-inline: 14px; font-size: 13px; }
.outline-button.compact { min-height: 36px; padding-inline: 12px; font-size: 12px; }
.text-button { border: 0; padding: 3px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 800; }
.text-button:hover { color: var(--coral); }

main { width: min(1500px, 100%); margin: 0 auto; }
.market-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.5fr);
  gap: clamp(32px, 7vw, 90px);
  align-items: center;
  padding: clamp(52px, 8vw, 110px) clamp(18px, 5vw, 68px) clamp(46px, 7vw, 82px);
  background: radial-gradient(circle at 86% 20%, rgba(199, 92, 59, 0.15), transparent 26%), linear-gradient(135deg, #fbfaf5, #f1f4ee);
}
.eyebrow {
  margin: 0 0 10px;
  color: var(--coral);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.07em;
}
.market-hero h1 {
  max-width: 800px;
  margin: 0;
  font-size: clamp(48px, 7vw, 92px);
  line-height: 0.95;
  letter-spacing: -0.05em;
}
.market-hero > div:first-child > p:not(.eyebrow) {
  max-width: 720px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: clamp(16px, 1.7vw, 20px);
  line-height: 1.75;
}
.hero-actions { display: flex; gap: 12px; margin-top: 30px; flex-wrap: wrap; }
.hero-market-card {
  display: grid;
  min-height: 285px;
  align-content: center;
  justify-items: center;
  gap: 12px;
  border: 1px solid rgba(199, 92, 59, 0.2);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 30px 70px rgba(104, 66, 48, 0.13);
  transform: rotate(2deg);
}
.hero-card-tag { padding: 5px 10px; border-radius: 999px; background: #f8e6df; color: var(--coral-dark); font-size: 11px; font-weight: 900; }
.hero-card-icon { display:grid; width:78px; height:78px; place-items:center; color: var(--green); }
.hero-card-icon .lucide { width:70px; height:70px; stroke-width:1.2; }
.hero-market-card strong { font-size: 22px; }
.hero-market-card small { color: var(--muted); font-weight: 800; }

.market-section, .messages-section { padding: clamp(46px, 7vw, 84px) clamp(18px, 5vw, 68px); }
.messages-section { border-top: 1px solid var(--line); background: #eef1ef; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.section-heading h2 { margin: 0; font-size: clamp(34px, 5vw, 58px); line-height: 1; letter-spacing: -0.035em; }
.section-note { max-width: 360px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; text-align: right; }
.market-layout { display: grid; grid-template-columns: 245px minmax(0, 1fr); gap: 22px; align-items: start; }
.filters {
  position: sticky;
  top: 92px;
  display: grid;
  gap: 15px;
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  box-shadow: var(--shadow);
}
.filter-heading { display: flex; align-items: center; justify-content: space-between; }
.filters label, .modal-form label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 800; }
input, select, textarea {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fcfdfd;
  color: var(--ink);
  outline: none;
}
input, select { min-height: 43px; padding: 0 11px; }
textarea { padding: 11px; line-height: 1.55; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--coral); box-shadow: 0 0 0 3px rgba(199, 92, 59, 0.12); }
.items-column { min-width: 0; }
.result-bar { display: flex; min-height: 44px; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 13px; }
.result-bar > span { color: var(--muted); font-size: 13px; font-weight: 800; }
.result-bar select { width: auto; min-height: 38px; background: transparent; }
.item-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.item-card {
  display: grid;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  box-shadow: 0 12px 32px rgba(27, 36, 48, 0.07);
}
.item-photo {
  position: relative;
  display: grid;
  aspect-ratio: 4 / 3;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(145deg, #ebe8dc, #dce7e1);
  color: rgba(27, 36, 48, 0.54);
  font-size: 58px;
}
.item-photo img { width: 100%; height: 100%; object-fit: cover; }
.item-photo > .lucide { width:64px; height:64px; color:var(--coral); stroke-width:1.25; }
.category-chip { position: absolute; top: 11px; left: 11px; padding: 5px 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.91); color: var(--ink); font-size: 10px; font-weight: 900; }
.item-body { display: grid; gap: 11px; padding: 16px; }
.item-title-row { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.item-title-row h3 { min-width: 0; margin: 0; font-size: 18px; line-height: 1.25; overflow-wrap: anywhere; }
.item-price { color: var(--coral-dark); font-size: 18px; font-weight: 950; white-space: nowrap; }
.item-description { min-height: 44px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.item-location, .item-seller { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; font-weight: 700; }
.item-location .lucide { width:13px; height:13px; flex:0 0 auto; }
.item-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 2px; }
.item-actions.single { grid-template-columns: 1fr; }
.item-actions button { min-height: 38px; }
.remove-button { border: 1px solid #efceca; border-radius: 8px; background: #fff6f5; color: #a74b42; cursor: pointer; font-size: 12px; font-weight: 900; }
.remove-button:hover { border-color: #a74b42; }
.empty-state { grid-column: 1 / -1; padding: 54px 20px; border: 1px dashed var(--line); border-radius: 12px; background: rgba(255,255,255,.6); color: var(--muted); text-align: center; line-height: 1.7; }
.empty-state strong { display: block; margin-bottom: 7px; color: var(--ink); font-size: 19px; }

.message-login-note { display: grid; justify-items: center; gap: 9px; padding: 46px 20px; border: 1px dashed #cfd7d2; border-radius: 12px; background: rgba(255,255,255,.62); text-align: center; }
.message-login-note strong { font-size: 20px; }
.message-login-note span { margin-bottom: 5px; color: var(--muted); font-size: 13px; }
.message-section-meta { display:grid; justify-items:end; gap:7px; }
.connection-status { display:inline-flex; min-height:28px; align-items:center; gap:7px; padding:0 9px; border:1px solid var(--line); border-radius:999px; background:var(--white); color:var(--muted); font-size:10px; font-weight:900; }
.connection-status .lucide { width:13px; height:13px; }
.connection-status.cloud { border-color:rgba(47,125,104,.24); background:#edf7f3; color:var(--green); }
.connection-status.local { border-color:#ead4c5; background:#fff7f1; color:#9e5c2c; }
.message-layout {
  display: grid;
  grid-template-columns: minmax(230px, 0.33fr) minmax(0, 0.67fr);
  min-height: 510px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  box-shadow: var(--shadow);
}
.conversation-list { border-right: 1px solid var(--line); background: #f8faf9; }
.conversation-heading { padding: 17px; border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 900; }
.conversation-button {
  display: grid;
  width: 100%;
  gap: 5px;
  padding: 14px 17px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.conversation-button:hover, .conversation-button.active { background: #f3e9e4; }
.conversation-button strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.conversation-button span { color: var(--muted); font-size: 11px; }
.chat-panel { display: grid; grid-template-rows: auto minmax(250px, 1fr) auto; min-width: 0; }
.chat-header { display: flex; align-items: center; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.chat-avatar { display: grid; width: 42px; height: 42px; flex: 0 0 auto; place-items: center; border-radius: 50%; background: var(--ink); color: var(--white); font-size: 12px; font-weight: 900; }
.chat-header h3 { margin: 0; font-size: 16px; }
.chat-header p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.message-history { display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow-y: auto; padding: 18px; }
.message-bubble { align-self: flex-start; max-width: min(78%, 560px); padding: 10px 12px; border-radius: 4px 13px 13px 13px; background: #eef1ef; font-size: 13px; line-height: 1.55; overflow-wrap: anywhere; }
.message-bubble.own { align-self: flex-end; border-radius: 13px 4px 13px 13px; background: #f1ddd6; }
.message-bubble small { display: block; margin-top: 5px; color: var(--muted); font-size: 9px; }
.message-delivery { display:inline-flex; align-items:center; gap:4px; margin-left:7px; font-weight:900; }
.message-delivery.read { color:var(--green); }
.message-empty { margin: auto; color: var(--muted); font-size: 13px; text-align: center; }
.message-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 13px; border-top: 1px solid var(--line); }
.message-form textarea { min-height: 76px; }

.market-footer { display: flex; justify-content: space-between; gap: 18px; padding: 24px clamp(18px, 5vw, 68px); border-top: 1px solid var(--line); background: var(--ink); color: #d9dfe6; font-size: 12px; }
.market-footer a { font-weight: 900; }
.market-footer a:hover { color: var(--white); }

.modal-backdrop { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 18px; overflow-y: auto; background: rgba(18, 25, 34, 0.62); }
.modal-dialog { position: relative; width: min(100%, 560px); max-height: calc(100vh - 36px); overflow-y: auto; padding: clamp(24px, 5vw, 38px); border-radius: 14px; background: var(--white); box-shadow: 0 28px 90px rgba(0,0,0,.25); }
.item-dialog { width: min(100%, 780px); }
.modal-dialog h2 { margin: 0; font-size: clamp(30px, 5vw, 46px); line-height: 1; letter-spacing: -0.035em; }
.modal-intro { margin: 14px 0 22px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.modal-close { position: absolute; top: 13px; right: 13px; display: grid; width: 36px; height: 36px; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: var(--white); cursor: pointer; font-size: 21px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 19px; padding: 4px; border-radius: 9px; background: #eef1ef; }
.auth-tab { min-height: 39px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; font-size: 13px; font-weight: 900; }
.auth-tab.active { background: var(--white); box-shadow: 0 2px 9px rgba(27,36,48,.08); }
.modal-form { display: grid; gap: 14px; }
.form-grid { display: grid; gap: 12px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-message { min-height: 19px; margin: 0; color: #ad4c43; font-size: 12px; font-weight: 800; }
.form-message.success { color: var(--green); }
.photo-preview { display: grid; min-height: 150px; place-items: center; overflow: hidden; border: 1px dashed var(--line); border-radius: 10px; background: #f5f6f2; color: var(--muted); font-size: 12px; }
.photo-preview img { width: 100%; max-height: 300px; object-fit: cover; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 80; max-width: min(360px, calc(100vw - 44px)); padding: 12px 16px; border-radius: 9px; background: var(--ink); color: var(--white); box-shadow: var(--shadow); font-size: 13px; font-weight: 800; }

@media (max-width: 1150px) {
  .item-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 880px) {
  .market-topbar { grid-template-columns: 1fr auto; }
  .market-nav { grid-column: 1 / -1; grid-row: 2; justify-content: center; padding-top: 6px; border-top: 1px solid rgba(27,36,48,.07); }
  .market-hero { grid-template-columns: 1fr; }
  .hero-market-card { display: none; }
  .market-layout { grid-template-columns: 1fr; }
  .filters { position: static; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-heading { grid-column: 1 / -1; }
  .message-layout { grid-template-columns: minmax(190px, .4fr) minmax(0, .6fr); }
}

@media (max-width: 640px) {
  html { scroll-padding-top: 130px; }
  .market-topbar { padding-inline: 14px; }
  .market-brand em, .account-actions > span { display: none !important; }
  .market-nav { gap: 18px; }
  .market-hero, .market-section, .messages-section { padding-inline: 16px; }
  .market-hero h1 { font-size: clamp(46px, 16vw, 70px); }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .section-note { text-align: left; }
  .message-section-meta { justify-items:start; }
  .filters { grid-template-columns: 1fr; }
  .filter-heading { grid-column: auto; }
  .item-grid { grid-template-columns: 1fr; }
  .message-layout { grid-template-columns: 1fr; }
  .conversation-list { max-height: 220px; overflow-y: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .chat-panel { min-height: 430px; }
  .message-form { grid-template-columns: 1fr; }
  .message-form button { min-height: 40px; }
  .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
  .market-footer { align-items: flex-start; flex-direction: column; }
}
