:root {
  --bg: #faf9f6;
  --sidebar-bg: #f2f0ea;
  --border: #e4e1d8;
  --text: #33322e;
  --text-muted: #6f6c64;
  --accent: #a58d6f;
  --accent-soft: #ece6db;
  --danger: #c4685a;
  --input-bg: #ffffff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #1e1e1c;
  --sidebar-bg: #242422;
  --border: #3a3934;
  --text: #f0eee6;
  --text-muted: #b3aea1;
  --accent: #d4b78e;
  --accent-soft: #3a382f;
  --danger: #e6968a;
  --input-bg: #2a2926;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.25s ease, color 0.25s ease;
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--text);
  white-space: nowrap;
}

.theme-icon {
  display: block;
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.icon-btn:active {
  transform: scale(0.95);
}

.search-wrap {
  padding: 0 18px 10px;
  position: relative;
}

#searchInput {
  width: 100%;
  padding: 8px 30px 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#searchInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.search-clear-btn {
  position: absolute;
  right: 26px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.search-clear-btn:hover {
  background: var(--accent);
  color: #fff;
}

.search-clear-btn.hidden {
  display: none !important;
}

.mobile-search-results {
  display: none;
  padding: 0 14px 12px;
  max-height: 280px;
  overflow-y: auto;
  flex-direction: column;
  gap: 6px;
}

.mobile-search-results.hidden {
  display: none !important;
}

.mobile-search-item {
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.mobile-search-item:hover,
.mobile-search-item:active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.mobile-search-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-search-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.entry-list {
  list-style: none;
  margin: 0;
  padding: 0 10px;
  overflow-y: auto;
  flex: 1;
}

/* ---------- Calendar (mobile) ---------- */

.calendar-view {
  display: none;
  padding: 0 14px 12px;
}

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.calendar-nav-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.calendar-nav-btn:hover {
  background: var(--accent-soft);
}

.calendar-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.calendar-toggle-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.calendar-toggle-btn:active {
  transform: scale(0.96);
  background: var(--accent-soft);
}

.calendar-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.calendar-arrow {
  display: inline-block;
  font-size: 10px;
  color: var(--accent);
  font-weight: 700;
  transition: transform 0.2s ease;
}

.calendar-view:not(.collapsed) .calendar-arrow {
  transform: rotate(180deg);
}

.calendar-view.collapsed .calendar-arrow {
  transform: rotate(0deg);
}

.calendar-collapsible {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease;
  opacity: 1;
}

.calendar-collapsible-inner {
  overflow: hidden;
}

.calendar-view.collapsed .calendar-collapsible {
  grid-template-rows: 0fr;
  opacity: 0;
  pointer-events: none;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 4px 0 6px;
  letter-spacing: 0.04em;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  padding: 2px 0 6px;
}

.calendar-day {
  width: 36px;
  height: 36px;
  margin: 0 auto;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.calendar-day.empty {
  visibility: hidden;
  pointer-events: none;
}

.calendar-day:disabled {
  cursor: default;
  opacity: 0.45;
}

.calendar-day.has-entry {
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  background: var(--accent-soft);
}

.calendar-day.has-entry::after {
  content: "";
  position: absolute;
  bottom: 3px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.calendar-day.has-entry:hover {
  background: var(--accent);
  color: #fff;
  transform: scale(1.08);
}

.calendar-day.has-entry:hover::after {
  background: #fff;
}

.calendar-day.active {
  background: var(--accent) !important;
  color: #fff !important;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transform: scale(1.05);
}

.calendar-day.active::after {
  background: #fff;
}

.calendar-day.today {
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

.group-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--input-bg);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 600;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 4px 0;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.18s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  user-select: none;
  text-align: left;
}

.group-header:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  transform: translateY(-1px);
}

.group-header:not(.collapsed) {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(165, 141, 111, 0.35);
}

[data-theme="dark"] .group-header:not(.collapsed) {
  color: #1e1e1c;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.group-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  color: inherit;
}

.group-header.collapsed .group-arrow {
  transform: rotate(-90deg);
}

.group-label {
  flex: 1;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-count {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 1px 7px;
  line-height: 1.4;
  transition: all 0.15s ease;
}

.group-header:not(.collapsed) .group-count {
  background: rgba(255, 255, 255, 0.3);
  color: #ffffff;
  font-weight: 700;
}

[data-theme="dark"] .group-header:not(.collapsed) .group-count {
  background: rgba(0, 0, 0, 0.2);
  color: #1e1e1c;
}

.group-items {
  padding: 2px 0 4px 6px;
  margin-bottom: 4px;
}

.group-items.hidden {
  display: none;
}

.entry-item {
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 2px;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.entry-item:hover {
  background: var(--accent-soft);
}

.entry-item.active {
  background: var(--accent-soft);
  border: 1.5px solid var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.entry-item .entry-item-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-item .entry-item-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  line-height: 1;
  min-height: 16px;
}

.entry-item .entry-item-date {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1;
}

.entry-item .entry-item-mood {
  font-size: 12.5px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  transform: translateY(-0.5px);
}

.entry-item .entry-item-preview {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-list-msg {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 24px 12px;
}

.sidebar-footer {
  display: flex;
  gap: 6px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.ghost-btn {
  flex: 1;
  text-align: center;
  padding: 8px 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.ghost-btn:hover {
  background: var(--accent-soft);
  color: var(--text);
}

/* ---------- Editor ---------- */

.editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 40px 60px;
  overflow-y: auto;
}

.empty-state {
  margin: auto;
  color: var(--text-muted);
  font-size: 15px;
  text-align: center;
}

.hidden {
  display: none !important;
}

.editor-form {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.editor-form.hidden {
  display: none;
}

.editor-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
}

.editor-top-left {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
}

.view-meta-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.view-date-badge {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.view-mood-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  font-size: 12px;
}

.editing-mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.editing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulseDot 1.5s infinite ease-in-out;
}

@keyframes pulseDot {
  0%, 100% {
    transform: scale(0.9);
    opacity: 0.6;
  }
  50% {
    transform: scale(1.25);
    opacity: 1;
  }
}

.editor-top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#editEntryBtn {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

#editEntryBtn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

#editEntryBtn:active {
  transform: scale(0.95);
}

#editEntryBtn .edit-icon {
  display: block;
}

#editEntryBtn .done-icon {
  display: none;
}

#editEntryBtn.is-editing {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

#editEntryBtn.is-editing .edit-icon {
  display: none;
}

#editEntryBtn.is-editing .done-icon {
  display: block;
}

