:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --text: #182322;
  --muted: #66706d;
  --border: #d9e0dc;
  --border-strong: #b8c5bf;
  --primary: #236b54;
  --primary-dark: #1b5744;
  --accent: #315f9d;
  --danger: #bd2d24;
  --warning: #a35d13;
  --warning-bg: #fff7eb;
  --notice-bg: #eff8f3;
  --shadow: 0 12px 30px rgba(22, 35, 32, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font: 15px/1.45 "Segoe UI", Arial, sans-serif;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

header {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(22, 35, 32, 0.04);
}

.brand {
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand:hover {
  text-decoration: none;
}

nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px 16px;
}

nav form {
  margin: 0;
}

.user-name {
  max-width: 220px;
  overflow: hidden;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-soft);
  text-overflow: ellipsis;
  white-space: nowrap;
}

main {
  width: min(1680px, calc(100vw - 32px));
  margin: 28px auto 48px;
}

h1,
h2,
h3 {
  margin: 0 0 16px;
  line-height: 1.2;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 17px;
}

p {
  margin: 0 0 12px;
}

.panel {
  margin-bottom: 16px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel.narrow {
  max-width: 420px;
  margin: clamp(36px, 9vh, 72px) auto;
}

.auth-card {
  padding: 28px;
}

.auth-card h1 {
  margin-bottom: 20px;
}

.auth-switch {
  margin: 18px 0 0;
  color: var(--muted);
  text-align: center;
}

.auth-switch a {
  font-weight: 700;
}

.panel.wide {
  width: 100%;
}

.schedule-panel {
  padding-inline: clamp(14px, 1.5vw, 20px);
}

.panel.warn {
  border-color: rgba(163, 93, 19, 0.45);
  background: var(--warning-bg);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.device-card {
  display: grid;
  align-content: start;
  gap: 12px;
}

.device-card h3 {
  margin-bottom: 0;
  overflow-wrap: anywhere;
}

.compact-dl {
  grid-template-columns: 112px 1fr;
  margin-bottom: 0;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 2px;
}

.card-actions form {
  margin: 0;
}

.stack {
  display: grid;
  gap: 14px;
}

.stack > *,
.form-grid > *,
.row-form > *,
.schedule-toolbar > * {
  min-width: 0;
}

.row-form,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}

.row-form label {
  flex: 1 1 220px;
}

.actions {
  margin-top: 16px;
}

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

.page-heading h1 {
  margin-bottom: 6px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.checks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px 16px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--text);
  font-weight: 650;
}

label.check,
label.inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
}

input,
select,
button,
.button-link {
  min-height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 8px 11px;
  font: inherit;
}

input,
select {
  width: 100%;
  min-width: 0;
  color: var(--text);
  background: var(--surface);
}

input[type="checkbox"] {
  width: auto;
  min-height: auto;
  accent-color: var(--primary);
}

input[type="file"] {
  padding: 8px;
}

input:focus,
select:focus,
button:focus-visible,
.button-link:focus-visible {
  outline: 3px solid rgba(35, 107, 84, 0.18);
  outline-offset: 2px;
  border-color: var(--primary);
}

button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  gap: 8px;
  color: #ffffff;
  background: var(--primary);
  border-color: var(--primary);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.button-link:hover {
  background: var(--primary-dark);
  text-decoration: none;
}

