/* Strategy Builder Modal Styling */
.sb-dialog {
  box-sizing: border-box;
  margin: auto;
  width: min(680px, calc(100% - 32px));
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  padding: 24px;
  border: 1px solid var(--hair);
  border-radius: var(--r-lg);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--sh-3);
  overscroll-behavior: contain;
}

.sb-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.sb-dialog:not([open]) {
  display: none;
}

.sb-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--hair);
  padding-bottom: 16px;
}

.sb-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.sb-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: var(--r-xs);
  background: var(--duck-bg);
  color: var(--duck-deep);
}

.sb-tag {
  font-size: 11px;
  color: var(--dim);
  padding: 2px 6px;
  border-radius: var(--r-xs);
  background: var(--panel);
}

.sb-title {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.sb-sub {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--dim);
}

.sb-close {
  font: inherit;
  font-size: 14px;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--hair);
  border-radius: var(--r-sm);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.sb-close:hover {
  border-color: var(--ink);
  background: var(--panel);
}

/* Tabs */
.sb-tabs {
  display: flex;
  gap: 6px;
  margin: 16px 0 20px;
  padding: 4px;
  background: var(--panel);
  border-radius: var(--r-sm);
}

.sb-tab {
  flex: 1;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 12px;
  border: none;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  text-align: center;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, font-weight 0.15s ease;
}

.sb-tab:hover {
  color: var(--ink);
}

.sb-tab.is-active {
  background: var(--paper);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--sh-1);
}

/* Panels */
.sb-panel {
  display: none;
}

.sb-panel.is-active {
  display: block;
  animation: sb-panel-in 0.24s ease both;
}

.sb-section {
  margin-bottom: 16px;
}

.sb-section-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.sb-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.sb-hint {
  font-size: 11px;
  color: var(--dim);
}

.sb-chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.sb-chip {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  /* Room on the right for the pick mark, so the text never moves when a
     chip is picked. */
  padding: 8px 32px 8px 12px;
  border: 1px solid var(--hair);
  border-radius: var(--r-sm);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.18s ease, background-color 0.18s ease,
              box-shadow 0.22s ease, transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sb-chip:active {
  transform: scale(0.985);
}

/* The pick mark: a filled check that springs in on the chip just picked and
   shrinks out of the one it replaced, so the eye follows the move. */
.sb-chip::after {
  content: '';
  position: absolute;
  top: 9px;
  right: 10px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--duck-deep) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 8.2l2.3 2.3 4.7-4.9' fill='none' stroke='%23fff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat;
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.14s ease, transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.sb-chip.is-active::after {
  opacity: 1;
  transform: scale(1);
}

/* A ring that ripples out once from the chip just clicked (added by
   strategy-builder.js on the pick, removed when it ends). */
.sb-chip.is-picked {
  animation: sb-ring 0.5s ease-out;
}

.sb-chip:hover {
  border-color: var(--duck-deep);
  background: color-mix(in srgb, var(--duck-bg) 45%, var(--paper));
}

.sb-chip.is-active {
  border-color: var(--duck-deep);
  background: var(--duck-bg);
  box-shadow: 0 0 0 1px var(--duck-deep);
}

.sb-chip-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}

.sb-chip.is-active .sb-chip-title {
  color: var(--duck-deep);
}

.sb-chip-desc,
.sb-chip-count {
  font-size: 11px;
  color: var(--dim);
  line-height: 1.3;
}

/* Preview Card */
.sb-preview-card {
  margin: 20px 0 18px;
  padding: 16px;
  border: 1px solid var(--hair);
  border-radius: var(--r-sm);
  background: var(--panel);
}

.sb-preview-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px 12px;
  margin-bottom: 8px;
}

.sb-preview-top > div:first-child {
  min-width: 0;
}

.sb-preview-pill {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--duck-deep);
  background: var(--duck-bg);
  padding: 2px 7px;
  border-radius: var(--r-xs);
  margin-bottom: 4px;
}

.sb-preview-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.sb-preview-cap {
  /* Shrinks and wraps: the capital line is a full sentence for a priced
     market ("One 100-share lot runs about … to …; all 3 names …"), and a
     `flex: none` pill ran straight out of the card. A long line wraps onto
     its own row under the title; a short one still sits beside it. */
  flex: 0 1 auto;
  max-width: 100%;
  box-sizing: border-box;
  line-height: 1.4;
  font-size: 12px;
  font-weight: 600;
  color: var(--dim);
  background: var(--paper);
  padding: 4px 8px;
  border-radius: var(--r-xs);
  border: 1px solid var(--hair);
}

