/* Wesal V2 — NG5 control & insight surfaces (settings, billing, analytics)
   and the shared dialog. Tokens only (tokens.css): every colour is a token
   that exists — test/ng31CustomerTableAndPaging.test.js fails on any bare
   var() naming a property defined nowhere. */

/* ==================== dialog ==================== */
.v2dlg-scrim {
  position: fixed; inset: 0; z-index: var(--z-layer);
  background: rgba(11, 21, 38, 0.5);
  display: grid; place-items: center; padding: 16px;
}
.v2dlg {
  width: min(460px, 100%); background: var(--w-surface); color: var(--w-ink);
  border-radius: var(--r-sheet); box-shadow: var(--e-float); padding: 22px;
  border-top: 4px solid var(--w-teal);
}
.v2dlg.danger { border-top-color: var(--w-danger); }
.v2dlg-title { font-size: 16px; font-weight: 700; margin: 0 0 8px; }
.v2dlg-body { font-size: 13.5px; color: var(--w-ink-2); margin: 0 0 16px; line-height: 1.7; white-space: pre-line; }
.v2dlg-typed { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--w-ink-2); margin-bottom: 16px; }
/* The duration field sits directly above its hint, so the gap belongs to the
   hint rather than the label. Kept narrow: it holds at most two digits, and a
   full-width box invites a paragraph. */
.v2dlg-num { margin-bottom: 4px; }
.v2dlg-num .input { max-width: 140px; min-height: 44px; }
/* Says which end date the days attach to, and turns into the range error when
   the value is out of bounds — same place, so the operator reads the
   correction where they are already looking. */
.v2dlg-hint { font-size: 12px; color: var(--w-ink-3, var(--w-ink-2)); margin: 0 0 16px; line-height: 1.6; }
.v2dlg-hint.danger { color: var(--w-danger); font-weight: 600; }
.v2dlg-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ── The dialog on a phone ──────────────────────────────────────────────────
   A confirmation that carries an impact table, a duration field and a reason
   textarea is taller than a 568px viewport. Without these rules the box
   simply ran past the bottom of the screen and the OK/Cancel row was
   unreachable — measured at 320×568 on the channel-activation dialog
   (2026-09-09). The box now fits the viewport and scrolls INTERNALLY, and the
   action row stays pinned at its foot so confirm/cancel are always within
   reach. Desktop is unchanged: the max-height only engages when needed. */
