:root {
  --promo-bg: #f5f7fb;
  --promo-card: #ffffff;
  --promo-border: rgba(15, 23, 42, .12);
  --promo-shadow: 0 14px 34px rgba(15, 23, 42, .08);
}

[data-bs-theme="dark"] {
  --promo-bg: #101318;
  --promo-card: #171b22;
  --promo-border: rgba(255, 255, 255, .12);
  --promo-shadow: none;
}

body {
  min-height: 100vh;
  background: var(--promo-bg);
}

.api-usage-widget {
  min-width: 0;
}

.api-usage-button {
  min-width: 0;
  white-space: nowrap;
}

.api-usage-label {
  color: var(--bs-secondary-color);
  font-weight: 600;
}

.api-usage-total {
  display: inline-block;
  max-width: 6.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}

.api-usage-menu {
  --usage-panel: rgba(127, 127, 127, .06);
  min-width: min(23rem, calc(100vw - 1.5rem));
  padding: .75rem;
}

.api-usage-title-row {
  align-items: flex-start;
  display: flex;
  gap: .75rem;
  justify-content: space-between;
  padding-bottom: .65rem;
}

.api-usage-hero {
  background: var(--usage-panel);
  border: 1px solid var(--promo-border);
  border-radius: .45rem;
  display: grid;
  gap: .12rem;
  margin-bottom: .65rem;
  padding: .65rem .75rem;
}

.api-usage-hero strong {
  font-size: 1.35rem;
  line-height: 1.1;
}

.api-usage-provider {
  border-bottom: 1px solid var(--promo-border);
  padding-bottom: .65rem;
  margin-bottom: .65rem;
}

.api-usage-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .5rem;
  margin-bottom: .75rem;
}

.api-usage-summary > div {
  background: var(--usage-panel);
  border: 1px solid var(--promo-border);
  border-radius: .4rem;
  display: grid;
  gap: .15rem;
  min-width: 0;
  padding: .5rem;
}

.api-usage-summary span {
  color: var(--bs-secondary-color);
  font-size: .76rem;
  line-height: 1.1;
}

.api-usage-summary strong {
  font-size: .92rem;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
}

.api-usage-provider {
  display: grid;
  gap: .35rem;
}

.api-usage-provider-head {
  align-items: center;
  display: flex;
  gap: .75rem;
  justify-content: space-between;
}

.api-usage-provider-head strong,
.api-usage-provider-meta strong {
  white-space: nowrap;
}

.api-usage-provider-meta {
  color: var(--bs-secondary-color);
  display: flex;
  flex-wrap: wrap;
  font-size: .78rem;
  gap: .25rem .65rem;
}

.api-usage-source-badge {
  border: 1px solid var(--promo-border);
  border-radius: 999px;
  color: var(--bs-body-color);
  line-height: 1.2;
  padding: .05rem .38rem;
}

.api-usage-provider:last-child {
  border-bottom: 0;
  margin-bottom: 0;
  padding-bottom: 0;
}

