* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #faf9f7;
  --ink: #1a1916;
  --muted: #a8a49e;
  --soft: #6b6860;
  --line: #e8e4de;
  --accent: #8b7355;
  --accent-soft: #c4b49a;
  --bubble-user: #ede9e2;
  --input-bg: #f3f1ed;
  --err-bg: #fdf0ef;
  --err-line: #f5c9c5;
  --err-ink: #9b4040;
  --sans: -apple-system, "Helvetica Neue", Arial, sans-serif;
}

html, body { height: 100%; }

body {
  font-family: Georgia, "Times New Roman", serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ---------- вход ---------- */

.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 50;
  padding: 24px;
}
.login-box {
  width: 100%; max-width: 320px; text-align: center;
  display: flex; flex-direction: column; gap: 14px;
}
.login-title { font-size: 26px; font-style: italic; }
.login-sub, .empty-sub, .mood-label {
  font-family: var(--sans); font-size: 11px; font-weight: 300;
  color: var(--muted); letter-spacing: .08em; text-transform: uppercase;
}
.divider, .empty-line {
  width: 40px; height: 1px; background: var(--accent-soft); margin: 6px auto;
}
.login-box input {
  padding: 12px 15px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--input-bg); font-family: var(--sans); font-size: 15px;
  outline: none; text-align: center;
}
.login-error { font-family: var(--sans); font-size: 12px; color: var(--err-ink); }

.btn-primary {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 11px 18px; font-family: var(--sans); font-size: 13px; font-weight: 400;
  cursor: pointer; transition: opacity .2s;
}
.btn-primary:active { opacity: .85; }
.btn-outline {
  background: none; border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 14px; font-family: var(--sans); font-size: 12.5px; font-weight: 300;
  color: var(--soft); cursor: pointer;
}

/* ---------- каркас ---------- */

#app {
  display: flex; flex-direction: column;
  height: 100dvh; max-width: 660px; margin: 0 auto;
}

header {
  padding: calc(14px + env(safe-area-inset-top)) 22px 12px;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: flex-end;
  flex-shrink: 0;
}
.app-title { font-size: 21px; font-style: italic; line-height: 1.2; }
.app-sub {
  font-family: var(--sans); font-size: 10px; font-weight: 300;
  color: var(--muted); letter-spacing: .08em; text-transform: uppercase; margin-top: 4px;
}
.app-date {
  font-family: var(--sans); font-size: 11px; font-weight: 300;
  color: var(--muted); text-align: right; line-height: 1.5;
}

.tab { flex: 1; display: flex; flex-direction: column; min-height: 0; }

nav {
  flex-shrink: 0; display: flex; border-top: 1px solid var(--line);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 0 7px; color: var(--muted);
  font-family: var(--sans); font-size: 10px; font-weight: 300; letter-spacing: .04em;
}
.nav-btn svg { width: 21px; height: 21px; }
.nav-btn.active { color: var(--accent); }

/* ---------- чат ---------- */

.mood-bar {
  padding: 9px 22px; border-bottom: 1px solid var(--line);
  display: flex; gap: 8px; align-items: center; flex-shrink: 0;
}
.mood-chips { display: flex; gap: 7px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.mood-chips::-webkit-scrollbar { display: none; }
.mood-chip {
  background: none; border: 1px solid var(--line); border-radius: 20px;
  padding: 4px 13px; font-family: var(--sans); font-size: 12px; font-weight: 300;
  color: var(--soft); cursor: pointer; transition: all .2s; white-space: nowrap;
}
.mood-chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.messages {
  flex: 1; overflow-y: auto; padding: 22px;
  display: flex; flex-direction: column; gap: 15px;
  -webkit-overflow-scrolling: touch;
}

.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  padding: 40px 16px; gap: 13px;
}
.empty-text { font-size: 19px; font-style: italic; color: var(--soft); max-width: 360px; line-height: 1.65; }

.msg { display: flex; flex-direction: column; max-width: 86%; }
.msg.user { align-items: flex-end; align-self: flex-end; }
.msg.assistant, .msg.error { align-items: flex-start; align-self: flex-start; }
.msg-bubble {
  padding: 12px 16px; font-size: 14.5px; line-height: 1.78; white-space: pre-wrap;
  overflow-wrap: break-word;
}
.msg.user .msg-bubble { background: var(--bubble-user); border-radius: 12px 12px 2px 12px; }
.msg.assistant .msg-bubble {
  background: #fff; border: 1px solid var(--line); border-radius: 12px 12px 12px 2px;
}
.msg.error .msg-bubble {
  background: var(--err-bg); border: 1px solid var(--err-line);
  border-radius: 12px 12px 12px 2px; color: var(--err-ink);
}
.msg-time { font-family: var(--sans); font-size: 10.5px; color: var(--muted); margin-top: 4px; }

