/*
 * Data grid styles. The structure and class names (.dg-*) follow
 * transactions_history.html; the colours are mapped onto the arena dark theme.
 * Breakpoint 992px = Bootstrap "lg" (d-lg-none / d-none d-lg-block on the website).
 */
:root {
  --dg-head: #5a4bd8;            /* website --brand-400 (table header, current page) */
  --dg-head-text: #fff;
  --dg-tint: rgba(124, 108, 255, .16);   /* website --brand-200 (tinted rows) */
  --dg-hover: rgba(255, 255, 255, .04);
  --dg-line-strong: #34466f;
  --dg-warning: var(--gold);     /* active filter */
  --dg-ink: #1a1400;
  --dg-ok: var(--green);
  --dg-bad: var(--red);
  --dg-r-sm: 8px;
  --dg-r-md: 12px;
}

/* ---- visibility helpers ------------------------------------------------- */
.dg-root .dg-m { display: none; }
@media (min-width: 992px) {
  .dg-root .dg-m { display: none !important; }
}
@media (max-width: 991.98px) {
  .dg-root .dg-d { display: none !important; }
  .dg-root .dg-m { display: block; }
  .dg-root .dg-mbar.dg-m { display: flex; }
}
.dg-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.dg-root { margin-bottom: 1.25rem; }
.dg-root .text-end { text-align: right; }

/* ---- toolbar --------------------------------------------------------------- */
.dg-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.dg-title { margin: 0; font-size: 1.15rem; font-weight: 600; }
.dg-tools { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; flex: 1 1 320px; justify-content: flex-end; }
.dg-clear { background: none; border: 0; padding: 0 .25rem; font: inherit; font-weight: 600; color: var(--gold); cursor: pointer; }
.dg-clear:hover { text-decoration: underline; }
.dg-clear[hidden] { display: none; }
.dg-linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--gold); cursor: pointer; text-decoration: underline; }

.dg-ctl {
  height: 38px; width: 100%; background: var(--panel2); color: var(--text);
  border: 1px solid var(--dg-line-strong); border-radius: var(--dg-r-sm);
  padding: 0 .75rem; font: inherit; font-size: .9rem;
}
.dg-ctl.sm { height: 32px; padding: 0 .5rem; font-size: .85rem; }
.dg-ctl:focus { outline: 2px solid var(--violet); outline-offset: 0; border-color: transparent; }
.dg-search { flex: 1 1 260px; max-width: 420px; width: auto; }
.dg-year { width: auto; min-width: 120px; }

.dg-tool {
  width: 38px; height: 38px; display: inline-grid; place-items: center; flex: none;
  border-radius: var(--dg-r-sm); cursor: pointer; background: var(--panel2);
  border: 1px solid var(--dg-line-strong); color: var(--muted); font-size: 1rem; padding: 0;
}
.dg-tool:hover { border-color: var(--violet); color: var(--text); }
.dg-tool.on { background: var(--dg-warning); border-color: var(--dg-warning); color: var(--dg-ink); }
.dg-tool.is-loading { opacity: 1; }

