/* Material Design 3 inspired tokens: light and dark schemes, CSS custom properties only. */

:root {
  --md-sys-motion-short: 150ms;
  --radius-m: 12px;
  --radius-l: 16px;
  --touch: 48px;
}

:root[data-theme="dark"],
:root[data-theme="auto"] {
  color-scheme: dark;
  --primary: #a8c8ff;
  --on-primary: #00305f;
  --primary-container: #00478c;
  --on-primary-container: #d6e3ff;
  --surface: #141218;
  --surface-container: #211f26;
  --surface-container-high: #2b2930;
  --on-surface: #e6e0e9;
  --on-surface-variant: #cac4d0;
  --outline: #938f99;
  --outline-variant: #49454f;
  --error: #ffb4ab;
  --on-error: #690005;
  --error-container: #93000a;
  --on-error-container: #ffdad6;
  --scrim: rgba(0, 0, 0, 0.6);
}

:root[data-theme="light"] {
  color-scheme: light;
  --primary: #3f6ada;
  --on-primary: #ffffff;
  --primary-container: #d8e2ff;
  --on-primary-container: #001945;
  --surface: #fef7ff;
  --surface-container: #f3edf7;
  --surface-container-high: #ece6f0;
  --on-surface: #1d1b20;
  --on-surface-variant: #49454f;
  --outline: #79747e;
  --outline-variant: #cac4d0;
  --error: #b3261e;
  --on-error: #ffffff;
  --error-container: #f9dedc;
  --on-error-container: #410e0c;
  --scrim: rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

/* view switching: class beats the display set on .login-view/.dash-view */
.hidden {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--surface);
  color: var(--on-surface);
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- typography ---------- */

.display {
  font-size: 2.6rem;
  font-weight: 400;
  letter-spacing: -0.5px;
  margin: 0;
}
.title {
  font-size: 1.4rem;
  font-weight: 500;
  margin: 0;
}
.card-value {
  /* fits narrow cards: no wrap, fluid size, units on the same baseline */
  font-size: clamp(1.75rem, 7.5vw, 2.6rem);
  font-weight: 400;
  letter-spacing: -1px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin-top: auto;
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
}

/* long values shrink instead of wrapping or overflowing */
.card-value .num {
  font-size: 1em;
  transition: font-size var(--md-sys-motion-short) ease;
}

@container (max-width: 180px) {
  .card-value {
    font-size: clamp(1.5rem, 8.5cqw, 2.2rem);
  }
}

.card-units {
  font-size: clamp(0.85rem, 3.2vw, 1rem);
  color: var(--on-surface-variant);
  font-weight: 400;
  flex-shrink: 1;
}

.trend {
  font-size: clamp(0.8rem, 3vw, 1rem);
  line-height: 1;
}
.trend-up {
  color: #e57757;
}
.trend-down {
  color: #6aa2e0;
}
/* semantic is temperature-oriented: warming = warm color, cooling = cool color */
.card-label {
  font-size: 0.95rem;
  color: var(--on-surface-variant);
  margin-top: 4px;
}
.supporting {
  font-size: 0.9rem;
  color: var(--on-surface-variant);
}
.error-text {
  color: var(--error);
  font-size: 0.9rem;
}

/* ---------- login ---------- */

.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: min(100%, 360px);
  background: var(--surface-container);
  border-radius: var(--radius-l);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-card .display {
  text-align: center;
}
.login-card .supporting {
  text-align: center;
  margin-top: -10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-label {
  font-size: 0.85rem;
  color: var(--on-surface-variant);
}

.field input {
  height: var(--touch);
  padding: 0 16px;
  border-radius: var(--radius-m);
  border: 1px solid var(--outline-variant);
  background: var(--surface);
  color: var(--on-surface);
  font-size: 1rem;
  outline: none;
  transition: border-color var(--md-sys-motion-short) ease;
}

.field input:focus {
  border-color: var(--primary);
  border-width: 2px;
  padding: 0 15px;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--touch);
  color: var(--on-surface-variant);
  font-size: 0.95rem;
}

.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

.btn-filled {
  height: var(--touch);
  border: none;
  border-radius: 100px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: filter var(--md-sys-motion-short) ease;
}

.btn-filled:active {
  filter: brightness(0.92);
}
.btn-filled:disabled {
  opacity: 0.6;
}

/* ---------- street forecast banner ---------- */

.card.forecast {
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 0;
  /* breathing room: the banner sits between the header and the card grid */
  margin: 12px 0;
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.card.forecast.warn {
  background: var(--error-container);
  color: var(--on-error-container);
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 100px;
  /* follows the banner's text color, so it adapts to warn restyling */
  background: color-mix(in srgb, currentColor 12%, transparent);
  font-size: 0.95rem;
  font-weight: 500;
  white-space: nowrap;
}

/* the hidden attribute must win over the display above (empty chip) */
.chip[hidden] {
  display: none;
}

.chip-trend {
  background: color-mix(in srgb, currentColor 20%, transparent);
}

.forecast-text {
  flex-basis: 100%;
  font-size: 0.92rem;
  opacity: 0.9;
  line-height: 1.35;
}

/* ---------- dashboard ---------- */

.dash-view {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px 24px;
}

.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.header-actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  width: var(--touch);
  height: var(--touch);
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--on-surface-variant);
  font-size: 1.3rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.icon-btn .icon {
  width: 24px;
  height: 24px;
  display: block;
}

.icon-btn.spin {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.icon-btn:active {
  background: var(--surface-container-high);
}

.stale-banner {
  background: var(--error-container);
  color: var(--on-error-container);
  border-radius: var(--radius-m);
  padding: 10px 14px;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  container-type: inline-size;
  container-name: card;
}

.card {
  background: var(--surface-container);
  border-radius: var(--radius-l);
  padding: 16px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  transition: background var(--md-sys-motion-short) ease;
}

.card.alert {
  background: var(--error-container);
  color: var(--on-error-container);
}

.card.alert .card-value,
.card.alert .card-label {
  color: var(--on-error-container);
}

.card .card-top {
  display: flex;
  align-items: center;
  gap: 8px;
}
.card .card-icon {
  font-size: 1.2rem;
}
.card-placeholder {
  color: var(--on-surface-variant);
  font-size: 2rem;
}

#updated {
  text-align: center;
  margin-top: 16px;
}

@media (min-width: 700px) {
  .cards {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
  }
  .card {
    min-height: 150px;
    padding: 20px;
  }
}

/* ---------- events & item pages ---------- */

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.subtitle {
  font-size: 1.05rem;
  font-weight: 500;
  margin: 20px 0 10px;
  color: var(--on-surface-variant);
}

.events {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.event-card {
  background: var(--surface-container);
  border-radius: var(--radius-l);
  padding: 16px;
}

.event-card.active {
  background: var(--error-container);
  color: var(--on-error-container);
}

.event-card.read {
  opacity: 0.55;
}

.event-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.event-name {
  font-weight: 500;
  font-size: 0.95rem;
}

.event-times {
  font-size: 0.85rem;
  color: var(--on-surface-variant);
  margin-top: 4px;
}

.event-card.active .event-times {
  color: var(--on-error-container);
  opacity: 0.8;
}

.event-current {
  font-size: 0.9rem;
  font-weight: 500;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.badge {
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 100px;
  background: var(--error);
  color: var(--on-error);
  flex-shrink: 0;
}

.btn-tonal {
  margin-top: 10px;
  height: 40px;
  padding: 0 16px;
  border: none;
  border-radius: 100px;
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-tonal:disabled {
  opacity: 0.5;
}

.item-hero {
  margin-top: 8px;
  position: relative;
  /* value is the hero of this card: center it, keep the timestamp below */
  justify-content: center;
}

.item-hero .card-value {
  /* cancel the dashboard "bottom-anchored" value */
  margin-top: 0;
  font-size: clamp(2.2rem, 10vw, 3rem);
}

.item-hero .supporting {
  margin-top: 6px;
}

/* the dashboard card's emoji, large and quiet, top-right of the hero */
.hero-icon {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 2.2rem;
  line-height: 1;
  opacity: 0.9;
}

.item-block {
  margin-top: 12px;
  container-type: inline-size;
}

.chart {
  width: 100%;
}

/* Full-bleed chart: on narrow screens the canvas spans edge-to-edge of the
   card while the rest of the card keeps its padding (negative margins). */
@container (max-width: 480px) {
  .chart {
    margin: 0 -16px;
    width: auto;
  }
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.ranges {
  display: flex;
  gap: 4px;
}

.range-btn {
  border: none;
  background: transparent;
  color: var(--on-surface-variant);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 100px;
  cursor: pointer;
}

.range-btn.on {
  background: var(--secondary-container);
  color: var(--on-secondary-container);
}

/* uPlot theming: font follows app tokens; legend is the hover value readout */
.item-chart.uplot {
  font-family: inherit;
  font-size: 11px;
  color: var(--on-surface-variant);
}

.item-chart .u-legend {
  margin-top: 6px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--on-surface);
}

.item-chart .u-legend th,
.item-chart .u-legend td {
  padding: 2px 8px 2px 0;
}

/* legend readout, not a series switch: labels look like plain text */
.item-chart .u-legend th {
  font-weight: 400;
  color: var(--on-surface-variant);
}

.item-chart .u-legend th:first-child {
  /* "Время" header wastes space on narrow screens */
  display: none;
}

.item-chart .u-legend td.u-value {
  font-weight: 500;
  color: var(--on-surface);
}

.item-chart .u-legend tr {
  margin-right: 0;
}

.item-chart .u-legend .u-marker {
  display: none;
}

.stats {
  width: 100%;
  border-collapse: collapse;
}
.stats th,
.stats td {
  text-align: right;
  padding: 8px 10px;
  font-variant-numeric: tabular-nums;
}
.stats th:first-child,
.stats td:first-child {
  text-align: left;
  color: var(--on-surface-variant);
}
.stats tr {
  border-bottom: 1px solid var(--outline-variant);
}
.stats tr:last-child {
  border-bottom: none;
}
