/* وطن — سوق المرحلة الحادية عشرة: عروض البيع والشراء، الأوڤر، وأرقام السوق.
   Colour carries meaning: sell = copper, buy = brand. Small text uses --ink-2 on --surface (AA). */

[hidden] { display: none !important; }

.market-main { padding-bottom: 34px; }
.market-main > * + * { margin-top: 16px; }
.market-section { scroll-margin-top: 112px; }
.market-main .btn-solid { color: var(--surface); }

.is-sell { --accent: var(--copper); }
.is-buy { --accent: var(--brand); }
.board-col[data-side="sell"] { --accent: var(--copper); }
.board-col[data-side="buy"] { --accent: var(--brand); }
b.is-sell, td.is-sell { color: var(--copper); }
b.is-buy, td.is-buy { color: var(--brand); }
.unit { margin-inline-start: 4px; font-size: 13px; font-style: normal; font-weight: 500; color: var(--ink-2); }

/* ---------- البطل المختصر ---------- */

.market-hero { grid-template-columns: minmax(0, 1fr); padding: clamp(22px, 2.8vw, 34px); }
.market-hero h1 { margin-top: 0; font-size: clamp(30px, 3.6vw, 44px); }
.market-hero .lede { margin-top: 10px; }
.market-hero-cta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.market-hero-cta a {
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto; width: auto; min-height: 44px; padding: 0 20px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
}
.market-hero-cta .btn-solid { background: var(--grad-gold); box-shadow: var(--glow-gold); color: var(--obsidian); }
.market-hero-cta .btn-solid:hover { background: var(--grad-gold); filter: brightness(1.06); }

/* ---------- أرقام السوق ---------- */

.market-main .section-head { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px 12px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.stats-grid .bk-tile > span { font-size: 13px; color: var(--ink-2); }
.stats-grid .bk-tile b { font-size: 25px; overflow-wrap: anywhere; }
#statsScope { max-width: 100%; white-space: normal; overflow-wrap: anywhere; text-align: start; }

/* ---------- زر المعلومة ---------- */

.info-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  flex: none; width: 20px; height: 20px; margin-inline-start: 6px; padding: 0;
  border: 1px solid var(--ink-2); border-radius: 50%;
  background: transparent; color: var(--ink-2);
  font-family: var(--display); font-size: 13px; font-style: italic; font-weight: 600; line-height: 1;
  vertical-align: middle;
  transition: background-color .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease);
}
.info-btn::after { content: ""; position: absolute; inset: -12px; }
.info-btn:hover,
.info-btn[aria-expanded="true"] { background: var(--brand); border-color: var(--brand); color: var(--surface); }
.info-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.info-pop {
  position: fixed; z-index: 60;
  max-width: min(260px, calc(100vw - 16px));
  padding: 10px 12px;
  border-radius: var(--radius-xs);
  background: var(--ink); color: var(--bg);
  box-shadow: var(--shadow-md);
  font-size: 13px; line-height: 1.6;
}

/* ---------- الروابط داخل البطاقات ---------- */

.link {
  position: relative;
  padding: 0; border: 0; background: none;
  color: var(--brand); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
}
.link::after { content: ""; position: absolute; inset: -12px -6px; }
.link:hover { color: var(--brand-deep); text-decoration: underline; text-underline-offset: 3px; }
.link:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

/* ---------- الفلاتر ---------- */

.filter-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; align-items: end; }
.filter-row--ranges { grid-template-columns: repeat(2, minmax(0, 1fr)) minmax(160px, .7fr); padding: 4px 14px 14px; }
.market-filters .bk-fold > summary { min-height: 44px; }
.filter-field { display: grid; gap: 5px; min-width: 0; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.filter-select,
.filter-input {
  width: 100%; min-width: 0; height: 44px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius-xs);
  background: var(--surface-2); color: var(--ink);
  font-family: var(--font); font-size: 14px;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease), background-color .2s var(--ease);
}
.filter-select {
  appearance: none;
  padding-inline-end: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(0% + 14px) 19px, calc(0% + 19px) 19px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}
.filter-select:focus,
.filter-input:focus {
  outline: 0; border-color: var(--brand-mid); background-color: var(--surface);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 8%, transparent);
}
.range-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }

/* ---------- اللوحة ---------- */

