:root {
  color-scheme: light;
  --bg: #f3f0ea;
  --surface: #ffffff;
  --surface-strong: #111416;
  --line: #d8d2c8;
  --line-strong: #a7a092;
  --text: #161a1d;
  --muted: #6d6f6b;
  --green: #0f8f72;
  --green-soft: #dff4ee;
  --red: #c94a3a;
  --red-soft: #fae7e2;
  --amber: #b87513;
  --amber-soft: #fff2d6;
  --blue: #2f6f9f;
  --blue-soft: #e1edf5;
  --shadow: 0 18px 50px rgba(20, 18, 14, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0) 220px),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0)),
    var(--surface-strong);
  box-shadow: var(--shadow);
}

.brand-mark span {
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.25rem, 4vw, 1.7rem);
  line-height: 1.1;
}

.brand p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.92rem;
}

.topbar-actions,
.action-row,
.live-actions,
.cloud-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.page-switcher {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(248, 246, 241, 0.94);
  backdrop-filter: blur(14px);
}

.page-button {
  display: grid;
  min-height: 50px;
  place-items: center;
  padding: 0 12px;
  color: var(--muted);
  border: 1px solid transparent;
  background: transparent;
  font-weight: 850;
}

.page-button:hover,
.page-button.is-active {
  color: #fff;
  border-color: var(--surface-strong);
  background: var(--surface-strong);
  box-shadow: 0 10px 22px rgba(17, 20, 22, 0.12);
}

.workspace {
  display: block;
}

.tool-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  padding: clamp(16px, 3vw, 24px);
}

.app-page {
  width: min(760px, 100%);
  margin: 0 auto;
}

.alarm-panel {
  width: min(860px, 100%);
}

.volume-panel {
  width: min(860px, 100%);
}

.app-page[hidden] {
  display: none;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
}

.panel-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--amber);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h2 {
  font-size: clamp(1.25rem, 3vw, 1.7rem);
  line-height: 1.1;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(68px, 1fr));
  gap: 4px;
  margin: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8f6f1;
}

.segmented label {
  display: grid;
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segmented span {
  display: grid;
  min-height: 36px;
  place-items: center;
  border-radius: 7px;
  color: var(--muted);
  font-weight: 750;
}

.segmented input:checked + span {
  color: #fff;
  background: var(--surface-strong);
}

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

.compact-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field span,
.live-strip span,
.metric span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.field-hint {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.field-wide {
  grid-column: 1 / -1;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  background: #fff;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 111, 159, 0.14);
}

.affix-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.affix-input:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 111, 159, 0.14);
}

.affix-input input {
  min-height: 44px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.affix-input b {
  display: grid;
  place-items: center;
  color: var(--muted);
  border-left: 1px solid var(--line);
  background: #f8f6f1;
}

.quick-presets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.quick-presets button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--text);
  border: 1px solid var(--line);
  background: #f8f6f1;
  font-size: 0.88rem;
  font-weight: 800;
}

