:root {
  font-size: 1em;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: sans-serif;
  color: #A62720;
  background: rgb(255, 212, 226);
}

body.week-offset-away {
  background: #fff;
}

body.week-offset-away .rectangle {
  background: #fff;
}

body.week-offset-away .task-checkbox {
  background: #fff;
}

body.week-offset-away .task-commit,
body.week-offset-away .task-delete {
  background: #fff;
}

.layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  min-height: 100vh;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 1em;
  padding: 1em;
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 1em;
  font-weight: 400;
}

.panel-titlebar {
  display: flex;
  align-items: center;
  gap: 0.5em;
}

.panel-titlebar-right {
  justify-content: space-between;
}

.panel-title {
  font: inherit;
}

.icon-button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  padding: 0;
  line-height: 1;
  cursor: pointer;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: transparent;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 1em;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  padding: 0.75em;
  width: min(20em, calc(100vw - 2em));
}

.modal-close {
  position: absolute;
  top: 0.25em;
  right: 0.25em;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  padding: 0;
  line-height: 1;
  cursor: pointer;
}

.auth-status {
  margin: 0;
  padding-right: 1.75em;
  font: inherit;
  font-size: 0.95em;
  line-height: 1.35;
  color: inherit;
  opacity: 0.92;
}

.auth-message {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.9em;
  line-height: 1.3;
}

.modal input {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0.05em solid #A62720;
  padding: 0.25em 0.5em;
}

.modal-actions {
  display: flex;
  gap: 0.5em;
  flex-wrap: wrap;
}

.modal-actions button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0.05em solid #A62720;
  padding: 0.25em 0.5em;
  cursor: pointer;
}

.modal-actions button:disabled {
  opacity: 0.55;
  cursor: default;
}

.week-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 0.75em;
  flex: 1;
  min-height: 0;
}

.rectangle {
  background: rgb(255, 212, 226);
  border: 0.05em solid #A62720;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 4em;
}

.tasks-field {
  flex: 1;
  min-height: 0;
  display: block; /* override .rectangle flex-centering for tasks list */
  overflow: auto;
  cursor: text;
}

@media (max-width: 900px) {
  body {
    font-size: clamp(14px, 3.5vw, 16px);
  }

  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: clamp(22rem, 58dvh, 34rem) minmax(0, 1fr);
    min-height: 100dvh;
  }

  .panel {
    min-height: 0;
    padding: 0.75em;
    gap: 0.75em;
  }

  .panel-titlebar {
    position: sticky;
    top: 0;
    z-index: 5;
    background: inherit;
  }

  .week-panel {
    height: 100%;
    min-height: 0;
  }

  .week-grid {
    overflow: auto;
  }

  .tasks-panel {
    min-height: 0;
  }

  .tasks-field {
    min-height: 0;
    height: 100%;
  }

  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

.tasks-list {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.task-row {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 0.5em;
  padding: 0.25em 0.5em;
  border: 0.05em solid transparent;
  border-radius: 0.15em;
}

.task-row:has(.task-text:focus) {
  border-color: #a62720;
}

.task-row.task-row-sub {
  padding-left: 2em;
}

.task-checkbox {
  flex: 0 0 auto;
  width: 1.2em;
  height: 1.2em;
  border: 0.05em solid #A62720;
  background: rgb(255, 212, 226);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.task-checkbox::after {
  content: "";
  display: block;
  font-size: 1em;
  line-height: 1;
}

.task-checkbox.checked {
  background: #A62720;
}

.task-checkbox.checked::after {
  content: "✓";
  color: #fff;
}

.task-commit {
  flex: 0 0 auto;
  font: inherit;
  color: #a62720;
  width: 1.4em;
  height: 1.4em;
  padding: 0;
  border: 0.05em solid #a62720;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
}

.task-row:has(.task-text:focus) .task-commit {
  opacity: 1;
  pointer-events: auto;
}

.task-commit::after {
  content: "✓";
  font-size: 0.9em;
}

.task-delete {
  flex: 0 0 auto;
  font: inherit;
  color: #a62720;
  width: 1.4em;
  height: 1.4em;
  padding: 0;
  border: 0.05em solid #a62720;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
}

.task-row:has(.task-text:focus) .task-delete {
  opacity: 1;
  pointer-events: auto;
}

.task-delete::after {
  content: "🗑";
  font-size: 0.75em;
  line-height: 1;
}

.task-text {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 1.2em;
  font: inherit;
  border: 0;
  outline: none;
  background: transparent;
  padding: 0;
  color: #A62720;
  width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  resize: none;
  overflow: hidden;
  line-height: 1.2;
}

.task-text:focus {
  outline: none;
  outline-offset: 0;
}

.task-row.completed {
  opacity: 0.5;
}

.task-row.completed .task-text {
  text-decoration: line-through;
  color: #A62720;
}

.day-rect {
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  min-width: 0;
  min-height: 0;
}

.day-label {
  padding-top: 0.25em;
  padding-left: 0.5em; /* matches task text indentation */
  align-self: flex-start;
}

.day-tasks {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  cursor: text;
  display: block;
}

.day-tasks .task-row {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto;
  align-items: start;
  column-gap: 0.5em;
}

.day-tasks .task-row:has(.task-text:focus),
.day-tasks .task-row:has(.task-commit:focus),
.day-tasks .task-row:has(.task-delete:focus) {
  z-index: 4;
}

.day-tasks .task-checkbox {
  grid-column: 1;
  grid-row: 1;
}

.day-tasks .task-row-actions {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0.15em;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.5em;
  align-items: center;
  justify-content: flex-start;
  pointer-events: none;
}

.day-tasks .task-row:has(.task-text:focus) .task-row-actions,
.day-tasks .task-row:has(.task-commit:focus) .task-row-actions,
.day-tasks .task-row:has(.task-delete:focus) .task-row-actions {
  pointer-events: auto;
}

.day-tasks .task-main {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.task-main {
  flex: 1;
  min-width: 0;
}