.board-tabs {
  display: none; gap: 4px; margin-bottom: 10px; padding: 4px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); box-shadow: var(--shadow-xs);
}
.board-tabs button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 0; min-height: 44px; padding: 0 8px;
  border: 0; border-radius: var(--radius-xs);
  background: transparent; color: var(--ink-2);
  font-size: 14px; font-weight: 600; white-space: nowrap;
}
.board-tabs button[aria-selected="true"] { background: var(--grad-brand); border-color: transparent; box-shadow: var(--glow-brand); color: var(--on-brand); }
.board-tabs button[data-board-tab="sell"][aria-selected="true"] { background: var(--grad-coral); color: var(--on-brand); box-shadow: 0 6px 16px -8px rgba(193, 59, 46, .8); }
.board-tabs .count-pill { background: color-mix(in srgb, var(--ink) 8%, transparent); color: inherit; }

.board-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
.board-grid.is-single { grid-template-columns: minmax(0, 1fr); }
.board-col {
  display: flex; flex-direction: column; min-width: 0; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow-xs);
}
.board-col-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line-2); }
.board-col-head h2 {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--display); font-size: 19px; font-weight: 600; letter-spacing: -.02em; color: var(--ink);
}
.board-col-head h2::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.offer-list { display: grid; gap: 10px; padding: 12px; }

.offer-card {
  min-width: 0; padding: 12px 14px;
  border: 1px solid var(--line); border-inline-start: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface); box-shadow: var(--shadow-xs);
}
.offer-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.offer-plots {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; min-width: 0;
  font-family: var(--display); font-size: 19px; font-weight: 600; line-height: 1.4; letter-spacing: -.02em; color: var(--ink);
}
.offer-plots .link { font-weight: 600; direction: ltr; unicode-bidi: isolate; }
.offer-plot-sep, .plot-more { font-size: 13px; color: var(--ink-2); }
.plot-more-btn { font: inherit; font-size: 13px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); cursor: pointer; }
.plot-more-btn:hover { border-color: var(--brand); color: var(--brand); }
.mine-kind { font-family: var(--font); font-size: 13px; font-weight: 600; letter-spacing: 0; color: var(--accent); }
.offer-badge {
  display: inline-flex; align-items: center; min-height: 24px; margin-inline-start: auto; padding: 0 9px;
  border-radius: 999px; background: var(--surface-3); color: var(--ink-2);
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.offer-top > .pill { margin-inline-start: auto; }
.offer-badge + .pill { margin-inline-start: 0; }
.offer-place { margin: 2px 0 0; font-size: 13px; line-height: 1.5; color: var(--ink-2); overflow-wrap: anywhere; }
.offer-price { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; margin-top: 6px; }
.offer-price b {
  font-family: var(--display); font-size: 20px; font-weight: 600; line-height: 1.3; letter-spacing: -.02em;
  color: var(--accent); overflow-wrap: anywhere;
}
.is-withdrawn { --accent: var(--ink-2); }
.chip {
  display: inline-flex; align-items: center; gap: 4px; min-height: 24px; padding: 0 9px;
  border-radius: 999px; background: var(--surface-2); color: var(--ink-2);
  font-size: 13px; white-space: nowrap;
}
.offer-pct {
  display: inline-flex; align-items: center; min-height: 24px; padding: 0 9px;
  border-radius: 999px; background: var(--surface-3); color: var(--ink-2);
  font-size: 13px; font-style: normal; font-weight: 600; white-space: nowrap;
}
.offer-note {
  margin: 6px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; line-height: 1.5; color: var(--ink-2);
}
.offer-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.offer-person { min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--ink-2); }
.offer-person b { font-weight: 600; color: var(--ink); }
.offer-contacts { display: flex; flex: none; gap: 6px; }
.contact-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--surface); color: var(--ink-2);
  transition: border-color .2s var(--ease), color .2s var(--ease), background-color .2s var(--ease);
}
.contact-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.contact-btn:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-tint); }
.contact-btn--wa { color: var(--live); }
.contact-btn--wa:hover { border-color: var(--live); color: var(--live); background: color-mix(in srgb, var(--live) 8%, var(--surface)); }
.contact-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.market-empty {
  padding: 22px 18px;
  border: 1px dashed var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); text-align: center;
}
.market-empty b { display: block; font-size: 14px; font-weight: 600; color: var(--ink); }
.market-empty .btn-quiet { min-height: 44px; margin-top: 10px; }
.market-unavailable { margin-top: 12px; }
.board-more {
  width: 100%; min-height: 44px; margin-top: 4px;
  border: 1px dashed var(--line); border-radius: var(--radius-xs); background: transparent;
  color: var(--ink); font-size: 14px; font-weight: 600;
}
.board-more:hover { border-style: solid; }

