:root {
  --bg-canvas: #F7F3EA;
  --bg-surface: #FFFFFF;
  --bg-warm: #FFF6EC;
  --bg-sage: #E7F2E9;
  --bg-danger: #FEF2F2;
  --forest-deep: #1F4733;
  --forest-mid: #28593E;
  --green-primary: #2A613B;
  --green-hover: #214F30;
  --green-soft: #DCEBE0;
  --amber-accent: #B45309;
  --amber-text: #9A4A0B;
  --danger-text: #991B1B;
  --ink-primary: #1D2B22;
  --ink-secondary: #46574C;
  --ink-on-dark: #E6EFE8;
  --border-subtle: #DFD8C8;
  --border-control: #788B7E;
  --radius-input: 10px;
  --radius-btn: 14px;
  --radius-card: 16px;
  --radius-hero: 22px;
  --radius-pill: 999px;
  --shadow-elevated: 0 10px 28px rgba(29, 43, 34, 0.14);
  --shadow-fab: 0 8px 18px rgba(31, 71, 51, 0.28);
  --font-sans: 'Plus Jakarta Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --sidebar-width: 256px;
  --topbar-height: 62px;
  --transition-fast: 150ms ease;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background-color: var(--bg-canvas);
  color: var(--ink-primary);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: clip;
}

img,
svg {
  display: block;
  max-width: 100%;
}

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

button {
  cursor: pointer;
}

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

:focus-visible {
  outline: 2px solid var(--green-primary);
  outline-offset: 2px;
}

.sidebar :focus-visible {
  outline: 2px solid #FFFFFF;
  outline-offset: 2px;
}

.is-hidden {
  display: none !important;
}

.m-0 {
  margin: 0;
}

.mb-xs {
  margin-bottom: 4px;
}

.mb-sm {
  margin-bottom: 12px;
}

.mb-md {
  margin-bottom: 18px;
}

.mb-lg {
  margin-bottom: 24px;
}

.mt-sm {
  margin-top: 12px;
}

.mt-auto {
  margin-top: auto;
}

.min-w-0 {
  min-width: 0;
}

.entry-detail-text {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.65;
}

.insight-progress {
  width: 100%;
  height: 12px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--bg-sage);
  accent-color: var(--green-primary);
  overflow: hidden;
  appearance: none;
}

.insight-progress::-webkit-progress-bar {
  background: var(--bg-sage);
  border-radius: var(--radius-pill);
}

.insight-progress::-webkit-progress-value {
  background: var(--green-primary);
  border-radius: var(--radius-pill);
}

.insight-progress::-moz-progress-bar {
  background: var(--green-primary);
  border-radius: var(--radius-pill);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 1000;
  background: var(--forest-deep);
  color: #FFFFFF;
  padding: 10px 16px;
  border-radius: var(--radius-btn);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  left: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.sidebar {
  display: none;
}

.app-workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: var(--topbar-height);
  padding: 8px 16px;
  background-color: rgba(247, 243, 234, 0.96);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.topbar-heading {
  min-width: 0;
  overflow: hidden;
}

.btn-topbar-menu {
  display: none;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--border-control);
  background: var(--bg-surface);
  color: var(--ink-primary);
  font-weight: 600;
  font-size: 0.9rem;
  flex-shrink: 0;
  transition: background-color var(--transition-fast);
}

.btn-topbar-menu:hover,
.btn-topbar-menu:active {
  background: var(--bg-sage);
}

.topbar-title {
  display: block;
  font-size: clamp(1rem, 2.5vw, 1.15rem);
  font-weight: 700;
  color: var(--ink-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sync-pill {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--bg-warm);
  color: var(--amber-text);
  border: 1px solid #E8C7A4;
  white-space: nowrap;
  flex-shrink: 0;
}

.sync-pill.is-online {
  background: var(--bg-sage);
  color: var(--green-primary);
  border-color: #B4D3BC;
}

.icon-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: var(--radius-btn);
  border: 1px solid transparent;
  background: var(--bg-surface);
  color: var(--ink-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.icon-btn:hover,
.icon-btn:active {
  background: var(--bg-sage);
  border-color: var(--border-control);
}

.icon-btn svg,
.btn-topbar-menu-icon svg {
  width: 20px;
  height: 20px;
}

.notif-count {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--amber-accent);
  color: #FFFFFF;
  font-size: 0.7rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.avatar-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: var(--radius-pill);
  border: 2px solid var(--green-primary);
  background: var(--bg-sage);
  color: var(--forest-deep);
  font-weight: 800;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition-fast);
}

