/* =====================================================================
   Miftah — Working tools (version 15)
   The undo toast, empty states with a next step, the side drawer, the
   "Why" inside match cards, the command bar, field checks, tables that
   stack on phones, the getting-started list, price per m², the property
   sheet (and how it prints) and the developer area.
   Everything is drawn from the tokens, so the three styles and both
   themes carry through; the property sheet alone is paper, white in
   every theme, because that is what it becomes.
   ===================================================================== */

:root { --drawer-w: 440px; }

/* --- Links that are not anchors ---------------------------------------- */
.link { color: var(--accent); font-weight: 500; cursor: pointer; }
.link:hover { text-decoration: underline; }
.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
:root[data-style="mono"] .link { color: var(--focus); }

/* A property or a person that opens its own page (role="link"): only as
   wide as what it says, plain at rest, tinted under the pointer, so it
   reads as its own target inside a match card that opens the drawer on a
   click. The spread ring gives the tint room without moving the text. */
.row[role="link"] { width: fit-content; max-width: 100%; }
.drawer-item.row-sb > .row[role="link"] { flex: 0 1 auto; }
.row-sb > .row[role="link"] { min-width: 0; }
/* A link that ends a drawer section keeps its hover ring above the next line */
.drawer-sec:has(> .row[role="link"]:last-child) { padding-bottom: 5px; }
:is(.row, .name)[role="link"] {
  border-radius: max(2px, calc(var(--r-sm) - 4px));
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.row[role="link"]:hover { background: var(--accent-soft); box-shadow: 0 0 0 5px var(--accent-soft); }
.name[role="link"]:hover { background: var(--accent-soft); box-shadow: 0 0 0 4px var(--accent-soft); color: var(--accent-text); }
.row[role="link"]:hover .cell-main { color: var(--accent-text); }

/* A phone number never breaks across lines, however narrow the column */
.cell-sub[dir="ltr"], .meta[dir="ltr"] { white-space: nowrap; }

.btn-quiet.danger { color: var(--crit-ink); }
.btn-quiet.danger:hover { background: var(--crit-bg); color: var(--crit-ink); }

/* --- Toast with an action ---------------------------------------------- */
#toast .toast-inner.has-action { pointer-events: auto; padding-inline-end: 8px; }
#toast .toast-inner {
  visibility: hidden;
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease), visibility 0s linear var(--t);
}
#toast.show .toast-inner { visibility: visible; transition-delay: 0s; }
@media (max-width: 1279px) {
  #app.has-drawer ~ #toast { bottom: calc(22px + 60px + env(safe-area-inset-bottom, 0px)); }
}
.toast-action {
  margin-inline-start: 8px;
  height: 28px;
  padding: 0 12px;
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--canvas) 18%, transparent);
  color: var(--canvas);
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}
.toast-action:hover { background: color-mix(in srgb, var(--canvas) 28%, transparent); }
.toast-action:focus-visible { outline: 2px solid var(--canvas); outline-offset: 2px; }

/* --- Empty states lead somewhere --------------------------------------- */
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 6px; }

/* --- Field checks -------------------------------------------------------- */
.field-error.is-warn { color: var(--warn-ink); }
.input.warned { border-color: var(--warn-mark); }
.input.warned:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn-mark) 22%, transparent); }

/* --- Side drawer ----------------------------------------------------------
   Fixed at the inline end, under the top bar. On a wide screen the page
   gives it room, so the list beside it is never covered; narrower, it
   sits over the page; on a phone it takes the whole width. */
.drawer {
  position: fixed;
  z-index: 55;
  top: var(--topbar-h);
  bottom: 0;
  inset-inline-end: 0;
  width: min(var(--drawer-w), 100vw);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-inline-start: 1px solid var(--border);
  box-shadow: var(--shadow-pop);
}
.drawer[hidden] { display: none; }
.drawer.is-entering { animation: mf-drawer .24s var(--ease) both; }
@keyframes mf-drawer { from { opacity: 0; transform: translateX(calc(var(--dir) * 28px)); } }

.drawer-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.drawer-title { flex: 1; min-width: 0; display: grid; gap: 6px; }
.drawer-eyebrow { font-size: 11.5px; font-weight: 600; color: var(--ink-3); }
.drawer-head h2 { font-size: 19px; font-weight: 600; letter-spacing: -.01em; line-height: 1.25; overflow-wrap: anywhere; }
.drawer-head h2:focus { outline: none; }
.drawer-body { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 18px 20px; overscroll-behavior: contain; }
.drawer-foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.drawer-sec { padding-top: 16px; }
.drawer-sec + .drawer-sec { margin-top: 2px; border-top: 1px solid var(--border); }
.drawer-sec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.drawer-sec-head h3 { margin: 0; }
.drawer-sec .next { margin: 0; }
.drawer-body > .next { margin-top: 16px; }
.dl-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.dl-row:last-of-type { border-bottom: 0; }
.dl-k { color: var(--ink-2); flex: none; }
.dl-v { text-align: end; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.drawer-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.drawer-item:last-child { border-bottom: 0; }
.drawer-item .score-bar { min-width: 0; max-width: 180px; }
.drawer-item.row-sb > .row { flex: 1 1 auto; min-width: 0; }
.drawer-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--r);
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 12.5px;
}
.drawer-note svg { flex: none; margin-top: 1px; }

@media (min-width: 1280px) {
  #app.has-drawer .page { margin-inline-end: var(--drawer-w); }
  .drawer { box-shadow: none; }
}
@media (max-width: 700px) {
  .drawer { width: 100%; border-inline-start: 0; }
}

table.data tbody tr.clickable:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

/* The record whose drawer is open is marked in its list */
table.data tbody tr.is-open,
table.data tbody tr.is-open td:last-child:has(.row-actions) { background: var(--accent-soft); }
table.data tbody tr.is-open .avatar { background: var(--surface); border-color: var(--accent-soft-2); }
.mcard.is-open { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* --- Match cards: a click opens the drawer, "Why" opens in place ------- */
.mcard[data-act] { cursor: pointer; }
.mcard-more { grid-column: 1 / -1; padding-top: 12px; border-top: 1px dashed var(--border-strong); cursor: default; }
.mcard-more:not([hidden]) { animation: mf-fade .2s var(--ease) both; }
.mcard-more-foot { display: flex; justify-content: flex-end; margin-top: 10px; }
.why-toggle .why-caret { transition: transform var(--t-fast) var(--ease); }
.why-toggle[aria-expanded="true"] { color: var(--accent-text); background: var(--accent-soft); }
.why-toggle[aria-expanded="true"] .why-caret { transform: rotate(180deg); }

/* --- Command bar ----------------------------------------------------------- */
.search-hit[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-text); }
.search-hit[aria-selected="true"] svg { color: var(--accent); }
#search-results .search-hit:hover:not([aria-selected="true"]) { background: transparent; color: var(--ink-2); }
#search-results .search-hit:hover:not([aria-selected="true"]) svg { color: var(--ink-3); }
.search-hit.is-command .strong { font-weight: 500; }
.search-keys { display: inline-flex; gap: 3px; flex: none; }
.search-keys kbd {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink-3);
  font: 600 10.5px/15px var(--font);
  text-align: center;
}

/* --- Automatic tasks say so ---------------------------------------------- */
.chip-auto { background: var(--info-bg); color: var(--info-ink); }