/* ---------- لوحة القطعة أو المنطقة ---------- */

.plot-panel { overflow: hidden; }
.plot-panel .card-head { align-items: center; padding-bottom: 6px; }
.plot-head-actions { display: flex; align-items: center; gap: 8px; }
.plot-panel .card-link {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 13px;
  border: 1px solid var(--line); border-radius: 999px;
}
.plot-facts {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; overflow: hidden;
  border-radius: var(--radius-sm); background: var(--line-2);
}
.plot-fact { min-width: 0; padding: 12px 14px; background: var(--surface-2); }
.plot-fact span { display: block; font-size: 13px; color: var(--ink-2); }
.plot-fact b {
  display: block; margin-top: 3px;
  font-family: var(--display); font-size: 16px; font-weight: 600; line-height: 1.35; color: var(--ink);
  overflow-wrap: anywhere;
}
.plot-market { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.plot-market .plot-fact { border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface); }

/* ---------- جدول المناطق ---------- */

.market-zones-table { min-width: 720px; }
.market-zones-table th { padding: 0; color: var(--ink-2); }
.market-zones-table th .th-sort {
  display: flex; align-items: center; gap: 4px; width: 100%; min-height: 44px; margin: 0; padding: 0 14px;
  border: 0; border-radius: 0; background: none; color: inherit;
  font: inherit; letter-spacing: inherit; text-align: right; white-space: nowrap; cursor: pointer;
}
.market-zones-table th .th-sort:hover { color: var(--brand); }
.market-zones-table th[aria-sort] .th-sort { color: var(--brand); font-weight: 600; }
.th-arrow { font-size: 13px; line-height: 1; color: var(--ink-2); }
.market-zones-table th[aria-sort] .th-arrow { color: var(--brand); }
.market-zones-table tbody tr { cursor: pointer; }
.market-zones-table tbody tr.is-on { background: var(--brand-soft); }
.market-zones-table tbody tr:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.market-zones-table .cell-zone { font-weight: 600; }
.market-zones-table .cell-city { color: var(--ink-2); }
.zones-card .empty-state { padding: 28px 18px; }

/* ---------- نموذج إضافة العرض ---------- */

.form-tabs {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 6px;
  border-bottom: 1px solid var(--line-2); background: var(--surface-2);
}
.form-tabs button {
  min-width: 0; min-height: 44px; padding: 0 10px;
  border: 0; border-radius: var(--radius-xs);
  background: transparent; color: var(--ink-2);
  font-size: 14px; font-weight: 600;
  transition: background-color .2s var(--ease), color .2s var(--ease), box-shadow .2s var(--ease);
}
.form-tabs button:hover { color: var(--ink); }
.form-tabs button[aria-selected="true"] { background: var(--grad-brand); color: var(--on-brand); box-shadow: var(--glow-brand); }
#addForm { display: grid; gap: 12px; padding: 16px 18px 18px; }
.form-pane { display: grid; gap: 10px; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.field-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-label { display: grid; gap: 5px; min-width: 0; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.field-label select,
.field-label input,
.field-label textarea {
  width: 100%; min-width: 0; height: 44px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius-xs);
  background: var(--surface-2); color: var(--ink);
  font-family: var(--font); font-size: 14px;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease), background-color .2s var(--ease);
}
.field-label select {
  appearance: none;
  padding-inline-end: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(0% + 14px) 19px, calc(0% + 19px) 19px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}
