/* Header */
.site-header { text-align: center; padding: 32px 20px 24px; border-bottom: 1px solid var(--line); }
.brand { font-family: var(--font-serif); font-size: 2.125rem; letter-spacing: 1px; }
.brand span { color: var(--accent); margin-left: 7px; }
.site-header > p { color: var(--muted); font-size: var(--text-sm); }

.user-chip {
  display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center;
  margin-top: 14px; font-size: var(--text-sm); color: var(--muted);
}
.user-chip strong { color: var(--brown); font-weight: 600; }

/* Config notice */
.notice {
  background: #fbeee9; color: var(--danger); border-bottom: 1px solid #ecc9c2;
  padding: 12px 20px; text-align: center; font-size: var(--text-sm);
}

/* Views */
.view { animation: view-in var(--dur) var(--ease) both; }
@keyframes view-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Login: a paper page held on with tape */
#view-login { padding: 56px 0 72px; }
.login-card {
  position: relative;
  width: min(420px, 100%);
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 44px 32px 30px;
  box-shadow: var(--shadow);
  transform: rotate(-0.6deg);
}
.login-card > * { transform: rotate(0.6deg); }
.login-card .tape { position: absolute; transform: translateX(-50%) rotate(-3deg); }
.tape {
  top: -13px; left: 50%;
  width: 96px; height: 28px;
  background: var(--tape); opacity: 0.85;
  clip-path: polygon(0 8%, 4% 0, 8% 10%, 12% 0, 100% 0, 96% 12%, 100% 25%, 96% 38%, 100% 50%, 96% 62%, 100% 75%, 96% 88%, 100% 100%, 12% 100%, 8% 90%, 4% 100%, 0 92%, 3% 75%, 0 58%, 3% 42%, 0 25%);
}
.login-card h1 { font-size: 1.875rem; margin-bottom: 6px; }
.login-card h1 span { color: var(--accent); margin-left: 6px; }
.login-card form { margin-top: 26px; }
.login-card .fine { margin-top: 18px; text-align: center; }

.password-wrap { display: flex; gap: 8px; }
.password-wrap input { flex: 1; min-width: 0; }

/* Welcome and diary */
.welcome { text-align: center; padding: 72px 15px 60px; }
.welcome h1 { font-size: clamp(2.125rem, 7vw, 3.0625rem); font-weight: 400; margin: 13px 0; }
.welcome > p:last-child { color: var(--muted); }

.diary { padding-bottom: 65px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 35px; }
.section-heading h2 { font-size: 1.6875rem; }

/* Timeline and cards */
.timeline { border-left: 1px solid var(--line); margin-left: 12px; padding-left: 28px; }
.card {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 38px 20px;
  box-shadow: var(--shadow);
}
.card--marker::before {
  content: "";
  position: absolute; left: -35px; top: 35px;
  width: 12px; height: 12px;
  background: var(--accent);
  border: 3px solid var(--cream);
  border-radius: 50%;
}
.empty-state { text-align: center; }
.empty-state span { font-size: 1.875rem; color: var(--accent); }
.empty-state h3 { font-size: var(--text-lg); margin: 8px 0; }
.empty-state p { color: var(--muted); font-size: var(--text-sm); }

/* Toasts */
.toast-region {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: min(420px, 92%); z-index: 50; pointer-events: none;
}
.toast {
  background: var(--brown); color: #fff; padding: 12px 18px; border-radius: 10px;
  font-size: var(--text-sm); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(8px); transition: opacity 0.25s, transform 0.25s;
}
.toast.is-in { opacity: 1; transform: none; }
.toast--error { background: var(--danger); }

/* Footer */
footer { text-align: center; padding: 30px 15px; border-top: 1px solid var(--line); color: var(--muted); font-size: var(--text-xs); }
footer span:last-child { display: block; font-family: var(--font-serif); font-size: 1.125rem; color: var(--brown); }

/* Diary timeline */
.timeline-toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: -8px 0 24px; }
.timeline-toolbar .fine { margin: 0; }
.timeline-more { margin-top: 8px; text-align: center; }
.empty-state .btn { margin-top: 14px; }