#editEntryBtn.is-editing:hover {
  opacity: 0.92;
}

#uploadMediaBtn {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

#uploadMediaBtn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

#uploadMediaBtn:active {
  transform: scale(0.95);
}

.danger-btn {
  margin-left: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.danger-btn:hover {
  background: rgba(196, 104, 90, 0.12);
  border-color: var(--danger);
  color: var(--danger);
}

.danger-btn:active {
  transform: scale(0.95);
}

/* ---------- View Mode Container ---------- */

.view-container {
  padding: 4px 0 16px;
  flex: 1;
  user-select: text;
}

.view-title {
  font-size: clamp(20px, 3.8vw, 28px);
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
  margin: 0 0 20px;
  font-family: inherit;
  letter-spacing: -0.02em;
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

.view-content {
  font-size: 16.5px;
  line-height: 1.8;
  color: var(--text);
}

.view-content p {
  margin: 0 0 1.25em;
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  -webkit-hyphens: auto;
}

.view-content p:last-child {
  margin-bottom: 0;
}

.view-content strong {
  font-weight: 600;
  color: var(--text);
}

.view-content em {
  font-style: italic;
  color: var(--accent);
}

.view-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.25em 0;
  padding: 4px 0 4px 16px;
  color: var(--text-muted);
  font-style: italic;
}

.view-content hr.view-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

.view-content .view-h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 1.5em 0 0.6em;
}

.view-content .view-h2 {
  font-size: 19px;
  font-weight: 600;
  margin: 1.3em 0 0.5em;
}

.view-content .view-h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 1.1em 0 0.4em;
}

