/* ===== export button and export popup (js/export-dialog.js) ===== */

/* the compact button row at the bottom of the sidebar */
.panel-footer .btn-primary{ flex:1 1 auto; min-height:44px; padding:10px 14px; }
.export-settings{ flex:0 0 auto; width:44px; min-height:44px; padding:0; display:inline-flex; align-items:center; justify-content:center; }
.topbar-actions .export-settings{ width:32px; height:32px; min-height:32px; }
.topbar-actions{ align-items:center; }
/* desktop: the button sits in the sidebar; on small screens it moves to the top bar */
@media (min-width: 861px){
  #btnExportTop, #btnExportSettingsTop{ display:none; }
}
@media (max-width: 860px){
  #btnExportTop{ min-height:32px; padding-left:16px; padding-right:16px; }
}

/* page behind the popup does not scroll */
html.xd-lock, html.xd-lock body{ overflow:hidden; }

.xd-backdrop{
  position:fixed; inset:0; z-index:110; display:flex; align-items:center; justify-content:center; padding:var(--space-4);
  background:rgba(var(--scrim-rgb),0.72); -webkit-backdrop-filter:blur(4px); backdrop-filter:blur(4px);
  animation:xd-fade 150ms ease both;
  overscroll-behavior:contain;
}
.xd-dialog{
  display:flex; flex-direction:column; width:100%; max-width:440px; max-height:calc(100dvh - 32px);
  background:var(--panel-bg); border:1px solid var(--border-strong); border-radius:var(--radius-lg); box-shadow:var(--shadow);
  animation:xd-pop 200ms var(--ease-out) both;
  outline:none;
}
@keyframes xd-fade{ from{ opacity:0; } to{ opacity:1; } }
@keyframes xd-pop{ from{ opacity:0; transform:translateY(8px) scale(0.97); } to{ opacity:1; transform:none; } }
@keyframes xd-sheet{ from{ transform:translateY(100%); } to{ transform:none; } }

.xd-head{ display:flex; align-items:center; justify-content:space-between; padding:14px 16px 4px 18px; }
.xd-title{ margin:0; font-size:var(--text-lg); font-weight:700; }
.xd-close{
  width:36px; height:36px; display:inline-flex; align-items:center; justify-content:center; border-radius:50%;
  background:transparent; border:1px solid transparent; color:var(--text-muted); cursor:pointer;
  transition:background-color 140ms ease, color 140ms ease, transform 140ms var(--ease-out);
}
.xd-close:hover{ background:var(--accent-soft); color:var(--text); }
.xd-close:active{ transform:scale(0.94); }

.xd-tabs{ display:flex; gap:2px; margin:6px 18px 0; padding:3px; background:var(--card-bg); border:1px solid var(--border); border-radius:var(--radius-pill); }
.xd-tab{
  flex:1; padding:7px 12px; border:none; border-radius:var(--radius-pill); background:transparent; color:var(--text-muted);
  font-size:var(--text-sm); font-weight:600; cursor:pointer;
  transition:background-color 160ms ease, color 160ms ease;
}
.xd-tab[aria-selected="true"]{ background:var(--accent); color:var(--accent-contrast); }
.xd-tab:disabled{ cursor:default; opacity:.6; }

.xd-body{ padding:12px 18px 4px; overflow-y:auto; overscroll-behavior:contain; min-height:0; }
.xd-panel[hidden]{ display:none; }
.xd-list{ display:flex; flex-direction:column; gap:6px; }
.xd-group{ font-size:10.5px; letter-spacing:.06em; text-transform:uppercase; color:var(--text-muted); margin:8px 2px 0; }
.xd-group:first-child{ margin-top:0; }

