/**
 * Adiwana Mansaca — Stylesheet Utama (Tema Terang Sejuk Nordik / Nordic Light)
 * Referensi: ui.shadcn.com, bg.ibelick.com, styles.refero.design, detail.design
 * Standar: Google Modern Web (Core Web Vitals CLS=0, Touch Targets >= 48px, WCAG 2.1 AA)
 */

:root {
  --bg-mist: #f8fafc;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  --border-cool: #e2e8f0;
  --border-strong: #cbd5e1;
  --ink-primary: #0f172a;
  --ink-secondary: #475569;
  --ink-muted: #64748b;
  --sage-primary: #2d6a4f;
  --sage-hover: #1b4332;
  --sage-tint: #d8f3dc;
  --sage-soft: #eef8f2;
  --frost-tint: #e0f2fe;
  --frost-ink: #0369a1;
  --amber-tint: #fef3c7;
  --amber-ink: #b45309;
  --danger-tint: #fee2e2;
  --danger-ink: #b91c1c;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow-card: 0 2px 10px -2px rgba(15, 23, 42, 0.05), 0 1px 3px rgba(15, 23, 42, 0.03);
  --shadow-elevated: 0 16px 36px -8px rgba(15, 23, 42, 0.12);
  --spring-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

img, canvas, svg, video {
  max-width: 100%;
  height: auto;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  background-color: var(--bg-mist);
  color: var(--ink-primary);
}

body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-mist);
  /* bg.ibelick.com radial dot pattern + subtle Nordic aurora mist */
  background-image:
    radial-gradient(at 85% 5%, rgba(216, 243, 220, 0.55) 0px, transparent 48%),
    radial-gradient(at 10% 30%, rgba(224, 242, 254, 0.5) 0px, transparent 50%),
    radial-gradient(#cbd5e1 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 22px 22px;
  background-attachment: fixed;
  color: var(--ink-primary);
  line-height: 1.5;
  min-height: 100dvh;
  padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
}

/* Focus Accessibility (Google Modern Web WCAG AA) */
:focus-visible {
  outline: 2.5px solid var(--sage-primary);
  outline-offset: 2px;
}

/* App Shell Container (Optimal Mobile First + Centered Desktop View) */
.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

@media (min-width: 960px) {
  .app-shell {
    max-width: 1080px;
    padding: 0 24px;
  }
}

/* Sticky Top Header (Frosted Nordic Glass) */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-cool);
  padding: 12px 16px;
}

.top-bar-inner {
  max-width: 1040px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(45, 106, 79, 0.2);
}

.brand-kicker {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sage-primary);
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink-primary);
  line-height: 1.15;
}

.role-pill-btn {
  min-height: 40px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-cool);
  background: var(--bg-surface);
  color: var(--ink-primary);
  font-size: 0.75rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.18s var(--spring-ease);
}

.role-pill-btn:hover {
  border-color: var(--sage-primary);
  background: var(--sage-soft);
}

.role-pill-btn.role-active {
  background: var(--sage-tint);
  color: var(--sage-primary);
  border-color: rgba(45, 106, 79, 0.35);
}

/* Main Content Area */
.main-content {
  flex: 1;
  padding: 16px;
}

.view-panel {
  display: none;
  animation: fadeIn 0.22s var(--spring-ease);
}

.view-panel.active {
  display: block;
}

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

/* Hero Eco-Metrics Card (bg.ibelick.com + shadcn/ui) */
.eco-hero-card {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-cool);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  margin-bottom: 16px;
}

.eco-hero-card::before {
  content: '';
  position: absolute;
  top: -55px;
  right: -45px;
  width: 210px;
  height: 210px;
  background: radial-gradient(circle, rgba(216, 243, 220, 0.85) 0%, rgba(224, 242, 254, 0.3) 55%, transparent 72%);
  pointer-events: none;
}

.eco-badge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  position: relative;
  z-index: 1;
}

.eco-live-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sage-primary);
  background: var(--sage-soft);
  border: 1px solid var(--sage-tint);
  padding: 4px 10px;
  border-radius: 999px;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25);
}

.eco-primary-metric {
  position: relative;
  z-index: 1;
  margin: 6px 0 4px 0;
}

.eco-big-number {
  font-size: 2.15rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink-primary);
}

.eco-unit {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink-secondary);
}