.quick-presets button:hover,
.quick-presets button.is-active {
  color: #fff;
  border-color: var(--surface-strong);
  background: var(--surface-strong);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.metric {
  display: grid;
  gap: 8px;
  min-height: 118px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfaf7;
}

.metric strong {
  overflow-wrap: anywhere;
  font-size: clamp(1.25rem, 5vw, 2rem);
  line-height: 1.05;
}

.metric button {
  justify-self: start;
  min-height: 34px;
  padding: 0 10px;
  color: var(--text);
  background: #ece8df;
}

.metric.primary {
  border-color: rgba(15, 143, 114, 0.24);
  background: var(--green-soft);
}

.metric.danger {
  border-color: rgba(201, 74, 58, 0.24);
  background: var(--red-soft);
}

.solid-button {
  padding: 0 16px;
  color: #fff;
  background: var(--surface-strong);
  box-shadow: 0 10px 22px rgba(17, 20, 22, 0.14);
}

.solid-button:hover {
  background: #23282b;
}

.ghost-button {
  padding: 0 14px;
  color: var(--text);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
}

.ghost-button:hover {
  border-color: var(--line-strong);
  background: #fff;
}

.action-row {
  margin-top: 16px;
}

.inline-message {
  min-height: 22px;
  color: var(--muted);
  font-size: 0.9rem;
}

.status-pill {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
  background: #ece8df;
  font-size: 0.84rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.active {
  color: #075c49;
  background: var(--green-soft);
}

.status-pill.warning {
  color: #7a4700;
  background: var(--amber-soft);
}

.add-alert {
  align-self: end;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: max(16px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
  background: rgba(17, 20, 22, 0.42);
  backdrop-filter: blur(10px);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-panel {
  width: min(620px, 100%);
  max-height: min(720px, 92vh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(17, 20, 22, 0.24);
  padding: clamp(16px, 4vw, 22px);
}

.modal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-heading h3 {
  margin: 0;
  font-size: 1.18rem;
  line-height: 1.2;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.live-strip,
.cloud-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfaf7;
}

.cloud-strip {
  border-color: rgba(47, 111, 159, 0.24);
  background: var(--blue-soft);
}

.active-alarm {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  padding: 14px;
  border: 2px solid rgba(201, 74, 58, 0.36);
  border-radius: 10px;
  background: #fff4f0;
  box-shadow: 0 14px 36px rgba(201, 74, 58, 0.14);
}

.active-alarm[hidden] {
  display: none;
}

.active-alarm span {
  display: block;
  color: var(--red);
  font-size: 0.8rem;
  font-weight: 900;
}

.active-alarm strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 1.15rem;
}

.active-alarm p {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.active-alarm-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.active-alarm-actions b {
  min-width: 70px;
  color: var(--red);
  font-size: 1.1rem;
  text-align: right;
}

.alarm-settings {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: end;
  margin-top: 14px;
}

.volume-field {
  grid-column: span 2;
}

.volume-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  gap: 10px;
  align-items: center;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.volume-control input {
  width: 100%;
  accent-color: var(--surface-strong);
}

.volume-control output {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  text-align: right;
}

.alarm-setting-actions {
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
}

.alarm-setting-actions button {
  width: 100%;
}

.live-strip strong,
.cloud-strip strong {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
  font-size: 1.2rem;
}

.live-actions,
.cloud-actions,
.cloud-strip .inline-message {
  grid-column: 1 / -1;
}

.monitor-settings {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 12px;
  align-items: end;
  margin-top: 14px;
}

.alerts-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.volume-summary,
.q70-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.volume-summary > div,
.q70-grid > div {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfaf7;
}

.volume-summary span,
.q70-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.volume-summary strong,
.q70-grid strong {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
  font-size: 1.22rem;
  line-height: 1.15;
}

.percentile-tone-safe {
  color: #16803c;
}

.percentile-tone-warning {
  color: #b77900;
}

.percentile-tone-heavy {
  color: #c2410c;
}

.percentile-tone-danger {
  color: #dc2626;
}

.volume-messages-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.volume-message-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  border: 1px solid rgba(47, 111, 159, 0.22);
  border-radius: 10px;
  color: #f8fbff;
  background: #203143;
}

.volume-message-card strong {
  display: grid;
  gap: 2px;
  font-size: 1rem;
  line-height: 1.36;
  overflow-wrap: anywhere;
}

.volume-message-lines span {
  display: block;
}

.volume-message-card .percentile-tone-safe {
  color: #55d67b;
}

.volume-message-card .percentile-tone-warning {
  color: #facc15;
}

.volume-message-card .percentile-tone-heavy {
  color: #fb923c;
}

.volume-message-card .percentile-tone-danger {
  color: #f87171;
}

.volume-message-card time {
  color: #b8c7d8;
  font-weight: 800;
  white-space: nowrap;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}

.section-heading h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

.alert-card,
.event-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.alert-card.triggered {
  border-color: rgba(184, 117, 19, 0.28);
  background: var(--amber-soft);
}

.events-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.event-card.strategy {
  border-color: rgba(47, 111, 159, 0.24);
  background: var(--blue-soft);
}

.event-card.manual {
  border-color: rgba(15, 143, 114, 0.22);
  background: var(--green-soft);
}

.alert-title,
.event-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.alert-title strong,
.event-title strong {
  overflow-wrap: anywhere;
}

.mini-pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 0 8px;
  color: var(--muted);
  background: #f1eee8;
  font-size: 0.75rem;
  font-weight: 800;
}

.alert-meta,
.event-meta {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.alert-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-actions button {
  min-height: 36px;
  padding: 0 10px;
}

.empty-state {
  display: grid;
  min-height: 86px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.44);
  text-align: center;
}

@media (max-width: 900px) {
  .workspace {
    display: block;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding-inline: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 10px;
  }

  .topbar-actions {
    justify-content: flex-end;
  }

  .page-switcher {
    margin-bottom: 12px;
  }

  .page-button {
    min-height: 48px;
  }

  .panel-heading,
  .alert-card,
  .event-card,
  .active-alarm,
  .alarm-settings,
  .monitor-settings {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    display: grid;
  }

  .panel-actions {
    justify-content: stretch;
  }

  .panel-actions > * {
    flex: 1 1 140px;
  }

  .segmented {
    width: 100%;
  }

  .form-grid,
  .compact-form,
  .metrics,
  .live-strip,
  .volume-summary,
  .q70-grid,
  .volume-message-card {
    grid-template-columns: 1fr;
  }

  .field-wide,
  .volume-field,
  .live-actions {
    grid-column: auto;
  }

  .live-actions,
  .cloud-actions,
  .modal-actions,
  .action-row {
    align-items: stretch;
  }

  .live-actions button,
  .cloud-actions button,
  .modal-actions button,
  .action-row button {
    flex: 1 1 140px;
  }

  .metric {
    min-height: 108px;
  }
}