.xd-row{
  position:relative; display:flex; align-items:center; gap:10px; min-height:44px; padding:6px 12px;
  background:var(--card-bg); border:1px solid var(--border); border-radius:var(--radius-md); cursor:pointer;
  transition:border-color 140ms ease, background-color 140ms ease, opacity 140ms ease;
}
.xd-row:has(input:checked){ border-color:rgba(var(--accent-rgb),0.5); background:var(--accent-soft); }
.xd-row:has(input:focus-visible){ outline:2px solid var(--accent); outline-offset:2px; }
.xd-row.off{ opacity:.45; cursor:default; }
.xd-row input{ position:absolute; opacity:0; inset:0; width:100%; height:100%; margin:0; cursor:inherit; }
.xd-switch{
  flex:0 0 auto; order:3; margin-left:auto; position:relative; width:34px; height:20px; border-radius:var(--radius-pill);
  background:var(--track-bg); border:1px solid var(--border-strong); transition:background-color 160ms ease, border-color 160ms ease;
}
.xd-switch::after{
  content:""; position:absolute; top:2px; left:2px; width:14px; height:14px; border-radius:50%; background:var(--text-muted);
  transition:transform 180ms var(--ease-out), background-color 160ms ease;
}
.xd-row input:checked ~ .xd-switch{ background:var(--accent); border-color:var(--accent); }
.xd-row input:checked ~ .xd-switch::after{ transform:translateX(14px); background:var(--accent-contrast); }
.xd-name{ order:1; font-size:var(--text-md); font-weight:700; min-width:3.4em; }
.xd-hint{ order:2; flex:1 1 auto; min-width:0; font-size:var(--text-xs); color:var(--text-muted); line-height:1.3; }

.xd-summary{
  margin:12px 0 8px; padding:8px 10px; font-size:var(--text-xs); line-height:1.4; word-break:break-word;
  color:var(--accent-strong); background:var(--accent-soft); border:1px solid rgba(var(--accent-rgb),0.2); border-radius:var(--radius-sm);
  font-variant-numeric:tabular-nums;
}
.xd-summary.empty{ color:var(--text-muted); background:transparent; border-color:var(--border); }

.xd-note{ margin:0 0 4px; font-size:var(--text-sm); color:var(--text-muted); line-height:1.45; }
.xd-action{ min-height:44px; margin-top:var(--space-2); }
.xd-paste{ display:block; width:100%; box-sizing:border-box; margin-top:var(--space-2); padding:10px 12px; font:inherit; font-size:var(--text-sm); color:inherit; background:transparent; border:1px solid var(--border, currentColor); border-radius:8px; resize:vertical; }

.xd-status{ min-height:20px; margin:4px 18px 0; display:flex; align-items:center; gap:8px; font-size:var(--text-sm); color:var(--text-muted); }
.xd-status.ok{ color:var(--ok); font-weight:600; }
.xd-status.error{ color:var(--danger); line-height:1.4; align-items:flex-start; }
.xd-spinner{
  width:14px; height:14px; border-radius:50%; border:2px solid var(--border-strong); border-top-color:var(--accent);
  animation:xd-spin 700ms linear infinite; flex:0 0 auto;
}
@keyframes xd-spin{ to{ transform:rotate(360deg); } }

.xd-foot{ padding:8px 18px 18px; }
.xd-foot[hidden]{ display:none; }
.xd-dialog > .xd-status:last-child{ margin-bottom:18px; }
.xd-download{ width:100%; min-height:46px; }
.xd-download:disabled{ opacity:.5; cursor:not-allowed; box-shadow:none; }

/* phones: a bottom sheet */
@media (max-width: 560px){
  .xd-backdrop{ align-items:flex-end; padding:0; }
  .xd-dialog{
    max-width:none; max-height:92dvh; border-radius:var(--radius-lg) var(--radius-lg) 0 0; border-bottom:none;
    animation:xd-sheet 240ms var(--ease-out) both;
    padding-bottom:env(safe-area-inset-bottom);
  }
}
@media (max-width: 380px){
  .xd-hint{ font-size:11px; }
  .xd-row{ padding-left:10px; padding-right:10px; gap:8px; }
}
@media (prefers-reduced-motion: reduce){
  .xd-backdrop, .xd-dialog{ animation:none; }
  .xd-spinner{ animation-duration:1.6s !important; }
}

/* very small phones: five top-bar buttons must fit on one row, so the Library button keeps only its icon */
@media (max-width: 420px){
  #btnLibrary{ padding-left:9px; padding-right:9px; min-height:32px; }
  #btnLibrary > span{ position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }
  #btnResetAll{ white-space:nowrap; }
}
