/*
 * Terminals — the back office for the restaurant's tills (terminals.js).
 *
 * Everything that exists only when the sync API is on is hidden until
 * terminals.js has found that it is (body.sync-on): the nav item, the
 * dashboard card, the department field in the menu editor. `!important`
 * because the permission gate writes inline `display` on nav items.
 */
body:not(.sync-on) .nav-item[data-view="terminals"],
body:not(.sync-on) .trm-dash-row,
body:not(.sync-on) #mi-reparto-field { display: none !important; }

.sidebar .nav-item[data-view="terminals"]::after { content: var(--i18n-nav-terminals, "Tills"); }

/* ── Tabs, banner ──────────────────────────────────────────────────────── */
.trm-tabs { display: flex; gap: 6px; margin: 4px 0 14px; overflow-x: auto; scrollbar-width: none; }
.trm-tabs::-webkit-scrollbar { display: none; }
.trm-tab {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); font-weight: 600; font-size: 13px; cursor: pointer;
}
.trm-tab.active { background: var(--text); color: #fff; border-color: var(--text); }
.trm-count {
  min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--amber-500); color: #fff;
  font-size: 11px; line-height: 18px; text-align: center;
}
.trm-tab.active .trm-count { background: rgba(255,255,255,.25); }

#trm-banner:empty { display: none; }
.trm-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; margin-bottom: 10px; border-radius: 12px; font-size: 13px; line-height: 1.45;
  border: 1px solid var(--border); background: var(--surface-2);
}
.trm-banner.warn { background: var(--amber-50); border-color: #fcd9a4; color: #7a4a06; }
.trm-banner.info { background: #eef4ff; border-color: #cddcfb; color: #1f3b73; }
.trm-banner .btn { flex: none; }

/* ── Cards, tables, filters ────────────────────────────────────────────── */
.trm-kpis { margin-bottom: 14px; }
.trm-card { padding: 16px; }
.trm-card .card-head { gap: 12px; flex-wrap: wrap; }
.trm-row { cursor: pointer; }
.trm-table td.num, .trm-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.trm-table .cell-sub { font-size: 11.5px; color: var(--text-3); }
.trm-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; margin-right: 5px; vertical-align: 1px; }
.trm-empty { padding: 28px 12px; text-align: center; }
.trm-loading { padding: 28px; text-align: center; color: var(--text-3); }
.trm-muted { color: var(--text-3); font-size: 12.5px; }
.trm-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.trm-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-bottom: 12px; }
.trm-field { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--text-3); min-width: 130px; }
.trm-field.sm { min-width: 84px; max-width: 110px; }
.trm-field.wide { width: 100%; margin-top: 10px; }
.trm-field .input { min-height: 34px; width: 100%; min-width: 0; box-sizing: border-box; }
.trm-archive-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 0 0 10px; flex-wrap: wrap; }
.trm-export select { min-width: 220px; }
.trm-pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; font-size: 12.5px; color: var(--text-3); }
.trm-danger { color: var(--rose-500) !important; border-color: #f5c2c7 !important; }

/* ── Dialogs ───────────────────────────────────────────────────────────── */
.trm-back {
  position: fixed; inset: 0; z-index: 1200; display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px; overflow-y: auto; background: rgba(15, 23, 42, .45); opacity: 0; transition: opacity .15s ease;
}
.trm-back.show { opacity: 1; }
/* The app's text prompt (RV.promptModal, z-index 80) opened from one of these
   dialogs — Rename — must come up above it, not behind. */
.trm-back ~ .pm-overlay { z-index: 1300; }
.trm-dialog {
  width: 560px; max-width: 100%; background: var(--surface, #fff); border-radius: 18px;
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.trm-dialog.wide { width: 920px; }
.trm-dhead { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--border-soft, var(--border)); }
.trm-dtitle { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.trm-dsub { font-size: 11.5px; color: var(--text-3); margin-top: 3px; word-break: break-all; }
.trm-x { font-size: 22px; line-height: 1; flex: none; }
.trm-dbody { padding: 16px 20px 20px; }
.trm-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 18px; margin: 0 0 14px; }
.trm-facts dt { font-size: 11px; color: var(--text-3); }
.trm-facts dd { margin: 2px 0 0; font-size: 13px; font-weight: 600; word-break: break-word; }
.trm-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.trm-sec { border-top: 1px solid var(--border-soft, var(--border)); padding-top: 14px; margin-top: 14px; }
.trm-sec h3 { font-size: 14px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
details.trm-sec > summary, .trm-rules > summary { cursor: pointer; font-weight: 600; font-size: 13.5px; }
.trm-rules { margin-top: 12px; }
.trm-warn { font-size: 12.5px; color: #7a4a06; background: var(--amber-50); border-radius: 10px; padding: 8px 10px; margin: 0 0 10px; }
.trm-edit input.input, .trm-edit select.input { width: 100%; min-width: 60px; }
.trm-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.trm-list { list-style: none; margin: 0; padding: 0; }
.trm-list li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--border-soft, var(--border)); font-size: 13px; }
.trm-mini { margin: 6px 0; padding-left: 18px; font-size: 12.5px; }
.trm-pick { display: flex; flex-direction: column; gap: 8px; }
.trm-pick-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; font-size: 13.5px; }
.trm-pick-row:has(input:checked) { border-color: var(--blue, #2d6fd6); background: #f3f7ff; }
.trm-two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }

/* Conflict: the orders side by side. */
.trm-ccols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.trm-ccol { border: 1px solid var(--border); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.trm-ccol-head { display: flex; flex-direction: column; gap: 4px; }
.trm-lines { list-style: none; margin: 0; padding: 0; font-size: 13px; flex: 1; }
.trm-lines li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; }
.trm-lines li.voided { text-decoration: line-through; color: var(--text-3); }
.trm-ctot { display: flex; justify-content: space-between; font-size: 13px; border-top: 1px solid var(--border-soft, var(--border)); padding-top: 6px; }

/* ── The dashboard card ────────────────────────────────────────────────── */
.trm-dash { display: grid; grid-template-columns: repeat(3, minmax(0, 150px)) 1fr; gap: 12px 20px; align-items: center; }
.trm-dash-kpi .mk-val.sm { font-size: 15px; }
.trm-dash-alerts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

/* ── Phones ────────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .trm-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .trm-two { grid-template-columns: 1fr; }
  .trm-dash { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .trm-dash-alerts { grid-column: 1 / -1; justify-content: flex-start; }
  .trm-back { padding: 0; align-items: stretch; }
  .trm-dialog, .trm-dialog.wide { width: 100%; border-radius: 0; min-height: 100%; }
  .trm-dhead, .trm-dbody { padding-left: 14px; padding-right: 14px; }
  .trm-banner { flex-direction: column; align-items: flex-start; }
  .trm-filters .trm-field { flex: 1 1 140px; min-width: 0; }
  .trm-filters .trm-field.sm { flex: 1 1 90px; min-width: 0; max-width: none; }
  .trm-export, .trm-export select { width: 100%; }

  /* A table becomes a stack of cards: each cell names its column. */
  .trm-table thead { display: none; }
  .trm-table, .trm-table tbody, .trm-table tr, .trm-table td { display: block; width: 100%; }
  .trm-table tr { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; padding: 8px 12px; background: var(--surface); }
  .trm-table tbody td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .trm-table tbody td::before { content: attr(data-label); color: var(--text-3); font-size: 11.5px; text-align: left; flex: none; max-width: 45%; }
  .trm-table tbody td:not([data-label])::before { content: none; }
  .trm-table tbody td > .trm-cell { min-width: 0; text-align: right; }
  .trm-table tbody td:not([data-label]) { justify-content: flex-end; }
  .trm-table td.num { text-align: right; }
  .trm-edit tbody td { display: grid; grid-template-columns: 40% 1fr; align-items: center; text-align: left; }
  .table-wrap:has(.trm-table) { overflow: visible; }
}
