/* ============ JOURNAL (home) ============ */
:root {
  --font-journal: 'Noto Serif SC', 'Songti SC', 'STSong', Georgia, serif;
  --journal-rule: rgba(120, 96, 60, 0.12);
}
html[data-theme='dark'] {
  --journal-rule: rgba(255, 255, 255, 0.06);
}

/* The journal needs a right rail, so home gets more width than the chat column. */
#screen-home.home-visible #recall-messages {
  max-width: 1180px;
  padding: 36px 32px 48px;
}

.journal {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-areas:
    'head side'
    'compose side'
    'feed side';
  grid-template-rows: auto auto 1fr;
  column-gap: 32px;
  align-items: start;
}
.journal-head {
  grid-area: head;
}
.journal-compose {
  grid-area: compose;
}
.journal-feed {
  grid-area: feed;
}
.journal-side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---- Date header ---- */
.journal-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}
.journal-year {
  font-family: var(--font-journal);
  font-size: 14px;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}
.journal-date {
  font-family: var(--font-journal);
  font-size: 40px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.02em;
  white-space: pre;
}
.journal-search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 240px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  color: var(--text-tertiary);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.journal-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.journal-search input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: none;
  font: inherit;
  font-size: 14px;
  color: var(--text-primary);
}
.journal-search input::-webkit-search-cancel-button {
  display: none;
}

/* ---- Composer: a ruled notebook page ---- */
.journal-composer {
  position: relative;
  padding: 18px 20px 14px 48px;
  border: 1px solid var(--border-card);
  border-radius: 16px;
  background: var(--surface-1);
  box-shadow: var(--shadow-card);
  transition: border-color 0.2s, box-shadow 0.2s;
}
/* Binding holes down the left edge. */
.journal-composer::before {
  content: '';
  position: absolute;
  left: 18px;
  top: 22px;
  bottom: 22px;
  width: 10px;
  background: radial-gradient(circle, var(--surface-3) 4px, transparent 5px) 0 0 / 10px 36px repeat-y;
}
.journal-composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border-card));
}
.journal-field {
  display: block;
  width: 100%;
  min-height: 72px;
  max-height: 320px;
  border: none;
  outline: none;
  resize: none;
  background: repeating-linear-gradient(to bottom, transparent 0 35px, var(--journal-rule) 35px 36px);
  font-family: var(--font-journal);
  font-size: 16px;
  line-height: 36px;
  color: var(--text-primary);
}
.journal-field::placeholder {
  color: var(--text-tertiary);
}
.journal-composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}
.journal-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}
.journal-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--cat, var(--text-tertiary)) 10%, transparent);
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.18s var(--ease);
}
.journal-pill:hover {
  color: var(--text-primary);
}
.journal-pill.active {
  border-color: var(--cat);
  background: color-mix(in srgb, var(--cat) 16%, transparent);
  color: var(--text-primary);
  font-weight: 600;
}
.journal-pill--add {
  background: none;
  border: 1px dashed var(--border-input);
  color: var(--text-tertiary);
}
.journal-pill-input {
  width: 120px;
  border: 1px solid var(--accent);
  background: var(--surface-1);
  color: var(--text-primary);
  outline: none;
  cursor: text;
}
.journal-publish {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  height: 36px;
  padding: 0 18px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.16s, transform 0.16s var(--ease-spring);
}
.journal-publish:hover {
  filter: brightness(1.08);
}
.journal-publish:active {
  transform: scale(0.96);
}
.journal .home-more {
  max-width: none;
  margin-top: 12px;
}
.journal .home-more:empty {
  display: none;
}

/* ---- Category tabs ---- */
.journal-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 28px 0 8px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.journal-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 12px;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}
.journal-tab:hover {
  color: var(--text-primary);
}
.journal-tab.active {
  border-bottom-color: var(--text-primary);
  color: var(--text-primary);
  font-weight: 600;
}
.journal-day-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  padding: 4px 10px;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font: inherit;
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
}
.journal-dot {
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--cat, var(--text-tertiary));
}