.field-label textarea { height: auto; min-height: 66px; padding: 10px 12px; resize: vertical; line-height: 1.6; }
.field-label select:focus,
.field-label input:focus,
.field-label textarea:focus {
  outline: 0; border-color: var(--brand-mid); background-color: var(--surface);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 8%, transparent);
}
.field-label input[aria-invalid="true"],
.field-label textarea[aria-invalid="true"],
.field-label select[aria-invalid="true"] { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.chip-add { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip-add .btn-quiet { min-height: 44px; }
.chip-hint { font-size: 13px; color: var(--ink-2); }
.cell-zone .zone-city { display: none; }
.buy-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.buy-chips:empty { display: none; }
.buy-chips.is-invalid { outline: 2px solid var(--red); outline-offset: 4px; border-radius: var(--radius-xs); }
.buy-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 44px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--brand-soft); color: var(--brand);
  font-size: 13px; font-weight: 500; text-align: start;
}
.buy-chip:hover { border-color: var(--brand); }
.buy-chip .chip-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.buy-chip .x { flex: none; font-size: 16px; line-height: 1; }
.form-notice {
  margin: 0; padding: 10px 12px; border-radius: var(--radius-xs);
  background: var(--copper-soft); color: var(--copper); font-size: 13px; line-height: 1.6;
}
.form-foot { display: flex; justify-content: flex-end; }
.form-foot .btn-solid { min-height: 44px; height: auto; padding: 0 22px; }

/* ---------- عروضي ---------- */

.key-note {
  margin: 0 0 10px; padding: 10px 12px; border-radius: var(--radius-xs);
  background: color-mix(in srgb, var(--gold) 14%, var(--surface)); color: var(--ink);
  font-size: 13px; line-height: 1.6;
}
.mine-list { display: grid; gap: 10px; }
.mine-card.is-withdrawn { border-inline-start-style: dashed; background: var(--surface-2); box-shadow: none; }
.mine-expiry { margin: 4px 0 0; font-size: 13px; color: var(--ink-2); }
.pill.active { background: color-mix(in srgb, var(--live) 14%, var(--surface)); color: color-mix(in srgb, var(--live) 55%, var(--ink)); }
.pill.expired { background: color-mix(in srgb, var(--gold) 22%, var(--surface)); color: var(--ink); }
.pill.withdrawn { background: var(--surface-3); color: var(--ink-2); }
.mine-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.mine-actions button,
.mine-edit button {
  min-height: 44px; padding: 0 13px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink-2);
  font-size: 13px; font-weight: 500;
  transition: border-color .2s var(--ease), color .2s var(--ease), background-color .2s var(--ease);
}
.mine-actions button:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-tint); }
.mine-actions button[data-mact="withdraw"] { color: var(--red); }
.mine-actions button[data-mact="withdraw"]:hover { border-color: var(--red); background: var(--red-soft); }
.mine-edit { display: flex; align-items: flex-end; gap: 6px; flex-wrap: wrap; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line-2); }
.mine-edit label { flex: 1 1 190px; }
.mine-edit button[data-mact="save-edit"] { background: var(--grad-brand); border-color: transparent; box-shadow: var(--glow-brand); color: var(--on-brand); }

/* ---------- الاستجابة ---------- */

@media (max-width: 1100px) {
  .filter-row--ranges { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plot-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .board-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .board-grid { grid-template-columns: minmax(0, 1fr); }
  .board-grid:not(.is-single) .board-col { display: none; }
  .board-grid:not(.is-single)[data-mobile-tab="sell"] .board-col[data-side="sell"],
  .board-grid:not(.is-single)[data-mobile-tab="buy"] .board-col[data-side="buy"] { display: flex; }
  .board-grid.is-single .board-col:not([hidden]) { display: flex; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .filter-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-row--ranges,
  .field-row,
  .field-row-3 { grid-template-columns: minmax(0, 1fr); }
  .stats-grid .bk-tile b { font-size: 20px; }
  .plot-market { grid-template-columns: minmax(0, 1fr); }
  .plot-panel .card-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  #addForm { padding: 14px; }
  .market-zones-table th:not([data-zkey="name"]):not([data-zkey="lowestAsk"]):not([data-zkey="bestBid"]),
  .market-zones-table td:not(.cell-zone):not(.dash-empty):not(:nth-child(5)):not(:nth-child(6)) { display: none; }
  .cell-zone .zone-city { display: block; font-size: 13px; color: var(--ink-2); }
  .market-zones-table { min-width: 0; }
  .market-zones-table td, .market-zones-table th .th-sort { padding-inline: 8px; }
  .market-zones-table th .th-sort { white-space: normal; }
}

@media (max-width: 340px) {
  .stats-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .info-btn,
  .board-tabs button,
  .form-tabs button,
  .contact-btn,
  .mine-actions button,
  .mine-edit button,
  .filter-select,
  .filter-input,
  .field-label select,
  .field-label input,
  .field-label textarea { transition: none; }
}
