/* App-wide styling. No CSS framework: a small utility layer below plus
   component styles built on Fluent UI design tokens (set by
   <FluentDesignTheme>), so light/dark both work. Fallbacks match dark.

   Surface levels (dark fallbacks):
   page          layer-1  #1a1a1e   darkest
   section card  layer-2  #242429   each major area gets one
   inner cards   layer-3  #2d2d33   scenario/model cards inside a section
   highlights    layer-4  #35353a   model summary, cost highlight        */

html, body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--neutral-layer-1, #1a1a1e);
    color: var(--neutral-foreground-rest, #e6e6e9);
    font-size: 15px;
}

h1 { font-size: 1.35rem; font-weight: 650; }
h2 { font-size: 1.2rem; font-weight: 650; }
h5 { font-size: 1rem; font-weight: 650; }
h6 { font-size: 0.9rem; font-weight: 600; }
h1, h2, h3, h4, h5, h6 { margin: 0; color: var(--neutral-foreground-rest, #e6e6e9); }
h1:focus, h1:focus-visible { outline: none; }

p { margin: 0 0 0.5rem 0; }

/* ---------- Utility layer (the only layout classes used in markup) ---------- */

.d-flex { display: flex; }
.d-block { display: block; }
.flex-wrap { flex-wrap: wrap; }
.flex-shrink-0 { flex-shrink: 0; }
.flex-grow-1 { flex-grow: 1; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.justify-content-center { justify-content: center; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 10px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }
.mt-2 { margin-top: 10px; }
.mt-auto { margin-top: auto; }
.ms-1 { margin-left: 4px; }
.mx-auto { margin-left: auto; margin-right: auto; }
.p-2 { padding: 8px; }
.p-3 { padding: 16px; }
.p-4 { padding: 24px; }
.py-3 { padding-top: 16px; padding-bottom: 16px; }
.py-4 { padding-top: 24px; padding-bottom: 24px; }
.pt-2 { padding-top: 8px; }

.small { font-size: 0.8rem; }
.text-muted { color: var(--neutral-foreground-hint, #9d9da5); }
.text-break { overflow-wrap: anywhere; }
.text-center { text-align: center; }
.min-w-0 { min-width: 0; }

hr { border: 0; border-top: 1px solid var(--neutral-stroke-divider-rest, #3d3d42); }

/* ---------- App frame & sections ---------- */

.app-container {
    max-width: 1500px;
    margin: 0 auto;
    padding: 0 16px 24px;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 500;
    background: var(--neutral-layer-1, #1a1a1e);
    border-bottom: 1px solid var(--neutral-stroke-divider-rest, #3d3d42);
    padding: 12px 0;
    margin-bottom: 20px;
}

/* No overflow:hidden here — it would clip the filter dropdowns' listboxes.
   Nothing inside paints past the rounded corners anyway. */
.section {
    background: var(--neutral-layer-2, #242429);
    border: 1px solid var(--neutral-stroke-divider-rest, #3d3d42);
    border-radius: 10px;
}

.section-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--neutral-stroke-divider-rest, #3d3d42);
}

.section-title { display: flex; align-items: center; gap: 8px; }
.section-title svg { flex-shrink: 0; }

.section-sub {
    font-size: 0.75rem;
    color: var(--neutral-foreground-hint, #9d9da5);
    margin-top: 2px;
}

.section-body { padding: 16px 18px; }

/* ---------- Grids (replace framework rows/cols) ---------- */

.scenario-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    gap: 14px;
}

/* Catalog cards: max 4 columns, stepping down responsively */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

@media (max-width: 1200px) { .cards-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 900px)  { .cards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px)  { .cards-grid { grid-template-columns: 1fr; } }

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding-top: 16px;
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.price-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 10px;
}

/* ---------- Forms ---------- */

.form-row { margin-bottom: 14px; }

.field-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--neutral-foreground-hint, #9d9da5);
    margin-bottom: 4px;
    min-height: 1.4rem;
}

.estimate-btn {
    height: 1.4rem;
    min-width: 0;
    font-size: 0.7rem;
    text-transform: none;
    letter-spacing: normal;
}

.estimate-btn::part(control) { padding: 0 7px; }

.token-hint {
    font-size: 0.72rem;
    color: var(--neutral-foreground-hint, #9d9da5);
    margin-top: 3px;
    min-height: 0.95rem;
    font-variant-numeric: tabular-nums;
}

.filters-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

/* ---------- Provider avatars ---------- */

.provider-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.18);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    flex-shrink: 0;
    user-select: none;
}

.provider-avatar img {
    width: 62%;
    height: 62%;
    display: block;
}

.provider-name {
    font-size: 0.72rem;
    color: var(--neutral-foreground-hint, #9d9da5);
    line-height: 1.2;
}

/* ---------- Cards ---------- */

.model-card {
    background: var(--neutral-layer-3, #2d2d33);
    border: 1px solid var(--neutral-stroke-divider-rest, #3d3d42);
    border-radius: 8px;
    font-size: 0.85rem;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px;
    transition: border-color 0.15s ease, transform 0.1s ease;
}

.model-card:hover {
    border-color: var(--accent-fill-rest, #479ef5);
    transform: translateY(-1px);
}

.scenario-card {
    background: var(--neutral-layer-3, #2d2d33);
    border: 1px solid var(--neutral-stroke-divider-rest, #3d3d42);
    border-radius: 8px;
    height: 100%;
}

.scenario-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--neutral-stroke-divider-rest, #3d3d42);
}

.scenario-body { padding: 14px 12px; }

.scenario-name {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--neutral-foreground-rest, #e6e6e9);
    font-weight: 600;
    font-size: 0.95rem;
    min-width: 60px;
    width: 100%;
    padding: 2px 6px;
}

.scenario-name:hover, .scenario-name:focus {
    border-color: var(--neutral-stroke-rest, #55555c);
    outline: none;
}

/* ---------- Chips ---------- */

.chip {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1;
    padding: 0.32em 0.6em;
    border-radius: 999px;
    white-space: nowrap;
}

.chip-global   { background: #0e5c2f; color: #7ee2a8; }
.chip-datazone { background: #0a4a6e; color: #7cc7f0; }
.chip-regional { background: #6e4a0a; color: #f0cf7c; }
.chip-unknown  { background: var(--neutral-fill-secondary-rest, #35353a); color: var(--neutral-foreground-hint, #9d9da5); }
.chip-region   { background: transparent; color: var(--neutral-foreground-hint, #9d9da5); border: 1px solid var(--neutral-stroke-divider-rest, #3d3d42); }
.chip-custom   { background: #6e0a4a; color: #f07cc7; }
.chip-cheapest { background: #0e5c2f; color: #7ee2a8; }

/* ---------- Prices ---------- */

.price-label {
    font-size: 0.68rem;
    color: var(--neutral-foreground-hint, #9d9da5);
}

.price-in  { color: #2fac67; font-weight: 600; }
.price-out { color: #3f9de0; font-weight: 600; }
.price-cached { color: #9678e0; font-weight: 600; }
.price-num { font-variant-numeric: tabular-nums; }

.cost-multiplier {
    color: #d8a637;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}

/* ---------- Model summary & picker ---------- */

.model-summary {
    background: var(--neutral-layer-4, #35353a);
    border: 1px solid var(--neutral-stroke-divider-rest, #3d3d42);
    border-radius: 6px;
    padding: 8px 10px;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.model-summary:hover { border-color: var(--accent-fill-rest, #479ef5); }

.picker-list {
    max-height: 52vh;
    overflow-y: auto;
    scrollbar-width: thin;
}

.picker-cols {
    display: grid;
    grid-template-columns: 1.7rem 1fr auto;
    gap: 10px;
    align-items: center;
}

.picker-head {
    padding: 8px 10px 6px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--neutral-foreground-hint, #9d9da5);
    border-bottom: 1px solid var(--neutral-stroke-divider-rest, #3d3d42);
}

.picker-row {
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid transparent;
}

.picker-row:hover {
    background: var(--neutral-layer-4, #35353a);
    border-color: var(--accent-fill-rest, #479ef5);
}

.picker-price {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    font-size: 0.82rem;
}

/* Hourly & PTU table */
.hourly-cols {
    display: grid;
    grid-template-columns: 1.7rem minmax(160px, 1fr) auto auto auto minmax(90px, auto);
    gap: 10px;
    align-items: center;
}

.hourly-row {
    padding: 7px 10px;
    border-radius: 6px;
    border: 1px solid transparent;
}

.hourly-row:hover {
    background: var(--neutral-layer-4, #35353a);
}

@media (max-width: 760px) {
    .hourly-cols { grid-template-columns: 1.7rem 1fr minmax(80px, auto); }
    .hourly-cols > :nth-child(3),
    .hourly-cols > :nth-child(4),
    .hourly-cols > :nth-child(5) { display: none; }
}

/* ---------- Cost breakdown ---------- */

/* Cost footer: two matched tiles — monthly headline (accent) beside the
   per request/day/year details. */
.cost-summary {
    display: grid;
    grid-template-columns: 1fr 1.4fr; /* the details table needs more width */
    gap: 10px;
    align-items: stretch;
    margin-top: 10px;
}

.cost-tile {
    background: var(--neutral-layer-4, #35353a);
    border: 1px solid var(--neutral-stroke-divider-rest, #3d3d42);
    border-radius: 8px;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 3px;
    text-align: center;
}

.cost-highlight { border-color: var(--accent-fill-rest, #479ef5); }

.cost-highlight .amount {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent-foreground-rest, #479ef5);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.cost-table { width: 100%; font-size: 0.78rem; border-collapse: collapse; }
.cost-table td { padding: 2px 0; text-align: left; white-space: nowrap; }
.cost-table td:last-child { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; padding-left: 8px; }

/* ---------- Banners & modal ---------- */

.stale-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    border: 1px solid #6e4a0a;
    border-radius: 8px;
    background: color-mix(in srgb, #6e4a0a 25%, transparent);
    font-size: 0.85rem;
}

.error-banner {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    border: 1px solid #b32121;
    border-radius: 8px;
}

.app-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-modal {
    background: var(--neutral-layer-2, #242429);
    border: 1px solid var(--neutral-stroke-divider-rest, #3d3d42);
    border-radius: 10px;
    width: min(540px, calc(100vw - 24px));
    max-height: 90vh;
    overflow-y: auto;
}

.app-modal .modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--neutral-stroke-divider-rest, #3d3d42);
}

.app-modal .modal-body { padding: 18px; }

.app-modal .modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 18px;
    border-top: 1px solid var(--neutral-stroke-divider-rest, #3d3d42);
}

.field-error { color: #f07c7c; font-size: 0.75rem; margin-top: 3px; }

/* ---------- Menus ---------- */

.menu-tokens {
    float: right;
    margin-left: 12px;
    color: var(--neutral-foreground-hint, #9d9da5);
    font-variant-numeric: tabular-nums;
}

/* ---------- Footer & legal pages ---------- */

.app-footer {
    border-top: 1px solid var(--neutral-stroke-divider-rest, #3d3d42);
    margin-top: 8px;
    padding: 14px 0;
    font-size: 0.75rem;
    color: var(--neutral-foreground-hint, #9d9da5);
}

.app-footer a {
    color: inherit;
    text-decoration: underline;
}

.app-footer a:hover {
    color: var(--accent-foreground-rest, #479ef5);
}

.legal { margin-top: 20px; }

.legal .section-body {
    max-width: 56rem;
    line-height: 1.55;
    font-size: 0.9rem;
}

.legal h6 {
    margin: 18px 0 6px;
}

.legal h6:first-of-type { margin-top: 0; }

.legal a { color: var(--accent-foreground-rest, #479ef5); }

/* ---------- Boot splash & error UI ---------- */

.boot-spinner {
    width: 2rem;
    height: 2rem;
    border: 3px solid #3d3d42;
    border-top-color: #479ef5;
    border-radius: 50%;
    animation: boot-spin 0.8s linear infinite;
}

@keyframes boot-spin { to { transform: rotate(360deg); } }

#blazor-error-ui {
    background: #6e4a0a;
    color: #f0e6cf;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.4);
    display: none;
    left: 0;
    padding: 10px 20px 11px;
    position: fixed;
    width: 100%;
    z-index: 2000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 12px;
    top: 8px;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 16px;
    color: white;
    border-radius: 8px;
}

.blazor-error-boundary::after { content: "An error has occurred."; }

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
    .section-head { padding: 10px 12px; }
    .section-body { padding: 12px; }
    .app-container { padding: 0 10px 16px; }
    .cost-highlight .amount { font-size: 1.1rem; }
}