.eco-subtitle {
  font-size: 0.8rem;
  color: var(--ink-secondary);
  position: relative;
  z-index: 1;
}

.eco-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--bg-subtle);
  position: relative;
  z-index: 1;
}

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

.stat-tile {
  background: var(--bg-mist);
  border: 1px solid var(--border-cool);
  border-radius: 14px;
  padding: 10px 12px;
}

.stat-tile-val {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--ink-primary);
  letter-spacing: -0.02em;
}

.stat-tile-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink-muted);
  margin-top: 2px;
}

/* Quick Action Row (detail.design tactile buttons, >= 48px touch target) */
.quick-action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.quick-btn {
  min-height: 76px;
  background: var(--bg-surface);
  border: 1px solid var(--border-cool);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: transform 0.16s var(--spring-ease), border-color 0.16s ease, background 0.16s ease;
  color: var(--ink-primary);
  font-family: inherit;
}

.quick-btn:hover {
  transform: translateY(-2px);
  border-color: var(--sage-primary);
  background: var(--sage-soft);
}

.quick-btn:active {
  transform: scale(0.97);
}

.quick-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--bg-subtle);
  color: var(--sage-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.quick-label {
  font-size: 0.76rem;
  font-weight: 700;
}

/* Section Headers */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 18px 0 10px 0;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink-primary);
  letter-spacing: -0.01em;
}

.section-link {
  background: none;
  border: none;
  color: var(--sage-primary);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  font-family: inherit;
}

.section-link:hover {
  background: var(--sage-soft);
}

/* Filter Chips (Horizontally Scrollable Mobile Bar) */
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 10px 2px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  min-height: 38px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-cool);
  background: var(--bg-surface);
  color: var(--ink-secondary);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}

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

/* Search Input (shadcn/ui Input) */
.search-bar-wrap {
  position: relative;
  margin-bottom: 12px;
}

.search-input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px 10px 42px;
  border-radius: 14px;
  border: 1px solid var(--border-cool);
  background: var(--bg-surface);
  color: var(--ink-primary);
  font-size: 0.9rem;
  font-family: inherit;
  box-shadow: var(--shadow-card);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-muted);
  pointer-events: none;
}

/* Tree Catalog Grid & Cards (CLS=0 explicit dimensions) */
.tree-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 720px) {
  .tree-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.tree-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-cool);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: transform 0.16s var(--spring-ease), border-color 0.16s ease;
  text-align: left;
  width: 100%;
  font-family: inherit;
}

.tree-card:hover {
  border-color: var(--sage-primary);
  transform: translateY(-2px);
}

.tree-thumb-box {
  width: 68px;
  height: 68px;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  background: var(--sage-soft);
  border: 1px solid var(--sage-tint);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  overflow: hidden;
  flex-shrink: 0;
}

.tree-thumb-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tree-card-body {
  flex: 1;
  min-width: 0;
}

.tree-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.tree-code-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--ink-muted);
}

.tree-card-title {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--ink-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-card-latin {
  font-size: 0.75rem;
  font-style: italic;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-meta-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.pill {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--bg-subtle);
  color: var(--ink-secondary);
}

.pill-sage {
  background: var(--sage-tint);
  color: var(--sage-primary);
}

.pill-frost {
  background: var(--frost-tint);
  color: var(--frost-ink);
}

.pill-amber {
  background: var(--amber-tint);
  color: var(--amber-ink);
}

/* Interactive Campus Eco-Map */
.campus-map-stage {
  position: relative;
  width: 100%;
  height: 360px;
  background: #f1f5f9;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  user-select: none;
}

.campus-map-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.map-pin-btn {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 2.5px solid var(--sage-primary);
  color: var(--sage-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.18);
  cursor: pointer;
  transition: transform 0.18s var(--spring-ease), background 0.15s ease;
  z-index: 5;
}

.map-pin-btn:hover,
.map-pin-btn.selected {
  transform: translate(-50%, -50%) scale(1.22);
  background: var(--sage-primary);
  color: #ffffff;
  z-index: 10;
}

.map-drawer-card {
  margin-top: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-cool);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-card);
}

/* Form Controls (shadcn/ui Fieldset) */
.form-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-cool);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
}

.form-group {
  margin-bottom: 14px;
}

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

.form-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-primary);
  margin-bottom: 5px;
}

