/*
 * SunnyWeb design layer on top of MudBlazor.
 * Tokens reference the MudBlazor theme variables so light and dark mode stay in sync.
 * Components in Shared/Ui render these classes; pages should not need inline styles.
 */

:root {
  --sr-font-sans: Roboto, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --sr-font-mono: "Roboto Mono", "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  --sr-gutter: 16px;
  --sr-section-gap: 16px;
  --sr-section-pad: 16px;
  --sr-page-max: 1600px;
  --sr-radius: var(--mud-default-borderradius, 8px);
  --sr-outline: 1px solid var(--mud-palette-lines-default);
  --sr-header-top: var(--mud-appbar-height, 56px);
  --sr-chart-height: 400px;
}

@media (min-width: 960px) {
  :root {
    --sr-gutter: 24px;
    --sr-section-gap: 24px;
    --sr-section-pad: 20px;
  }
}

html, body {
  font-family: var(--sr-font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ---------- Text utilities ---------- */

.sr-num {
  font-family: var(--sr-font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.sr-mono {
  font-family: var(--sr-font-mono);
  font-size: .8125rem;
  letter-spacing: -0.01em;
}

.sr-muted {
  color: var(--mud-palette-text-secondary) !important;
}

.sr-nowrap {
  white-space: nowrap;
}

.sr-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.sr-period {
  display: flex;
  align-items: center;
  gap: 2px;
}

.sr-period__picker {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.sr-period__picker .mud-input-control {
  margin: 0;
  width: 168px;
  flex: none;
}

.sr-period__picker .mud-input-control + .mud-input-control {
  width: 128px;
}

.sr-period__current {
  white-space: nowrap;
}

.sr-period__current--icon {
  display: none !important;
}

@media (max-width: 599.98px) {
  .sr-period {
    flex: 1 1 100%;
    min-width: 0;
  }

  .sr-period .mud-icon-button {
    padding: 8px;
  }

  .sr-period__picker {
    flex: 1 1 auto;
  }

  .sr-period__picker .mud-input-control,
  .sr-period__picker .mud-input-control + .mud-input-control {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
  }

  .sr-period__current--text {
    display: none !important;
  }

  .sr-period__current--icon {
    display: inline-flex !important;
  }
}

.sr-spin .mud-icon-root {
  animation: sr-spin 900ms linear infinite;
}

@keyframes sr-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sr-spin .mud-icon-root {
    animation-duration: 2.4s;
  }
}

/* ---------- Shell ---------- */

.sr-content {
  max-width: var(--sr-page-max);
  margin-inline: auto;
  padding: 0 var(--sr-gutter) 48px;
}

.sr-layout--appbar-collapsed {
  --sr-header-top: 0px;
}

.sr-layout--appbar-collapsed .mud-main-content {
  padding-top: 0;
}

.sr-layout--appbar-collapsed .mud-drawer.mud-drawer-clipped-always {
  top: 0;
  height: 100%;
}

.sr-nav-section {
  padding: 20px 16px 6px 20px;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--mud-palette-text-secondary);
}

.sr-nav-section:first-child {
  padding-top: 12px;
}

.sr-nav {
  padding-bottom: 16px;
}

.sr-nav .mud-nav-link {
  margin: 1px 8px;
  width: calc(100% - 16px);
  padding-top: 7px;
  padding-bottom: 7px;
  border-radius: var(--sr-radius);
}

.sr-nav .mud-nav-link.active:not(.mud-nav-link-disabled) {
  font-weight: 600;
}

.sr-drawer {
  border-right: var(--sr-outline);
}

/* App bar */

.sr-appbar .mud-toolbar {
  gap: 4px;
}

.sr-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin-left: 4px;
  color: inherit;
  text-decoration: none;
}

.sr-brand__logo {
  flex: none;
}

.sr-brand__name {
  overflow: hidden;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sr-brand__version {
  padding: 1px 8px;
  font-family: var(--sr-font-mono);
  font-size: .75rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  border-radius: 999px;
  background: rgba(255, 255, 255, .16);
}

.sr-appbar__user {
  margin-right: 8px;
  font-size: .875rem;
  opacity: .9;
}

.sr-appbar__avatar {
  cursor: pointer;
  font-size: .75rem !important;
  font-weight: 600;
  color: var(--mud-palette-appbar-background) !important;
  background: var(--mud-palette-appbar-text) !important;
}

.sr-account-menu {
  min-width: 220px;
  padding: 8px 0;
}

.sr-account-menu__user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 16px;
}

.sr-account-menu__text {
  min-width: 0;
}

.sr-appbar-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 20px;
  padding: 0;
  color: var(--mud-palette-appbar-text);
  background: var(--mud-palette-appbar-background);
  border: 0;
  cursor: pointer;
  opacity: .75;
  transition: opacity 150ms ease-out;
}

.sr-appbar-strip:hover,
.sr-appbar-strip:focus-visible {
  opacity: 1;
}

@media (max-width: 599.98px) {
  .sr-brand__version {
    display: none;
  }
}

.sr-state--page {
  --sr-state-min: 60vh;
}

/* ---------- Page header ---------- */

.sr-page-header {
  position: sticky;
  top: var(--sr-header-top);
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
  margin: 0 calc(-1 * var(--sr-gutter)) var(--sr-section-gap);
  padding: 16px var(--sr-gutter) 14px;
  background: var(--mud-palette-background);
  border-bottom: var(--sr-outline);
}

@supports (animation-timeline: scroll()) {
  .sr-page-header {
    animation: sr-header-stuck linear both;
    animation-timeline: scroll(root);
    animation-range: 0 32px;
  }
}

@keyframes sr-header-stuck {
  to {
    box-shadow: 0 8px 16px -14px rgba(0, 0, 0, .45);
  }
}

.sr-page-header__titles {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 280px;
}

.sr-page-header__icon {
  flex: none;
  color: var(--mud-palette-primary);
}

.sr-page-header__text {
  min-width: 0;
}

.sr-page-header__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: 2px;
  font-size: .8125rem;
  line-height: 1.4;
  color: var(--mud-palette-text-secondary);
}

