/* ================= v2: simpler, mobile-first UI ================= */
input, select, textarea { font-size: 16px; min-height: 42px; }      /* 16px stops iOS zoom on focus */
.btn { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: .9rem; }
.btn.grow { flex: 1; }
.inline-label { display: inline-flex; gap: 8px; align-items: center; }
.inline-label select { width: auto; margin: 0; }

/* sidebar */
.sidenav { width: 230px; padding: 8px 0 30px; }
.main { margin-right: 230px; }
.sidenav .nav-user { display: none; padding: 14px 20px; color: #fff; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidenav .nav-user small { display: block; color: var(--nav-text); }
.nav-group { padding: 14px 20px 4px; font-size: .75rem; color: #7f8ea0; letter-spacing: .3px; }
.sidenav a { display: flex; align-items: center; gap: 10px; padding: 9px 20px; }
.sidenav a i { font-style: normal; width: 20px; text-align: center; opacity: .8; }
.nav-overlay, .bottom-nav { display: none; }

/* dashboard quick actions */
.quick-actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 18px; }
.qa { display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--border);
      color: var(--text); box-shadow: var(--shadow); }
.qa:hover { text-decoration: none; border-color: var(--primary); }
.qa i { font-style: normal; font-size: 1.4rem; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
        background: var(--primary-soft); color: var(--primary-2); margin-bottom: 4px; }
