:root {
  /* Bảng màu xanh lá (đậm -> kem) */
  --green-forest: #245024;  /* xanh rừng đậm */
  --green-mid:    #388538;  /* xanh lá vừa */
  --green-sage:   #7aae6a;  /* xanh sage */
  --green-light:  #cce08a;  /* xanh nhạt */
  --green-cream:  #eef3df;  /* kem */

  /* Vai trò giao diện (theme sáng, nền trắng, nhấn xanh) */
  --bg-doc: #ffffff;
  --bg-sidebar: #f6f8f1;
  --bg-hover: #eaf0df;
  --bg-active: #dde9c9;
  --ink: #1f2d16;
  --muted: #6f7d5c;
  --accent: #3a8a36;
  --accent-dark: #2d6e2a;
  --border: #dde3d2;
  --danger: #d33a2c;
  --star: #d8a200;
}

* { box-sizing: border-box; }

/* Đảm bảo thuộc tính hidden luôn ẩn, kể cả khi phần tử có display: flex */
[hidden] { display: none !important; }

/* Nút mở menu + nền mờ — mặc định ẩn (chỉ hiện trên điện thoại) */
.menu-toggle {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 46;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  background: var(--bg-sidebar);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1.2rem;
  cursor: pointer;
}
.back-btn {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 46;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  background: var(--bg-sidebar);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
  transition: background .15s, border-color .15s, transform .12s;
}
.back-btn svg { display: block; }
.back-btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.back-btn:active { transform: scale(.92); }
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 48;
}

html, body { height: 100%; }

body.app {
  margin: 0;
  display: flex;
  height: 100vh;
  overflow: hidden;
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg-doc);
  color: var(--ink);
  line-height: 1.6;
}

input, textarea, button { font: inherit; color: inherit; }

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: .6rem .5rem;
  overflow-y: auto;
}

.sidebar-head {
  display: flex;
  align-items: center;
  padding: .3rem .5rem .6rem;
}
.workspace { font-weight: 700; font-size: 1rem; }

.new-note {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 6px;
  padding: .45rem .6rem;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
}
.new-note:hover { background: var(--bg-hover); color: var(--ink); }

.sidebar-search { padding: .4rem .3rem .6rem; }
.sidebar-search input {
  width: 100%;
  background: #eef3df;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .4rem .6rem;
  font-size: .85rem;
}
.sidebar-search input::placeholder { color: #9aa88a; }
.sidebar-search input:focus { outline: none; border-color: var(--accent); }

.sidebar-section-label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  padding: .3rem .6rem;
}

