:root {
  color-scheme: dark;
  --bg: #120f0a;
  --bg-2: #1f1710;
  --surface: rgba(32, 24, 17, 0.94);
  --surface-strong: rgba(41, 30, 19, 0.98);
  --line: rgba(255, 201, 146, 0.16);
  --line-strong: rgba(255, 167, 79, 0.28);
  --text: #f8efe5;
  --muted: #c7b39d;
  --accent: #ff8a1e;
  --accent-strong: #ffb15c;
  --accent-soft: rgba(255, 138, 30, 0.16);
  --ok: #f0b15f;
  --danger: #ff8e76;
  --shadow: 0 14px 32px rgba(0, 0, 0, 0.24);
  --radius: 8px;
  --nav-height: 76px;
}

html[data-theme='light'] {
  color-scheme: light;
  --bg: #f4eadf;
  --bg-2: #e7d7c8;
  --surface: rgba(252, 245, 236, 0.94);
  --surface-strong: rgba(255, 249, 242, 0.98);
  --line: rgba(90, 65, 41, 0.12);
  --line-strong: rgba(255, 138, 30, 0.24);
  --text: #22170f;
  --muted: #6f5b49;
  --accent: #ea6d10;
  --accent-strong: #ff8a1e;
  --accent-soft: rgba(234, 109, 16, 0.12);
  --ok: #946117;
  --danger: #a84f3f;
  --shadow: 0 12px 26px rgba(54, 35, 16, 0.12);
}

html[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0c0a08;
  --bg-2: #14100d;
  --surface: rgba(19, 16, 13, 0.94);
  --surface-strong: rgba(26, 21, 17, 0.98);
  --line: rgba(255, 191, 120, 0.12);
  --line-strong: rgba(255, 138, 30, 0.26);
  --text: #f6ede4;
  --muted: #c9b8a8;
  --accent: #ff8a1e;
  --accent-strong: #ffb15c;
  --accent-soft: rgba(255, 138, 30, 0.14);
  --ok: #ffb15c;
  --danger: #ff8e76;
  --shadow: 0 14px 30px rgba(0, 0, 0, 0.3);
}

html[data-theme='orange'] {
  color-scheme: dark;
  --bg: #100d0a;
  --bg-2: #23160d;
  --surface: rgba(28, 19, 11, 0.95);
  --surface-strong: rgba(38, 25, 14, 0.98);
  --line: rgba(255, 170, 80, 0.14);
  --line-strong: rgba(255, 138, 30, 0.34);
  --text: #fff2e7;
  --muted: #d1b79e;
  --accent: #ff8a1e;
  --accent-strong: #ffb25f;
  --accent-soft: rgba(255, 138, 30, 0.2);
  --ok: #ffc06b;
  --danger: #ff9a83;
  --shadow: 0 16px 36px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Trebuchet MS", Verdana, sans-serif;
  background:
    radial-gradient(900px 600px at 12% 4%, rgba(255, 138, 30, 0.18) 0%, transparent 60%),
    radial-gradient(700px 460px at 88% 8%, rgba(255, 197, 129, 0.12) 0%, transparent 58%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--text);
  overflow: hidden;
}

body:not(.is-authenticated) .bottom-nav {
  display: none;
}

body:not(.is-authenticated) .topbar {
  display: none;
}

body:not(.is-authenticated) .shell {
  padding-bottom: 14px;
}

.shell {
  position: relative;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 12px calc(var(--nav-height) + 20px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.shell::before,
.shell::after {
  content: '';
  position: fixed;
  inset: auto;
  border-radius: 50%;
  filter: blur(44px);
  pointer-events: none;
  opacity: 0.5;
}

.shell::before {
  width: 180px;
  height: 180px;
  left: -36px;
  top: 10px;
  background: rgba(255, 138, 30, 0.14);
}

.shell::after {
  width: 220px;
  height: 220px;
  right: -70px;
  bottom: 24px;
  background: rgba(255, 177, 92, 0.1);
}

.topbar,
.panel,
.section-head,
.bottom-nav {
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.topbar {
  position: sticky;
  top: 12px;
  z-index: 20;
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #1b1209;
}

.brand-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.brand-copy strong,
.section-head h2,
.panel h1 {
  margin: 0;
  letter-spacing: -0.02em;
}

.eyebrow,
.section-kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.topbar-actions {
  display: grid;
  grid-template-rows: auto auto;
  justify-items: end;
  align-content: center;
  gap: 6px;
}

.status-chip,
.action-btn,
.icon-btn,
.nav-btn,
input,
button {
  border-radius: var(--radius);
}

.status-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--accent-soft);
}

.equipment-top {
  width: 170px;
}

.equipment-top select {
  width: 100%;
  min-height: 28px;
  padding: 5px 8px;
  font-size: 12px;
}

.icon-btn,
.action-btn,
.nav-btn,
button {
  font: inherit;
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: linear-gradient(180deg, var(--surface-strong) 0%, var(--surface) 100%);
}

.icon-btn,
.action-btn {
  min-height: 32px;
  padding: 0 12px;
  font-weight: 700;
  cursor: pointer;
}

.shell-content {
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
  display: grid;
  gap: 12px;
}

.app {
  padding: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

h1,
h2 {
  margin: 0;
}

p {
  color: var(--muted);
  margin: 8px 0 14px;
}

.panel,
.stack {
  display: grid;
  gap: 12px;
}

.panel {
  border-radius: 14px;
  padding: 14px;
}

.panel-head,
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.section-head {
  border-radius: 14px;
  padding: 12px 14px;
}

.form {
  display: grid;
  gap: 10px;
}

.auth-notice {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13px;
  line-height: 1.35;
  background: rgba(255, 138, 30, 0.12);
  color: var(--text);
}

.auth-notice.warning {
  border-color: rgba(255, 177, 92, 0.55);
  background: rgba(255, 177, 92, 0.16);
}

.auth-notice.error {
  border-color: rgba(255, 110, 96, 0.65);
  background: rgba(255, 110, 96, 0.14);
}

input,
button {
  font: inherit;
  padding: 11px 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface-strong);
  color: var(--text);
}

button {
  cursor: pointer;
  font-weight: 700;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 138, 30, 0.45);
}

