:root {
  --primary: #2E7D32;
  --primary-deep: #1B5E20;
  --primary-soft: #E8F5E9;
  --bg: #F7FBF7;
  --surface: #ffffff;
  --text: #1C1C1C;
  --text-muted: #6B7280;
  --overdue: #C62828;
  --overdue-soft: #FFEBEE;
  --today: #EF6C00;
  --today-soft: #FFF3E0;
  --upcoming: #2E7D32;
  --upcoming-soft: #E8F5E9;
  --danger: #B71C1C;
  --border: rgba(46, 125, 50, 0.14);
  --shadow: 0 10px 30px rgba(27, 94, 32, 0.08);
  --radius: 16px;
  --radius-sm: 12px;
  --tap: 48px;
  --pad: 16px;
  --font: "Figtree", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 18px; /* base lớn hơn mặc định 16px */
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(165, 214, 167, 0.45), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(46, 125, 50, 0.12), transparent 50%),
    var(--bg);
}

body {
  -webkit-font-smoothing: antialiased;
  font-size: 1rem;
  line-height: 1.45;
}

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

a {
  color: var(--primary-deep);
}

.layout {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.92);
  border-right: 1px solid var(--border);
  padding: calc(16px + env(safe-area-inset-top)) 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  z-index: 40;
}

.sidebar-brand .brand-name {
  font-size: 1.35rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
  background: var(--primary-soft);
  color: var(--primary-deep);
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
}

.sidebar-backdrop {
  display: none;
  pointer-events: none;
}

.menu-toggle {
  display: none;
}

.app-shell {
  flex: 1;
  min-width: 0;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: calc(52px + env(safe-area-inset-top));
  padding: calc(10px + env(safe-area-inset-top)) var(--pad) 10px;
  background: rgba(247, 251, 247, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand-block {
  flex: 1;
  min-width: 0;
}

.header-title {
  margin: 0;
  font-family: var(--display);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--primary-deep);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 86vw);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
    pointer-events: none;
    z-index: 40;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
    pointer-events: auto;
  }

  /* Chỉ hiện khi mở menu — không dùng display:block cố định (đè mất [hidden]) */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(16, 40, 18, 0.4);
    z-index: 35;
    pointer-events: none;
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
    pointer-events: auto;
  }

  .sidebar-backdrop[hidden] {
    display: none !important;
    pointer-events: none !important;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .header-title {
    font-size: 1.35rem;
  }
}

.brand-name {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.6rem, 5vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--primary-deep);
  line-height: 1.1;
}

.brand-tagline {
  margin: 4px 0 0;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.app-main {
  flex: 1;
  padding: var(--pad);
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
}

.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--primary-deep);
  border-color: var(--border);
}

.btn-soft {
  background: var(--primary-soft);
  color: var(--primary-deep);
}

.btn-danger {
  background: var(--danger);
}

.btn-icon {
  width: var(--tap);
  padding: 0;
  font-size: 1.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}

.field input,
.field select,
.field textarea {
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

.field textarea {
  min-height: 88px;
  resize: vertical;
}

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-row input {
  flex: 1;
  min-height: var(--tap);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  background: var(--surface);
}

.filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 14px;
  scrollbar-width: none;
}

.filter-bar::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.tree-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tree-card {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  width: 100%;
  animation: rise 0.35s ease both;
}

.tree-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tree-thumb-zoom,
.detail-photo {
  cursor: zoom-in;
}

.detail-photo {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--primary-soft);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(8, 20, 10, 0.88);
  display: grid;
  place-items: center;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top));
  animation: rise 0.2s ease both;
}

.lightbox-img {
  max-width: min(100%, 920px);
  max-height: min(88dvh, 88vh);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.lightbox-close {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: 12px;
  z-index: 1;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  min-width: 44px;
}

.tree-card:nth-child(2) { animation-delay: 0.04s; }
.tree-card:nth-child(3) { animation-delay: 0.08s; }
.tree-card:nth-child(4) { animation-delay: 0.12s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.tree-thumb {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--primary-soft);
}

.tree-thumb.placeholder {
  display: grid;
  place-items: center;
  color: var(--primary);
  font-size: 1.6rem;
}

.tree-meta h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
  font-weight: 700;
}

.tree-meta p {
  margin: 0;
  color: var(--text-muted);
  font-size: 1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
  margin-top: 8px;
}

.badge.overdue { background: var(--overdue-soft); color: var(--overdue); }
.badge.today { background: var(--today-soft); color: var(--today); }
.badge.upcoming { background: var(--upcoming-soft); color: var(--upcoming); }

.state-panel {
  display: grid;
  place-items: center;
  min-height: 40vh;
  text-align: center;
  gap: 12px;
  padding: 24px;
  color: var(--text-muted);
}

.state-panel h2 {
  margin: 0;
  color: var(--text);
  font-family: var(--display);
  font-size: 1.35rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--primary-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.detail-hero {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.detail-hero img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--primary-soft);
}

.detail-hero h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.85rem;
  color: var(--primary-deep);
}

.detail-grid {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.info-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 1.05rem;
}

.info-row dt {
  color: var(--text-muted);
  font-weight: 600;
}

.info-row dd {
  margin: 0;
  word-break: break-word;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0;
}

.section-title {
  margin: 20px 0 10px;
  font-size: 1rem;
  font-weight: 700;
}

.history-item {
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 8px;
}

.history-item strong {
  display: block;
  margin-bottom: 4px;
}

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  animation: rise 0.3s ease both;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}

.validation {
  color: var(--overdue);
  font-size: 0.9rem;
  margin: 0 0 12px;
}

.map-box {
  height: 280px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.map-box[hidden] {
  display: none !important;
}

.loc-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.loc-actions .btn {
  width: 100%;
  font-size: 0.92rem;
  padding: 0 10px;
}

.overview-lead {
  margin: 0 0 16px;
  color: var(--text-muted);
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 640px) {
  .stat-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  animation: rise 0.35s ease both;
}

.stat-card:nth-child(2) { animation-delay: 0.05s; }
.stat-card:nth-child(3) { animation-delay: 0.1s; }

.stat-label {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

.stat-value {
  margin: 8px 0 4px;
  font-family: var(--display);
  font-size: clamp(2rem, 6vw, 2.6rem);
  line-height: 1;
  color: var(--primary-deep);
}

.stat-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.stat-returned .stat-value { color: var(--upcoming); }
.stat-active .stat-value { color: var(--today); }

.overview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #16351a;
  color: #fff;
  padding: 12px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 100;
  max-width: min(90vw, 420px);
  box-shadow: var(--shadow);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 40, 18, 0.45);
  display: grid;
  place-items: end center;
  z-index: 50;
  padding: 16px;
}

.modal-sheet {
  width: min(100%, 480px);
  background: var(--surface);
  border-radius: 20px 20px 16px 16px;
  padding: 20px;
  animation: rise 0.25s ease both;
}

.modal-sheet h2 {
  margin: 0 0 8px;
  font-family: var(--display);
}

.modal-sheet p,
.modal-message {
  margin: 0 0 16px;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
}

.modal-sheet.modal-error h2 { color: var(--overdue); }
.modal-sheet.modal-warning h2 { color: var(--today); }
.modal-sheet.modal-info h2 { color: var(--primary-deep); }

.modal-sheet.modal-error {
  border-top: 4px solid var(--overdue);
}

.modal-sheet.modal-warning {
  border-top: 4px solid var(--today);
}

.modal-sheet.modal-info {
  border-top: 4px solid var(--primary);
}

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

.settings-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
}

@media (min-width: 720px) {
  .app-header {
    padding-top: 20px;
  }
}