.avatar-btn:hover,
.avatar-btn:active {
  background: var(--green-soft);
}

.main-view {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
}

.main-view:focus-visible {
  outline: 2px solid var(--green-primary);
  outline-offset: -2px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 45;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: end;
  gap: 4px;
  box-shadow: 0 -4px 16px rgba(29, 43, 34, 0.08);
}

.bottom-nav-item {
  min-height: 52px;
  border: 0;
  background: transparent;
  color: var(--ink-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.74rem;
  font-weight: 600;
  border-radius: 12px;
  padding: 4px 2px;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.bottom-nav-item svg {
  width: 21px;
  height: 21px;
}

.bottom-nav-item.is-active {
  color: var(--green-primary);
  background: var(--bg-sage);
  font-weight: 700;
}

.bottom-nav-fab {
  width: 54px;
  height: 54px;
  margin: -18px auto 2px;
  border-radius: var(--radius-pill);
  border: 3px solid var(--bg-surface);
  background: var(--green-primary);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-fab);
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.bottom-nav-fab:hover,
.bottom-nav-fab:active {
  background: var(--green-hover);
  transform: translateY(-1px);
}

.bottom-nav-fab svg {
  width: 24px;
  height: 24px;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 18px;
  min-width: 0;
}

.card-warm {
  background: var(--bg-warm);
  border-color: #EAD3B5;
}

.card-sage {
  background: var(--bg-sage);
  border-color: #C3D9C8;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.section-title {
  margin: 0;
  font-size: clamp(1.05rem, 2.2vw, 1.2rem);
  font-weight: 700;
  color: var(--ink-primary);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.section-title svg {
  width: 20px;
  height: 20px;
  color: var(--green-primary);
  flex-shrink: 0;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-title {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  font-weight: 800;
  line-height: 1.25;
  color: var(--ink-primary);
}

.page-subtitle {
  margin: 4px 0 0;
  font-size: 0.94rem;
  color: var(--ink-secondary);
}

.btn {
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius-btn);
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 0.94rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--green-primary);
  color: #FFFFFF;
}

.btn-primary:hover,
.btn-primary:active {
  background: var(--green-hover);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--ink-primary);
  border-color: var(--border-control);
}

.btn-secondary:hover,
.btn-secondary:active {
  background: var(--bg-sage);
}

.btn-ghost {
  background: transparent;
  color: var(--green-primary);
  padding: 8px 12px;
}

.btn-ghost:hover,
.btn-ghost:active {
  background: var(--bg-sage);
}

.btn-danger {
  background: var(--bg-danger);
  color: var(--danger-text);
  border-color: #E2A3A3;
}

.btn-danger:hover,
.btn-danger:active {
  background: #FDE2E2;
}

.btn-block {
  width: 100%;
}

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

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  min-height: 40px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-control);
  background: var(--bg-surface);
  color: var(--ink-primary);
  font-size: 0.86rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.pill:hover {
  background: var(--bg-sage);
}

.pill.is-active {
  background: var(--green-primary);
  border-color: var(--green-primary);
  color: #FFFFFF;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--bg-sage);
  color: var(--green-primary);
}

.badge-warm {
  background: var(--bg-warm);
  color: var(--amber-text);
}

.badge-danger {
  background: var(--bg-danger);
  color: var(--danger-text);
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-pill);
  background: var(--bg-sage);
  color: var(--forest-deep);
  border: 2px solid #C6DACB;
  font-weight: 800;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-lg {
  width: 68px;
  height: 68px;
  font-size: 1.35rem;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

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

.field-label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink-primary);
}

.field-hint {
  font-size: 0.82rem;
  color: var(--ink-secondary);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  border-radius: var(--radius-input);
  border: 1.5px solid var(--border-control);
  background: var(--bg-surface);
  color: var(--ink-primary);
  font-size: 0.96rem;
}

.textarea {
  min-height: 112px;
  resize: vertical;
  line-height: 1.55;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--green-primary);
}

.form-error {
  padding: 10px 13px;
  border-radius: var(--radius-input);
  background: var(--bg-danger);
  border: 1px solid #E5A5A5;
  color: var(--danger-text);
  font-size: 0.88rem;
  font-weight: 600;
}

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