.button-link.small {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

button.ghost {
  color: var(--primary);
  background: var(--surface);
  border-color: var(--border-strong);
}

button.ghost:hover {
  color: #ffffff;
  background: var(--primary);
  border-color: var(--primary);
}

button.danger {
  color: var(--danger);
  border-color: rgba(189, 45, 36, 0.55);
}

button.danger:hover {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}

.compact-button {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 9px 8px;
  border-bottom: 1px solid #e5ebe7;
  text-align: left;
  vertical-align: top;
}

th {
  color: #31413d;
  background: #eef3f0;
  font-weight: 750;
}

dl {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 6px 8px;
  margin: 0 0 16px;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
}

code {
  font-family: Consolas, "Courier New", monospace;
  overflow-wrap: anywhere;
}

.facts {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.facts div {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px;
  align-items: start;
}

.facts span,
.muted {
  color: var(--muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.summary-item {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.summary-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.summary-item strong {
  font-size: 16px;
}

.summary-item.tech code {
  font-size: 14px;
}

.data-table td:nth-child(3),
.data-table td:nth-child(4) {
  white-space: nowrap;
}

.settings-section {
  display: grid;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid #e5ebe7;
}

.settings-section:first-child {
  padding-top: 0;
  border-top: 0;
}

.settings-section h2 {
  margin-bottom: 0;
}

.settings-table {
  margin-top: 2px;
}

.check.compact {
  min-height: 40px;
}

.zone-check {
  margin-right: 10px;
  margin-bottom: 4px;
}

.notice {
  padding: 10px 12px;
  margin-bottom: 16px;
  border: 1px solid #b9d7c4;
  border-radius: 8px;
  color: #1c4d3c;
  background: var(--notice-bg);
}

.day-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.day-tab {
  display: flex;
  min-height: 44px;
  align-items: center;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-soft);
}

.day-tab:hover {
  border-color: var(--border-strong);
  text-decoration: none;
}

.day-tab.active {
  border-color: var(--primary);
  background: var(--notice-bg);
  box-shadow: inset 0 0 0 1px rgba(35, 107, 84, 0.16);
}

.day-tab.weekend {
  color: var(--danger);
}

.day-tab.special {
  border-color: rgba(163, 93, 19, 0.35);
  background: var(--warning-bg);
}

.day-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 750;
  line-height: 1.2;
}

.schedule-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(180px, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

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

.schedule-edit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-start;
}

.schedule-items {
  display: grid;
  gap: 10px;
}

.schedule-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.schedule-item details {
  min-width: 0;
}

.schedule-item-summary {
  display: grid;
  grid-template-columns: auto 48px minmax(120px, auto) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 56px;
  padding: 10px 12px;
  cursor: pointer;
}

.schedule-item-summary::-webkit-details-marker {
  display: none;
}

.schedule-item-summary::after {
  content: ">";
  justify-self: end;
  color: var(--muted);
  font-weight: 800;
  transform: rotate(90deg);
}

.schedule-item details[open] .schedule-item-summary::after {
  transform: rotate(-90deg);
}

.event-kind {
  width: fit-content;
  padding: 2px 8px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.event-number {
  font-size: 18px;
  line-height: 1;
  text-align: center;
}

.event-time {
  color: #31413d;
  font-weight: 800;
  white-space: nowrap;
}

.event-music {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.schedule-delete {
  margin: 10px 12px 0 0;
  white-space: nowrap;
}

.schedule-item-body {
  display: grid;
  gap: 0;
  border-top: 1px solid #e5ebe7;
}

.schedule-job-group {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.schedule-job-group + .schedule-job-group {
  border-top: 1px solid #e5ebe7;
}

.schedule-job-group h3 {
  margin-bottom: 0;
  color: #31413d;
  font-size: 15px;
}

.schedule-job-grid {
  display: grid;
  grid-template-columns: minmax(128px, 150px) minmax(220px, 1fr) minmax(190px, 240px);
  gap: 10px;
  align-items: end;
}

.clock-field,
.music-field,
.media-field {
  gap: 4px;
}

.clock-field {
  min-width: 128px;
}

.clock-field span,
.music-field span,
.media-field span,
.relay-seconds span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.clock-input {
  width: 100%;
  min-width: 128px;
  max-width: 160px;
  min-height: 44px;
  padding: 8px;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.music-field input,
.media-field select {
  min-height: 44px;
}

.relay-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
}

.relay-grid .relay-editor {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  min-width: 0;
}

.relay-name {
  color: #31413d;
  font-size: 12px;
  font-weight: 800;
}

.relay-seconds {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 6px;
}

.relay-seconds input {
  min-height: 34px;
  padding: 5px 7px;
}

.relay-editor select {
  min-height: 38px;
}

.empty-state {
  padding: 18px 10px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 720px) {
  body {
    font-size: 14px;
  }

  header {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 12px;
  }

  nav {
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
  }

  main {
    width: calc(100% - 32px);
    margin-top: 12px;
    padding: 0;
  }

  h1 {
    font-size: 22px;
  }

  .panel {
    padding: 14px;
  }

  .panel.narrow {
    width: calc(100vw - 32px);
    max-width: calc(100vw - 32px);
    margin: 20px auto;
  }

  .auth-card {
    padding: 20px;
  }

  .row-form > *,
  .actions > *,
  .schedule-toolbar > * {
    flex: 1 1 100%;
  }

  .page-heading {
    display: grid;
  }

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

  .schedule-toolbar {
    grid-template-columns: 1fr;
  }

  .schedule-item {
    grid-template-columns: 1fr;
  }

  .schedule-delete {
    width: calc(100% - 24px);
    margin: 0 12px 12px;
  }

  .schedule-item-summary {
    grid-template-columns: auto 42px minmax(86px, auto) minmax(0, 1fr) auto;
    gap: 8px;
  }

  .schedule-job-grid {
    grid-template-columns: 1fr;
  }

  .clock-input {
    max-width: 100%;
  }

  .facts div {
    grid-template-columns: 1fr;
  }

  dl {
    grid-template-columns: 64px 1fr;
  }
}
