:root {
  --page: #f4f2ec;
  --ink: #1f2522;
  --muted: #66706a;
  --line: #d8d4c8;
  --panel: #fffdf8;
  --panel-strong: #ffffff;
  --brand: #2f6651;
  --brand-dark: #1f4d3b;
  --danger: #b24136;
  --warning: #a86e19;
  --shadow: 0 18px 50px rgba(42, 43, 37, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app-shell {
  width: 100%;
  margin: 0 auto;
  padding: clamp(18px, 1.6vw, 34px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 0 24px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 6vw, 3.7rem);
  line-height: 0.95;
}

h2 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.topbar-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.ghost-button,
.template-list button,
.icon-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
}

.primary-button {
  background: var(--brand);
  color: #fff;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--brand-dark);
}

.ghost-button {
  background: #ebe7db;
  border-color: #d7d0c0;
  color: var(--ink);
}

.ghost-button.active-view {
  background: #ffffff;
  border-color: var(--brand);
  color: var(--brand-dark);
}

.planner-layout {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: clamp(18px, 1.4vw, 28px);
  align-items: start;
}

.app-view[hidden] {
  display: none;
}

.settings-layout {
  display: block;
}

.settings-panel {
  display: grid;
  gap: 20px;
  width: min(620px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.settings-panel h2 {
  margin-bottom: 8px;
  font-size: 1.35rem;
}

.settings-panel p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

.controls-panel {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 16px;
}

.block-form,
.details-panel,
.templates {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
  color: #3f4944;
  font-size: 0.85rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c9c4b8;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(47, 102, 81, 0.24);
  outline-offset: 2px;
}

.time-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.time-grid > label:only-child {
  grid-column: 1 / -1;
}

.template-list {
  display: grid;
  gap: 9px;
}

.template-list button {
  width: 100%;
  background: #ffffff;
  border-color: #d7d0c0;
  color: #26312c;
  text-align: left;
}

.details-empty p,
.details-empty-note,
.details-description,
.details-header p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.details-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.details-header h2 {
  margin-bottom: 4px;
}

.details-header button,
.todo-list button {
  min-height: 32px;
  border: 1px solid #d7d0c0;
  border-radius: 8px;
  background: #fbfaf5;
  color: var(--ink);
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 900;
}

.details-description {
  margin-bottom: 14px;
}

.todo-form {
  margin-top: 14px;
}

.todo-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.todo-input-row .primary-button {
  min-width: 66px;
}

.todo-list {
  display: grid;
  gap: 8px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.todo-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border: 1px solid #ded8cb;
  border-radius: 8px;
  background: #ffffff;
  padding: 9px;
  color: #38443e;
  font-size: 0.9rem;
}

.todo-list span::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 8px;
  border-radius: 999px;
  background: var(--brand);
  vertical-align: middle;
}

.week-section {
  min-width: 0;
}

.week-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 2px 16px;
}

.week-toolbar p {
  margin-bottom: 0;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 12px;
  min-width: 220px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.schedule-view-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.view-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.schedule-view-controls .ghost-button,
.view-switcher .ghost-button {
  min-height: 36px;
  padding: 0 11px;
  font-size: 0.78rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #81908a;
}

.week-grid {
  --day-column-width: 260px;
  --visible-day-count: 7;
  display: grid;
  grid-template-columns: repeat(var(--visible-day-count), minmax(var(--day-column-width), 1fr));
  gap: 14px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 14px;
  scroll-snap-type: x proximity;
  cursor: grab;
  scrollbar-gutter: stable;
  user-select: none;
  -webkit-overflow-scrolling: touch;
}

.week-grid.panning {
  cursor: grabbing;
  scroll-snap-type: none;
}

.week-grid.resizing-columns {
  cursor: col-resize;
  scroll-snap-type: none;
}

.day-column {
  position: relative;
  min-width: 0;
  min-height: clamp(560px, calc(100vh - 220px), 980px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.72);
  overflow: hidden;
  scroll-snap-align: start;
}

.column-resizer {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 3;
  width: 10px;
  height: 100%;
  cursor: col-resize;
}

.column-resizer::after {
  content: "";
  position: absolute;
  top: 14px;
  right: 3px;
  width: 2px;
  height: calc(100% - 28px);
  border-radius: 999px;
  background: transparent;
}

.column-resizer:hover::after,
.week-grid.resizing-columns .column-resizer::after {
  background: rgba(47, 102, 81, 0.38);
}

.day-column.drag-over {
  border-color: var(--brand);
  background: #f2fbf4;
}

.day-column.full {
  border-color: rgba(178, 65, 54, 0.6);
}

.day-header {
  display: grid;
  gap: 8px;
  padding: 13px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-strong);
  border-radius: 8px 8px 0 0;
}

.day-time-settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.day-time-settings label {
  margin-bottom: 0;
  gap: 5px;
  font-size: 0.74rem;
}

.day-time-settings input {
  min-height: 34px;
  padding: 7px 8px;
  font-size: 0.82rem;
}

.bedtime-note {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.day-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.day-title-row h3 {
  min-width: 0;
  margin: 0;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.add-day-button {
  width: 34px;
  height: 34px;
  border: 1px solid #d7d0c0;
  border-radius: 8px;
  background: #f4f2ec;
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 900;
  line-height: 1;
}

.meter {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: #e5e0d4;
}

.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--brand);
  transition: width 160ms ease;
}

.full .meter-fill {
  background: var(--danger);
}

.day-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.day-meta .over {
  color: var(--danger);
}

.block-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-width: 0;
  min-height: calc(clamp(560px, calc(100vh - 220px), 980px) - 92px);
  padding: 14px 12px;
}