.state-box {
  background: var(--bg-surface);
  border: 1px dashed var(--border-control);
  border-radius: var(--radius-card);
  padding: 28px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.state-box-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-pill);
  background: var(--bg-sage);
  color: var(--green-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.state-box-icon svg {
  width: 24px;
  height: 24px;
}

.state-box.is-error {
  background: var(--bg-danger);
  border-color: #E2A3A3;
}

.state-box.is-error .state-box-icon {
  background: #FCE3E3;
  color: var(--danger-text);
}

.state-box-title {
  margin: 0;
  font-size: 1.04rem;
  font-weight: 700;
}

.state-box-desc {
  margin: 0;
  max-width: 44ch;
  font-size: 0.92rem;
  color: var(--ink-secondary);
}

.state-box-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
}

.modal-backdrop,
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(20, 36, 27, 0.56);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}

.modal-panel {
  width: 100%;
  max-width: 560px;
  max-height: 90dvh;
  background: var(--bg-surface);
  border-radius: var(--radius-hero);
  box-shadow: var(--shadow-elevated);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header,
.drawer-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-title,
.drawer-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
}

.drawer-backdrop {
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
}

.drawer-panel {
  width: min(310px, 88vw);
  height: 100%;
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-elevated);
}

.drawer-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.drawer-nav-item {
  min-height: 44px;
  padding: 10px 14px;
  border: 0;
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--ink-primary);
  font-weight: 600;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
}

.drawer-nav-item svg {
  width: 19px;
  height: 19px;
  color: var(--green-primary);
}

.drawer-nav-item.is-active {
  background: var(--bg-sage);
  color: var(--forest-deep);
  font-weight: 700;
}

.drawer-footer {
  padding: 14px;
  border-top: 1px solid var(--border-subtle);
}

.toast-root {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 110;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: var(--radius-btn);
  background: var(--forest-deep);
  color: #FFFFFF;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-elevated);
}

.toast-item.is-error {
  background: var(--danger-text);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.tab-btn {
  min-height: 44px;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--ink-secondary);
  font-weight: 700;
  font-size: 0.9rem;
}

.tab-btn.is-active {
  background: var(--green-primary);
  border-color: var(--green-primary);
  color: #FFFFFF;
}

@media (min-width: 640px) {
  .btn-topbar-menu {
    display: inline-flex;
  }

  .sync-pill {
    display: inline-flex;
  }

  .form-row-2 {
    grid-template-columns: 1fr 1fr;
  }

  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }

  .main-view {
    padding: 22px 24px calc(100px + env(safe-area-inset-bottom));
  }
}

@media (min-width: 1024px) {
  .app-shell {
    flex-direction: row;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100dvh;
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--forest-deep);
    color: var(--ink-on-dark);
    padding: 18px 14px 14px;
    overflow-y: auto;
  }

  .sidebar-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 6px;
    padding: 4px 8px 16px;
    border-bottom: 1px solid rgba(230, 239, 232, 0.16);
    margin-bottom: 12px;
  }

  .sidebar-brand-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    color: #FFFFFF;
  }

  .sidebar-brand-sub {
    margin: 0;
    font-size: 0.78rem;
    color: var(--ink-on-dark);
  }

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

  .sidebar-link {
    min-height: 44px;
    padding: 9px 13px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--ink-on-dark);
    font-size: 0.9rem;
    font-weight: 600;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 11px;
    transition: background-color var(--transition-fast);
  }

  .sidebar-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
  }

  .sidebar-link:hover {
    background: rgba(255, 255, 255, 0.11);
  }

  .sidebar-link.is-active {
    background: #356B47;
    color: #FFFFFF;
    font-weight: 700;
  }

  .sidebar-footer {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(230, 239, 232, 0.16);
  }

  .sidebar-scenery {
    margin-bottom: 10px;
    opacity: 0.9;
  }

  .sidebar-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .sidebar-user-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .sidebar-user-name {
    font-size: 0.88rem;
    font-weight: 700;
    color: #FFFFFF;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sidebar-user-role {
    font-size: 0.76rem;
    color: var(--ink-on-dark);
  }

  .btn-sidebar-logout {
    min-height: 44px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid rgba(230, 239, 232, 0.45);
    background: transparent;
    color: #FFFFFF;
    font-size: 0.82rem;
    font-weight: 700;
  }

  .btn-sidebar-logout:hover {
    background: rgba(255, 255, 255, 0.14);
  }

  .btn-topbar-menu,
  .bottom-nav {
    display: none;
  }

  .topbar {
    padding: 10px 28px;
  }

  .main-view {
    padding: 26px 32px 44px;
  }

  .toast-root {
    bottom: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