.v2dlg {
  max-height: calc(100dvh - 32px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  display: flex; flex-direction: column;
  box-sizing: border-box;
}
.v2dlg-body { overflow-wrap: anywhere; }
.v2dlg-actions { position: sticky; bottom: 0; background: var(--w-surface); padding-top: 8px; margin-top: auto; }
/* A short factual note under the impact table (activation: nothing moves on
   Meta). Plain body tone, never a warning colour — it is information. */
.v2dlg-note { font-size: 12.5px; color: var(--w-ink-2); line-height: 1.7; margin: 10px 0 0; overflow-wrap: anywhere; }
.adm-lc-impact th, .adm-lc-impact td { overflow-wrap: anywhere; vertical-align: top; }
@media (max-width: 480px) {
  .v2dlg-scrim { padding: 10px; align-items: end; }
  .v2dlg { width: 100%; padding: 16px 14px; max-height: calc(100dvh - 20px); max-height: calc(100vh - 20px); }
  .v2dlg-title { font-size: 15px; }
  .v2dlg-num .input { max-width: 100%; }
  .v2dlg-actions { gap: 8px; }
  .v2dlg-actions .btn { flex: 1 1 auto; min-height: 44px; justify-content: center; }
  .adm-lc-impact th { width: 38%; font-size: 12px; }
  .adm-lc-impact td { font-size: 12.5px; }
}
.btn-danger { background: var(--w-danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); }
[data-theme="dark"] .btn-danger { color: #1A0B09; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ==================== settings rail layout ==================== */
.ctl-wrap { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 20px; align-items: start; }
.ctl-rail { position: sticky; top: 0; display: flex; flex-direction: column; gap: 8px; }
.ctl-rail-search { position: relative; display: flex; align-items: center; }
.ctl-rail-search .s-ico { position: absolute; inset-inline-start: 10px; color: var(--w-ink-3); display: flex; pointer-events: none; }
.ctl-rail-search .input { padding-inline-start: 32px; }
.ctl-rail-nav { display: flex; flex-direction: column; gap: 2px; }
.ctl-rail-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 9px 12px;
  border-radius: var(--r-ctl); color: var(--w-ink-2); text-decoration: none;
  font-size: 13.5px; font-weight: 500; min-height: 44px;
}
.ctl-rail-item:hover { background: var(--w-surface-2); color: var(--w-ink); }
.ctl-rail-item.active { background: var(--w-teal-soft); color: var(--w-teal-strong); font-weight: 700; }
[data-theme="dark"] .ctl-rail-item.active { color: var(--w-teal); }
.ctl-rail-item .n-ico { display: grid; place-items: center; width: 20px; flex-shrink: 0; margin-top: 2px; }
.ctl-rail-item .ri-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ctl-rail-item .ri-sub { font-size: 11.5px; color: var(--w-ink-3); font-weight: 400; }
/* NG6 final recheck, found by the G-6 sweep rather than reported: --w-ink-3 is
   tuned against --w-surface (6.22:1 there in dark), but the ACTIVE rail item
   swaps its background to --w-teal-soft, where the same ink measures 4.06:1 —
   under the 4.5 this 11.5px text needs. Light is unaffected (4.92:1). Predates
   NG6; it surfaces here because the integration email and the store-integration
   notification both now land on this screen with this item active, so it is the
   label a merchant arrives on. --w-ink-2 is the next step in the same ramp:
   5.57:1, still secondary to the item's own title. */
[data-theme="dark"] .ctl-rail-item.active .ri-sub { color: var(--w-ink-2); }
.ctl-rail-empty { font-size: 12.5px; color: var(--w-ink-3); padding: 8px 12px; }

.ctl-body { min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.ctl-sec { display: flex; flex-direction: column; gap: 14px; }
.ctl-card { background: var(--w-surface); border-radius: var(--r-card); box-shadow: var(--e-raised); padding: 18px; }
.ctl-card-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.ctl-card-head h2 { font-size: 16px; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 8px; }
.ctl-card-head .ctl-sub { flex: 1 1 100%; font-size: 12.5px; color: var(--w-ink-2); margin: 0; line-height: 1.7; }
.ctl-card-head .ctl-state { margin-inline-start: auto; }

/* status: icon + label + colour, never colour alone */
.ctl-state { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.ctl-state.ok { background: var(--w-success-soft); color: var(--w-success); }
.ctl-state.warn { background: var(--w-warn-soft); color: var(--w-warn); }
.ctl-state.off { background: var(--w-surface-3); color: var(--w-ink-2); }
.ctl-state.danger { background: var(--w-danger-soft); color: var(--w-danger); }
.ctl-state.info { background: var(--w-info-soft); color: var(--w-info); }

/* the reason + next step block under a status */
.ctl-why { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--w-ink-2); line-height: 1.7; background: var(--w-surface-2); border-radius: 10px; padding: 10px 12px; }
.ctl-why .ic { flex: 0 0 auto; margin-top: 3px; color: var(--w-ink-3); }
.ctl-why.warn { background: var(--w-warn-soft); color: var(--w-warn); }
.ctl-why.warn .ic { color: var(--w-warn); }
.ctl-why.danger { background: var(--w-danger-soft); color: var(--w-danger); }
.ctl-why.danger .ic { color: var(--w-danger); }
.ctl-why strong { font-weight: 700; }

.ctl-kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 6px 14px; font-size: 13px; margin: 10px 0; }
.ctl-kv dt { color: var(--w-ink-3); }
.ctl-kv dd { margin: 0; color: var(--w-ink); overflow-wrap: anywhere; }
.ctl-kv dd bdi { font-variant-numeric: tabular-nums; }
.ctl-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.ctl-actions .spacer { flex: 1; }

.ctl-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; max-width: 640px; }
.ctl-field { display: flex; flex-direction: column; gap: 5px; }
.ctl-field label, .ctl-field .lbl { font-size: 12.5px; font-weight: 600; color: var(--w-ink-2); }
.ctl-field .hint { font-size: 11.5px; color: var(--w-ink-3); line-height: 1.6; }
.ctl-field .err { font-size: 12px; color: var(--w-danger); }
.ctl-field textarea.input { min-height: 110px; resize: vertical; }
.ctl-inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ctl-code { font-family: var(--font-en); font-size: 13px; background: var(--w-surface-2); border: 1px solid var(--w-line); border-radius: 8px; padding: 6px 10px; overflow-wrap: anywhere; direction: ltr; unicode-bidi: isolate; display: inline-block; max-width: 100%; }
.ctl-code.big { font-size: 22px; font-weight: 700; letter-spacing: .12em; padding: 10px 16px; }
.ctl-switch { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 13.5px; }
.ctl-switch input { width: 20px; height: 20px; accent-color: var(--w-teal); }