.post { padding: 26px 22px; margin-bottom: 24px; animation: card-in var(--dur) var(--ease) both; }
.post-meta {
  display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap;
  gap: 2px 12px; margin-bottom: 8px; color: var(--muted); font-size: var(--text-xs);
}
.post-author { color: var(--accent); font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
.post-title { font-size: var(--text-lg); margin-bottom: 6px; overflow-wrap: anywhere; }
.post-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.post-note { color: var(--muted); font-size: var(--text-sm); font-style: italic; margin-top: 10px; }
@keyframes card-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.skeleton {
  min-height: 110px; margin-bottom: 24px;
  background: linear-gradient(90deg, var(--paper) 25%, #f4ecdd 50%, var(--paper) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* Add a moment dialog
   Never set `display` on the dialog itself: a closed <dialog> must stay hidden. */
.composer {
  box-sizing: border-box;
  width: min(560px, calc(100% - 24px)); /* % of the viewport, so a desktop scrollbar can't push it under */
  max-width: calc(100% - 24px); /* overrides the browser's default dialog cap, which leaves wider gutters */
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px); /* phones: follow the visible area as the browser bar moves */
  margin: auto; /* a modal dialog is centred both ways */
  padding: 28px 24px 22px;
  overflow-y: auto; /* tall form or short screen: the dialog scrolls inside itself */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--paper);
  color: var(--brown);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(105, 81, 62, 0.25);
}
.composer::backdrop { background: rgba(105, 81, 62, 0.4); }

#composer-form { margin: 0; }
.composer h2 { font-size: 1.5rem; margin-bottom: 4px; }
.composer .muted { margin-bottom: 18px; font-size: var(--text-sm); }
.optional { color: var(--muted); font-weight: 400; }

/* Title and message */
.composer #moment-title,
.composer #moment-body {
  display: block;
  width: 100%;
  padding: 0 14px;
  font: inherit;
  color: var(--brown);
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.composer #moment-title { min-height: var(--tap); }
.composer #moment-body { min-height: 140px; padding: 12px 14px; line-height: 1.6; resize: vertical; }
.composer #moment-title:focus-visible,
.composer #moment-body:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(140, 99, 67, 0.25);
}
.composer #moment-title[aria-invalid="true"],
.composer #moment-body[aria-invalid="true"] { border-color: var(--danger); }
.composer #moment-title[readonly],
.composer #moment-body[readonly] { opacity: 0.7; }

/* Photo picker */
.composer #moment-photo {
  display: block;
  width: 100%;
  padding: 8px;
  font: inherit;
  font-size: var(--text-sm);
  color: var(--muted);
  background: var(--cream);
  border: 1px dashed var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.composer #moment-photo::file-selector-button {
  min-height: 36px;
  margin-right: 12px;
  padding: 0 16px;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--brown);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.composer #moment-photo:hover::file-selector-button { background: var(--paper); border-color: var(--accent-soft); }
.composer #moment-photo:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.composer #moment-photo:disabled { opacity: 0.6; cursor: not-allowed; }
.composer #moment-photo:disabled::file-selector-button { cursor: not-allowed; }

.composer-preview {
  display: block;
  width: 100%;
  max-height: 260px;
  margin: 10px 0;
  object-fit: contain; /* the whole photo is visible, never cropped */
  background: var(--cream);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
}

/* Cancel + Save moment */
.composer-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 10px; }
.composer-actions .btn { min-width: 120px; }

@media (max-width: 480px) {
  .composer { padding: 22px 16px 18px; }
  .composer-actions { flex-direction: column-reverse; align-items: stretch; } /* Save on top, full width */
  .composer-actions .btn { width: 100%; }
}

