/* Phone/Lite pricing: one flat sheet. Wide Pro keeps the table accordion. */

#grid tbody > tr.is-collapsed {
  display: none !important;
}

/* Fee steps are divs. Global td nowrap + fixed row-height mashed the old nested table. */
#grid.price-narrow > tbody > tr.pr-fee-row,
#grid.price-narrow > tbody > tr.pr-fee-row > td {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  box-sizing: border-box;
  white-space: normal;
}
.pr-vol-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  margin: 4px 0 8px;
  min-width: 0;
}
.pr-vol-board .ft-field { min-width: 0; }
.pr-vol-board input.rbi {
  width: 100%;
  min-width: 0;
  min-height: 36px;
}
@media (min-width: 701px) {
  .pr-vol-board { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.pr-fee-row .ft-card {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  text-align: left;
}
.pr-fee-row .ft-head {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 12px;
}
.pr-fee-row .ft-head small { display: inline; opacity: .78; }
.pr-fee-row .ft-side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
}
.pr-fee-row .ft-side + .ft-side {
  margin-top: 4px;
  border-top: 1px solid var(--ui-border, rgba(127,127,127,.18));
}
.pr-fee-row .ft-side-label {
  font-size: var(--ui-secondary-size, 12px);
  font-weight: 600;
  opacity: .78;
}
.pr-fee-row .ft-prose,
.pr-fee-row .led-rate-note-ok,
.pr-fee-row .led-rate-note-bad {
  display: block;
  margin-top: 4px;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
  line-height: 1.4;
}
.pr-fee-row .ft-steps { display: flex; flex-direction: column; gap: 10px; }
.pr-fee-row .ftrow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px;
  gap: 6px 8px;
  align-items: end;
}
.pr-fee-row .ft-field-from { grid-column: 1 / 3; }
.pr-fee-row .ftrow .ftdel { grid-column: 3; grid-row: 1; min-height: 36px; }
.pr-vol-row .ftrow {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px;
}
.pr-vol-row .ft-field-from { grid-column: auto; }
.pr-vol-row .ftrow .ftdel {
  grid-column: 3;
  grid-row: 1;
  width: 36px;
  min-width: 36px;
  justify-self: end;
}
.pr-fee-row .ft-field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  min-width: 0;
}
.pr-fee-row .ft-field > span {
  font-size: var(--ui-secondary-size, 12px);
  color: var(--tg-theme-hint-color, #777);
  text-align: left;
  white-space: normal;
}
.pr-fee-row .ftrow input { width: 100% !important; min-width: 0; min-height: 36px; }
.pr-fee-row .pr-row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.pr-fee-row .pr-row-actions .rk,
.pr-fee-row .pr-row-actions .btn { flex: 1 1 calc(50% - 4px); min-width: 0; }

@container (min-width: 560px) {
  .pr-fee-row .ftrow {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) 36px;
  }
  .pr-fee-row .ft-field-from { grid-column: auto; }
  .pr-fee-row .ftrow .ftdel { grid-column: auto; grid-row: auto; }
  .pr-fee-row .pr-row-actions { justify-content: flex-end; }
  .pr-fee-row .pr-row-actions .rk,
  .pr-fee-row .pr-row-actions .btn { flex: 0 0 auto; }
  .pr-vol-row .ftrow {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px;
  }
  .pr-vol-row .ftrow .ftdel {
    grid-column: 3;
    width: 36px;
    min-width: 36px;
  }
}

/* Rate cells must look like fields. Dark Telegram + 82px borderless inputs
   made an empty с/с look like blank space until focus. */