/* rows (phone numbers, webhooks, batches) */
.ctl-rows { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.ctl-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border: 1px solid var(--w-line); border-radius: 12px; padding: 10px 14px; min-height: 52px; }
.ctl-row .r-main { flex: 1 1 200px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ctl-row .r-t { font-weight: 600; font-size: 13.5px; overflow-wrap: anywhere; }
.ctl-row .r-s { font-size: 12px; color: var(--w-ink-3); overflow-wrap: anywhere; }
.ctl-row .r-act { display: flex; gap: 6px; align-items: center; margin-inline-start: auto; }

/* provider cards grid */
.ctl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 14px; }

/* table-ish preview (import sample) */
.ctl-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ctl-table th, .ctl-table td { text-align: start; padding: 6px 8px; border-bottom: 1px solid var(--w-line); vertical-align: top; overflow-wrap: anywhere; }
.ctl-table th { color: var(--w-ink-3); font-weight: 600; font-size: 11.5px; }
.ctl-table-wrap { overflow-x: auto; max-width: 100%; }
.ctl-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.ctl-progress { height: 8px; border-radius: 999px; background: var(--w-surface-3); overflow: hidden; margin: 8px 0; }
.ctl-progress > span { display: block; height: 100%; background: var(--w-teal); }

/* mobile rail: horizontal chips */
@media (max-width: 900px) {
  .ctl-wrap { grid-template-columns: minmax(0, 1fr); }
  .ctl-rail { position: static; }
  .ctl-rail-nav { flex-direction: row; overflow-x: auto; flex-wrap: nowrap; gap: 6px; padding-bottom: 4px; scrollbar-width: thin; }
  .ctl-rail-item { flex: 0 0 auto; border: 1px solid var(--w-line); padding: 8px 12px; }
  .ctl-rail-item .ri-sub { display: none; }
  .ctl-kv { grid-template-columns: 1fr; gap: 2px 0; }
  .ctl-kv dt { margin-top: 6px; }
}
@media (max-width: 480px) {
  .ctl-grid { grid-template-columns: 1fr; }
}

/* ==================== billing ==================== */
.bil-hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 12px; }
.bil-stat { background: var(--w-surface); border-radius: var(--r-card); box-shadow: var(--e-raised); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.bil-stat .k-label { font-size: 12px; font-weight: 600; color: var(--w-ink-2); }
.bil-stat .k-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.bil-stat .k-def { font-size: 12px; color: var(--w-ink-3); line-height: 1.6; }
.bil-usage { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--w-line); }
.bil-usage:last-child { border-bottom: 0; }
.bil-usage .u-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; flex-wrap: wrap; }
.bil-usage .u-def { font-size: 12px; color: var(--w-ink-3); line-height: 1.6; }
.bil-usage .u-num { font-variant-numeric: tabular-nums; font-weight: 600; }
.bil-bar { height: 8px; border-radius: 999px; background: var(--w-surface-3); overflow: hidden; }
.bil-bar > span { display: block; height: 100%; background: var(--w-teal); }
.bil-bar.warn > span { background: var(--w-warn); }
.bil-bar.danger > span { background: var(--w-danger); }

/* ==================== analytics ==================== */
/* NG5.1 review (WCAG 1.4.10 reflow): a column's minimum is never wider than
   its container — at 196px CSS (a 390px phone at 200 % zoom) minmax(300px)
   forced a 300px column and a horizontal scroll. min(Npx, 100%) keeps the
   same layout wherever N fits. */
