:root {
  color-scheme: light;
  --bg: #f7f4ee;
  --surface: #fffdf8;
  --surface-2: #f1eee4;
  --text: #211f1b;
  --muted: #7c7568;
  --border: #e4dfd3;
  --border-strong: #d6cfbf;
  --accent: #2f6b4f;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe6;
  --danger: #b4442f;
  --radius: 14px;
  --radius-sm: 9px;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16171a;
  --surface: #1d1f23;
  --surface-2: #23262b;
  --text: #e9e6df;
  --muted: #9b9789;
  --border: #2c3037;
  --border-strong: #3a3f48;
  --accent: #7fc4a1;
  --accent-ink: #102a20;
  --accent-soft: #22352c;
  --danger: #e2826d;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background-color: var(--bg);
  background-image: radial-gradient(1100px 480px at 50% -260px, var(--accent-soft), transparent 72%);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 clamp(14px, 4vw, 34px) 64px;
}

/* ---------- Верхняя панель ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  gap: 12px;
  padding: 20px 0 14px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
}

.topbar__title {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(25px, 3.6vw, 32px);
  font-weight: 600;
  letter-spacing: -0.015em;
}

.topbar__stats {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.topbar__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.search {
  position: relative;
  display: block;
}

.search__icon {
  position: absolute;
  top: 50%;
  left: 11px;
  width: 15px;
  height: 15px;
  margin-top: -8px;
  color: var(--muted);
  pointer-events: none;
}

.search__input {
  width: 220px;
  padding: 8px 12px 8px 32px;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
}

.search__input::placeholder {
  color: var(--muted);
}

.quick-add {
  display: flex;
  gap: 8px;
}

.quick-add__input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
}

.quick-add__input::placeholder {
  color: var(--muted);
}

/* ---------- Кнопки и меню ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.button:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.button--primary {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: transparent;
}

.button--primary:hover {
  color: var(--accent-ink);
  background: color-mix(in srgb, var(--accent) 85%, #000);
}

.button--icon {
  padding: 8px 11px;
  line-height: 1;
}

.button--dashed {
  justify-self: start;
  color: var(--muted);
  background: transparent;
  border-style: dashed;
}

.button--danger:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.menu {
  position: relative;
}

.menu__list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  display: grid;
  min-width: 230px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 18px 40px -20px rgba(20, 18, 12, 0.45);
}

.menu__list[hidden] {
  display: none;
}

.chevron {
  font-size: 17px;
  line-height: 0.9;
}

.menu__list button {
  padding: 9px 11px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.menu__list button:hover {
  background: var(--surface-2);
}

/* ---------- Таблица ---------- */

.board {
  margin-top: 18px;
}