/* Photos on post cards */
.post-photo { margin: 12px 0 0; }
.post-photo img {
  display: block; width: 100%; max-height: 560px; object-fit: contain;
  background: var(--cream); border: 1px solid var(--line-soft); border-radius: 10px;
}
.post-photo .post-note { margin-top: 0; }
/* Replies under each diary moment */
.post-replies {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.reply-section + .reply-section {
  margin-top: 20px;
}

.reply-heading {
  font-size: var(--text-sm);
  font-weight: 700;
  margin-bottom: 10px;
}

.reply-list {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.reply-item {
  padding: 11px 13px;
  background: var(--cream);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  overflow-wrap: anywhere;
}

.reply-meta {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: var(--text-xs);
}

.reply-author {
  color: var(--accent);
  font-weight: 700;
}

.reply-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: var(--text-sm);
}

.reply-empty,
.reply-error {
  color: var(--muted);
  font-size: var(--text-xs);
  margin-bottom: 10px;
}

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

.reply-form {
  display: grid;
  gap: 9px;
}

.reply-input {
  box-sizing: border-box;
  width: 100%;
  min-height: 76px;
  padding: 11px 13px;
  resize: vertical;
  font: inherit;
  font-size: var(--text-sm);
  color: var(--brown);
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.reply-input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(140, 99, 67, 0.2);
}

.reply-form .btn {
  justify-self: start;
}

/* Messages navigation */
.app-nav {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

.app-nav .btn {
  min-width: 100px;
}

/* Inbox contact */
.chat-contact {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 15px;
  text-align: left;
  color: var(--brown);
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  font: inherit;
}

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

.chat-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 25px;
}

.chat-contact-info {
  display: grid;
  flex: 1;
  gap: 4px;
  min-width: 0;
}

.chat-contact-info > span {
  overflow: hidden;
  color: var(--muted);
  font-size: var(--text-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 15px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.chat-header h2 {
  margin: 0;
}

.chat-header p {
  margin: 4px 0 0;
}

/* Chat messages */
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 280px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 18px 4px;
}

.chat-bubble {
  max-width: min(78%, 430px);
  padding: 11px 14px;
  border-radius: 17px;
  overflow-wrap: anywhere;
}

.chat-bubble p {
  margin: 0;
  white-space: pre-wrap;
}

.chat-bubble.sent {
  align-self: flex-end;
  color: white;
  background: var(--accent);
  border-bottom-right-radius: 5px;
}

.chat-bubble.received {
  align-self: flex-start;
  color: var(--brown);
  background: var(--cream);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}

.chat-message-meta {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
  margin-top: 6px;
  font-size: 10px;
  opacity: 0.8;
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.chat-form textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 13px;
  resize: vertical;
  font: inherit;
  color: var(--brown);
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 13px;
}

.chat-form textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(140, 99, 67, 0.2);
}

.chat-status {
  min-height: 18px;
  margin-top: 8px;
}

.chat-date-divider {
  align-self: center;
  color: var(--muted);
  font-size: var(--text-xs);
  padding: 5px 10px;
}

@media (max-width: 480px) {
  .chat-bubble {
    max-width: 88%;
  }

  .chat-messages {
    max-height: 60vh;
  }

  .chat-form .btn {
    min-width: 65px;
  }
}

/* Midnight Dark Theme — Messages only */
#view-messages {
  color: #f3efff;
  background: #11111b;
  border: 1px solid #29283a;
  border-radius: 20px;
  padding: 0 20px 24px;
}

#view-messages .welcome h1 {
  color: #f5efff;
}

#view-messages .welcome > p:last-child,
#view-messages .fine {
  color: #aaa5bd;
}

#view-messages .eyebrow {
  color: #b9a0ff;
}

#view-messages .section-heading h2,
#view-messages .chat-header h2 {
  color: #f3efff;
}

#view-messages .chat-contact {
  color: #f3efff;
  background: #201f30;
  border: 1px solid #39364e;
  border-radius: 16px;
}

#view-messages .chat-contact:hover {
  background: #29263e;
  border-color: #9273ed;
}

#view-messages .chat-avatar {
  color: white;
  background: linear-gradient(135deg, #9b72f5, #6544bd);
}

#view-messages .chat-contact-info > span {
  color: #aaa5bd;
}

#view-messages .chat-header {
  border-color: #39364e;
}

#view-messages .chat-bubble.sent {
  color: white;
  background: linear-gradient(135deg, #9168ed, #7048c8);
  border: none;
}

#view-messages .chat-bubble.received {
  color: #f0ecfa;
  background: #29283a;
  border: 1px solid #3b394f;
}

#view-messages .chat-message-meta {
  color: #d5c8f5;
}

#view-messages .chat-date-divider {
  color: #aaa5bd;
}

#view-messages .chat-form {
  border-color: #39364e;
}

#view-messages .chat-form textarea {
  color: #f3efff;
  background: #201f30;
  border: 1px solid #45415c;
  border-radius: 14px;
}

#view-messages .chat-form textarea::placeholder {
  color: #928ca8;
}

#view-messages .chat-form textarea:focus-visible {
  border-color: #a58aff;
  box-shadow: 0 0 0 3px rgba(165, 138, 255, 0.18);
}

#view-messages .chat-form .btn-primary {
  color: white;
  background: #7955d6;
  border-color: #7955d6;
}

#view-messages .chat-form .btn-primary:hover {
  background: #906fe8;
}

#view-messages .btn-quiet {
  color: #d4c5ff;
}

#view-messages #unread-count {
  color: white;
  background: #7955d6;
  border-radius: 20px;
  padding: 2px 7px;
}

#view-messages .chat-status {
  color: #c4b3f5;
}

@media (max-width: 480px) {
  #view-messages {
    padding-left: 14px;
    padding-right: 14px;
  }
}

/* Activity status and chat header alignment */
#view-messages .chat-header {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 64px;
}

#view-messages .chat-header > div {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  min-width: 0;
}

#view-messages .chat-header h2 {
  line-height: 1.2;
  margin: 0;
}

#view-messages #chat-presence,
#view-messages #inbox-presence {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
}

#view-messages .chat-contact {
  align-items: center;
  min-height: 78px;
}

#view-messages .chat-contact-info {
  align-content: center;
  gap: 5px;
}

