html {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

.routine-edit-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 100dvh;
  padding-bottom: 0;
  background: #f6f8f6;
  overflow: hidden;
  overscroll-behavior: none;
}

.chat-header {
  position: relative;
  z-index: 1100;

  flex: 0 0 auto;

  display: flex;
  align-items: center;
  justify-content: space-between;

  min-height: 68px;
  padding:
    max(12px, env(safe-area-inset-top, 0px))
    var(--space-4)
    var(--space-3);

  background: #e8f4f1;
  border-bottom: 1px solid #d6e2df;
}

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

.chat-header-logo {
  display: block;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  object-fit: contain;
}

.chat-header-wordmark {
  display: block;
  width: auto;
  height: 30px;
  object-fit: contain;
}

.account-button {
  display: grid;
  place-items: center;
  flex-shrink: 0;

  width: 42px;
  height: 42px;
  padding: 0;

  color: #24364f;
  background: #ffffff;
  border: 1px solid #d6e2df;
  border-radius: 50%;
}

.account-button svg {
  display: block;
  width: 27px;
  height: 27px;

  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.account-button:hover {
  background: var(--color-primary-soft);
}

.account-button:active {
  transform: scale(0.96);
}

.routine-edit-main {
  flex: 1 1 auto;
  min-height: 0;
  width: min(100%, 680px);
  margin: 0 auto;
  padding: 8px 16px
    calc(
      var(--bottom-nav-height) +
      var(--safe-area-bottom) +
      28px
    );

  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: none;
  -webkit-overflow-scrolling: touch;
}

.routine-back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 34px;
  margin-left: -8px;
  padding: 0 8px;
  color: #527773;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.routine-back-link svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.routine-edit-heading {
  margin: 4px 0 12px;
}

.routine-edit-kicker {
  margin: 0 0 5px;
  color: #2fa99d;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.routine-edit-heading h1 {
  margin: 0 0 7px;
  color: #24364f;
  font-size: 28px;
  line-height: 1.25;
}

.routine-edit-heading > p:last-child {
  margin: 0;
  color: #71807e;
  font-size: 14px;
  line-height: 1.6;
}

.routine-page-status {
  margin: 56px 0;
  color: #71807e;
  font-size: 14px;
  text-align: center;
}

.routine-page-status.is-error {
  color: #b91c1c;
}

.routine-form {
  display: grid;
  gap: 18px;
}

.routine-form[hidden] {
  display: none;
}

.routine-form-card {
  overflow: hidden;
  background: #ffffff;
  border: 1px solid #d8e4e1;
  border-radius: 20px;
  box-shadow: 0 5px 18px rgba(36, 54, 79, 0.06);
}

.routine-field {
  min-width: 0;
  margin: 0;
  padding: 18px;
  border: 0;
}

.routine-field + .routine-field {
  border-top: 1px solid #e5eeec;
}

.routine-field > label:first-child,
.routine-field > legend {
  display: block;
  width: 100%;
  margin: 0 0 9px;
  padding: 0;
  color: #374151;
  font-size: 13px;
  font-weight: 800;
}

.routine-field-help {
  margin: -3px 0 12px;
  color: #71807e;
  font-size: 12px;
  line-height: 1.5;
}

.routine-field input[type="text"],
.routine-field input[type="time"],
.routine-field select,
.routine-field textarea {
  display: block;
  width: 100%;
  margin: 0;
  padding: 12px 13px;
  color: #24364f;
  background: #fbfdfc;
  border: 1px solid #cddedb;
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
}

.routine-field input[type="time"] {
  min-height: 48px;
}

.routine-field textarea {
  min-height: 108px;
  resize: vertical;
}

.routine-field input:focus,
.routine-field select:focus,
.routine-field textarea:focus {
  border-color: #2fa99d;
  box-shadow: 0 0 0 3px rgba(47, 169, 157, 0.12);
  outline: 0;
}

.routine-field input:disabled {
  color: #9aa8a5;
  background: #eef3f2;
}

.routine-day-options {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 7px;
}

.routine-day-option {
  display: block;
  min-width: 0;
  cursor: pointer;
}

.routine-day-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.routine-day-option span {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  max-height: 48px;
  color: #527773;
  background: #f2f8f7;
  border: 1px solid #d2e4e1;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 800;
}

.routine-day-option input:checked + span {
  color: #ffffff;
  background: #2fa99d;
  border-color: #2fa99d;
  box-shadow: 0 4px 10px rgba(47, 169, 157, 0.22);
}

.routine-day-option input:focus-visible + span {
  outline: 2px solid #168f85;
  outline-offset: 2px;
}

.routine-field > label.routine-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  margin: 0;
  cursor: pointer;
}

.routine-field input[type="time"] + label.routine-toggle-row {
  margin-top: 14px;
}

.routine-toggle-row > span:first-child {
  display: grid;
  gap: 4px;
}

.routine-toggle-row strong {
  color: #374151;
  font-size: 14px;
  line-height: 1.4;
}

.routine-toggle-row small {
  color: #71807e;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
}

.routine-switch {
  position: relative;
  flex: 0 0 auto;
  width: 50px;
  height: 30px;
}

.routine-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
}

.routine-switch-track {
  position: absolute;
  inset: 0;
  background: #cbd7d5;
  border-radius: 999px;
  transition: background 0.18s ease;
}

.routine-switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(36, 54, 79, 0.22);
  transition: transform 0.18s ease;
}

.routine-switch input:checked + .routine-switch-track {
  background: #2fa99d;
}

.routine-switch input:checked + .routine-switch-track::after {
  transform: translateX(20px);
}

.routine-switch input:focus-visible + .routine-switch-track {
  outline: 2px solid #168f85;
  outline-offset: 2px;
}

.routine-form-actions {
  display: grid;
  gap: 10px;
}

.routine-save-button,
.routine-delete-button {
  width: 100%;
  min-height: 52px;
  padding: 0 18px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 800;
}

.routine-save-button {
  color: #ffffff;
  background: #2fa99d;
  border: 1px solid #2fa99d;
  box-shadow: 0 5px 15px rgba(47, 169, 157, 0.2);
}

.routine-delete-button {
  color: #b64f4f;
  background: transparent;
  border: 1px solid #e5bcbc;
}

.routine-save-button:disabled,
.routine-delete-button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.routine-save-button:active,
.routine-delete-button:active {
  transform: scale(0.99);
}

.routine-save-button:focus-visible,
.routine-delete-button:focus-visible,
.routine-back-link:focus-visible,
.account-button:focus-visible {
  outline: 2px solid #168f85;
  outline-offset: 2px;
}

@media (max-width: 420px) {
  .routine-edit-main {
    padding-inline: 14px;
  }

  .routine-edit-heading h1 {
    font-size: 25px;
  }

  .routine-field {
    padding: 16px;
  }

  .routine-day-options {
    gap: 5px;
  }

  .routine-day-option span {
    font-size: 13px;
  }
}
