:root {
  --bg: #f4efe6;
  --panel: #fff8eb;
  --ink: #2a241f;
  --muted: #6f6257;
  --line: #d4c9b8;
  --accent: #b5452a;
  --accent-2: #1b6f7a;
  --danger: #8f2635;
  --done: #8e8e93;
  --shadow: 0 12px 24px rgba(28, 16, 3, 0.12);
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 20%, #f8d7a6 0, transparent 30%),
    radial-gradient(circle at 80% 10%, #e2f0d8 0, transparent 26%),
    linear-gradient(145deg, #f4efe6, #eadcc8 70%);
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 1.25rem;
  display: grid;
  gap: 1rem;
  align-content: start;
  min-width: 0;
  overflow-x: hidden;
}

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

.task-form {
  display: grid;
  gap: 0.5rem;
}

.task-form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  align-items: center;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: #fff;
  color: var(--ink);
  padding: 0.6rem 0.7rem;
  min-width: 0;
  width: 100%;
}

button {
  border: none;
  border-radius: 0.5rem;
  background: var(--accent);
  color: #fff;
  padding: 0.6rem 0.85rem;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

button:hover {
  filter: brightness(1.1);
}

button:active {
  transform: translateY(1px);
}

button.ghost {
  background: #e7ddcf;
  color: var(--ink);
}

button.danger {
  background: var(--danger);
}

.task-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.task-header-row h2 {
  font-size: 1rem;
}

.task-list {
  list-style: none;
  display: grid;
  gap: 0.5rem;
  padding: 0;
  margin: 0;
  max-height: calc(100vh - 255px);
  overflow: auto;
}

.task-pill {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: #fff;
  padding: 0.48rem 0.5rem 0.48rem 0.7rem;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45);
}

.task-pill.selected {
  border-color: var(--accent-2);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.45),
    0 0 0 2px rgba(27, 111, 122, 0.2);
}

.task-pill-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  cursor: grab;
  border-radius: 0.45rem;
  padding: 0.2rem 0.2rem 0.2rem 0;
}

.task-pill-content:active {
  cursor: grabbing;
}

.task-color {
  width: 0.68rem;
  height: 0.68rem;
  border-radius: 999px;
  flex-shrink: 0;
}

.task-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.delete-task {
  background: #eee4d5;
  color: #5e4b36;
  border-radius: 0.4rem;
  padding: 0.2rem 0.45rem;
}

.task-record {
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: #fff;
  padding: 0.7rem;
  display: grid;
  gap: 0.55rem;
  min-width: 0;
}

.task-record.hidden {
  display: none;
}

.task-record-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.task-record-head h2 {
  font-size: 1rem;
}

.settings-view {
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
  padding: 1rem;
  overflow: auto;
}

.settings-card {
  max-width: 700px;
  display: grid;
  gap: 0.7rem;
}

.category-form-row {
  grid-template-columns: minmax(0, 1fr) 56px auto;
}

.recurring-form-row {
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 110px auto;
  align-items: center;
}

.recurring-pickers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.picker-box {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.45rem 0.55rem 0.55rem;
}

.picker-box legend {
  padding: 0 0.25rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.picker-actions {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
}

.picker-actions button {
  padding: 0.22rem 0.45rem;
  font-size: 0.76rem;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem 0.45rem;
  max-height: 146px;
  overflow: auto;
}

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

.check-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.84rem;
}

.check-item input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.recurring-group-color {
  padding: 200px;
}

#category-color {
  padding: 0.2rem;
  height: 42px;
}

.category-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
  max-height: 420px;
  overflow: auto;
}

.category-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  padding: 0.3rem 0.35rem 0.3rem 0.55rem;
  background: #fffaf0;
  font-size: 0.88rem;
}

.category-item-main {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  min-width: 0;
  flex: 1;
}

.category-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.category-actions {
  display: flex;
  gap: 0.35rem;
}

.category-actions input[type="color"] {
  width: 38px;
  height: 32px;
  padding: 0.14rem;
}

.delete-category {
  background: #eee4d5;
  color: #5e4b36;
  border-radius: 0.35rem;
  padding: 0.12rem 0.35rem;
}

.planner {
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 1rem;
  gap: 1rem;
  min-width: 0;
  position: relative;
}

.planner-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.week-controls,
.actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.week-controls h2 {
  margin-left: 0.25rem;
  font-size: 1.02rem;
}

.calendar-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  background: rgba(255, 255, 255, 0.68);
  box-shadow: var(--shadow);
}

.calendar {
  min-width: 980px;
  display: grid;
  grid-template-columns: 80px repeat(7, minmax(118px, 1fr));
}

.cell {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  min-height: 28px;
  position: relative;
  background: rgba(255, 255, 255, 0.45);
}

.cell.hour-start {
  border-bottom: 0;
}

.corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 4;
  background: #ece2d2;
}