/* ---- desktop table ---------------------------------------------------------- */
.dg-card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.dg-scroll { overflow-x: auto; border-radius: inherit; }
.dg-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.dg-table thead th {
  background: var(--dg-head); color: var(--dg-head-text); font-weight: 600; white-space: nowrap;
  border: 0; padding: 1rem; vertical-align: middle; text-align: left;
  font-size: .875rem; text-transform: none; letter-spacing: 0;
}
.dg-table thead th.num, .dg-table thead th.text-end { text-align: right; }
.dg-table tbody td { padding: 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.dg-table tbody tr:last-child td { border-bottom: 0; }
.dg-table tbody tr:hover > td { background: var(--dg-hover); }
.dg-table tbody tr.dg-settle > td { background: var(--dg-tint); }
.dg-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.dg-table tfoot th, .dg-table tfoot td { padding: 1rem; border-top: 1px solid var(--line); text-align: left; text-transform: none; letter-spacing: 0; font-size: .875rem; color: var(--text); }
.dg-table tfoot th.num { text-align: right; }
.dg-table td.dg-empty { text-align: center; padding: 1.5rem 1rem; color: var(--muted); }
.dg-table tr.dg-empty-row:hover > td { background: transparent; }
.dg-table small { font-size: .8rem; }
.dg-table .muted, .dg-table small.muted { color: var(--muted); }
.dg-table a { color: var(--gold); }

.dg-th { display: flex; align-items: center; gap: .25rem; }
.dg-th.end { justify-content: flex-end; }
.dg-ico {
  width: 20px; height: 20px; display: grid; place-items: center; border-radius: 4px; cursor: pointer; padding: 0;
  background: rgba(255, 255, 255, .18); border: 1px solid rgba(255, 255, 255, .55); color: #fff; font-size: .75rem; line-height: 1;
}
.dg-ico:hover { background: rgba(255, 255, 255, .32); }
.dg-ico.on { background: var(--dg-warning); border-color: var(--dg-warning); color: var(--dg-ink); }
.dg-ico:focus-visible, .dg-tool:focus-visible, .dg-act:focus-visible, .dg-pg:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* status badges (.dg-st) - icons are CSS masks so no icon font is needed */
.dg-st { display: inline-flex; align-items: center; gap: .25rem; font-weight: 600; font-size: .875rem; white-space: nowrap; }
.dg-st::before {
  content: ""; width: 1em; height: 1em; flex: none; background: currentColor;
  -webkit-mask: var(--dg-ico) center / contain no-repeat; mask: var(--dg-ico) center / contain no-repeat;
}
.dg-st.ok { color: var(--dg-ok); --dg-ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0m-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05'/%3E%3C/svg%3E"); }
.dg-st.bad { color: var(--dg-bad); --dg-ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0M5.354 4.646a.5.5 0 1 0-.708.708L7.293 8l-2.647 2.646a.5.5 0 0 0 .708.708L8 8.707l2.646 2.647a.5.5 0 0 0 .708-.708L8.707 8l2.647-2.646a.5.5 0 0 0-.708-.708L8 7.293z'/%3E%3C/svg%3E"); }
.dg-st.warn { color: var(--dg-warning); --dg-ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0M8 3.5a.5.5 0 0 0-1 0V9a.5.5 0 0 0 .252.434l3.5 2a.5.5 0 0 0 .496-.868L8 8.71z'/%3E%3C/svg%3E"); }
.pos { color: var(--green); } .neg { color: var(--red); }

.dg-actions { display: flex; gap: .25rem; }
.dg-act {
  width: 30px; height: 28px; display: grid; place-items: center; border-radius: var(--dg-r-sm); cursor: pointer;
  text-decoration: none; background: transparent; font-size: .875rem; border: 1px solid; padding: 0;
}
.dg-act.view { color: var(--gold); border-color: var(--gold); }
.dg-act.view:hover { background: var(--gold); color: var(--dg-ink); }

/* ---- popover ------------------------------------------------------------------- */
.dg-pop {
  position: absolute; z-index: 20; width: 230px; padding: 1rem; background: var(--panel2); color: var(--text);
  border: 1px solid var(--dg-line-strong); border-radius: var(--dg-r-md); box-shadow: 0 10px 24px rgba(0, 0, 0, .45);
}
.dg-pop[hidden] { display: none; }
.dg-pop label { display: block; font-size: .875rem; font-weight: 600; margin-bottom: .25rem; }
.dg-pop .dg-pop-row { display: flex; gap: .5rem; margin-top: .5rem; }

/* ---- footer / pager ------------------------------------------------------------- */
.dg-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  margin-top: 1rem; padding: .5rem 1rem; background: var(--panel2); border: 1px solid var(--line); border-radius: var(--dg-r-md);
}
.dg-foot[hidden] { display: none; }
.dg-pager { display: flex; gap: .25rem; flex-wrap: wrap; }
.dg-pg {
  min-width: 34px; height: 32px; padding: 0 .5rem; border-radius: var(--dg-r-sm); cursor: pointer; font: inherit; font-size: .875rem; font-weight: 500;
  background: var(--panel); color: var(--text); border: 1px solid var(--dg-line-strong); display: inline-grid; place-items: center; text-decoration: none;
}
button.dg-pg:hover { border-color: var(--violet); color: var(--gold); }
.dg-pg.on { background: var(--dg-head); border-color: var(--dg-head); color: #fff; cursor: default; }
.dg-pg.disabled { opacity: .5; cursor: not-allowed; }
.dg-gap { display: inline-grid; place-items: center; min-width: 28px; color: var(--muted); }
.dg-foot-right { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.dg-per { display: flex; align-items: center; gap: .5rem; margin: 0; font-size: .875rem; color: var(--muted); }
.dg-per select { width: auto; }
.dg-showing { font-size: .875rem; color: var(--text); font-variant-numeric: tabular-nums; }
.dg-jump { display: flex; gap: .25rem; margin: 0; }
.dg-jump input { width: 64px; }
.dg-jump input::-webkit-outer-spin-button, .dg-jump input::-webkit-inner-spin-button { margin: 0; }
.btn.sm { padding: .25rem .75rem; font-size: .85rem; border-radius: var(--dg-r-sm); height: 32px; }

/* ---- mobile: controls ---------------------------------------------------------- */
.dg-mbar { flex-direction: column; gap: .5rem; margin-bottom: .75rem; }
.dg-msearch { position: relative; }
.dg-msearch .dg-ctl { height: 48px; padding-left: 2.6rem; padding-right: 2.6rem; font-size: 1rem; border-radius: var(--dg-r-md); }
.dg-msearch-ico { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 1.15rem; display: grid; pointer-events: none; }
.dg-msearch-x { position: absolute; right: .35rem; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; display: grid; place-items: center; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; }
.dg-msearch-x[hidden] { display: none; }
.dg-mrow { display: flex; gap: .5rem; align-items: center; }
.dg-mrow .dg-ctl { flex: 1 1 0; min-width: 0; height: 48px; border-radius: var(--dg-r-md); }
.dg-mrow .dg-tool { width: 44px; height: 44px; }

/* ---- mobile: card (OrderCard in order_widgets.dart) ---------------------------- */
.dg-cards { margin-top: .25rem; }
.dg-mcard { padding: 16px; margin-bottom: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--dg-r-md); }
.dg-mcard.dg-settle { background: var(--dg-tint); }
.dg-mline { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 2px 0; font-size: 13px; }
.dg-ml { color: var(--muted); flex: none; }
.dg-mv { text-align: right; color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.dg-mv small { font-size: inherit; }
.dg-mv a { color: var(--gold); }
.dg-mtop { font-size: 1rem; font-weight: 600; padding: 0; }
.dg-mtop .dg-ml, .dg-mtop .dg-mv { font-size: 1rem; font-weight: 600; color: var(--text); }
.dg-rule { border: 0; border-top: 1px solid var(--line); margin: 8px 0; height: 0; }
.dg-mbadge { margin-top: 8px; align-items: center; }
.dg-mview { display: block; width: 100%; min-height: 38px; margin-top: 12px; text-align: center; }
.dg-mempty { text-align: center; color: var(--muted); padding: 40px 0; margin: 0; }

/* mobile pager: [Previous] [current] [Next], then per-page / showing / jump (transactions_screen.dart _footer) */
@media (max-width: 991.98px) {
  .dg-foot { flex-direction: column; align-items: stretch; padding: 12px; gap: 12px; margin-top: 4px; }
  .dg-pager { flex-wrap: nowrap; gap: 12px; }
  .dg-pager .dg-pg { flex: 1 1 0; min-width: 0; height: 36px; }
  .dg-pager .dg-num, .dg-pager .dg-gap { display: none; }
  .dg-foot-right { flex-wrap: nowrap; gap: 8px; justify-content: space-between; }
  .dg-per span { display: none; }
  .dg-per select { width: 96px; height: 40px; }
  .dg-showing { flex: 1 1 auto; text-align: center; font-size: 12px; }
  .dg-jump { flex: none; }
  .dg-jump input { width: 56px; height: 40px; }
  .dg-jump .btn.sm { height: 40px; }
  .dg-toolbar { margin-bottom: .5rem; gap: .5rem; flex-wrap: nowrap; }
  .dg-title { font-size: 1.05rem; flex: 1 1 auto; }
  .dg-tools { flex: 0 0 auto; flex-wrap: nowrap; }
  .dg-tools .dg-tool { width: 44px; height: 44px; }
}

/* ---- details: bottom sheet (phones) / centred modal (large screens) ------------- */
html.dg-lock { overflow: hidden; }
.dg-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); opacity: 0; transition: opacity .25s ease; z-index: 100; }
.dg-backdrop.open { opacity: 1; }
.dg-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 101; max-height: 92vh; display: flex; flex-direction: column;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 20px 20px 0 0; transform: translateY(100%); transition: transform .32s cubic-bezier(.2, .8, .2, 1);
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom, 0px)); outline: 0;
}
.dg-sheet.open { transform: translateY(0); }
.dg-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 12px; }
.dg-sheet-title { margin: 0; font-size: 1.05rem; font-weight: 600; }
.dg-sheet-x { display: none; width: 32px; height: 32px; place-items: center; background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; border-radius: 6px; }
.dg-sheet-x:hover { color: var(--text); background: var(--panel2); }
.dg-sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.dg-sheet-foot { display: flex; gap: 12px; margin-top: 12px; }
.dg-sheet-foot .btn { flex: 1 1 0; text-align: center; }