.sr-page-header__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-left: auto;
}

@media (max-width: 599.98px) {
  .sr-page-header {
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .sr-page-header__actions {
    width: 100%;
    justify-content: space-between;
    gap: 4px;
  }

  .sr-page-header__actions .mud-button-root.mud-button-text {
    min-width: 0;
    padding-inline: 6px;
  }
}

.sr-page-body {
  display: flex;
  flex-direction: column;
  gap: var(--sr-section-gap);
  min-width: 0;
}

/* ---------- Section card ---------- */

.sr-section {
  min-width: 0;
  background: var(--mud-palette-surface);
  border: var(--sr-outline);
  border-radius: var(--sr-radius);
}

.sr-section__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 14px var(--sr-section-pad) 0;
  min-height: 48px;
}

.sr-section--flush > .sr-section__header {
  padding-bottom: 12px;
  border-bottom: var(--sr-outline);
}

.sr-section__icon {
  flex: none;
  color: var(--mud-palette-text-secondary);
}

.sr-section__titles {
  flex: 1 1 200px;
  min-width: 0;
}

.sr-section__subtitle {
  margin-top: 1px;
  font-size: .8125rem;
  line-height: 1.4;
  color: var(--mud-palette-text-secondary);
}

.sr-section__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.sr-section__body {
  padding: 16px var(--sr-section-pad) var(--sr-section-pad);
  min-width: 0;
}

.sr-section--flush > .sr-section__body {
  padding: 0;
  overflow-x: auto;
}

.sr-section > .sr-section__body:first-child {
  padding-top: var(--sr-section-pad);
}

/* Side-by-side sections in one grid row share the row height. */
.mud-grid-item > .sr-section {
  height: 100%;
}

/* Expansion panels used as sections share the section surface. */
.sr-panels .mud-expand-panel {
  background: var(--mud-palette-surface);
  border: var(--sr-outline);
  border-radius: var(--sr-radius) !important;
  box-shadow: none !important;
  margin: 0 !important;
}

.sr-panels {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sr-panels .mud-expand-panel::before {
  display: none;
}

.sr-panels .mud-expand-panel-header {
  padding: 14px var(--sr-section-pad);
  min-height: 48px;
}

/* Panel titles match SectionCard titles (h6). */
.sr-panels .mud-expand-panel-header .mud-expand-panel-text {
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.4;
  min-width: 0;
}

.sr-panels .mud-expand-panel-content {
  padding: 0 var(--sr-section-pad) var(--sr-section-pad);
}

/* Keep the native one-line header height. A summary that cannot fit beside the
   title wraps as a whole into a clipped second row, never stretching the panel. */
.sr-panel-header {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  align-items: center;
  gap: 16px 24px;
  height: 1lh;
  overflow: hidden;
}

.sr-panel-header__title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  max-width: 100%;
  height: 100%;
  white-space: nowrap;
}

.sr-panel-header__label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sr-panel-header__warning {
  display: inline-flex;
  flex: none;
}

