/* --- Modal --- */
.modal-overlay {
  display: flex;
  position: fixed; inset: 0;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(8px) saturate(120%);
  backdrop-filter: blur(8px) saturate(120%);
  z-index: 100;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-out),
              visibility 0s linear var(--dur-base);
}
.modal-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity var(--dur-base) var(--ease-out), visibility 0s;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 800px;
  max-width: calc(100vw - var(--space-7));
  max-height: calc(100vh - var(--space-8));
  max-height: calc(100dvh - var(--space-8));
  padding: var(--space-6);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow-y: auto; /* safety net: never exceed the viewport, even on very short screens */
  /* Enters from slightly below, settles without overshoot; exits faster. */
  transform: scale(0.96) translateY(8px);
  opacity: 0;
  transition: transform 160ms var(--ease-in), opacity 160ms var(--ease-in);
}
.modal-overlay.open .modal {
  transform: none;
  opacity: 1;
  transition: transform var(--dur-slow) var(--ease-out), opacity var(--dur-base) var(--ease-out);
}
.modal-tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-3);
  flex-shrink: 0;
}
.modal-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  min-height: 32px;
  padding: 6px var(--space-3);
  color: var(--muted);
  font-size: var(--text-sm);
  font-family: inherit;
  cursor: pointer;
  transition: color 100ms var(--ease-out), border-color 100ms var(--ease-out);
}
.modal-tab:hover { color: var(--text); }
.modal-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.modal-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.modal-tab-panel { display: none; }
.modal-tab-panel.active {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
.modal-tab-panel > * { flex-shrink: 0; }
.modal h2 { font-size: var(--text-lg); font-weight: 600; margin-bottom: var(--space-1); letter-spacing: var(--tracking-tight); }
.modal .subtitle { font-size: var(--text-sm); color: var(--muted); margin-bottom: var(--space-5); }
.field { margin-bottom: var(--space-3); }
.field label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  margin-bottom: 5px;
}
.field-row { display: flex; gap: var(--space-1); }
.field input[type="text"],
.field input[type="password"],
.field input[type="number"] {
  width: 100%;
  padding: 7px var(--space-2);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: var(--text-base);
  font-family: inherit;
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.field .hint { font-size: var(--text-sm); color: var(--muted); margin-top: var(--space-1); }
.field .hint a { color: var(--accent); text-decoration: none; }
.field .hint a:hover { text-decoration: underline; }
.modal-actions { display: flex; gap: var(--space-2); margin-top: var(--space-5); align-items: center; }
.modal-actions .spacer { flex: 1; }
.btn-sm { padding: 6px var(--space-3); font-size: var(--text-sm); }
.btn-danger { border-color: var(--red); color: var(--red); background: transparent; }
.btn-danger:hover { background: color-mix(in srgb, var(--red) 12%, transparent); }
.p-free-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text);
  cursor: pointer;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
.p-free-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  margin: 0;
  flex-shrink: 0;
}
.price-grid input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.unpriced-badge {
  margin-left: var(--space-2);
  padding: 1px 6px;
  border-radius: 10px;
  font-size: var(--text-xs);
  font-weight: 500;
  background: var(--unpriced-bg);
  color: var(--orange);
  border: 1px solid var(--unpriced-border);
  letter-spacing: 0;
  text-transform: none;
  vertical-align: middle;
}

.price-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 var(--space-3);
}
#p-model-select {
  width: 100%;
  padding: 7px var(--space-2);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: var(--text-base);
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out);
}
#p-model-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.modal > * { flex-shrink: 0; }
/* The configured-models list is the only region allowed to grow/shrink:
   it absorbs overflow and scrolls internally, so header, close button and
   action buttons stay visible no matter how many models are priced. */
#p-configured-field {
  flex: 1 1 auto;
  min-height: 40px;
  display: flex;
  flex-direction: column;
}
#p-configured-field label { flex-shrink: 0; }
#p-configured-list {
  flex: 1 1 auto;
  min-height: 40px;
  overflow-y: auto;
}
.price-grid-head, .price-item {
  display: grid;
  /* name gets the leftover space and a generous minimum; numbers keep stable widths */
  grid-template-columns: minmax(220px, 1fr) repeat(4, 64px) 92px 28px;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
}
.price-grid-head {
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-1);
  white-space: nowrap;
}
.price-item {
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: var(--text-sm);
}
.price-item strong { color: var(--text); }
.price-grid-head .num, .price-item .num {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-align: right;
  white-space: nowrap;
}
.price-item .num { color: var(--text); }
.price-item .p-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.price-item .p-src { margin-right: 5px; }
.price-item .p-src svg { width: 13px; height: 13px; vertical-align: -2px; }
.price-item .p-src.src-manual { color: var(--orange); }
.price-item .p-src.src-auto { color: var(--green); }
.price-item .p-src.src-fail { color: var(--red); }
.price-item .price-meta {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: var(--text-xs);
  color: var(--muted);
}
.btn-remove {
  padding: 2px var(--space-1);
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: var(--text-sm);
  transition: color 100ms var(--ease-out), background-color 100ms var(--ease-out), transform 100ms var(--ease-out);
}
.btn-remove:hover { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.btn-remove:active { transform: scale(0.92); }
.btn-remove:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-remove svg { width: 12px; height: 12px; }

.modal-close {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: var(--text-icon);
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: background-color 100ms var(--ease-out), color 100ms var(--ease-out), transform 100ms var(--ease-out);
}
.modal-close:hover { background: var(--surface2); color: var(--text); }
.modal-close:active { transform: scale(0.92); }
.modal-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.modal-close svg { width: 16px; height: 16px; }
#modal-status { font-size: var(--text-sm); margin-top: var(--space-3); min-height: 18px; }
#modal-status.ok { color: var(--green); }
#modal-status.err { color: var(--red); }

#p-resync-btn { width: 100%; justify-content: center; }
#p-resync-status { font-size: var(--text-sm); color: var(--muted); margin-top: var(--space-1); min-height: 14px; }

.security-note {
  margin-top: var(--space-4);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: var(--text-sm);
  color: var(--muted);
  line-height: 1.5;
}
.security-note strong { color: var(--text); }

/* --- Undo toast --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: var(--space-5);
  z-index: 300;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  max-width: min(520px, calc(100vw - 2 * var(--space-4)));
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface2);
  box-shadow: var(--shadow-md);
  color: var(--text);
  font-size: var(--text-sm);
  opacity: 0;
  transform: translate(-50%, var(--space-2));
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-base) var(--ease-out);
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}
.toast-action {
  flex-shrink: 0;
  min-height: 32px;
  padding: 3px var(--space-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.toast-action:hover { background: var(--accent); color: var(--on-accent); }
.toast-action:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