.empty-entry-text {
  color: var(--text-muted);
  font-style: italic;
}

/* ---------- Edit Mode Container ---------- */

.edit-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.edit-meta-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.edit-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.edit-field-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.edit-date-input,
.edit-mood-select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.edit-date-input:focus,
.edit-mood-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.entry-title-input {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: clamp(20px, 3.8vw, 28px);
  font-weight: 700;
  line-height: 1.35;
  outline: none;
  margin-bottom: 14px;
  padding: 4px 0;
  font-family: inherit;
  resize: none;
  overflow: hidden;
  width: 100%;
  box-sizing: border-box;
  word-break: break-word;
  overflow-wrap: break-word;
}

.entry-title-input::placeholder {
  color: var(--text-muted);
}

.entry-content-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 1.7;
  outline: none;
  resize: none;
  font-family: inherit;
  padding: 4px 0;
}

.entry-content-input::placeholder {
  color: var(--text-muted);
}

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 4px;
}

.save-status {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Sequential Entry Navigation ---------- */

.entry-nav {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.entry-nav-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  text-align: left;
}

.entry-nav-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.entry-nav-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.entry-nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.entry-nav-arrow {
  font-size: 18px;
  line-height: 1;
  color: var(--accent);
  font-weight: 700;
}

.entry-nav-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.entry-nav-text.next-align {
  text-align: right;
}

.entry-nav-sub {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
}

.entry-nav-label {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.entry-nav-date {
  display: none;
}

.entry-nav-title {
  display: block;
}

/* ---------- Gallery ---------- */

.gallery-panel {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-left: 1px solid var(--border);
  padding: 20px 16px;
  overflow-y: auto;
}

.gallery-panel.hidden {
  display: none;
}

.gallery-header {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.gallery-item {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--input-bg);
}

.gallery-item img,
.gallery-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-item .video-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border-radius: 5px;
  padding: 1px 5px;
}

.gallery-delete-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #ffffff;
  border: none;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease, transform 0.1s ease;
  z-index: 2;
  padding: 0;
}

.gallery-item:hover .gallery-delete-badge {
  opacity: 1;
}

.gallery-delete-badge:hover {
  background: var(--danger);
  transform: scale(1.1);
}

/* ---------- Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.lightbox.hidden {
  display: none;
}

.lightbox-content img,
.lightbox-content video {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 28px;
  font-size: 32px;
  line-height: 1;
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
}

/* ---------- Passcode Lock Screen ---------- */

.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.lock-screen.hidden {
  display: none !important;
}

.lock-screen.unlocking {
  opacity: 0;
  transform: scale(1.03);
  pointer-events: none;
}

.lock-card {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.lock-header {
  margin-bottom: 24px;
}

.lock-logo {
  display: block;
  margin: 0 auto 12px;
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
}

.lock-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 6px;
}

.lock-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}

.pin-dots {
  display: flex;
  gap: 16px;
  margin: 10px 0 16px;
  transition: transform 0.2s ease;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  background: transparent;
  transition: all 0.15s ease;
}

.pin-dot.filled {
  background: var(--accent);
  transform: scale(1.15);
}

.pin-dot.success {
  background: #27ae60;
  border-color: #27ae60;
  transform: scale(1.2);
}

.pin-dot.error {
  background: var(--danger);
  border-color: var(--danger);
}