.form-hint {
  font-size: 0.7rem;
  color: var(--ink-muted);
  margin-top: 3px;
}

.form-control, input, select, textarea {
  font-size: 16px;
}

.form-control {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-cool);
  background: var(--bg-mist);
  color: var(--ink-primary);
  font-size: 16px;
  font-family: inherit;
}

.form-control:focus {
  background: var(--bg-surface);
  border-color: var(--sage-primary);
  outline: none;
}

textarea.form-control {
  min-height: 82px;
  resize: vertical;
}

/* Auto-suggest Botany List */
.suggest-box {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.suggest-pill {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--sage-tint);
  background: var(--sage-soft);
  color: var(--sage-primary);
  cursor: pointer;
  font-family: inherit;
}

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

/* Buttons */
.btn {
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 14px;
  font-size: 0.86rem;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  transition: all 0.16s var(--spring-ease);
  text-decoration: none;
}

.btn-primary {
  background: var(--sage-primary);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(45, 106, 79, 0.25);
}

.btn-primary:hover {
  background: var(--sage-hover);
}

.btn-dark {
  background: var(--ink-primary);
  color: #ffffff;
}

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

.btn-outline:hover {
  background: var(--bg-subtle);
}

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

.btn-block {
  width: 100%;
}

/* Bottom Navigation Bar (Mobile Thumb Zone >= 48px targets, Always Pinned to Viewport) */
.bottom-nav {
  position: fixed !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  width: 100% !important;
  height: auto;
  min-height: 70px;
  padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-cool);
  box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08);
  z-index: 99 !important;
  display: flex;
  justify-content: center;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

.bottom-nav-inner {
  width: 100%;
  max-width: 560px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  padding: 0 6px;
}

.nav-tab {
  min-height: 54px;
  border: none;
  background: none;
  color: var(--ink-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  border-radius: 12px;
}

.nav-tab.active {
  color: var(--sage-primary);
}

.nav-tab-add {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--sage-primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  font-weight: 800;
  margin-top: -14px;
  box-shadow: 0 6px 16px rgba(45, 106, 79, 0.35);
}

/* Native Dialog Modals (Tree Detail & Role Auth) */
dialog.nordic-dialog {
  margin: auto;
  width: calc(100% - 24px);
  max-width: 520px;
  max-height: 90dvh;
  border: 1px solid var(--border-cool);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: var(--ink-primary);
  box-shadow: var(--shadow-elevated);
  padding: 0;
  overflow: hidden;
}

dialog.nordic-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
}

.dialog-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-cool);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 2;
}

.dialog-body {
  padding: 18px;
  overflow-y: auto;
  max-height: calc(90dvh - 64px);
}

/* Printable Tree Badge Card inside Modal */
.nordic-print-badge {
  background: #ffffff;
  border: 2px solid #0f172a;
  border-radius: 18px;
  padding: 16px;
  text-align: center;
  margin: 14px 0;
  box-shadow: var(--shadow-card);
}

.badge-top-strip {
  background: #2d6a4f;
  color: #ffffff;
  padding: 8px 10px;
  border-radius: 10px;
  margin-bottom: 10px;
}

.badge-qr-wrap {
  width: 170px;
  height: 170px;
  margin: 10px auto;
  padding: 8px;
  border: 1.5px solid #0f172a;
  border-radius: 12px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.badge-qr-wrap svg {
  width: 100%;
  height: 100%;
}

/* Toast Notification */
.toast-banner {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink-primary);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  box-shadow: var(--shadow-elevated);
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s var(--spring-ease);
  z-index: 100;
}

.toast-banner.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Print Layout for A4 Batch Tree QR Badges (@media print) */
.print-sheet-container {
  display: none;
}

@media print {
  body {
    background: #ffffff !important;
    padding: 0 !important;
    color: #000000 !important;
  }
  .app-shell,
  .top-bar,
  .bottom-nav,
  dialog,
  .toast-banner {
    display: none !important;
  }
  .print-sheet-container {
    display: block !important;
    width: 100%;
  }
  .print-grid-a4 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12mm;
    padding: 8mm;
  }
  .print-badge-item {
    border: 2px solid #0f172a;
    border-radius: 12px;
    padding: 12px;
    text-align: center;
    page-break-inside: avoid;
    break-inside: avoid;
  }
}