.note-list { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.note-empty { color: var(--muted); font-size: .85rem; padding: .4rem .6rem; font-style: italic; }

.note-item {
  display: flex;
  align-items: center;
  gap: .45rem;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 6px;
  padding: .4rem .6rem;
  cursor: pointer;
  color: var(--ink);
}
.note-item:hover { background: var(--bg-hover); }
.note-item.active { background: var(--bg-active); }
.note-item.active .note-name { color: var(--ink); }
.note-icon { font-size: .95rem; flex-shrink: 0; }
.note-name {
  flex: 1;
  font-size: .9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-face { font-size: .95rem; flex-shrink: 0; }

/* Widget thời tiết dưới đáy sidebar */
.weather {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: .8rem;
  padding: .55rem .7rem;
  background: #eef3df;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .85rem;
}
.weather-icon { font-size: 1.3rem; line-height: 1; }
.weather-temp { font-weight: 700; color: var(--accent); }
.weather-meta { color: var(--muted); font-size: .8rem; }
.weather-loading { color: var(--muted); font-style: italic; }

/* ===================== DOCUMENT ===================== */
.doc {
  flex: 1;
  overflow: hidden;        /* thanh trên cố định; phần dưới cuộn */
  display: flex;
  flex-direction: column;
}
.doc-scroll {
  flex: 1;
  overflow-y: auto;        /* cả ảnh bìa + nội dung cuộn cùng nhau (kiểu Notion) */
}

.doc-topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .6rem 1.2rem;
  background: var(--bg-doc);
  border-bottom: 1px solid var(--border);
}
.doc-crumb { color: var(--muted); font-size: .9rem; }
.doc-tools { display: flex; align-items: center; gap: .8rem; }
.save-status {
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  padding: .18rem .6rem;
  border-radius: 999px;
  transition: background .2s, color .2s;
}
.save-status:empty { padding: 0; }
.save-status.is-saving { background: #fff3d4; color: #9a7400; }
.save-status.is-saved { background: #e1f0d3; color: var(--accent-dark); animation: status-pop .35s ease; }
.save-status.is-error { background: #fbe1de; color: var(--danger); }
@keyframes status-pop {
  0% { transform: scale(.7); opacity: .3; }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); opacity: 1; }
}
.doc-tool {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  padding: .3rem .55rem;
  font-size: .85rem;
}
.doc-tool:hover { background: var(--bg-hover); color: var(--ink); }
.doc-tool.danger:hover { background: rgba(225, 6, 0, .15); color: var(--danger); }

.doc-body {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 1.6rem 3.5rem 4rem;
}

.doc-title {
  background: none;
  border: none;
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--ink);
  padding: 0;
  margin-bottom: .8rem;
}
.doc-title::placeholder { color: #9aa88a; }
.doc-title:focus { outline: none; }

.doc-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.doc-date { color: var(--muted); font-size: .85rem; }
.doc-mood {
  background: none;
  border: none;
  color: var(--ink);
  font-size: .85rem;
  width: 140px;
}
.doc-mood::placeholder { color: #9aa88a; }
.doc-mood:focus { outline: none; }

.doc-content {
  width: 100%;
  min-height: 50vh;
  overflow: hidden;       /* tự giãn theo nội dung (auto-grow trong JS) */
  background: none;
  border: none;
  resize: none;
  font-size: 1.05rem;
  line-height: 1.7;
  padding: 0;
}
.doc-content::placeholder { color: #9aa88a; }
.doc-content:focus { outline: none; }

/* Ô chọn ngày của ghi chú */
.doc-date-input {
  background: #eef3df;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--ink);
  font-size: .82rem;
  padding: .25rem .5rem;
}
.doc-date-input:focus { outline: none; border-color: var(--accent); }
.doc-date-input::-webkit-calendar-picker-indicator { filter: invert(.8); cursor: pointer; }

/* Ảnh trong ghi chú */
/* Ảnh bìa full-width ở đầu ghi chú (kiểu Notion) — nhiều ảnh thành slider */
.cover-slider { position: relative; }
.note-cover {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
}
.note-cover::-webkit-scrollbar { display: none; }
.note-cover:empty { display: none; }
.cover-photo {
  position: relative;
  flex: 0 0 100%;
  scroll-snap-align: start;
}
.cover-photo img {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}

/* Nút ‹ › và chấm — chỉ hiện khi có nhiều ảnh */
.slider-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .45);
  color: #fff;
  border: none;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  line-height: 1;
  z-index: 2;
}
.slider-arrow.prev { left: 10px; }
.slider-arrow.next { right: 10px; }
.slider-arrow:hover { background: rgba(0, 0, 0, .65); }
.cover-slider.has-multi .slider-arrow { display: flex; }

.slider-dots {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  display: none;
  justify-content: center;
  gap: 6px;
  z-index: 2;
}
.cover-slider.has-multi .slider-dots { display: flex; }
.slider-dots .dot {
  width: 8px;
  height: 8px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .55);
  cursor: pointer;
}
.slider-dots .dot.active { background: #fff; }
.note-img-del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .65);
  color: var(--ink);
  cursor: pointer;
  font-size: .85rem;
  line-height: 1;
}
.note-img-del:hover { background: var(--danger); }

.note-images-bar {
  display: flex;
  align-items: center;
  gap: .8rem;
  margin-top: 1.2rem;
}
.add-image {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  background: #eef3df;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .45rem .9rem;
  font-size: .88rem;
  cursor: pointer;
  color: var(--ink);
}
.add-image:hover { border-color: var(--accent); color: var(--accent); }

/* Nút chèn ảnh dạng icon (nằm trong hàng meta, cạnh ô ngày) */
.add-image-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 30px;
  background: #eef3df;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}
.add-image-icon:hover { border-color: var(--accent); }

/* ===== Đánh giá cảm xúc ===== */
.rating { display: flex; align-items: center; gap: .15rem; }
.rating .face {
  background: none;
  border: none;
  padding: .1rem .2rem;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  filter: grayscale(1);
  opacity: .45;
  transition: opacity .12s, transform .12s, filter .12s;
}
.rating .face:hover { opacity: .85; filter: grayscale(.3); }
.rating .face.active {
  filter: none;
  opacity: 1;
  transform: scale(1.18);
  background: var(--bg-hover);
}
.rating-clear {
  background: none;
  border: none;
  color: var(--muted);
  font-size: .8rem;
  margin-left: .25rem;
  padding: .15rem .35rem;
  cursor: pointer;
  border-radius: 4px;
}
.rating-clear:hover { background: var(--bg-hover); color: var(--ink); }