.log {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.log__col--date {
  width: 150px;
}

.log__col--progress {
  width: 108px;
}

.log thead th {
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  color: var(--muted);
  text-transform: uppercase;
  text-align: left;
  border-bottom: 1px solid var(--border-strong);
}

.log__th--right {
  text-align: right;
}

.row {
  border-bottom: 1px solid var(--border);
  transition: background-color 0.15s ease;
}

.row:hover {
  background: color-mix(in srgb, var(--surface) 70%, transparent);
}

.row--today {
  background: color-mix(in srgb, var(--accent-soft) 55%, transparent);
}

.cell {
  padding: 13px 12px;
  vertical-align: top;
}

.cell--date {
  font-weight: inherit;
  text-align: left;
}

.date {
  display: grid;
  gap: 1px;
}

.date__top {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.date__day {
  font-family: var(--serif);
  font-size: 25px;
  line-height: 1;
}

.date__month {
  font-size: 12px;
  color: var(--muted);
}

.date__weekday {
  font-size: 12px;
  color: var(--muted);
}

.badge {
  justify-self: start;
  margin-top: 3px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: uppercase;
  background: var(--accent-soft);
  border-radius: 999px;
}

.tasks {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.task {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.task__box {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 3px 0 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.task__text {
  font-size: 14px;
  cursor: pointer;
}

.task.is-done .task__text {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.cell--thoughts p {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  font-family: var(--serif);
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.cell--progress {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}

.progress {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: 2px 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.progress.is-complete {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: transparent;
}

.muted {
  font-size: 13.5px;
  color: var(--muted);
}

/* ---------- Редактор дня ---------- */

.row--editor {
  background: var(--surface);
}

.cell--editor {
  padding: 0;
  border-bottom: 1px solid var(--border-strong);
}

.editor {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.editor__head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.editor__date {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.editor__date-value {
  font-family: var(--serif);
  font-size: 17px;
}

.editor__actions {
  display: flex;
  gap: 8px;
}

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

.editor__task {
  display: flex;
  gap: 9px;
  align-items: center;
}

.editor__task-input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.editor__task-input::placeholder {
  color: var(--muted);
}

.editor__task-input.is-done {
  color: var(--muted);
  text-decoration: line-through;
}

.editor__remove-task {
  flex: none;
  padding: 4px 8px;
  font-size: 15px;
  line-height: 1;
}

.editor__empty {
  font-size: 13.5px;
  color: var(--muted);
}

.editor__field {
  display: grid;
  gap: 6px;
}

.editor__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  color: var(--muted);
  text-transform: uppercase;
}

.editor__thoughts {
  width: 100%;
  min-height: 88px;
  padding: 12px 14px;
  overflow: hidden;
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  resize: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.editor__thoughts::placeholder {
  color: var(--muted);
}

/* ---------- Пустое состояние, подвал, диалог ---------- */

.empty {
  margin: 26px 0 0;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

.foot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 30px;
  padding-top: 14px;
  font-size: 12.5px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.foot__hint {
  margin: 0;
}

.foot__status {
  margin: 0;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.25s ease;
}

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

.foot__status.is-error {
  color: var(--danger);
}

.dialog {
  width: min(360px, calc(100vw - 32px));
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.5);
}

.dialog::backdrop {
  background: rgba(20, 18, 14, 0.4);
  backdrop-filter: blur(2px);
}

.dialog__form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.dialog__title {
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
}

.field {
  display: grid;
  gap: 6px;
}

.field__label {
  font-size: 12px;
  color: var(--muted);
}

.field__input {
  padding: 9px 11px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

.dialog__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin: 0;
  padding: 0;
}

/* ---------- Мобильная раскладка ---------- */

@media (max-width: 760px) {
  .topbar__tools {
    width: 100%;
  }

  .search {
    flex: 1;
  }

  .search__input {
    width: 100%;
  }

  .log,
  .log tbody,
  .log tr,
  .log th,
  .log td {
    display: block;
    width: auto;
  }

  .log thead {
    display: none;
  }

  .log tr {
    margin-bottom: 10px;
    padding: 13px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }

  .log tr.row--editor {
    padding: 0;
  }

  .cell {
    padding: 0;
  }

  .cell--date {
    margin-bottom: 8px;
  }

  .date {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: baseline;
  }

  .date__day {
    font-size: 21px;
  }

  .badge {
    margin-top: 0;
  }

  .cell--thoughts {
    margin-top: 9px;
  }

  .cell--thoughts p {
    -webkit-line-clamp: 4;
  }

  .cell--progress {
    justify-content: space-between;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
  }

  .editor {
    padding: 14px;
  }
}

/* ---------- Печать ---------- */

@media print {
  body {
    background: #fff;
    color: #000;
  }

  .topbar {
    position: static;
    background: none;
    backdrop-filter: none;
  }

  .topbar__tools,
  .quick-add,
  .foot,
  .button,
  .menu,
  .editor__remove-task,
  .editor__actions {
    display: none !important;
  }

  .cell--editor {
    border-bottom: 1px solid #ddd;
  }

  .editor__task-input,
  .editor__thoughts {
    height: auto !important;
    padding: 0;
    background: none;
    border: 0;
  }

  .row {
    break-inside: avoid;
  }
}