/* --- Getting started ------------------------------------------------------- */
.start-wrap { margin-bottom: 16px; }
.start-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.start-step {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  font-size: 13.5px;
  font-weight: 500;
}
.start-step.is-next { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.start-step.is-done { background: var(--surface-2); color: var(--ink-3); }
.start-mark {
  width: 26px;
  height: 26px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.start-step.is-next .start-mark { background: var(--accent); color: var(--accent-ink); }
.start-step.is-done .start-mark { background: var(--good-bg); color: var(--good-ink); }

/* --- Price per m² ------------------------------------------------------------ */
.ppm { padding: 10px 0 11px; border-bottom: 1px solid var(--border); }
.ppm-strip { position: relative; height: 18px; margin: 10px 6px 2px; }
.ppm-track { position: absolute; inset-inline: 0; top: 8px; height: 2px; border-radius: 1px; background: var(--surface-3); }
.ppm-dot {
  position: absolute;
  top: 5px;
  width: 8px;
  height: 8px;
  margin-inline-start: -4px;
  border-radius: 50%;
  background: var(--border-strong);
  box-shadow: 0 0 0 2px var(--surface);
}
.ppm-dot.is-this { top: 3px; width: 12px; height: 12px; margin-inline-start: -6px; background: var(--accent); }
.ppm-median { position: absolute; top: 1px; width: 2px; height: 16px; margin-inline-start: -1px; border-radius: 1px; background: var(--ink-2); }
.ppm-scale { display: flex; justify-content: space-between; margin: 0 2px; }

/* --- Developer area ------------------------------------------------------------ */
.dev-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 1px dashed var(--warn-mark);
  border-radius: var(--r-pill);
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.dev-chip[hidden] { display: none; }
/* Phones, and tablets where the side panel leaves the bar narrow: the chip
   keeps its icon and "as Name", the language moves to Settings */
@media (max-width: 560px), (min-width: 701px) and (max-width: 900px) {
  .dev-chip { padding: 0 9px; }
  .dev-chip > span:not(.dev-chip-set) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .topbar-tools:has(> .dev-chip:not([hidden])) .lang-switch { display: none; }
}
.dev-chip-set { padding: 1px 7px; border-radius: var(--r-pill); background: var(--warn-mark); color: #1B1300; font-size: 11px; }
.dev-status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--r);
  background: var(--warn-bg);
  color: var(--warn-ink);
}
.dev-status > span { flex: 1; min-width: 0; font-size: 13px; }
.dev-status .dim { color: inherit; opacity: .85; }
.dev-code {
  margin: 10px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font: 12px/1.55 'IBM Plex Mono', ui-monospace, monospace;
  white-space: pre-wrap;
  word-break: break-all;
  text-align: start;
}
/* The version line is text to the eye; five presses open the gate */
.version-line {
  display: block;
  margin: 28px auto 4px;
  padding: 6px 10px;
  border: 0;
  background: none;
  color: var(--ink-3);
  font-size: 12px;
  text-align: center;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* --- Tables stack into cards on a phone -------------------------------------
   Each cell shows its column name (ui.table writes data-label); the first
   cell is the row's identity and the row actions stay at its side. */
@media (max-width: 640px) {
  .table-wrap { overflow: visible; }
  table.data, table.data tbody { display: block; width: 100%; }
  table.data thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  table.data tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 7px 12px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
  }
  table.data tbody tr:last-child { border-bottom: 0; }
  /* label on one side, everything the cell holds stacked on the other */
  table.data td {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    column-gap: 12px;
    min-width: 0;
    padding: 0;
    border: 0;
    text-align: end;
  }
  table.data td::before {
    content: attr(data-label);
    grid-column: 1;
    grid-row: 1 / span 6;
    max-width: 42vw;
    color: var(--ink-3);
    font-size: 12px;
    font-weight: 500;
    text-align: start;
  }
  table.data td > * { grid-column: 2; justify-self: end; }
  table.data td:not([data-label])::before { content: none; }
  table.data td > .col { align-items: flex-end; }
  table.data td:first-child { grid-column: 1; grid-row: 1; display: block; text-align: start; }
  table.data td:first-child > * { justify-self: stretch; }
  table.data td:first-child::before { content: none; }
  table.data td:first-child > .col { align-items: flex-start; }
  table.data td:last-child:has(.row-actions) {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
    position: static;
    background: transparent;
  }
  table.data tbody tr.clickable:hover td:last-child:has(.row-actions) { background: transparent; }
  table.data tbody tr.is-open td:last-child:has(.row-actions) { background: transparent; }
}

/* --- Property sheet ----------------------------------------------------------- */
.modal.modal-wide { max-width: 780px; }
.sheet-tools { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.sheet-frame { padding: 14px; border: 1px solid var(--border); border-radius: var(--r); background: var(--canvas); }

/* Paper: the same in every theme and style */
.sheet {
  --surface: #FFFFFF;
  --surface-2: #F1F3F2;
  --surface-3: #E7EBE9;
  --border: #E1E5E3;
  --border-strong: #C6CFCA;
  max-width: 680px;
  margin: 0 auto;
  padding: 28px 30px;
  border-radius: 6px;
  background: #FFFFFF;
  color: #15191A;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 10px 28px rgba(0, 0, 0, .08);
  font-size: 13px;
  line-height: 1.5;
  text-align: start;
}
.sheet[lang="ar"] { font-family: var(--font-ar); }
.sheet { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 2px solid #15191A;
}
.sheet-brand { display: flex; align-items: center; gap: 10px; }
.sheet-brand b { display: block; font-size: 15px; }
.sheet-brand div > span { display: block; font-size: 12px; color: #59635F; }
.sheet-mark { width: 30px; height: 30px; flex: none; display: grid; place-items: center; border-radius: 8px; background: #0D7A50; color: #FFFFFF; }
.sheet-meta { display: grid; gap: 2px; text-align: end; font-size: 11.5px; color: #59635F; }
.sheet-photo { position: relative; margin-top: 16px; aspect-ratio: 16 / 9; overflow: hidden; border-radius: 6px; background: #F1F3F2; }
.sheet-photo > img, .sheet-photo > svg { display: block; width: 100%; height: 100%; object-fit: cover; }
.sheet-photo-tag {
  position: absolute;
  bottom: 8px;
  inset-inline-start: 8px;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .62);
  color: #FFFFFF;
  font-size: 10.5px;
  font-weight: 600;
}
.sheet-lead { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px 20px; margin-top: 16px; }
:root .sheet .sheet-title { font-size: 22px; font-weight: 700; line-height: 1.2; letter-spacing: -.01em; }
.sheet-where { margin-top: 4px; color: #59635F; }
.sheet-price { display: grid; justify-items: end; gap: 3px; }
.sheet-price b { font-size: 24px; line-height: 1.1; color: #0B6B47; font-variant-numeric: tabular-nums; }
.sheet-price > span { font-size: 12px; color: #59635F; }
.sheet-sec { margin-top: 18px; }
:root .sheet .sheet-sec h3 { margin-bottom: 8px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #59635F; }
:root .sheet[lang="ar"] .sheet-sec h3 { font-size: 12.5px; letter-spacing: 0; text-transform: none; }
.sheet-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 18px; margin: 0; }
.sheet-facts > div { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid #E1E5E3; }
.sheet-facts dt { color: #59635F; }
.sheet-facts dd { margin: 0; font-weight: 600; text-align: end; }
.sheet-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.sheet-chip { display: inline-flex; align-items: center; padding: 3px 10px; border: 1px solid #C6CFCA; border-radius: 999px; font-size: 12px; font-weight: 500; color: #15191A; }
.sheet-foot { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; margin-top: 22px; padding-top: 12px; border-top: 1px solid #E1E5E3; color: #59635F; }
.sheet-foot b { color: #15191A; }

@media (max-width: 640px) {
  .sheet-frame { padding: 8px; }
  .sheet { padding: 18px 16px; }
  .sheet-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sheet-price { justify-items: start; }
}

/* Printing prints the sheet and nothing else, however printing starts
   (the Print button, Ctrl+P, the browser menu), for as long as the sheet
   is on screen. Nothing is toggled on a timer, so a late mobile print
   cannot catch the property page, with its owner and buyers, behind it. */
@media print {
  :root:has(#sheet-frame), :root:has(#sheet-frame) body { background: #FFFFFF !important; height: auto; overflow: visible; }
  :root:has(#sheet-frame) body > *:not(#overlay) { display: none !important; }
  :root:has(#sheet-frame) #overlay { position: static; display: block; padding: 0; background: none; }
  :root:has(#sheet-frame) .modal { max-width: none; max-height: none; border: 0; box-shadow: none; overflow: visible; background: #FFFFFF; animation: none; }
  :root:has(#sheet-frame) .modal-head,
  :root:has(#sheet-frame) .modal-foot,
  :root:has(#sheet-frame) .sheet-tools,
  :root:has(#sheet-frame) .modal-body > p { display: none !important; }
  :root:has(#sheet-frame) .modal-body { padding: 0; overflow: visible; }
  :root:has(#sheet-frame) .sheet-frame { padding: 0; border: 0; background: none; }
  :root:has(#sheet-frame) .sheet { max-width: none; padding: 0; box-shadow: none; }
  @page { margin: 14mm; }
}

/* ---------------------------------------------------------------------
   Roles and permissions (version 16)
   What a role does not see is replaced by a quiet line with a padlock;
   the Team page's table shows fixed cells the same way.
   --------------------------------------------------------------------- */
.perm-hidden { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 400; color: var(--ink-3); }
.perm-hidden svg, .perm-fixed svg { flex: none; }
.perm-fixed { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.perm-fixed svg { color: var(--ink-3); }
.perm-cell { gap: 4px; min-width: 0; }
.perm-select { width: 100%; min-width: 0; max-width: 300px; }
.perm-select.is-changed { border-color: var(--accent); }
.perm-was { color: var(--accent-text); }
.perm-table td { vertical-align: middle; }
@media (min-width: 641px) {
  .perm-table td:first-child { min-width: 220px; }
}
/* On a phone the stacked rows give each choice the full value column */
@media (max-width: 640px) {
  .perm-table td > .perm-cell { justify-self: stretch; align-items: stretch; }
  .perm-select { max-width: none; }
}
/* The developer's "as Nadia" pill never pushes the bar past a phone's width */
@media (max-width: 560px) {
  .dev-chip-set { display: inline-block; max-width: 26vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
}

/* A segmented choice with more options than one row holds wraps (Settings → Style) */
.segmented.segmented-wrap { display: flex; flex-wrap: wrap; width: fit-content; max-width: 100%; row-gap: 3px; }