/* ===================== LỊCH THÁNG ===================== */
.calendar-view {
  flex: 1;
  overflow-y: auto;
  padding: 2.5rem 3rem 4rem;
  max-width: 1500px;
  margin: 0 auto;
  width: 100%;
}
/* Chia 2 cột: lịch (trái) | ảnh (phải) — cao bằng nhau */
.cal-split {
  display: flex;
  gap: 2.5rem;
  align-items: stretch;
}
.cal-left { flex: 1.6 1 0; min-width: 0; display: flex; flex-direction: column; }
.cal-right {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  justify-content: center;   /* căn giữa khối ảnh theo chiều dọc */
  gap: .9rem;
}

.cover-panel {
  width: 100%;
  aspect-ratio: 4 / 3;       /* khớp ảnh phong cảnh, ít bị cắt */
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 34px rgba(0, 0, 0, .45);
}
.cover-img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }

/* ===== Lightbox: xem ảnh phóng to ===== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, .85);
  cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, .5);
  cursor: default;
}
.lightbox-close {
  position: absolute;
  top: 14px;
  right: 18px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .5);
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(0, 0, 0, .75); }
.cover-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .4rem;
  color: var(--muted);
  font-size: 2.5rem;
}
.cover-placeholder span { font-size: .9rem; }

.cover-upload {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: .55rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
}
.cover-upload:hover { background: var(--accent-dark); color: #fff; }
.cover-status { font-size: .82rem; text-align: center; min-height: 1em; }

.cal-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  margin-bottom: 1.5rem;
}
.cal-title { font-size: 1.5rem; font-weight: 800; color: var(--ink); min-width: 180px; text-align: center; }
.cal-nav {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  font-size: 1.2rem;
  width: 38px;
  height: 38px;
  cursor: pointer;
}
.cal-nav:hover { background: var(--bg-hover); border-color: var(--accent); }

.cal-weekdays,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr)); /* minmax(0,..) cho phép co lại, tránh tràn ngang */
  gap: 8px;
}
.cal-weekdays {
  margin-bottom: 8px;
}
.cal-weekdays span {
  text-align: center;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  padding: .2rem 0;
}

.cal-cell {
  position: relative;
  min-width: 0;
  aspect-ratio: 1.25 / 1;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .4rem .5rem;
  display: flex;
  flex-direction: column;
}
.cal-cell.empty { background: none; border: none; }
.cal-day { font-size: .85rem; color: var(--muted); }
.cal-face {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  line-height: 1;
}
.cal-cell.has-entry {
  cursor: pointer;
  background: #eef6e2;
  border-color: #cfe3b6;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.cal-cell.has-entry:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(58, 138, 54, .25);
}
.cal-cell.today {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  background: rgba(58, 138, 54, .08);
}


.cal-hint {
  margin: 1.4rem auto 0;
  width: fit-content;
  display: flex;
  align-items: center;
  gap: .45rem;
  font-size: .82rem;
  color: var(--accent-dark);
  background: #eef6e2;
  border: 1px solid #cfe3b6;
  padding: .5rem .9rem;
  border-radius: 999px;
}
.cal-hint::before { content: "🔥"; }
.muted { color: var(--muted); }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 768px) {
  /* Sidebar thành ngăn kéo (drawer): ẩn sang trái, trượt vào khi mở */
  .menu-toggle { display: flex; }
  /* Màn chi tiết (ghi chú): ẩn ☰, hiện nút ← quay lại lịch */
  body.on-doc .menu-toggle { display: none; }
  body.on-doc .back-btn { display: flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80%;
    max-width: 300px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 50;
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 0 0 40px rgba(0, 0, 0, .6);
  }
  body.sidebar-open .sidebar-backdrop { display: block; }

  /* Chừa chỗ cho nút ☰ ở góc trên trái */
  .doc-topbar {
    padding-left: 3.6rem;
    min-height: 54px;        /* đủ cao để nút ☰ không đè xuống tiêu đề */
    box-sizing: border-box;
  }
  .calendar-view { padding: 3.4rem 1.2rem 4rem; }

  /* Lịch + tài liệu xếp gọn trên màn nhỏ */
  .cal-split { flex-direction: column; }
  .cal-right { width: 100%; order: -1; }   /* ẢNH lên trên LỊCH */
  .cover-panel { aspect-ratio: 16 / 10; }   /* ảnh thấp hơn cho gọn */

  /* Lịch: thu nhỏ khoảng cách + chữ để 7 cột vừa màn hình */
  .cal-weekdays, .cal-grid { gap: 5px; }
  .cal-weekdays span { font-size: .68rem; }
  .cal-cell { aspect-ratio: 1 / 1; border-radius: 8px; padding: .3rem; }
  .cal-day { font-size: .75rem; }
  .cal-face { font-size: 1.25rem; }
  .cal-title { font-size: 1.2rem; min-width: 0; }

  .doc-body { padding: 1rem 1.2rem 4rem; }
  .doc-title { font-size: 1.7rem; }
}