.day-header {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #ece2d2;
  padding: 0.5rem;
  min-height: 64px;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 0.15rem;
}

.day-header small {
  color: var(--muted);
}

.time-cell {
  background: #ece2d2;
  position: sticky;
  left: 0;
  z-index: 2;
  padding: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  align-items: start;
  justify-content: center;
}

.time-cell.sub-hour {
  font-size: 0;
  padding-top: 0;
  padding-bottom: 0;
}

.slot {
  padding: 0;
  display: flex;
  gap: 2px;
  align-items: stretch;
}

.slot.drag-over {
  outline: 2px dashed var(--accent-2);
  outline-offset: -3px;
  background: #f0f8fa;
}

.scheduled-task {
  height: 100%;
  flex: 1 1 0;
  min-width: 0;
  border-radius: 0.3rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  color: #fff;
  font-size: 0.86rem;
  padding: 0.25rem 0.35rem 0.25rem 0.45rem;
  user-select: none;
  cursor: grab;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.scheduled-task:active {
  cursor: grabbing;
}

.scheduled-task.is-continuation {
  border-radius: 0.08rem;
  padding: 0;
  margin-top: -1px;
  margin-bottom: -1px;
  height: calc(100% + 2px);
  border-top: 0;
  border-bottom: 0;
}

.scheduled-task.is-start:not(.is-end) {
  border-bottom-left-radius: 0.08rem;
  border-bottom-right-radius: 0.08rem;
  margin-bottom: -1px;
  height: calc(100% + 1px);
  border-bottom: 0;
}

.scheduled-task.is-end:not(.is-start) {
  border-top-left-radius: 0.08rem;
  border-top-right-radius: 0.08rem;
  margin-top: -1px;
  height: calc(100% + 1px);
  border-top: 0;
}

.scheduled-task-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

textarea {
  resize: vertical;
  min-height: 90px;
}

.remove-slot {
  background: rgba(255, 255, 255, 0.24);
  color: #fff;
  padding: 0.06rem 0.38rem;
  border-radius: 0.35rem;
}

.resize-handle {
  position: absolute;
  left: 50%;
  transform: translate(-50%, 0);
  width: 18px;
  height: 9px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  background: rgba(15, 15, 15, 0.25);
  cursor: ns-resize;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.resize-handle.top {
  top: 0;
  transform: translate(-50%, -50%);
}

.resize-handle.bottom {
  bottom: 0;
  transform: translate(-50%, 50%);
}

.scheduled-task:hover .resize-handle {
  opacity: 1;
  pointer-events: auto;
}

.toast {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font-size: 0.84rem;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.modal-overlay {
  position: absolute;
  top: 78px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(18, 14, 10, 0.42);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 1rem;
}

.modal-card {
  width: min(920px, calc(100% - 1rem));
  background: #fff9ee;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  box-shadow: var(--shadow);
  padding: 0.9rem;
  display: grid;
  gap: 0.8rem;
  min-height: 720px;
  max-height: calc(100vh - 120px);
  overflow: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.modal-head h2 {
  font-size: 1.1rem;
}

.modal-details {
  margin: 0;
  display: grid;
  gap: 0.55rem;
}

.modal-details > div {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 0.6rem;
  align-items: start;
}

.modal-details dt {
  color: var(--muted);
  font-size: 0.88rem;
  padding-top: 0.45rem;
}

.modal-details dd {
  margin: 0;
  min-width: 0;
  width: 100%;
  justify-self: stretch;
}

.modal-notes-section,
.modal-checklist-section {
  grid-template-columns: 1fr !important;
  gap: 0.35rem !important;
}

.modal-notes-section dt,
.modal-checklist-section dt {
  padding-top: 0;
}

.modal-details .task-form-row {
  grid-template-columns: minmax(0, 1fr) 110px;
  column-gap: 0.9rem;
  align-items: center;
}

.modal-notes-wrap {
  gap: 0.45rem;
  width: 100%;
}

#modal-task-notes {
  min-height: 150px;
  width: 100%;
  box-sizing: border-box;
}

.notes-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

.modal-checklist-wrap {
  gap: 0.45rem;
  width: 100%;
}

.modal-checklist-wrap .task-form-row {
  grid-template-columns: minmax(0, 1fr) 84px;
  column-gap: 0.9rem;
  width: 100%;
}

.modal-checklist-wrap .task-form-row button {
  width: 100%;
  min-width: 0;
}

#modal-checklist-input {
  width: 100%;
}

.checklist-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
  max-height: 300px;
  overflow: auto;
}

.checklist-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: #fffaf0;
  padding: 0.28rem 0.32rem 0.28rem 0.5rem;
}

.modal-details .task-form-row button {
  padding: 0.42rem 0.6rem;
  width: 100%;
  min-width: 0;
  justify-self: stretch;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .task-list {
    max-height: 220px;
  }
}
