/* HUB Mobile 2.0 / issuance: responsive controls without changing editing or ledger data.
 * The wide ledger is deliberately kept inside its own touch-scroll region.
 */
@media (max-width: 680px) {
  .page {min-width:0;max-width:100%;padding:9px 8px 30px;gap:9px}
  .page > section,.card,.table-card,.period-card {min-width:0;max-width:100%}
  .toolbar {padding:11px 12px;gap:10px;flex-direction:column;align-items:stretch}
  .toolbar > div:first-child {display:flex;flex-wrap:wrap;align-items:center;gap:6px}
  .toolbar strong {font-size:16px}
  .toolbar .actions {width:100%;display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:7px}
  .toolbar .actions > .btn {min-width:0;min-height:44px;white-space:normal}
  .source-card {padding:12px}
  .source-grid {display:grid;grid-template-columns:minmax(0,1fr);gap:10px}
  .source-grid > *,.source-grid label {min-width:0;max-width:100%}
  .source-actions {display:flex;flex-wrap:wrap;gap:7px}
  .source-actions .btn {min-height:44px;flex:1 1 120px}
  .stats {grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
  .stat {min-width:0;padding:11px 12px;gap:4px}
  .stat span {font-size:11px;line-height:1.3}
  .stat strong {font-size:clamp(18px,5vw,23px);overflow-wrap:anywhere}
  .period-card {padding:10px;gap:8px}
  .period-head {min-width:0;flex-wrap:wrap;gap:8px}
  .period-head > div.period-years:first-child {width:100%;justify-content:flex-start;scrollbar-width:thin}
  .period-tab,.month-tab {min-height:44px}
  .period-months {width:100%;max-width:100%;overflow-x:auto;overscroll-behavior-x:contain;
    -webkit-overflow-scrolling:touch;padding-bottom:4px}
  .period-months > .month-tab {min-width:106px}
  .year-average-margin {justify-content:flex-start;overflow-wrap:anywhere}
  .table-head {padding:10px;align-items:stretch}
  .filters {display:grid;grid-template-columns:repeat(2,minmax(0,1fr));align-items:stretch;gap:8px}
  .filters > * {min-width:0;max-width:100%;width:100%;margin:0}
  .filters > input[type="search"] {grid-column:1/-1;min-width:0;width:100%;flex:none}
  .filters input,.filters select,.columns-menu > summary {
    width:100%;min-width:0;max-width:100%;height:auto;min-height:44px;
    padding:10px 9px;font-size:13px;line-height:1.3
  }
  .columns-menu {position:relative}
  .columns-menu > summary {align-items:center;justify-content:center}
  .columns-menu-pop {right:0;left:auto;width:min(288px,calc(100vw - 36px));
    max-width:calc(100vw - 36px);max-height:min(450px,70dvh)}
  .table-wrap {max-width:100%;min-width:0;overflow-x:auto!important;overflow-y:auto!important;
    overscroll-behavior-x:contain;-webkit-overflow-scrolling:touch;touch-action:pan-x pan-y;
    scrollbar-width:thin!important}
  .table-wrap::-webkit-scrollbar {height:6px!important;display:block!important}
  #issuanceTable {width:max-content;min-width:100%}
  /* Native swipe scrolling is easier than a second thin scrollbar on phones. */
  #hscroll {display:none!important}
  .table-foot {gap:10px;flex-wrap:wrap;padding:10px}
  .table-foot > * {min-width:0}
  .manager-modal {padding:8px!important;align-items:center;justify-content:center}
  .manager-dialog,.entity-dialog,.bank-dialog {
    width:100%;max-width:100%;
    height:auto;max-height:calc(100dvh - 24px);
    border-radius:15px
  }
  .manager-picker-body {grid-template-columns:minmax(0,1fr);min-height:0}
  .manager-departments {display:flex;gap:5px;max-height:96px;overflow-x:auto;overflow-y:auto}
  .manager-users,.entity-items,.bank-options {min-height:0;overflow-y:auto}
  .manager-dialog header,.entity-dialog header,.bank-dialog header {padding:12px}
  .manager-dialog footer,.entity-dialog footer,.bank-dialog footer {padding:10px;gap:6px;flex-wrap:wrap}
  .manager-dialog footer .btn,.entity-dialog footer .btn,.bank-dialog footer .btn {
    min-height:44px;flex:1 1 120px
  }
  .manager-search-wrap,.entity-search-wrap,.bank-search-wrap {padding:10px}
  .manager-search-wrap input,.entity-search-wrap input,.bank-search-wrap input {min-height:44px}
}
@media (max-width: 350px) {
  .stats {grid-template-columns:minmax(0,1fr)}
  .filters {grid-template-columns:minmax(0,1fr)}
  .filters > input[type="search"] {grid-column:1}
}


/* Mobile 2.0 / issuance compact KPIs + period drawer.
 * Desktop period selectors, refresh/sync handlers and row editing stay intact. */
.mobile-issuance-filters-open,.mobile-issuance-filters-dialog:not([open]){display:none}
@media(max-width:680px){
  .page{gap:9px!important}
  #issuanceToolbar {
    display:flex!important;flex-flow:row nowrap!important;align-items:center!important;
    justify-content:flex-end!important;gap:7px!important;
    padding:8px!important;min-width:0!important;min-height:0!important;
  }
  #issuanceToolbar .issuance-toolbar-status{display:none!important}
  #issuanceToolbar .actions {
    display:flex!important;flex-flow:row nowrap!important;align-items:center!important;
    justify-content:flex-end!important;gap:7px!important;
    width:100%!important;min-width:0!important;min-height:44px!important;
  }
  #issuanceToolbar .mobile-issuance-filters-open{
    display:inline-flex!important;align-items:center;justify-content:center;
    flex:1 1 0;gap:7px;min-width:0;max-width:none;
    min-height:44px;padding:0 12px;border:1px solid #cdb5e8;
    border-radius:11px;background:var(--accent-soft);color:var(--accent);
    font:800 12px/1.2 inherit;cursor:pointer;
  }
  #issuanceToolbar .mobile-issuance-filters-open svg {
    flex:0 0 19px;width:19px;height:19px
  }
  #issuanceToolbar .actions > #refreshBtn,
  #issuanceToolbar .actions > #syncBtn {
    display:grid!important;place-items:center!important;
    flex:0 0 44px!important;width:44px!important;max-width:44px!important;
    min-width:44px!important;height:44px!important;min-height:44px!important;
    padding:0!important;margin:0!important;
    overflow:hidden;font-size:0!important;line-height:0!important;
    white-space:nowrap!important;letter-spacing:0!important;
  }
  #issuanceToolbar .actions > #refreshBtn::after,
  #issuanceToolbar .actions > #syncBtn::after {
    display:block!important;color:inherit;
    font:700 24px/1 sans-serif;
    width:28px;height:28px;text-align:center;line-height:28px;
  }
  #issuanceToolbar .actions > #refreshBtn::after {content:"↻"}
  #issuanceToolbar .actions > #syncBtn::after {content:"⇄"}
  #issuanceToolbar .actions > .btn.is-busy::after {content:""!important;display:none!important}
  #issuanceToolbar .actions > .btn.is-busy::before {margin:0!important;width:17px;height:17px}
  #issuanceToolbar .actions > .btn.is-done::after {content:"✓"!important}

  /* Four equal-width cards; never reflow to a two-row desktop-style grid. */
  .page > .stats {
    display:grid!important;grid-template-columns:repeat(4,minmax(0,1fr))!important;
    width:100%!important;min-width:0;max-width:100%;
    gap:5px!important;align-items:stretch!important;
  }
  .page > .stats > .stat {
    display:flex!important;flex-direction:column!important;
    align-items:flex-start!important;justify-content:space-between!important;
    gap:7px!important;min-width:0!important;min-height:80px!important;
    max-width:100%;padding:9px 6px!important;border-radius:12px;
    box-shadow:none!important;
  }
  .page > .stats > .stat span {
    display:block;min-width:0;max-width:100%;
    line-height:1.18!important;font-size:9px!important;font-weight:700;
    white-space:normal!important;overflow-wrap:anywhere;
  }
  .page > .stats > .stat strong {
    display:block;font-size:clamp(16px,4.2vw,21px)!important;line-height:1.1!important;
    font-variant-numeric:tabular-nums;white-space:nowrap;
    min-width:0;max-width:100%;letter-spacing:-.035em;
  }
  /* Actual year/month selection moved to one button in the toolbar. */
  .page > .period-card {padding:8px 11px!important;gap:0!important}
  .page > .period-card > .period-head,
  .page > .period-card > .period-months {display:none!important}
  .page > .period-card > .year-average-margin{
    display:flex!important;justify-content:flex-start!important;
    flex-wrap:wrap;gap:5px;min-width:0;
    font-size:11px!important;line-height:1.3!important
  }
  .page > .period-card > .year-average-margin:empty{display:none!important}
  .page > .period-card:has(>.year-average-margin:empty){display:none!important}

  body.mobile-issuance-filter-open{overflow:hidden!important}
  dialog.mobile-issuance-filters-dialog[open]{
    display:block!important;position:fixed!important;
    inset:auto 0 0 0!important;transform:none!important;
    width:100vw!important;max-width:100vw!important;
    height:auto;max-height:90dvh;margin:0!important;padding:0!important;
    border:1px solid var(--line);border-bottom:0;
    border-radius:21px 21px 0 0!important;
    background:var(--panel,#fff);color:inherit;
    box-shadow:0 -12px 45px rgba(20,10,32,.26);
    overflow:hidden!important;z-index:9999
  }
  dialog.mobile-issuance-filters-dialog::backdrop{
    background:rgba(20,14,28,.63);backdrop-filter:blur(3px)
  }
  .mobile-issuance-sheet{
    display:flex;flex-direction:column;
    height:min(68dvh,520px);max-height:90dvh;min-height:0;
  }
  .mobile-issuance-sheet-head{
    flex:0 0 auto;display:flex;justify-content:space-between;align-items:center;
    gap:8px;padding:15px 16px;border-bottom:1px solid var(--line)
  }
  .mobile-issuance-sheet-head small{font-size:10px;color:var(--muted)}
  .mobile-issuance-sheet-head h2{font-size:19px;line-height:1.25;margin:4px 0 0}
  .mobile-issuance-sheet-head button {
    display:grid;place-items:center;flex:0 0 44px;
    width:44px;height:44px;border:1px solid var(--line);
    border-radius:11px;background:var(--accent-soft);color:inherit;
    font-size:24px;cursor:pointer
  }
  .mobile-issuance-sheet-content{
    flex:1 1 auto;min-height:0;overflow-y:auto;overscroll-behavior:contain;
    display:flex;flex-direction:column;gap:14px;padding:18px 16px
  }
  .mobile-issuance-sheet-content label{display:flex;flex-direction:column;gap:6px}
  .mobile-issuance-sheet-content label>span{font-size:12px;font-weight:750;color:var(--muted)}
  .mobile-issuance-sheet-content select{
    width:100%;min-height:47px;padding:11px 12px;font-size:15px;
    color:inherit;background:var(--panel,#fff);border:1px solid var(--line);
    border-radius:11px
  }
  .mobile-issuance-hint{color:var(--muted);font-size:12px;line-height:1.4;margin:2px 0}
  .mobile-issuance-error{color:#c33b44;font-size:12px}
  .mobile-issuance-error[hidden]{display:none!important}
  .mobile-issuance-sheet-footer {
    flex:0 0 auto;display:grid;grid-template-columns:1fr 1.3fr;
    gap:9px;padding:12px 16px max(13px,env(safe-area-inset-bottom));
    border-top:1px solid var(--line);background:var(--panel,#fff)
  }
  .mobile-issuance-sheet-footer button {
    min-height:48px;border-radius:11px;border:1px solid var(--line);
    background:var(--accent-soft);color:inherit;
    font-weight:800;font-size:13px;cursor:pointer
  }
  #mobileIssuanceApply {background:var(--accent);border-color:var(--accent);color:#fff}
  #mobileIssuanceApply:disabled{opacity:.5;cursor:default}
}
@media(max-width:350px){
  .page > .stats{gap:4px!important}
  .page > .stats > .stat{padding:8px 5px!important;min-height:80px!important}
  .page > .stats > .stat span{font-size:8px!important}
  .page > .stats > .stat strong{font-size:16px!important}
  #issuanceToolbar .actions{gap:5px!important}
  #issuanceToolbar .mobile-issuance-filters-open{padding:0 7px;gap:4px}
}


/* Mobile 2.0 / issuance filter sheet: explicit theme surface palette.
 * Issuance uses --line/--accent but does not declare --panel. The former
 * var(--panel,#fff) fallback was white even when data-theme="dark". */
@media (max-width:680px) {
  dialog.mobile-issuance-filters-dialog {
    --issuance-sheet-bg:#ffffff;
    --issuance-sheet-text:#241b27;
    --issuance-sheet-muted:#756d79;
    --issuance-sheet-field:#f7f4fa;
    --issuance-sheet-border:#e5dfe8;
    --issuance-sheet-secondary:#f0e9fb;
    --issuance-sheet-accent:#713bbf;
    --issuance-sheet-on-accent:#ffffff;
    --issuance-sheet-danger:#b12d44;
    color-scheme:light;
  }
  html[data-theme="dark"] dialog.mobile-issuance-filters-dialog {
    --issuance-sheet-bg:#211b27;
    --issuance-sheet-text:#f4edf6;
    --issuance-sheet-muted:#c7b9ce;
    --issuance-sheet-field:#2c2432;
    --issuance-sheet-border:#4d4054;
    --issuance-sheet-secondary:#392945;
    --issuance-sheet-accent:#8752c6;
    --issuance-sheet-on-accent:#ffffff;
    --issuance-sheet-danger:#ffb1bb;
    color-scheme:dark;
  }
  dialog.mobile-issuance-filters-dialog[open] {
    background:var(--issuance-sheet-bg)!important;
    color:var(--issuance-sheet-text)!important;
    border-color:var(--issuance-sheet-border)!important;
  }
  dialog.mobile-issuance-filters-dialog .mobile-issuance-sheet,
  dialog.mobile-issuance-filters-dialog .mobile-issuance-sheet-head,
  dialog.mobile-issuance-filters-dialog .mobile-issuance-sheet-content,
  dialog.mobile-issuance-filters-dialog .mobile-issuance-sheet-footer {
    color:var(--issuance-sheet-text);
    background:var(--issuance-sheet-bg);
    border-color:var(--issuance-sheet-border);
  }
  dialog.mobile-issuance-filters-dialog .mobile-issuance-sheet-head h2 {
    color:var(--issuance-sheet-text);
  }
  dialog.mobile-issuance-filters-dialog .mobile-issuance-sheet-head small,
  dialog.mobile-issuance-filters-dialog .mobile-issuance-sheet-content label>span,
  dialog.mobile-issuance-filters-dialog .mobile-issuance-hint {
    color:var(--issuance-sheet-muted);
  }
  dialog.mobile-issuance-filters-dialog .mobile-issuance-sheet-head button,
  dialog.mobile-issuance-filters-dialog .mobile-issuance-sheet-footer button:not(#mobileIssuanceApply) {
    color:var(--issuance-sheet-text);
    background:var(--issuance-sheet-secondary);
    border-color:var(--issuance-sheet-border);
  }
  dialog.mobile-issuance-filters-dialog .mobile-issuance-sheet-content select {
    color:var(--issuance-sheet-text);
    background:var(--issuance-sheet-field);
    border-color:var(--issuance-sheet-border);
    color-scheme:inherit;
  }
  dialog.mobile-issuance-filters-dialog .mobile-issuance-sheet-content select option {
    color:var(--issuance-sheet-text);
    background:var(--issuance-sheet-field);
  }
  dialog.mobile-issuance-filters-dialog #mobileIssuanceApply {
    color:var(--issuance-sheet-on-accent);
    background:var(--issuance-sheet-accent);
    border-color:var(--issuance-sheet-accent);
  }
  dialog.mobile-issuance-filters-dialog .mobile-issuance-error {
    color:var(--issuance-sheet-danger);
  }
}