.ana-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(190px, 100%), 1fr)); gap: 12px; }
.ana-two { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 14px; }
.ana-chart { display: flex; flex-direction: column; gap: 8px; }
.ana-chart .ana-plot { width: 100%; min-width: 0; }
.ana-chart svg { width: 100%; height: auto; display: block; max-width: 100%; }
/* NG5.1 (WCAG 1.4.11): the incoming/outgoing segments of one bar are hue-only
   neighbours (teal vs info measures 1.56:1 light, 1.00:1 dark), so a 1px
   surface-coloured stroke separates them at >= 4.8:1 in both themes. */
.ana-chart .bar { fill: var(--w-teal); stroke: var(--w-surface); stroke-width: 1; }
.ana-chart .bar.in { fill: var(--w-teal); }
.ana-chart .bar.out { fill: var(--w-info); }
.ana-chart .axis { stroke: var(--w-line-strong); stroke-width: 1; }
.ana-chart text { fill: var(--w-ink-2); font-size: var(--fs-chart-tick); font-weight: 500; font-family: var(--font-en); font-variant-numeric: tabular-nums; }
.ana-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: var(--fs-chart-legend); color: var(--w-ink-2); }
.ana-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 4px; vertical-align: middle; }
.ana-legend i.in { background: var(--w-teal); }
.ana-legend i.out { background: var(--w-info); }
.ana-def { font-size: 12px; color: var(--w-ink-3); line-height: 1.7; }
.ana-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ana-list li { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--w-line); }
.ana-list li:last-child { border-bottom: 0; }
.ana-list .num { font-variant-numeric: tabular-nums; font-weight: 600; }
.ana-meter { height: 6px; border-radius: 999px; background: var(--w-surface-3); overflow: hidden; flex: 1 1 80px; align-self: center; }
.ana-meter > span { display: block; height: 100%; background: var(--w-teal); }

@media (pointer: coarse) {
  .ctl-wrap .btn, .ctl-wrap .input, .ctl-wrap select.input, .ctl-rail-item,
  .bil-wrap .btn, .bil-wrap .input, .ana-wrap .btn, .ana-wrap .input, .ana-wrap .kpi { min-block-size: 44px; }
}

/* ==================== team ====================
   .ctl-table was built for the two- and three-column reporting tables that
   Analytics and the import preview use: `width: 100%`, `overflow-wrap:
   anywhere`, and no minimum width — which means the wrapper's `overflow-x:
   auto` can never engage, because the table always fits by shrinking.

   Team is the first FIVE-column table on it, and its rows carry an email
   address and three buttons. Measured at 375px before this block: the name
   column was 35px wide, the address column 41px and wrapped over eight lines,
   «مشرف» broke across three, and every row was 161px tall. Nothing overflowed
   — it was simply unreadable.

   So Team opts out of character-level breaking at every width, and below the
   phone breakpoint each row becomes a labelled card instead of a squeezed
   grid: no horizontal scrolling, no shredded words, nothing hidden. The ARIA
   roles in team.js are what keep it a table for assistive technology once CSS
   stops laying it out as one. */
.ctl-table.tm-table th, .ctl-table.tm-table td { overflow-wrap: normal; word-break: normal; }
.ctl-table.tm-table td > bdi { overflow-wrap: anywhere; }
.tm-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

@media (max-width: 640px) {
  .tm-table tbody tr {
    display: block;
    border: 1px solid var(--w-line);
    border-radius: var(--r-card, 12px);
    padding: 10px 12px;
    margin-bottom: 10px;
    background: var(--w-surface);
  }
  .tm-table thead { display: none; }
  .tm-table, .tm-table tbody { display: block; width: 100%; }
  .tm-table tbody td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    width: auto;
    border-bottom: 0;
    padding: 5px 0;
    text-align: start;
  }
  .tm-table tbody td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--w-ink-3);
    font-size: 11.5px;
    font-weight: 600;
  }
  .tm-table tbody td[data-actions]::before, .tm-table tbody td[data-edit]::before { content: none; }
  .tm-table tbody td[data-actions] {
    display: block;
    margin-top: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--w-line);
  }
  .tm-table tbody td[data-edit] { display: block; padding: 0; }
  .tm-table tbody tr:last-child { margin-bottom: 0; }
  .tm-actions .btn { flex: 1 1 auto; justify-content: center; min-block-size: 40px; }
  /* stacked rows fit the viewport, so the wrapper has nothing left to scroll */
  .tm-table-wrap { overflow-x: visible; }
}