#grid.price-narrow input.rbi {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--tg-theme-text-color, #111) 22%, var(--tg-theme-hint-color, #888));
  background: var(--tg-theme-bg-color, #fff);
  border-radius: 10px;
  color: var(--tg-theme-text-color, #111);
  box-sizing: border-box;
}
html[data-theme="dark"] #grid.price-narrow input.rbi {
  background: rgba(0, 0, 0, .28);
  border-color: rgba(255, 255, 255, .28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
}
#grid.price-narrow input.rbi::placeholder {
  color: var(--tg-theme-hint-color, #888);
  opacity: .85;
}
#grid.price-narrow input.rbi:focus {
  border-color: var(--tg-theme-link-color, #3390ec);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--tg-theme-link-color, #3390ec) 28%, transparent);
}
#grid.price-narrow input.ft {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--tg-theme-text-color, #111) 22%, var(--tg-theme-hint-color, #888));
  background: var(--tg-theme-bg-color, #fff);
  border-radius: 10px;
  color: var(--tg-theme-text-color, #111);
  box-sizing: border-box;
}
html[data-theme="dark"] #grid.price-narrow input.ft {
  background: rgba(0, 0, 0, .28);
  border-color: rgba(255, 255, 255, .28);
}

@media (max-width: 760px) {
  #grid.price-narrow thead {
    display: none;
  }
  #grid.price-narrow > tbody > tr.pr-info-row,
  #grid.price-narrow > tbody > tr.pr-cabinet-row,
  #grid.price-narrow > tbody > tr.cur-hdr,
  #grid.price-narrow > tbody > tr.pr-data-row,
  #grid.price-narrow > tbody > tr.pr-fee-row,
  #grid.price-narrow > tbody > tr.led-derived-rate-row,
  #grid.price-narrow > tbody > tr[data-role="row"] {
    margin: 0;
    padding: 8px 0;
    border: 0;
    border-bottom: 1px solid rgba(127, 127, 127, .12);
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  #grid.price-narrow > tbody > tr[data-role="row"] {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px 10px;
    height: auto;
    padding: 16px 4px 18px;
  }
  #grid.price-narrow > tbody > tr[data-role="row"] > td {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    height: auto;
    min-width: 0;
    padding: 0 !important;
    text-align: left;
    white-space: normal;
  }
  #grid.price-narrow > tbody > tr[data-role="row"] > td.txt {
    grid-column: 1 / -1;
    padding-bottom: 4px !important;
  }
  #grid.price-narrow > tbody > tr[data-role="row"] > td.pr-cost {
    grid-column: 1 / -1;
    padding-bottom: 2px !important;
  }
  #grid.price-narrow > tbody > tr[data-role="row"] > td.pr-avg {
    grid-column: 1 / -1;
    padding: 8px 10px !important;
    border-radius: 10px;
  }
  #grid.price-narrow > tbody > tr[data-role="row"] > td.pr-avg-live {
    font-weight: 650;
    background: color-mix(in srgb, var(--tg-theme-link-color, #3390ec) 16%, transparent);
    box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--tg-theme-link-color, #3390ec) 45%, transparent);
  }
  #grid.price-narrow > tbody > tr[data-role="row"] > td[data-label]::before {
    display: block;
    text-align: left;
    margin: 0 0 2px;
  }
  #grid.price-narrow > tbody > tr[data-role="row"] input {
    width: 100% !important;
    min-width: 0;
    min-height: 40px;
  }
  #grid.price-narrow > tbody > tr.pr-info-row > td,
  #grid.price-narrow > tbody > tr.pr-cabinet-row > td {
    display: block;
    width: 100%;
    padding: 0 0 6px;
    border: 0;
    background: transparent;
  }
  #grid.price-narrow > tbody > tr.pr-info-row .pr-hint-bar {
    justify-content: flex-start;
    gap: 6px;
    padding: 0;
  }
  #grid.price-narrow .pr-cabinet-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 6px 8px;
    align-items: end;
  }
  #grid.price-narrow .pr-cabinet-line > span { grid-column: 1 / -1; }
  #grid.price-narrow .pr-cabinet-line .btn { grid-column: auto; min-width: 0; }
  #grid.price-narrow > tbody > tr.cur-hdr {
    padding: 16px 4px 10px;
  }
  #grid.price-narrow > tbody > tr.cur-hdr .cur-chev {
    display: none;
  }
  #grid.price-narrow > tbody > tr.is-collapsed {
    display: none !important;
  }
  #grid.price-narrow > tbody > .pr-fee-row {
    padding: 8px 0 10px;
  }
  /* Volume cards keep data-role=row for hide-empty; do not use the 2-col rate grid. */
  #grid.price-narrow > tbody > tr.pr-vol-row[data-role="row"],
  #grid.price-narrow > tbody > tr.pr-vol-row {
    display: block;
    grid-template-columns: none;
    gap: 0;
    padding: 8px 0 12px;
  }
  #grid.price-narrow > tbody > tr.pr-vol-row[data-role="row"] > td,
  #grid.price-narrow > tbody > tr.pr-vol-row > td {
    display: block;
    width: 100%;
    max-width: 100%;
    grid-column: 1 / -1;
    padding: 0 !important;
  }
  #grid.price-narrow > tbody > .pr-data-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px 8px;
    padding: 8px 0 10px;
  }
  #grid.price-narrow > tbody > .pr-data-row > td.txt,
  #grid.price-narrow > tbody > .pr-data-row > td.acts {
    grid-column: 1 / -1;
  }
  #grid.price-narrow .pr-provenance { display: block; margin-top: 6px; }
  #deal-form-modal #form .nf-preview-bar { pointer-events:none; position:relative; z-index:1; }
  #deal-form-modal #form .nf-actions-sticky {
    position: fixed; left: 0; right: 0;
    bottom: env(safe-area-inset-bottom, 0px);
    margin: 0; padding: 8px 12px;
    z-index: 12;
    pointer-events: auto;
  }
}

@media (max-width: 420px) {
  body.lite .wallet-card .ui-actions,
  body.pro .wallet-card .ui-actions,
  .wallet-card .ui-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px;
  }
  .wallet-card .ui-actions > button,
  .wallet-card .ui-actions > .rk,
  .wallet-card .ui-actions > .del {
    width: auto;
    min-width: 0;
    max-width: none;
  }
}
