:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-soft: #f8faf9;
  --ink: #17201b;
  --muted: #66706b;
  --line: #d9ded7;
  --control: #ffffff;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --warn: #a16207;
  --cool: #2563eb;
  --focus: rgba(37, 99, 235, 0.22);
  --danger: #b91c1c;
  --shadow: 0 18px 45px rgba(23, 32, 27, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101614;
  --panel: #18211e;
  --panel-soft: #111a17;
  --ink: #eef4ef;
  --muted: #a9b8b0;
  --line: #2f3d37;
  --control: #111a17;
  --accent: #2dd4bf;
  --accent-dark: #14b8a6;
  --warn: #facc15;
  --cool: #60a5fa;
  --focus: rgba(45, 212, 191, 0.26);
  --danger: #f87171;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control);
  color: var(--ink);
  cursor: pointer;
  padding: 0 16px;
}

button:hover {
  border-color: var(--muted);
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

button.primary:hover {
  background: var(--accent-dark);
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(360px, 1.6fr);
  gap: 24px;
  align-items: end;
  margin-bottom: 18px;
}

.topbar-side {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 10px;
  align-items: stretch;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1;
}

h2 {
  font-size: 22px;
  line-height: 1.1;
}

.status-strip,
.phase-band {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.icon-button {
  width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.status-strip > div,
.phase-band > div {
  min-width: 0;
  padding: 14px;
  border-left: 1px solid var(--line);
}

.status-strip > div:first-child,
.phase-band > div:first-child {
  border-left: 0;
}

.status-strip span,
.phase-band span,
.temp-control span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.status-strip strong,
.phase-band strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, 0.9fr);
  gap: 18px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.cycle-panel,
.ac-panel,
.profile-panel {
  padding: 18px;
}

.side-stack {
  display: grid;
  gap: 18px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.switch {
  position: relative;
  display: inline-flex;
  width: 72px;
  height: 38px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  width: 100%;
  border-radius: 999px;
  background: #c9d1cc;
  transition: background 0.15s ease;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 5px;
  left: 5px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
  transition: transform 0.15s ease;
}

.switch input:checked + span {
  background: var(--accent);
}

.switch input:checked + span::after {
  transform: translateX(34px);
}

.settings-form {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.profile-form {
  display: grid;
  gap: 12px;
}

.profile-list {
  display: grid;
  gap: 8px;
}

.profile-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
}

.profile-row.selected {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.profile-row input {
  width: 18px;
  min-height: 18px;
  margin: 2px 0 0;
  padding: 0;
  accent-color: var(--accent);
}

.profile-row-text {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.profile-row-text strong,
.profile-row-text span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-row-text strong {
  font-size: 15px;
}

.profile-row-text span {
  color: var(--muted);
  font-size: 12px;
}

.profile-schedule {
  grid-column: 2;
  width: max-content;
  max-width: 100%;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
}

.profile-schedule.scheduled {
  border-color: var(--warn);
  color: var(--warn);
}

.profile-empty {
  margin: 0;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}

fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

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

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control);
  color: var(--ink);
  padding: 0 12px;
}

input:focus,
select:focus,
button:focus-visible,
.switch input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.form-actions,
.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.temp-control {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.temp-control > div {
  min-height: 72px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.temp-control strong {
  color: var(--cool);
  font-size: 34px;
  line-height: 1;
}

.temp-control button {
  height: 72px;
  padding: 0;
  font-size: 28px;
}

.meta-list {
  display: grid;
  gap: 0;
  margin: 18px 0 0;
  border-top: 1px solid var(--line);
}

.meta-list div {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.meta-list dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.meta-list dd {
  margin: 0;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message {
  min-height: 24px;
  margin: 16px 0 0;
  color: var(--muted);
}

.message.error {
  color: var(--danger);
}

.profile-summary {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100vw - 20px, 680px);
    padding-top: 14px;
  }

  .topbar,
  .control-grid {
    grid-template-columns: 1fr;
  }

  .topbar-side {
    grid-template-columns: minmax(0, 1fr) 44px;
  }

  .status-strip,
  .phase-band {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-strip > div,
  .phase-band > div {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .status-strip > div:nth-child(-n + 2),
  .phase-band > div:nth-child(-n + 2) {
    border-top: 0;
  }

  .status-strip > div:nth-child(even),
  .phase-band > div:nth-child(even) {
    border-left: 1px solid var(--line);
  }

  fieldset {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .status-strip,
  .phase-band {
    grid-template-columns: 1fr;
  }

  .status-strip > div,
  .phase-band > div,
  .status-strip > div:nth-child(even),
  .phase-band > div:nth-child(even) {
    border-left: 0;
  }

  .status-strip > div:nth-child(2),
  .phase-band > div:nth-child(2) {
    border-top: 1px solid var(--line);
  }

  .panel-header {
    align-items: start;
  }

  .meta-list div {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .meta-list dd {
    text-align: left;
  }
}