.auth-shell {
  min-height: calc(100vh - 58px);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.auth-card,
.panel {
  background: var(--promo-card);
  border: 1px solid var(--promo-border);
  border-radius: .5rem;
  box-shadow: var(--promo-shadow);
}

.auth-card {
  width: min(100%, 420px);
  padding: 1.25rem;
}

.promo-grid {
  display: grid;
  grid-template-columns: minmax(440px, 560px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
  min-width: 0;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-header {
  min-width: 0;
  padding: .9rem 1rem;
  border-bottom: 1px solid var(--promo-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}

.panel-body {
  padding: 1rem;
  min-width: 0;
}

.promo-tabs {
  --bs-nav-tabs-border-color: var(--promo-border);
}

#sample-tab #status {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  margin: 0;
}

#sample-tab #status:not(.d-none) {
  border-top: 0;
}

#sample-tab #status:not(.d-none) + .preview-frame {
  border-top: 0;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

#sample-tab #status.d-none + .preview-frame {
  margin-top: 1rem;
}

.tab-pane:not(#sample-tab) {
  padding-top: 1rem;
}

.preview-frame {
  min-height: 520px;
  background: rgba(127, 127, 127, .08);
  border: 1px solid var(--promo-border);
  border-radius: .5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.preview-frame img {
  display: block;
  width: 100%;
  max-width: 520px;
  height: auto;
}

.review-panel {
  border-top: 1px solid var(--promo-border);
  margin-top: 1rem;
  padding-top: 1rem;
}

.review-summary {
  color: var(--bs-secondary-color);
  margin-top: .45rem;
}

.review-issues {
  color: var(--bs-secondary-color);
  margin-top: .45rem;
  padding-left: 1.2rem;
}

.review-issues:empty {
  display: none;
}

.empty-preview {
  text-align: center;
  color: var(--bs-secondary-color);
  padding: 2rem;
}

.price-summary {
  border: 1px solid var(--promo-border);
  border-radius: .5rem;
  padding: .9rem;
  background: rgba(127, 127, 127, .05);
}

.side-audit {
  border-top: 1px solid var(--promo-border);
  margin-top: 1rem;
  padding-top: 1rem;
}

.form-action-stack {
  display: grid;
  gap: .55rem;
}

.reference-preset {
  align-items: center;
  border: 1px solid var(--promo-border);
  border-radius: .45rem;
  display: grid;
  gap: .65rem;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  margin-top: .6rem;
  padding: .55rem;
}

.reference-preset img {
  aspect-ratio: 1;
  background: rgba(127, 127, 127, .08);
  border: 1px solid var(--promo-border);
  border-radius: .35rem;
  height: 56px;
  object-fit: cover;
  width: 56px;
}

.reference-preset-body {
  min-width: 0;
}

#reference-preset-name,
#reference-preset-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-audit .price-table-compact {
  font-size: .68rem;
  line-height: 1.1;
}

.side-audit .price-table-compact th,
.side-audit .price-table-compact td {
  padding-left: .12rem;
  padding-right: .12rem;
}

.side-audit .price-table-compact th {
  line-height: 1.05;
  white-space: normal;
}

.side-audit .price-table-compact td {
  white-space: nowrap;
}

.side-audit .price-table-compact th:first-child,
.side-audit .price-table-compact td:first-child {
  overflow-wrap: anywhere;
  white-space: normal;
}

.station-data-block {
  border-top: 1px solid var(--promo-border);
  margin-top: .9rem;
  padding-top: .9rem;
}

.station-data-list {
  display: grid;
  gap: .55rem;
  margin: 0;
}

.station-data-list dt {
  font-size: .85rem;
  font-weight: 700;
  line-height: 1.2;
}

.station-data-list dd {
  font-size: .86rem;
  line-height: 1.3;
  margin: .16rem 0 0;
  overflow-wrap: anywhere;
}

.old-price {
  color: var(--bs-secondary-color);
  text-decoration: line-through;
  white-space: nowrap;
}

.price-table {
  font-size: .82rem;
  min-width: 380px;
}

.price-table th,
.price-table td {
  white-space: nowrap;
}

.prompt-editor {
  min-height: 340px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: .9rem;
  line-height: 1.45;
  resize: vertical;
}

.prompt-save-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
}

.prompt-save-row .form-control {
  flex: 1 1 260px;
  min-width: 0;
}

.prompt-actions {
  display: flex;
  flex: 0 0 auto;
  gap: .5rem;
  justify-content: flex-end;
  margin-left: auto;
}

.prompt-actions .btn {
  white-space: nowrap;
}

.history-list,
.saved-prompt-list {
  display: grid;
  gap: .75rem;
  max-height: 680px;
  overflow: auto;
  padding-right: .15rem;
}

.history-item,
.saved-prompt-item,
.empty-list {
  border: 1px solid var(--promo-border);
  border-radius: .5rem;
  background: rgba(127, 127, 127, .04);
}

.history-item {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: .75rem;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  padding: .65rem;
}

.saved-prompt-item,
.empty-list {
  padding: .75rem;
}

.history-thumb-frame {
  align-self: start;
  aspect-ratio: 4 / 5;
  background: rgba(127, 127, 127, .08);
  border: 1px solid var(--promo-border);
  border-radius: .4rem;
  display: block;
  max-width: 112px;
  overflow: hidden;
  width: 112px;
}

.history-list img.history-thumb {
  display: block;
  height: 100%;
  max-width: none;
  object-fit: cover;
  width: 100%;
}

.history-body {
  min-width: 0;
}

.history-prompt,
.saved-prompt-text {
  color: var(--bs-secondary-color);
  display: -webkit-box;
  font-size: .84rem;
  line-height: 1.35;
  margin-top: .35rem;
  overflow: hidden;
  -webkit-box-orient: vertical;
}

.history-prompt {
  -webkit-line-clamp: 3;
}

.saved-prompt-text {
  -webkit-line-clamp: 4;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: .6rem;
}

@media (max-width: 1100px) {
  .promo-grid {
    grid-template-columns: 1fr;
  }
  .preview-frame {
    min-height: 420px;
  }
}

@media (max-width: 560px) {
  .container-fluid {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }
  .navbar-brand small {
    display: none;
  }
  .api-usage-total {
    max-width: 5.6rem;
  }
  .api-usage-widget .api-usage-menu {
    left: 1rem !important;
    min-width: 0;
    position: fixed !important;
    right: 1rem !important;
    top: 4.25rem !important;
    transform: none !important;
    width: auto;
  }
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }
  .reference-preset {
    align-items: stretch;
    grid-template-columns: 48px minmax(0, 1fr);
  }
  .reference-preset img {
    height: 48px;
    width: 48px;
  }
  .reference-preset .btn {
    grid-column: 1 / -1;
    justify-content: center;
  }
  .prompt-save-row {
    align-items: stretch;
    flex-direction: column;
  }
  .prompt-actions {
    justify-content: flex-end;
    margin-left: 0;
  }
  .history-item {
    grid-template-columns: 88px minmax(0, 1fr);
  }
  .history-thumb-frame {
    max-width: 88px;
    width: 88px;
  }
}