.pin-dots.shake {
  animation: pinShake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes pinShake {
  10%, 90% { transform: translate3d(-2px, 0, 0); }
  20%, 80% { transform: translate3d(4px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
  40%, 60% { transform: translate3d(6px, 0, 0); }
}

.pin-error {
  min-height: 20px;
  font-size: 12px;
  color: var(--danger);
  font-weight: 600;
  margin-bottom: 12px;
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px 20px;
  width: 100%;
  max-width: 260px;
  margin-bottom: 20px;
}

.pin-key {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.pin-key:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.pin-key:active {
  transform: scale(0.92);
  background: var(--accent);
  color: #ffffff;
}

.pin-key-spacer {
  width: 62px;
  height: 62px;
}

.pin-remember-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.pin-remember-wrap input {
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- Scrollbars ---------- */

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  html, body {
    height: auto;
  }
  .app {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  .sidebar {
    width: 100%;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .entry-list,
  .sidebar-footer {
    display: none;
  }
  .calendar-view {
    display: block;
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
  .calendar-view.collapsed {
    padding: 6px 12px;
  }
  .calendar-view.collapsed .calendar-nav {
    margin-bottom: 0;
  }
  .calendar-toggle-btn {
    padding: 4px 10px;
  }
  .calendar-arrow {
    font-size: 9px;
  }
  .calendar-nav {
    margin-bottom: 4px;
  }
  .calendar-nav-btn {
    width: 24px;
    height: 24px;
    font-size: 14px;
  }
  .calendar-label {
    font-size: 12px;
  }
  .calendar-weekdays {
    font-size: 10px;
    margin-bottom: 2px;
  }
  .calendar-day {
    width: 34px;
    height: 34px;
    font-size: 12px;
  }
  .mobile-search-results:not(.hidden) {
    display: flex;
  }
  .editor {
    flex: none;
    min-height: 0;
    overflow: visible;
    padding: 16px 18px 40px;
  }
  .editor-form {
    height: auto;
  }
  .editor-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
  }
  .editor-top-left {
    min-width: 0;
  }
  .edit-meta-row {
    gap: 10px;
    margin-bottom: 12px;
  }
  .view-date-badge {
    font-size: 12.5px;
  }
  .view-title {
    font-size: 22px;
    margin-bottom: 14px;
    line-height: 1.3;
  }
  .view-content {
    font-size: 15.5px;
    line-height: 1.75;
  }
  .entry-title-input {
    font-size: 22px;
  }
  .entry-content-input {
    font-size: 16px;
    line-height: 1.75;
    flex: none;
    min-height: 120px;
    overflow: hidden;
  }
  .entry-nav {
    margin-top: 20px;
    padding-top: 14px;
    gap: 8px;
  }
  .entry-nav-btn {
    padding: 8px 10px;
  }
  .entry-nav-title {
    display: none;
  }
  .entry-nav-date {
    display: block;
  }
  .gallery-panel {
    width: 100%;
    max-height: none;
    overflow: visible;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .gallery-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 480px) {
  .brand-logo {
    width: 26px;
    height: 26px;
  }
  .brand-title {
    font-size: 16px;
  }
  .icon-btn {
    width: 34px;
    height: 34px;
  }
  .edit-meta-row {
    gap: 8px;
    margin-bottom: 10px;
  }
  .edit-date-input,
  .edit-mood-select {
    padding: 5px 8px;
    font-size: 12px;
  }
  .entry-title-input {
    font-size: 20px;
  }
  .entry-content-input {
    font-size: 15px;
  }
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .lightbox-close {
    top: 10px;
    right: 14px;
  }
}

/* ---------- Passcode Lock Screen Overlay ---------- */

.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transition: opacity 0.25s ease, visibility 0.25s ease;
  user-select: none;
}

.lock-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.lock-screen.unlocking {
  opacity: 0;
  transform: scale(1.02);
  transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.lock-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.lock-header {
  margin-bottom: 24px;
}

.lock-logo {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  margin-bottom: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  object-fit: cover;
}

.lock-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0 0 4px;
}

.lock-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}

/* PIN Dots */
.pin-dots {
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
  transition: transform 0.1s ease;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.15);
  box-shadow: 0 0 8px rgba(165, 141, 111, 0.4);
}

.pin-dot.success {
  background: #10b981;
  border-color: #10b981;
  transform: scale(1.2);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.pin-dot.error {
  background: var(--danger);
  border-color: var(--danger);
  transform: scale(1.15);
  box-shadow: 0 0 10px rgba(196, 104, 90, 0.5);
}

.pin-dots.shake {
  animation: pinShake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes pinShake {
  10%, 90% { transform: translate3d(-2px, 0, 0); }
  20%, 80% { transform: translate3d(4px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
  40%, 60% { transform: translate3d(6px, 0, 0); }
}

.pin-error {
  font-size: 12px;
  color: var(--danger);
  min-height: 20px;
  margin-bottom: 16px;
  font-weight: 500;
}

/* Numeric Keypad */
.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 68px);
  gap: 14px;
  justify-content: center;
  margin-bottom: 22px;
}

.pin-key {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--sidebar-bg);
  color: var(--text);
  font-size: 24px;
  font-weight: 500;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.pin-key:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.pin-key:active {
  transform: scale(0.92);
  background: var(--border);
}

.pin-key-spacer {
  width: 68px;
  height: 68px;
}

.pin-remember-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.pin-remember-wrap input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- Custom Confirmation Dialog Modal ---------- */

.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 99990;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.2s;
}

.dialog-overlay.is-visible {
  opacity: 1;
  visibility: visible;
}

.dialog-card {
  width: 100%;
  max-width: 400px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 24px 22px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  transform: scale(0.94) translateY(6px);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dialog-overlay.is-visible .dialog-card {
  transform: scale(1) translateY(0);
}

.dialog-icon-wrap {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.dialog-icon-wrap.danger {
  background: rgba(196, 104, 90, 0.15);
  color: var(--danger);
}

.dialog-icon-wrap.info {
  background: var(--accent-soft);
  color: var(--accent);
}

.dialog-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.dialog-message {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text-muted);
  margin: 0 0 22px;
  word-break: break-word;
}

.dialog-actions {
  width: 100%;
  display: flex;
  gap: 10px;
}

.dialog-btn {
  flex: 1;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.dialog-cancel-btn {
  background: var(--input-bg);
  border-color: var(--border);
  color: var(--text);
}

.dialog-cancel-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.dialog-btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.dialog-btn-danger:hover {
  opacity: 0.92;
  box-shadow: 0 2px 10px rgba(196, 104, 90, 0.4);
}

.dialog-btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.dialog-btn-primary:hover {
  opacity: 0.92;
  box-shadow: 0 2px 10px rgba(165, 141, 111, 0.4);
}

.dialog-btn:active {
  transform: scale(0.97);
}

/* ---------- Toast Notifications ---------- */

.toast-container {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 100000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

@media (max-width: 720px) {
  .toast-container {
    bottom: 24px;
    right: 16px;
    left: 16px;
    align-items: center;
  }
}

.toast {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-size: 13.5px;
  font-weight: 600;
  max-width: 380px;
  cursor: pointer;
  transform: translateY(12px) scale(0.95);
  opacity: 0;
  transition: all 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast.is-visible {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.toast.is-leaving {
  transform: translateY(6px) scale(0.92);
  opacity: 0;
}

.toast-icon {
  flex-shrink: 0;
}

.toast-success .toast-icon {
  color: #10b981;
}

.toast-error .toast-icon {
  color: var(--danger);
}

.toast-info .toast-icon {
  color: var(--accent);
}

/* ---------- Chrome / Android PWA Install Prompt ---------- */

.install-prompt-overlay {
  position: fixed;
  inset: 0;
  z-index: 99995;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.25s;
}

.install-prompt-overlay.is-visible {
  opacity: 1;
  visibility: visible;
}

.install-prompt-card {
  width: 100%;
  max-width: 380px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px 22px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  transform: scale(0.92) translateY(8px);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.install-prompt-overlay.is-visible .install-prompt-card {
  transform: scale(1) translateY(0);
}

.install-prompt-badge {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  background: var(--accent-soft);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.install-prompt-icon {
  width: 58px;
  height: 58px;
  border-radius: 14px;
  object-fit: cover;
}

.install-prompt-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.install-prompt-desc {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text-muted);
  margin: 0 0 22px;
}

.install-prompt-actions {
  width: 100%;
  display: flex;
  gap: 10px;
}

.install-prompt-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.install-btn-secondary {
  background: var(--input-bg);
  border-color: var(--border);
  color: var(--text);
}

.install-btn-secondary:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.install-btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.install-btn-primary:hover {
  opacity: 0.92;
  box-shadow: 0 2px 10px rgba(165, 141, 111, 0.4);
}

.install-prompt-btn:active {
  transform: scale(0.97);
}