.sr-panel-header__summary {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  height: 100%;
  margin-inline-start: auto;
  color: var(--mud-palette-text-secondary);
  font-size: .875rem;
  font-weight: 400;
  white-space: nowrap;
}

/* ---------- Stats ---------- */

.sr-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--sr-stat-min, 200px)), 1fr));
  gap: 20px 24px;
}

.sr-stat-grid--compact {
  --sr-stat-min: 160px;
  gap: 16px 20px;
}

.sr-stat {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.sr-stat--boxed {
  padding: 16px;
  background: var(--mud-palette-surface);
  border: var(--sr-outline);
  border-radius: var(--sr-radius);
}

.sr-stat__icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: color-mix(in srgb, currentColor 12%, transparent);
}

.sr-stat__icon.mud-default-text,
.sr-stat__icon:not([class*="-text"]) {
  color: var(--mud-palette-text-secondary);
}

.sr-stat__body {
  min-width: 0;
  flex: 1 1 auto;
}

.sr-stat__label {
  font-size: .8125rem;
  line-height: 1.35;
  color: var(--mud-palette-text-secondary);
}

.sr-stat__value {
  margin-top: 2px;
  font-family: var(--sr-font-mono);
  font-size: 1.5rem;
  font-weight: 500;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  color: var(--mud-palette-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sr-stat__value--text {
  font-family: var(--sr-font-sans);
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}

.sr-stat__unit {
  margin-left: 4px;
  font-family: var(--sr-font-sans);
  font-size: .8125rem;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--mud-palette-text-secondary);
}

.sr-stat__caption {
  margin-top: 2px;
  font-size: .75rem;
  line-height: 1.4;
  color: var(--mud-palette-text-secondary);
}

.sr-stat__extra {
  margin-top: 8px;
}

.sr-stat--compact .sr-stat__icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.sr-stat--compact .sr-stat__value {
  font-size: 1.125rem;
}

/* ---------- Key/value lists ---------- */

.sr-kv {
  display: grid;
  grid-template-columns: minmax(120px, max-content) minmax(0, 1fr);
  gap: 8px 20px;
  margin: 0;
}

.sr-kv dt {
  font-size: .8125rem;
  color: var(--mud-palette-text-secondary);
}

.sr-kv dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ---------- Tables ---------- */

.mud-table .mud-table-head .mud-table-cell,
.mud-simple-table table thead th {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--mud-palette-text-secondary);
  white-space: nowrap;
}

.mud-table.sr-table,
.mud-simple-table.sr-table {
  background: transparent;
  box-shadow: none;
}

.sr-cell-num,
.mud-table-cell.sr-cell-num,
.mud-simple-table td.sr-cell-num,
.mud-simple-table th.sr-cell-num {
  text-align: right !important;
  white-space: nowrap;
}

td.sr-cell-num,
.mud-table-body .sr-cell-num {
  font-family: var(--sr-font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* ---------- Charts ---------- */

.sr-chart {
  width: 100%;
  min-height: var(--sr-chart-height);
}

.sr-chart--compact {
  --sr-chart-height: 300px;
}

/* ---------- States ---------- */

.sr-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--sr-state-min, 160px);
  padding: 32px 16px;
  text-align: center;
  color: var(--mud-palette-text-secondary);
}

.sr-state--compact {
  --sr-state-min: 0px;
  padding: 16px;
}

.sr-state__title {
  font-size: .9375rem;
  font-weight: 500;
  color: var(--mud-palette-text-primary);
}

.sr-state__text {
  max-width: 60ch;
  font-size: .875rem;
}

.sr-state__action {
  margin-top: 8px;
}

/* ---------- Log panel ---------- */

.sr-log {
  max-height: 400px;
  overflow: auto;
  padding: 12px 16px;
  font-family: var(--sr-font-mono);
  font-size: .8125rem;
  line-height: 1.6;
  background: var(--mud-palette-background-gray);
  border-radius: var(--sr-radius);
}

/* ---------- Blazor error UI ---------- */

#blazor-error-ui {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: none;
  padding: 12px 48px 12px 24px;
  font-family: var(--sr-font-sans);
  font-size: .875rem;
  color: var(--mud-palette-warning-text, #1f1f1f);
  background: var(--mud-palette-warning, #f59e0b);
  box-shadow: 0 -4px 16px -8px rgba(0, 0, 0, .35);
}

#blazor-error-ui .reload {
  margin-left: 12px;
  font-weight: 600;
  color: inherit;
}

#blazor-error-ui .dismiss {
  position: absolute;
  top: 10px;
  right: 16px;
  cursor: pointer;
}