.timeline-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  min-width: 0;
}

.timeline-time {
  position: sticky;
  left: 0;
  z-index: 1;
  padding-top: 7px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 900;
  line-height: 1.2;
  text-align: right;
}

.schedule-block {
  --accent: #81908a;
  --duration-units: 1;
  min-width: 0;
  max-width: 100%;
  min-height: calc(52px + (var(--duration-units) - 1) * 10px);
  border: 1px solid #d7d0c0;
  border-left: 6px solid var(--accent);
  border-radius: 8px;
  background: #fff;
  padding: 8px 9px;
  box-shadow: 0 8px 18px rgba(42, 43, 37, 0.08);
  overflow: hidden;
  overflow-wrap: anywhere;
  touch-action: none;
}

.schedule-block.locked {
  background: #f8f5ec;
  border-style: solid;
  box-shadow: none;
}

.schedule-block.selected {
  min-height: calc(82px + (var(--duration-units) - 1) * 14px);
  padding: 10px;
}

.schedule-block[draggable="true"] {
  cursor: grab;
  user-select: text;
}

.schedule-block.dragging {
  opacity: 0.48;
}

.schedule-block.selected {
  border-color: rgba(47, 102, 81, 0.72);
  box-shadow: 0 0 0 3px rgba(47, 102, 81, 0.16), 0 8px 18px rgba(42, 43, 37, 0.08);
}

.block-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.block-title {
  min-width: 0;
  margin: 0 0 4px;
  font-size: 0.88rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.block-time {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
}

.duration {
  display: inline-flex;
  white-space: nowrap;
  border-radius: 999px;
  background: #f1eee6;
  padding: 3px 7px;
  color: #44504a;
  font-size: 0.68rem;
  font-weight: 900;
}

.block-description {
  margin: 7px 0 10px;
  color: #5b665f;
  font-size: 0.86rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.timeline-gap {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  width: 100%;
  border: 1px dashed #d2cbbb;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.45);
  padding: 7px 9px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: left;
}

.timeline-gap:hover,
.timeline-gap:focus-visible {
  border-color: var(--brand);
  background: #ffffff;
  color: var(--brand-dark);
}

.timeline-gap span:last-child {
  margin-left: auto;
  color: var(--brand-dark);
}

.block-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.block-actions button {
  flex: 1 1 72px;
  min-height: 32px;
  min-width: 0;
  border: 1px solid #d7d0c0;
  border-radius: 8px;
  background: #fbfaf5;
  color: var(--ink);
  padding: 0 9px;
  font-size: 0.78rem;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 110px;
  border: 1px dashed #cfc8b8;
  border-radius: 8px;
  color: #79837c;
  font-size: 0.86rem;
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 5;
  width: min(360px, calc(100vw - 36px));
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  border-radius: 8px;
  background: #26312c;
  color: #fff;
  padding: 13px 15px;
  box-shadow: var(--shadow);
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.work,
[data-category="work"] {
  --accent: #3f6f9e;
  background-color: #3f6f9e;
}

.sleep,
[data-category="sleep"] {
  --accent: #6b658f;
  background-color: #6b658f;
}

.wake,
[data-category="wake"] {
  --accent: #2f6651;
  background-color: #2f6651;
}

.bed,
[data-category="bed"] {
  --accent: #6b658f;
  background-color: #6b658f;
}

.self-care,
[data-category="self-care"] {
  --accent: #3f8b76;
  background-color: #3f8b76;
}

.home,
[data-category="home"] {
  --accent: #bf7a30;
  background-color: #bf7a30;
}

.rest,
[data-category="rest"] {
  --accent: #8a7e42;
  background-color: #8a7e42;
}

.social,
[data-category="social"] {
  --accent: #9b5f73;
  background-color: #9b5f73;
}

.schedule-block[data-category] {
  background-color: #fff;
}

.schedule-block.locked[data-category] {
  background-color: #f8f5ec;
}

@media (max-width: 1020px) {
  .planner-layout {
    grid-template-columns: 1fr;
  }

  .controls-panel {
    position: static;
    grid-template-columns: minmax(0, 1.3fr) minmax(240px, 0.7fr);
  }

  .day-column {
    min-height: 560px;
  }
}

@media (min-width: 1800px) {
  .week-grid {
    grid-template-columns: repeat(var(--visible-day-count), minmax(max(var(--day-column-width), 250px), 1fr));
  }
}

@media (min-width: 2300px) {
  .planner-layout {
    grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  }

  .week-grid {
    grid-template-columns: repeat(var(--visible-day-count), minmax(max(var(--day-column-width), 280px), 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 16px;
  }

  .topbar,
  .week-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .schedule-view-controls,
  .view-switcher {
    justify-content: stretch;
  }

  .schedule-view-controls > .ghost-button,
  .view-switcher .ghost-button {
    flex: 1 1 auto;
  }

  .topbar-actions,
  .form-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .controls-panel,
  .time-grid {
    grid-template-columns: 1fr;
  }

  .legend {
    justify-content: flex-start;
    min-width: 0;
  }

  .week-grid {
    grid-template-columns: repeat(var(--visible-day-count), minmax(min(88vw, var(--day-column-width)), 1fr));
  }

  .block-list {
    padding: 12px 10px;
  }

  .timeline-row {
    grid-template-columns: 50px minmax(0, 1fr);
  }

  .block-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .day-time-settings {
    grid-template-columns: 1fr;
  }

  .todo-input-row,
  .todo-list li {
    grid-template-columns: 1fr;
  }
}