/* ---- Timeline ---- */
.journal-day {
  position: relative;
  padding: 18px 0 4px 24px;
}
/* The spine that threads the days together. */
.journal-day::before {
  content: '';
  position: absolute;
  left: 5px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
}
.journal-day-title {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-family: var(--font-journal);
  font-size: 16px;
  font-weight: 600;
}
.journal-day-title::before {
  content: '';
  position: absolute;
  left: -24px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 2px solid var(--bg);
}
.journal-day-title span:first-child {
  font-weight: 700;
}
.journal-day-sep {
  color: var(--text-tertiary);
}
.journal-entries {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-card);
  border-radius: 12px;
  background: var(--surface-1);
  overflow: hidden;
}
.journal-entry {
  display: grid;
  /* Fixed chip column so the text starts at the same x on every row. */
  grid-template-columns: 44px 84px minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
  padding: 12px 16px;
  border: none;
  border-top: 1px solid var(--line-soft);
  background: none;
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}
.journal-entry:first-child {
  border-top: none;
}
.journal-entry:hover {
  background: var(--card-bg-hover);
}
.journal-time {
  padding-top: 1px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-tertiary);
}
.journal-cat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--cat) 12%, transparent);
  color: color-mix(in srgb, var(--cat) 75%, var(--text-primary));
  font-size: 12px;
  white-space: nowrap;
  justify-self: start;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.journal-text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 14.5px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.journal-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: 180px;
}
.journal-tag {
  padding: 1px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-tertiary);
  font-size: 11.5px;
  white-space: nowrap;
}
.journal-empty {
  padding: 48px 0;
  text-align: center;
  font-family: var(--font-journal);
  color: var(--text-tertiary);
}

/* ---- Right rail ---- */
.journal-card {
  padding: 18px;
  border: 1px solid var(--border-card);
  border-radius: 16px;
  background: var(--surface-1);
  box-shadow: var(--shadow-card);
}
.journal-card:empty {
  display: none;
}
.journal-cal-head {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 12px;
}
.journal-cal-title {
  flex: 1;
  font-family: var(--font-journal);
  font-size: 17px;
  font-weight: 600;
}
.journal-cal-nav {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
}
.journal-cal-nav:hover {
  background: var(--surface-2);
}
.journal-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px 0;
  text-align: center;
}
.journal-cal-wd {
  padding-bottom: 6px;
  font-size: 11.5px;
  color: var(--text-tertiary);
}
.journal-cal-day {
  justify-self: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.journal-cal-day:hover {
  background: var(--surface-2);
}
.journal-cal-day.written {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
}
.journal-cal-day.today {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}
.journal-cal-day.selected {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}
.journal-side-title {
  margin-bottom: 12px;
  font-family: var(--font-journal);
  font-size: 17px;
  font-weight: 600;
}
.journal-stat {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) 28px 96px;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 14px;
}
.journal-stat-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.journal-stat-n {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
}
.journal-stat-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
.journal-stat-bar span {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--cat);
}
.journal-side .brief {
  margin-top: 0;
}
.journal-side .brief-grid {
  grid-template-columns: 1fr;
}

/* ---- Narrow screens: one column, the month above the days ---- */
@media (max-width: 1000px) {
  .journal {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'head' 'compose' 'side' 'feed';
  }
  .journal-side {
    margin-top: 16px;
  }
}
@media (max-width: 640px) {
  #screen-home.home-visible #recall-messages {
    padding: 20px 16px 32px;
  }
  .journal-head {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }
  .journal-date {
    font-size: 30px;
  }
  .journal-search {
    width: 100%;
  }
  .journal-composer {
    padding-left: 40px;
  }
  .journal-composer::before {
    left: 14px;
  }
  .journal-composer-row {
    flex-direction: column;
    align-items: stretch;
  }
  .journal-entry {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 6px 12px;
  }
  .journal-text,
  .journal-tags {
    grid-column: 1 / -1;
  }
  .journal-tags {
    justify-content: flex-start;
    max-width: none;
  }
}