.typing {
  display: flex; gap: 5px; padding: 14px 18px; background: #fff;
  border: 1px solid var(--line); border-radius: 12px 12px 12px 2px; align-self: flex-start;
}
.typing i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent-soft);
  animation: pulse 1.4s infinite;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes pulse {
  0%, 80%, 100% { transform: scale(.8); opacity: .4; }
  40% { transform: scale(1); opacity: 1; }
}

.composer {
  padding: 10px 16px 12px; border-top: 1px solid var(--line);
  flex-shrink: 0; background: var(--bg);
}
.suggestions { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 10px; }
.suggestion {
  background: none; border: 1px solid var(--line); border-radius: 20px;
  padding: 5px 14px; font-family: var(--sans); font-size: 12.5px; font-weight: 300;
  color: var(--soft); cursor: pointer;
}
.input-row { display: flex; gap: 8px; align-items: flex-end; }
#chat-input {
  flex: 1; background: var(--input-bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 11px 14px;
  font-family: Georgia, serif; font-size: 16px; color: var(--ink);
  resize: none; outline: none; line-height: 1.6;
  min-height: 44px; max-height: 140px; overflow-y: auto;
}
#send-btn, #mic-btn {
  width: 44px; height: 44px; border-radius: 8px; border: none; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: background .2s;
}
#send-btn { background: var(--accent); color: #fff; }
#send-btn:disabled { background: var(--line); cursor: default; }
#mic-btn { background: none; border: 1px solid var(--line); color: var(--soft); }
#mic-btn.rec { background: var(--err-bg); border-color: var(--err-line); color: var(--err-ink); animation: recpulse 1.2s infinite; }
@keyframes recpulse { 50% { opacity: .55; } }

/* ---------- дневник ---------- */

.diary-toolbar {
  display: flex; gap: 9px; padding: 14px 22px 10px; flex-shrink: 0; align-items: center;
}
#diary-search {
  flex: 1; background: var(--input-bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 13px; font-family: var(--sans); font-size: 14px;
  outline: none; color: var(--ink); -webkit-appearance: none;
}
.diary-editor { padding: 0 22px 10px; display: flex; flex-direction: column; gap: 9px; }
#diary-text {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; font-family: Georgia, serif; font-size: 15px;
  line-height: 1.7; resize: vertical; outline: none; color: var(--ink);
}
.diary-editor-actions { display: flex; gap: 8px; }

.diary-list { flex: 1; overflow-y: auto; padding: 6px 22px 20px; }
.diary-date-header {
  font-family: var(--sans); font-size: 11px; font-weight: 300;
  color: var(--muted); letter-spacing: .07em; text-transform: uppercase;
  margin: 16px 0 8px;
}
.diary-card {
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 13px 16px; margin-bottom: 9px; cursor: pointer;
}
.diary-card-text {
  font-size: 14px; line-height: 1.7; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.diary-card-meta { font-family: var(--sans); font-size: 11px; color: var(--muted); margin-top: 7px; }
.diary-empty { text-align: center; color: var(--muted); font-style: italic; padding: 48px 20px; font-size: 15px; }

.diary-view { flex: 1; overflow-y: auto; padding: 14px 22px 24px; }
#diary-back { margin-bottom: 14px; }
.diary-view-entry { font-size: 15px; line-height: 1.8; white-space: pre-wrap; }
.diary-view .msg { max-width: 92%; margin-bottom: 13px; }

/* ---------- вдохновение ---------- */

.inspo-toolbar {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  padding: 14px 22px 10px; flex-shrink: 0;
}
.inspo-hint { font-size: 13.5px; font-style: italic; color: var(--soft); line-height: 1.5; }
.inspo-upload-label { display: inline-block; flex-shrink: 0; }
.inspo-grid {
  flex: 1; overflow-y: auto; padding: 4px 22px 20px;
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
  align-content: start;
}
@media (min-width: 480px) { .inspo-grid { grid-template-columns: repeat(3, 1fr); } }
.inspo-item {
  aspect-ratio: 3/4; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line); background: var(--input-bg); cursor: pointer;
}
.inspo-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.inspo-empty { grid-column: 1/-1; text-align: center; color: var(--muted); font-style: italic; padding: 48px 20px; font-size: 15px; }

.lightbox {
  position: fixed; inset: 0; z-index: 60; background: rgba(26,25,22,.93);
  display: flex; align-items: center; justify-content: center;
}
.lightbox img { max-width: 94vw; max-height: 84vh; border-radius: 6px; }
#lightbox-close {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 16px;
  background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; padding: 8px;
}
#lightbox-delete {
  position: absolute; bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  background: none; border: 1px solid rgba(255,255,255,.4); color: rgba(255,255,255,.85);
  border-radius: 20px; padding: 7px 18px; font-family: var(--sans); font-size: 12.5px; cursor: pointer;
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }
