:root {
  --bg: #0f0e14;
  --surface: #1a1822;
  --surface-2: #24212e;
  --text: #f3f0f8;
  --muted: #a39db8;
  --primary: #9aa6f0;
  --primary-press: #7e8fea;
  --danger: #e8a0a0;
  --ok: #9edcb7;
  --radius: 1rem;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(5.5rem + var(--safe-bottom));
}

a {
  color: var(--primary);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
  background: rgba(15, 14, 20, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--text);
  text-decoration: none;
}

.brand img {
  width: 2rem;
  height: 2rem;
  border-radius: 0.55rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.lang-btn,
.icon-btn {
  appearance: none;
  border: 0;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 0.45rem 0.7rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.icon-btn[aria-pressed="true"],
.lang-btn[aria-pressed="true"] {
  background: var(--primary);
  color: #1a1630;
}

main {
  max-width: 32rem;
  margin: 0 auto;
  padding: 1rem;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.panel h2 {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.muted {
  color: var(--muted);
  font-size: 0.92rem;
}

.child-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.child-chip {
  appearance: none;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  font: inherit;
  cursor: pointer;
}

.child-chip.is-active {
  border-color: var(--primary);
  background: rgba(126, 143, 234, 0.2);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.status-pill.is-asleep {
  color: var(--ok);
}

.event-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.event-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-variant-numeric: tabular-nums;
}

.event-list li:first-child {
  border-top: 0;
}

.event-row {
  cursor: pointer;
  border-radius: 0.5rem;
  margin: 0 -0.35rem;
  padding-left: 0.35rem;
  padding-right: 0.35rem;
}

.event-row:hover,
.event-row:focus-visible {
  background: rgba(126, 143, 234, 0.12);
  outline: none;
}

.field-label {
  display: block;
  margin: 0.85rem 0 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.panel-head h2 {
  margin: 0;
}

.range-toggle {
  display: inline-flex;
  gap: 0.25rem;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0.15rem;
}

.range-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.range-btn.is-active {
  background: var(--primary);
  color: #171428;
  font-weight: 650;
}

.bars {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
  height: 5.5rem;
  margin-top: 0.75rem;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  min-width: 0;
}

.bar {
  width: 100%;
  max-width: 1.35rem;
  border-radius: 0.35rem 0.35rem 0.15rem 0.15rem;
  background: var(--primary);
  opacity: 0.85;
}

.bar-col span {
  font-size: 0.7rem;
  color: var(--muted);
}

.child-manage {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
}

.child-manage li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.child-manage li:first-child {
  border-top: 0;
}

.row.tight {
  margin-top: 0;
  flex-wrap: nowrap;
}

.row.tight .btn {
  padding: 0.45rem 0.7rem;
  font-size: 0.85rem;
}

input[type="datetime-local"] {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.85rem;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  padding: 0.75rem 0.85rem;
  margin-bottom: 0.75rem;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  input[type="datetime-local"] {
    color-scheme: light;
  }
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.toast-undo {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  padding: 0;
}

.toast.has-undo {
  pointer-events: auto;
  border-radius: 1rem;
  padding-right: 0.85rem;
}

.fab-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.75rem 1rem calc(0.75rem + var(--safe-bottom));
  background: linear-gradient(180deg, transparent, rgba(15, 14, 20, 0.95) 30%);
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.fab {
  pointer-events: auto;
  width: min(100%, 32rem);
  appearance: none;
  border: 0;
  border-radius: 1.1rem;
  padding: 1.05rem 1.25rem;
  font: inherit;
  font-size: 1.15rem;
  font-weight: 650;
  background: var(--primary);
  color: #171428;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.fab:active {
  background: var(--primary-press);
}

.fab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 0.85rem;
  padding: 0.7rem 0.95rem;
  font: inherit;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

.btn-primary {
  background: var(--primary);
  color: #171428;
  font-weight: 600;
}

.btn-danger {
  background: rgba(232, 160, 160, 0.15);
  color: var(--danger);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

input[type="text"],
textarea {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.85rem;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  padding: 0.75rem 0.85rem;
}

textarea {
  min-height: 4.5rem;
  resize: vertical;
}

.install-hint {
  font-size: 0.9rem;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(6.25rem + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  padding: 0.65rem 1rem;
  border-radius: 999px;
  font-size: 0.92rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 20;
  max-width: 90vw;
}

.toast.is-visible {
  opacity: 1;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}

.sheet.is-open {
  display: flex;
}

.sheet-card {
  width: min(100%, 32rem);
  background: var(--surface);
  border-radius: 1.25rem 1.25rem 0 0;
  padding: 1rem 1rem calc(1rem + var(--safe-bottom));
}

.sheet-card h3 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.offset-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
  margin: 0.75rem 0 1rem;
}

.offset-row button {
  appearance: none;
  border: 0;
  border-radius: 0.75rem;
  padding: 0.85rem 0.25rem;
  font: inherit;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

.offset-row button.is-active {
  background: var(--primary);
  color: #171428;
  font-weight: 650;
}

.hidden {
  display: none !important;
}

.text-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.25rem 0.1rem;
}

.collapse {
  margin-top: 0.85rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 0.35rem;
}

.collapse-toggle {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 0.75rem 0;
  cursor: pointer;
  min-height: 2.75rem;
  text-align: left;
}

.collapse-chevron {
  color: var(--muted);
  transition: transform 0.15s ease;
}

.collapse-toggle[aria-expanded="true"] .collapse-chevron {
  transform: rotate(180deg);
}

.collapse-body {
  padding-bottom: 0.35rem;
}

.cue-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.cue-list li {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 2.75rem;
  padding: 0.15rem 0;
}

.cue-list input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.muted.small {
  font-size: 0.82rem;
  margin: 0.35rem 0 0.5rem;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0.5rem 0;
}

.sheet-tall {
  align-items: stretch;
}

.sheet-card-tall {
  max-height: min(94vh, 52rem);
  overflow: auto;
  border-radius: 1.25rem 1.25rem 0 0;
}

.mode-toggle {
  margin: 0.65rem 0 0.85rem;
}

.session-rows {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 0.75rem;
}

.session-row {
  padding: 0.75rem;
  border-radius: 0.85rem;
  background: var(--bg);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.session-row .row {
  margin-top: 0.45rem;
}

.session-row input[type="date"],
.session-row input[type="time"],
.session-row input[type="text"] {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.75rem;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  padding: 0.65rem 0.75rem;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  .collapse {
    border-top-color: rgba(45, 42, 90, 0.08);
  }

  .session-row input[type="date"],
  .session-row input[type="time"],
  .session-row input[type="text"] {
    color-scheme: light;
  }
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f3f8;
    --surface: #ffffff;
    --surface-2: #ece7f2;
    --text: #2d2a5a;
    --muted: #5c5878;
    --primary: #7e8fea;
    --primary-press: #6a7ad9;
  }

  .app-header {
    background: rgba(246, 243, 248, 0.92);
    border-bottom-color: rgba(45, 42, 90, 0.08);
  }

  .fab-dock {
    background: linear-gradient(180deg, transparent, rgba(246, 243, 248, 0.95) 30%);
  }
}