.dg-dl { margin: 0; }
.dg-dl-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.dg-dl-row:last-child { border-bottom: 0; }
.dg-dl dt { color: var(--muted); font-weight: 400; flex: none; }
.dg-dl dd { margin: 0; text-align: right; color: var(--text); overflow-wrap: anywhere; min-width: 0; }

.dg-fsheet .dg-flabel { margin-bottom: 12px; }
.dg-fsheet label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.dg-fsheet .dg-ctl { height: 44px; }

@media (min-width: 992px) {
  .dg-sheet {
    left: 50%; right: auto; top: 50%; bottom: auto; width: min(560px, calc(100% - 2rem));
    border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.5rem;
    opacity: 0; transform: translate(-50%, -46%) scale(.97); transition: transform .22s ease, opacity .22s ease;
  }
  .dg-sheet.open { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  .dg-sheet-x { display: grid; }
  .dg-sheet-title { font-size: 1.2rem; }
  .dg-dl-row { display: grid; grid-template-columns: 9rem 1fr; gap: .5rem 1rem; font-size: .9rem; border-bottom: 0; padding: .35rem 0; }
  .dg-dl dd { text-align: left; font-weight: 500; }
  .dg-sheet-foot { justify-content: flex-end; }
  .dg-sheet-foot .btn { flex: 0 0 auto; }
}

/* ---- static (summary) table: same skin, no controls --------------------------------- */
.dg-static .dg-table { min-width: 0; }

/* ---- print ------------------------------------------------------------------------- */
@media print {
  html.dg-printing body * { visibility: hidden; }
  html.dg-printing .dg-print-target .dg-card, html.dg-printing .dg-print-target .dg-card * { visibility: visible; }
  html.dg-printing .dg-print-target .dg-card { position: absolute; left: 0; top: 0; width: 100%; border: 0; background: #fff; }
  html.dg-printing .dg-noprint, html.dg-printing .dg-ico, html.dg-printing .dg-pop { display: none !important; }
  html.dg-printing .dg-table { color: #000; }
  html.dg-printing .dg-table thead th { background: #fff !important; color: #000 !important; border-bottom: 2px solid #000; }
  html.dg-printing .dg-table tbody td, html.dg-printing .dg-table tbody tr.dg-settle > td { background: #fff !important; color: #000; border-color: #bbb; }
  html.dg-printing .dg-table a { color: #000; }
}

@media (prefers-reduced-motion: reduce) {
  .dg-sheet, .dg-backdrop { transition: none; }
}

.dg-table .fw { font-weight: 600; }