button.secondary {
  background: var(--accent-soft);
}

.btn-sm {
  width: fit-content;
  min-width: 70px;
  padding: 6px 10px;
  font-size: 12px;
}

.channels {
  display: grid;
  gap: 10px;
}

.settings-panel {
  display: grid;
  gap: 12px;
}

.setting-row {
  display: grid;
  gap: 6px;
}

.setting-row span {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.setting-actions {
  display: grid;
  gap: 8px;
}

.channel-card {
  border: 3px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.channel-card.ok-card {
  border-color: rgba(126, 227, 157, 0.66);
  box-shadow: 0 0 0 1px rgba(126, 227, 157, 0.12), var(--shadow);
}

.channel-card.freeze-card {
  border-color: rgba(255, 110, 96, 0.88);
  box-shadow: 0 0 0 1px rgba(255, 110, 96, 0.18), var(--shadow);
}

.channel-card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: fill;
  background: linear-gradient(135deg, rgba(255, 138, 30, 0.08), rgba(255, 255, 255, 0.03));
}

.channel-content {
  padding: 7px;
  display: grid;
  gap: 4px;
}

.channel-title {
  line-height: 1.2;
}

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

.channel-statuses {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.channel-empty {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 12px;
  color: var(--muted);
  text-align: center;
  background: rgba(255, 138, 30, 0.06);
}

.tag {
  display: inline-flex;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.tag.ok {
  color: var(--ok);
  background: rgba(255, 177, 92, 0.16);
}

.tag.freeze {
  color: var(--danger);
  background: rgba(255, 142, 118, 0.16);
}

.channel-card.ok-card .tag.ok {
  border: 1px solid rgba(126, 227, 157, 0.32);
}

.channel-card.freeze-card .tag.freeze {
  border: 1px solid rgba(255, 110, 96, 0.34);
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(100%, 480px);
  z-index: 30;
  border-radius: 16px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.nav-btn {
  min-height: 56px;
  padding: 8px 10px;
  display: grid;
  place-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.08);
}

html[data-theme='light'] .nav-btn {
  background: rgba(255, 255, 255, 0.56);
}

.nav-btn.active {
  color: var(--text);
  border-color: rgba(255, 138, 30, 0.5);
  background: linear-gradient(180deg, rgba(255, 138, 30, 0.24) 0%, var(--accent-soft) 100%);
}

.nav-icon {
  width: 16px;
  height: 16px;
  position: relative;
  display: inline-block;
}

.nav-icon-home::before,
.nav-icon-home::after,
.nav-icon-refresh::before,
.nav-icon-refresh::after,
.nav-icon-theme::before,
.nav-icon-theme::after {
  content: '';
  position: absolute;
}

.nav-icon-home::before {
  inset: 4px 3px 2px;
  border: 2px solid currentColor;
  border-top: none;
  border-radius: 2px;
}

.nav-icon-home::after {
  width: 11px;
  height: 11px;
  left: 2px;
  top: -1px;
  border-left: 2px solid currentColor;
  border-top: 2px solid currentColor;
  transform: rotate(45deg);
}

.nav-icon-refresh::before {
  inset: 2px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
}

.nav-icon-refresh::after {
  width: 6px;
  height: 6px;
  right: 0;
  top: 2px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: rotate(35deg);
}

.nav-icon-theme::before {
  inset: 2px;
  border-radius: 50%;
  border: 2px solid currentColor;
}

.nav-icon-theme::after {
  width: 4px;
  height: 4px;
  left: 50%;
  top: 2px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: currentColor;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(12px);
  opacity: 0;
  transition: 0.2s ease;
  background: var(--surface-strong);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.hidden {
  display: none;
}

@media (max-width: 900px) {
  .topbar {
    align-items: stretch;
  }

  .topbar-actions {
    justify-items: stretch;
  }

  .equipment-top {
    width: 100%;
  }
}