.sb-preview-desc {
  margin: 0 0 10px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--dim);
}

.sb-preview-names {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.sb-ticker {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--r-xs);
  background: var(--paper);
  border: 1px solid var(--hair);
  color: var(--ink);
}

/* The preview answers each pick: its lines settle in, one after another,
   whenever the composed id changes (strategy-builder.js toggles the class). */
.sb-preview-card.is-swapping .sb-preview-pill,
.sb-preview-card.is-swapping .sb-preview-title,
.sb-preview-card.is-swapping .sb-preview-cap,
.sb-preview-card.is-swapping .sb-preview-desc,
.sb-preview-card.is-swapping .sb-preview-names {
  animation: sb-swap 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.sb-preview-card.is-swapping .sb-preview-title { animation-delay: 0.03s; }
.sb-preview-card.is-swapping .sb-preview-cap { animation-delay: 0.05s; }
.sb-preview-card.is-swapping .sb-preview-desc { animation-delay: 0.07s; }
.sb-preview-card.is-swapping .sb-preview-names { animation-delay: 0.09s; }

@keyframes sb-ring {
  from { box-shadow: 0 0 0 1px var(--duck-deep), 0 0 0 0 color-mix(in srgb, var(--duck-deep) 35%, transparent); }
  to { box-shadow: 0 0 0 1px var(--duck-deep), 0 0 0 9px transparent; }
}

@keyframes sb-swap {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@keyframes sb-panel-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sb-chip,
  .sb-chip::after {
    transition: none;
  }
  .sb-chip:active {
    transform: none;
  }
  .sb-chip.is-picked,
  .sb-panel.is-active,
  .sb-preview-card.is-swapping * {
    animation: none;
  }
}

/* Foot actions */
.sb-foot {
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-top: 1px solid var(--hair);
  padding-top: 16px;
}

.sb-actions {
  display: flex;
  gap: 10px;
}

/* The three buttons are the shared family's (components.css: --primary is
   the green go, --secondary and --explore are outlined); .sb-btn keeps only
   the gap between a label and its arrow. */
.sb-btn {
  gap: 6px;
}

/* The primary label names the account ("Start on Paper Slot 4"), so it
   holds one line and trims a long nickname rather than stranding its last
   word under the arrow. */
.sb-btn--primary {
  flex: 0 1 auto;
  min-width: 0;
}

.sb-btn--primary span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* View All Configurations Drawer */
.sb-all-configs summary {
  font-size: 12px;
  font-weight: 600;
  color: var(--duck-deep);
  cursor: pointer;
  user-select: none;
}

.sb-all-configs summary:hover {
  text-decoration: underline;
}

.sb-configs-table-wrap {
  margin-top: 12px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--hair);
  border-radius: var(--r-sm);
}

.sb-configs-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sb-config-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--hair);
  transition: background 0.12s ease;
}

.sb-config-item:last-child {
  border-bottom: none;
}

.sb-config-item:hover {
  background: var(--panel);
}

.sb-config-item.is-selected {
  background: var(--duck-bg);
}

.sb-config-item-info {
  min-width: 0;
}

.sb-config-item-title {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}

.sb-config-item-id {
  font-size: 10px;
  color: var(--dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.sb-config-item-pick {
  flex: none;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border: 1px solid var(--hair);
  border-radius: var(--r-xs);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.sb-config-item.is-selected .sb-config-item-pick {
  border-color: var(--duck-deep);
  background: var(--duck-deep);
  color: var(--on-accent);
}

/* Card trigger styling */
.sc-builder-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--r-xs);
  background: var(--duck-bg);
  color: var(--duck-deep);
  border: 1px solid color-mix(in srgb, var(--duck) 20%, var(--paper));
  cursor: pointer;
  margin-left: 8px;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.sc-builder-pill:hover {
  background: var(--duck-deep);
  color: var(--on-accent);
  border-color: var(--duck-deep);
}

/* Responsive */
@media (max-width: 600px) {
  .sb-dialog {
    padding: 18px;
  }
  .sb-chips {
    grid-template-columns: 1fr;
  }
  .sb-actions {
    flex-direction: column;
  }
  .sb-btn {
    width: 100%;
  }
}