.qa span { font-weight: 700; }
.qa small { color: var(--muted); }
.qa-pos { background: var(--primary); color: #fff; border-color: var(--primary); }
.qa-fx { background: #1e40af; color: #fff; border-color: #1e40af; }
.qa-pos i, .qa-fx i { background: rgba(255,255,255,.2); color: #fff; }
.qa-pos small, .qa-fx small { color: inherit; opacity: .85; }

/* quick entry forms (transaction / exchange) */
.quick-form { max-width: 720px; }
.quick-form .block { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.block-title { font-weight: 700; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; }
.seg { display: grid; gap: 8px; margin-bottom: 8px; }
.seg-3 { grid-template-columns: repeat(3, 1fr); }
.seg-2 { grid-template-columns: repeat(2, 1fr); }
.seg-opt { margin: 0; position: relative; }
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt span { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 52px; padding: 8px; border-radius: 12px;
                border: 2px solid var(--border); background: #fff; font-weight: 700; cursor: pointer; text-align: center; font-size: 1.05rem; }
.seg-opt span i { font-style: normal; font-size: 1.2rem; }
.seg-opt input:checked + span { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-2); }
.seg-opt.t-deposit input:checked + span { border-color: #2563eb; background: #e8f0fe; color: #1e40af; }
.seg-opt.t-purchase input:checked + span { border-color: #b45309; background: #fef3e2; color: #92400e; }
.small-seg .seg-opt span { min-height: 42px; font-size: .95rem; }
.seg-opt input:focus-visible + span { outline: 3px solid #9fd8ca; }
.type-hint { margin: -2px 2px 10px; min-height: 1.2em; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { margin: 0; position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: flex; flex-direction: column; padding: 8px 14px; border-radius: 10px; border: 2px solid var(--border); background: #fff; cursor: pointer; min-width: 120px; }
.chip span small { color: var(--muted); font-weight: 400; }
.chip input:checked + span { border-color: var(--primary); background: var(--primary-soft); }
.chip-group-title { width: 100%; font-size: .8rem; color: var(--muted); margin-top: 4px; }
.chip-btn { border: 1px solid var(--border); background: #f7f8fb; border-radius: 20px; padding: 6px 12px; font: inherit; font-size: .9rem; cursor: pointer; direction: ltr; }
.chip-btn:active { background: var(--primary-soft); }
.quick-amounts { margin-top: 8px; }
.amount-input { font-size: 2rem !important; font-weight: 700; text-align: center; direction: ltr; min-height: 60px; letter-spacing: .5px; }
.rate-input { font-size: 1.5rem !important; min-height: 52px; }
.search-input { margin: 8px 0; }
.big-select { min-height: 50px; font-size: 1.05rem; }
[hidden] { display: none !important; }

.result-card { background: var(--primary); color: #fff; border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; }
.quick-form[data-type="deposit"] .result-card { background: #1e40af; }
.quick-form[data-type="purchase"] .result-card { background: #92400e; }
.result-main { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.result-main b { font-size: 1.8rem; direction: ltr; }
.result-sub { display: flex; gap: 16px; flex-wrap: wrap; font-size: .9rem; opacity: .9; margin-top: 4px; }
.result-sub b { direction: ltr; display: inline-block; }
.result-card .muted { color: #fff; opacity: .75; }
.result-card .link { color: #fff; text-decoration: underline; margin-top: 6px; }
.fees-edit { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; background: rgba(255,255,255,.12); padding: 10px; border-radius: 10px; }
.fees-edit label { margin: 0; color: #fff; font-size: .85rem; }
.fees-edit input { color: var(--text); }
.fees-edit .link { grid-column: 1 / -1; justify-self: start; }
details.more > summary { cursor: pointer; font-weight: 700; color: var(--primary); }
details.more[open] > summary { margin-bottom: 10px; }
.action-bar { display: flex; gap: 8px; margin: 10px 0 20px; }
.saved-box { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; background: #e7f6ee; border: 1px solid #b7e2c8;
             border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; max-width: 720px; }
.saved-actions { display: flex; gap: 6px; }

/* device commission tiers */
.fee-types details { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; }
.fee-types summary { cursor: pointer; padding: 4px 0; }
.fees-tbl input { min-width: 70px; min-height: 38px; }

.filters-toggle { display: none !important; }
.grid-2 > *, .grid-3 > *, .form-grid > * { min-width: 0; }   /* let wide tables scroll instead of stretching the page */
.table-wrap { max-width: 100%; -webkit-overflow-scrolling: touch; }
html, body { overflow-x: hidden; }

@media (min-width: 901px) {
  .quick-form .form-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- phones ---------- */
@media (max-width: 900px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .topbar { height: 52px; padding: 0 10px; }
  .topbar .user > a { display: none; }
  .brand { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
  .sidenav { top: 0; width: 280px; z-index: 40; padding-top: 0; }
  .sidenav .nav-user { display: block; }
  body.nav-open .nav-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  .main { margin-right: 0; padding: 64px 10px 20px; }
  h1 { font-size: 1.2rem; }
  .card { padding: 12px; border-radius: 12px; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat b { font-size: 1.1rem; }
  .quick-actions { grid-template-columns: repeat(2, 1fr); }
  .qa { padding: 12px; }

  .bottom-nav { display: flex; position: fixed; bottom: 0; right: 0; left: 0; z-index: 30; background: var(--card);
                border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px 8px; color: var(--muted); font-size: .72rem; }
  .bottom-nav a i { font-style: normal; font-size: 1.25rem; line-height: 1.3; }
  .bottom-nav a.active { color: var(--primary); }
  .bottom-nav a.bn-action i { background: var(--primary); color: #fff; border-radius: 12px; width: 40px; height: 30px; display: grid; place-items: center; }
  .bottom-nav a:hover { text-decoration: none; }

  /* entry forms: sticky save bar above the bottom nav */
  .action-bar { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); background: var(--bg); padding: 8px 0; margin: 0; z-index: 5; }
  .amount-input { font-size: 1.8rem !important; }
  .result-main b { font-size: 1.5rem; }
  .fees-edit { grid-template-columns: 1fr; }
  .chip span { min-width: 0; }
  .device-chips .chip { flex: 1 1 calc(50% - 8px); }

  /* filters fold behind a button */
  .filters-toggle { display: inline-flex !important; margin-bottom: 8px; }
  form.filters:not(.open) > label, form.filters:not(.open) > button:not(.filters-toggle) { display: none; }
  form.filters > label { flex: 1 1 45%; min-width: 0; }

  /* list tables become cards */
  table.rtable thead { display: none; }
  table.rtable, table.rtable tbody, table.rtable tr, table.rtable td, table.rtable tfoot { display: block; width: 100%; }
  table.rtable tr { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; padding: 6px 10px; background: var(--card); }
  table.rtable td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 10px; }
  table.rtable td::before { content: attr(data-label); color: var(--muted); font-size: .85em; flex-shrink: 0; }
  table.rtable td:not([data-label])::before, table.rtable td[data-label=""]::before { content: none; }
  table.rtable td:empty { display: none; }
  table.rtable td > .cv { text-align: left; }
  table.rtable tr:hover td { background: none; }
  table.rtable tr.cancelled td { text-decoration: none; }
  table.rtable tr.cancelled { opacity: .55; }
  .fees-tbl.rtable td input { max-width: 55%; }
}
@media print { .bottom-nav, .nav-overlay, .quick-actions, .action-bar, .saved-box { display: none !important; } }

/* optional brand logos (only when assets/brand/ exists) */
.brand-logo { height: 34px; width: auto; display: block; }
.login-logo { display: block; width: 200px; max-width: 70%; height: auto; margin: 0 auto 10px; }
.print-logo { display: block; height: 52px; width: auto; margin: 0 auto 4px; }
@media (max-width: 900px) { .brand-logo { height: 28px; } }

/* device cards with payment-company logos */
.device-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.device-cards .chip-group-title { grid-column: 1 / -1; margin: 4px 0 -2px; }
.dev-card { margin: 0; position: relative; }
.dev-card input { position: absolute; opacity: 0; pointer-events: none; }
.dev-card > span { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 12px 8px; min-height: 118px;
                   border: 2px solid var(--border); border-radius: 14px; background: #fff; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.dev-card > span b { font-size: .95rem; line-height: 1.3; }
.dev-card > span small { color: var(--muted); font-size: .78rem; }
.dev-card input:checked + span { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px rgba(27,154,102,.12); }
.dev-card input:focus-visible + span { outline: 3px solid #9fd8ca; }
.dev-logo { height: 46px; max-width: 110px; width: auto; object-fit: contain; display: block; }
.prov-initial { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 12px; color: #fff; font-weight: 700; font-size: 1.3rem;
                background: hsl(var(--h, 150) 55% 40%); }
.prov-logo { height: 30px; max-width: 80px; width: auto; object-fit: contain; vertical-align: middle; }
.prov-logo.prov-initial { width: 30px; height: 30px; font-size: .95rem; border-radius: 8px; display: inline-grid; }
.prov-cell { white-space: nowrap; }
.logo-preview { display: inline-block; margin: 4px 0; }
.fee-field { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); flex-wrap: wrap; }
.fee-field label { margin: 0; font-weight: 700; min-width: 70px; }
.fee-input { flex: 1; display: flex; align-items: center; gap: 8px; }
.fee-input input { margin: 0; font-size: 1.25rem; font-weight: 700; text-align: center; direction: ltr; max-width: 220px; }
.payroll-tbl input { min-width: 90px; margin: 0; }
@media (max-width: 900px) {
  .device-cards { grid-template-columns: repeat(2, 1fr); }
  .dev-card > span { min-height: 104px; }
  .fee-input input { max-width: none; }
}

/* payment-company cards (step 1) above the device cards (step 2) */
.company-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 6px; }
.co-card { margin: 0; position: relative; }
.co-card input { position: absolute; opacity: 0; pointer-events: none; }
.co-card > span { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 14px 8px; min-height: 120px;
                  border: 2px solid var(--border); border-radius: 16px; background: #fff; cursor: pointer; text-align: center; transition: border-color .15s, box-shadow .15s; }
.co-card > span small { color: var(--muted); font-size: .78rem; }
.co-card input:checked + span { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px rgba(27,154,102,.12); }
.co-card input:focus-visible + span { outline: 3px solid #9fd8ca; }
.co-logo { height: 52px; max-width: 120px; width: auto; object-fit: contain; display: block; }
.co-logo.prov-initial { width: 52px; height: 52px; font-size: 1.5rem; }
.devices-title { margin-top: 14px; }
.device-cards .dev-card > span { min-height: 0; padding: 10px 8px; }
.device-cards.single .dev-card > span { border-style: dashed; }
@media (max-width: 900px) {
  .company-cards { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .co-card > span { min-height: 104px; padding: 10px 4px; }
  .co-logo { height: 42px; max-width: 90px; }
}
