/* ==========================================================================
   Journal page
   ========================================================================== */

.journal-dashboard {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* ---- Header ---- */
.journal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.journal-header h1 {
  color: #4a3728;
  font-size: 24px;
  margin: 0;
}

.journal-session-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.session-select {
  padding: 9px 12px;
  border: 1px solid #d4c5b0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: #4a3728;
  background: #fffdf9;
  min-width: 200px;
}
.session-select:focus {
  outline: none;
  border-color: #7a6855;
}

.new-session-btn {
  padding: 9px 16px;
  background: #7a6855;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.15s;
}
.new-session-btn:hover { background: #5d4f3e; }

/* ---- Empty state ---- */
.journal-empty {
  text-align: center;
  padding: 60px 20px;
  color: #a08060;
  font-size: 15px;
}

/* ---- Panel (chat-style) ---- */
.journal-panel {
  display: flex;
  flex-direction: column;
  height: 68vh;
  min-height: 420px;
  background: #fffdf9;
  border: 1px solid #e8ddd0;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(74, 55, 40, 0.06);
}

.journal-entries {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.journal-entries-empty {
  text-align: center;
  color: #b0998a;
  font-size: 14px;
  padding: 40px 20px;
}

/* ---- Entry row ---- */
.journal-entry {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 6px;
  border-radius: 8px;
  transition: background 0.15s;
}
.journal-entry:hover {
  background: #faf3ea;
}
.journal-entry:hover .journal-entry-delete {
  opacity: 1;
}

.journal-entry-time {
  order: 1;
  flex-shrink: 0;
  background: none;
  border: none;
  color: #a08060;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  white-space: nowrap;
  margin-top: 1px;
}
.journal-entry-time:hover {
  background: #efe3d3;
  color: #6b5540;
}

.journal-time-editor {
  order: 1;
  flex-shrink: 0;
  font-size: 12px;
  font-family: inherit;
  padding: 3px 5px;
  border: 1px solid #BB5D4C;
  border-radius: 6px;
  color: #4a3728;
  background: #fff;
}

.journal-entry-body {
  order: 2;
  flex: 1;
  min-width: 0;
}

.journal-entry-linebreak {
  order: 3;
  flex-basis: 0;
  width: 0;
  height: 0;
}

.journal-entry-text {
  font-size: 14.5px;
  color: #3a2c20;
  line-height: 1.45;
  cursor: text;
  word-wrap: break-word;
  white-space: pre-wrap;
  padding: 4px 6px;
  border-radius: 6px;
}
.journal-entry-text:hover {
  background: #efe3d3;
}

.journal-entry-edit-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font-size: 14.5px;
  font-family: inherit;
  line-height: 1.45;
  color: #3a2c20;
  padding: 4px 6px;
  border: 1px solid #BB5D4C;
  border-radius: 6px;
  background: #fff;
  resize: none;
  overflow: hidden;
}
.journal-entry-edit-input:focus { outline: none; }

.journal-entry-reactions {
  order: 4;
  flex-shrink: 0;
  display: flex;
  gap: 2px;
  margin-top: 1px;
}

.reaction-btn {
  background: none;
  border: none;
  font-size: 15px;
  padding: 4px 5px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.35;
  filter: grayscale(1);
  transition: opacity 0.15s, filter 0.15s, background 0.15s;
}
.reaction-btn:hover {
  opacity: 0.75;
  filter: grayscale(0.4);
}
.reaction-btn.active {
  opacity: 1;
  filter: grayscale(0);
  background: #f4e9da;
}

.journal-entry-delete {
  order: 5;
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 13px;
  color: #c0392b;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  margin-top: 1px;
}
.journal-entry-delete:hover {
  background: #fdecea;
}

/* ---- Input bar ---- */
.journal-input-bar {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #e8ddd0;
  background: #fff;
}

.journal-entry-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #d4c5b0;
  border-radius: 20px;
  font-size: 14.5px;
  font-family: inherit;
  line-height: 1.4;
  color: #4a3728;
  background: #fdf9f4;
  resize: none;
  overflow: hidden;
  max-height: 160px;
}
.journal-entry-input:focus {
  outline: none;
  border-color: #7a6855;
  background: #fff;
}

.journal-entry-send-btn {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: #BB5D4C;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
.journal-entry-send-btn:hover { background: #a34d3d; }

/* ---- New Session modal ---- */
.journal-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(74, 55, 40, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.15s;
  padding: 20px;
}
.journal-modal-overlay.visible { opacity: 1; }

.journal-modal {
  background: #fffdf9;
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
  transform: scale(0.96);
  transition: transform 0.15s;
}
.journal-modal-overlay.visible .journal-modal { transform: scale(1); }

.journal-modal-title {
  font-size: 16px;
  font-weight: 700;
  color: #4a3728;
  margin-bottom: 14px;
}

.journal-modal-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid #d4c5b0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: #4a3728;
  margin-bottom: 16px;
}
.journal-modal-input:focus {
  outline: none;
  border-color: #7a6855;
}

.journal-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.journal-modal-cancel-btn {
  padding: 8px 14px;
  background: none;
  border: 1px solid #d4c5b0;
  border-radius: 8px;
  color: #6b5540;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}
.journal-modal-create-btn {
  padding: 8px 16px;
  background: #7a6855;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
}
.journal-modal-create-btn:hover { background: #5d4f3e; }

/* ---- Undo toast (shown after deleting an entry) ---- */
.journal-undo-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  background: #3a2518;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13.5px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 1500;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
}
.journal-undo-toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
.journal-undo-toast-msg {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.journal-undo-toast-btn {
  flex-shrink: 0;
  background: #BB5D4C;
  color: #fff;
  border: none;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.journal-undo-toast-btn:hover { background: #a34d3d; }

@media (max-width: 768px) {
  .journal-undo-toast {
    left: 16px;
    right: 16px;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    transform: translateY(12px);
    max-width: none;
  }
  .journal-undo-toast.visible {
    transform: translateY(0);
  }
}

/* ---- Mobile ---- */
@media (max-width: 600px) {
  .journal-panel {
    height: 72vh;
    border-radius: 12px;
  }
  .journal-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .journal-session-controls {
    width: 100%;
  }
  .session-select {
    flex: 1;
    min-width: 0;
  }

  /* Entry rows: reflow from one packed line (time | text | reactions | del)
     into two clean lines:
       line 1 -- time on the left; reactions + delete grouped flush right
       line 2 -- text (wraps), full width
     The invisible .journal-entry-linebreak span forces the wrap to land
     exactly after delete and before text, regardless of DOM order. Extra
     gap between the reaction buttons (and before delete) makes it harder
     to fat-finger delete when aiming for zzz. */
  .journal-entry {
    flex-wrap: wrap;
    row-gap: 4px;
    column-gap: 14px;
  }
  .journal-entry-time {
    order: 1;
    font-size: 11px;
  }
  .journal-entry-reactions {
    order: 2;
    margin-left: auto;
    gap: 12px;
  }
  .reaction-btn {
    padding: 6px 8px;
  }
  .journal-entry-delete {
    order: 3;
    opacity: 0.55; /* hover-to-reveal doesn't work on touch, so keep it visible */
  }
  .journal-entry-linebreak {
    order: 4;
    flex-basis: 100%;
    width: 0;
    height: 0;
  }
  .journal-entry-body {
    order: 5;
    flex: 1 1 100%;
    width: 100%;
  }
}
