/* ==========================================================================
   Lao Ethnic Garden — Modern Layout v2
   Sidebar + Top Header + Main Content
   ========================================================================== */

:root {
  /* ===== Brand colors ===== */
  --leg-primary: #16a34a;
  --leg-primary-dark: #0f7a36;
  --leg-primary-light: #6cb252;
  --leg-accent: #98a832;
  --leg-gradient: linear-gradient(180deg, #16a34a 0%, #6cb252 50%, #98a832 100%);

  /* ===== Light theme (default) ===== */
  --leg-bg: #f6faf5;
  --leg-surface: #ffffff;
  --leg-surface-alt: #f9fafb;
  --leg-text: #1f2937;
  --leg-text-muted: #6b7280;
  --leg-heading: #0f172a;
  --leg-border: #e5e7eb;
  --leg-border-strong: #d1d5db;
  --leg-overlay: rgba(15, 23, 42, 0.5);

  --leg-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --leg-shadow: 0 4px 16px -2px rgba(22, 163, 74, 0.08), 0 2px 8px -2px rgba(0, 0, 0, 0.05);
  --leg-shadow-lg: 0 10px 32px -4px rgba(22, 163, 74, 0.12), 0 8px 20px -6px rgba(0, 0, 0, 0.08);

  /* ===== Sizes ===== */
  --leg-sidebar-w: 280px;
  --leg-topbar-h: 60px;
  --leg-radius: 6px;
  --leg-radius-lg: 8px;
  --leg-transition: 300ms cubic-bezier(0.4, 0, 0.2, 1);

  /* ===== Typography ===== */
  --leg-font-sans: 'Inter', 'Noto Sans Lao Looped', 'Noto Sans Lao', 'Lao', 'Sarabun', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --leg-font-heading: 'Plus Jakarta Sans', 'Noto Sans Lao Looped', 'Noto Sans Lao', 'Lao', system-ui, sans-serif;
  --leg-font-lao: 'Noto Sans Lao Looped', 'Noto Sans Lao', 'Lao', sans-serif;
  --leg-font-size-xs: 0.72rem;
  --leg-font-size-sm: 0.82rem;
  --leg-font-size-base: 0.92rem;
  --leg-font-size-lg: 1.05rem;
  --leg-font-size-xl: 1.25rem;
  --leg-font-size-2xl: 1.5rem;
  --leg-font-size-3xl: 1.9rem;
  --leg-font-size-4xl: 2.35rem;
  --leg-line-height-tight: 1.2;
  --leg-line-height-snug: 1.4;
  --leg-line-height-normal: 1.6;
  --leg-line-height-relaxed: 1.75;
  --leg-tracking-tight: -0.02em;
  --leg-tracking-normal: 0;
  --leg-tracking-wide: 0.025em;
  --leg-font-weight-regular: 400;
  --leg-font-weight-medium: 500;
  --leg-font-weight-semibold: 600;
  --leg-font-weight-bold: 700;
  --leg-font-weight-extrabold: 800;
}

/* ===== Dark theme ===== */
:root[data-theme="dark"] {
  --leg-bg: #0b1220;
  --leg-surface: #121a2a;
  --leg-surface-alt: #19243a;
  --leg-text: #e5e7eb;
  --leg-text-muted: #9ca3af;
  --leg-heading: #f8fafc;
  --leg-border: #1f2a44;
  --leg-border-strong: #2a3a5a;
  --leg-overlay: rgba(0, 0, 0, 0.7);

  --leg-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --leg-shadow: 0 4px 16px -2px rgba(0, 0, 0, 0.45), 0 2px 8px -2px rgba(0, 0, 0, 0.3);
  --leg-shadow-lg: 0 10px 32px -4px rgba(0, 0, 0, 0.55), 0 8px 20px -6px rgba(0, 0, 0, 0.4);
}

/* Respect user's system preference on first load (only if no explicit theme set) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --leg-bg: #0b1220;
    --leg-surface: #121a2a;
    --leg-surface-alt: #19243a;
    --leg-text: #e5e7eb;
    --leg-text-muted: #9ca3af;
    --leg-heading: #f8fafc;
    --leg-border: #1f2a44;
    --leg-border-strong: #2a3a5a;
    --leg-overlay: rgba(0, 0, 0, 0.7);
    --leg-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
    --leg-shadow: 0 4px 16px -2px rgba(0, 0, 0, 0.45), 0 2px 8px -2px rgba(0, 0, 0, 0.3);
    --leg-shadow-lg: 0 10px 32px -4px rgba(0, 0, 0, 0.55), 0 8px 20px -6px rgba(0, 0, 0, 0.4);
  }
}

/* Reset body layout */
html, body {
  margin: 0;
  padding: 0;
  background: var(--leg-bg);
  color: var(--leg-text);
  min-height: 100vh;
  font-family: var(--leg-font-sans);
  font-size: var(--leg-font-size-base);
  line-height: var(--leg-line-height-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--leg-transition), color var(--leg-transition);
}

/* Typography scale */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--leg-font-heading);
  color: var(--leg-heading);
  font-weight: var(--leg-font-weight-bold);
  line-height: var(--leg-line-height-tight);
  letter-spacing: var(--leg-tracking-tight);
  margin: 0 0 0.5em 0;
}
h1 { font-size: var(--leg-font-size-4xl); font-weight: var(--leg-font-weight-extrabold); }
h2 { font-size: var(--leg-font-size-3xl); font-weight: var(--leg-font-weight-extrabold); }
h3 { font-size: var(--leg-font-size-2xl); font-weight: var(--leg-font-weight-bold); }
h4 { font-size: var(--leg-font-size-xl); }
h5 { font-size: var(--leg-font-size-lg); }
h6 { font-size: var(--leg-font-size-base); }
p  { line-height: var(--leg-line-height-relaxed); }

body.leg-app {
  padding-left: var(--leg-sidebar-w);
  padding-top: var(--leg-topbar-h);
}

/* ==========================================================================
   TOP HEADER
   ========================================================================== */
.leg-topbar {
  position: fixed;
  top: 0;
  left: var(--leg-sidebar-w);
  right: 0;
  height: var(--leg-topbar-h);
  background: var(--leg-surface);
  border-bottom: 1px solid var(--leg-border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: 1030;
  box-shadow: var(--leg-shadow-sm);
  transition: left var(--leg-transition), background-color var(--leg-transition);
}
/* Seamless connection: hide the sidebar right border where topbar meets it */
.leg-sidebar::after {
  content: '';
  position: absolute;
  top: var(--leg-topbar-h);
  right: -1px;
  bottom: 0;
  width: 1px;
  background: var(--leg-border);
}
.leg-sidebar {
  border-right: 0;
}

.leg-topbar__burger {
  display: none;
  background: transparent;
  border: none;
  padding: 8px;
  margin-right: 12px;
  color: var(--leg-primary);
  cursor: pointer;
  border-radius: 6px;
  transition: background var(--leg-transition);
}
.leg-topbar__burger:hover { background: rgba(22, 163, 74, 0.12); }
:root[data-theme="dark"] .leg-topbar__burger:hover { background: rgba(108, 178, 82, 0.18); }
.leg-topbar__burger svg { width: 24px; height: 24px; }

.leg-topbar__title {
  font-family: var(--leg-font-heading);
  font-size: 0.95rem;
  font-weight: var(--leg-font-weight-bold);
  color: var(--leg-primary-dark);
  flex: 1 1 auto;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: var(--leg-tracking-tight);
}
:root[data-theme="dark"] .leg-topbar__title { color: #7dd499; }

.leg-topbar__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.leg-topbar__action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--leg-text);
  text-decoration: none;
  transition: all var(--leg-transition);
  cursor: pointer;
}
.leg-topbar__action:hover {
  background: rgba(22, 163, 74, 0.1);
  color: var(--leg-primary);
  border-color: rgba(22, 163, 74, 0.2);
}
:root[data-theme="dark"] .leg-topbar__action {
  color: var(--leg-text);
}
:root[data-theme="dark"] .leg-topbar__action:hover {
  background: rgba(108, 178, 82, 0.18);
  color: #a7d88e;
  border-color: rgba(108, 178, 82, 0.3);
}
.leg-topbar__action svg { width: 20px; height: 20px; }

/* Admin Create button — distinctive green */
.leg-topbar__create {
  background: var(--leg-gradient) !important;
  color: #fff !important;
  border-color: transparent !important;
  box-shadow: 0 2px 8px rgba(22, 163, 74, 0.3);
}
.leg-topbar__create:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.4);
  background: var(--leg-gradient) !important;
  color: #fff !important;
}
.leg-create-menu {
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--leg-border);
  border-radius: 8px;
  box-shadow: var(--leg-shadow-lg);
}
.leg-create-menu .dropdown-item {
  border-radius: 6px;
  padding: 9px 12px;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 2px;
  color: var(--leg-text);
}
.leg-create-menu .dropdown-item:hover {
  background: rgba(22, 163, 74, 0.08);
  color: var(--leg-primary-dark);
}
:root[data-theme="dark"] .leg-create-menu {
  background: var(--leg-surface);
}
:root[data-theme="dark"] .leg-create-menu .dropdown-item {
  color: var(--leg-text);
}
:root[data-theme="dark"] .leg-create-menu .dropdown-item:hover {
  background: rgba(108, 178, 82, 0.15);
  color: #a7d88e;
}

/* Theme toggle: sun shows in dark mode, moon shows in light mode */
.leg-theme-toggle svg { transition: transform 400ms ease, opacity 200ms ease; }
.leg-theme-icon--sun  { display: none; }
.leg-theme-icon--moon { display: block; }
:root[data-theme="dark"] .leg-theme-icon--sun  { display: block; }
:root[data-theme="dark"] .leg-theme-icon--moon { display: none; }
.leg-theme-toggle:hover svg { transform: rotate(15deg); }

.leg-topbar__lang {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--leg-border);
  background: var(--leg-surface);
  color: var(--leg-text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--leg-transition);
}
.leg-topbar__lang:hover {
  border-color: var(--leg-primary);
  color: var(--leg-primary);
}

/* ==========================================================================
   SIDEBAR
   ========================================================================== */
.leg-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--leg-sidebar-w);
  background: var(--leg-surface);
  border-right: 1px solid var(--leg-border);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform var(--leg-transition);
  overflow: hidden;
}

.leg-sidebar__brand {
  /* Match top bar height exactly so the seam is seamless */
  min-height: var(--leg-topbar-h);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  flex-shrink: 0;
  background: var(--leg-gradient);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: var(--leg-shadow-sm);
  position: relative;
}
.leg-sidebar__brand::after {
  /* Subtle glow accent line */
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
}

.leg-sidebar__brand img {
  height: 40px;
  width: auto;
  flex-shrink: 0;
  /* Make the white-on-white logo visible on green bg */
  filter: brightness(0) invert(1) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
}
.leg-sidebar__brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}
.leg-sidebar__brand-text strong {
  font-family: var(--leg-font-heading);
  font-size: 0.92rem;
  font-weight: var(--leg-font-weight-extrabold);
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: var(--leg-tracking-tight);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}
.leg-sidebar__brand-text small {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.88);
  font-weight: 500;
}
:root[data-theme="dark"] .leg-sidebar__brand {
  background: linear-gradient(180deg, #0f7a36 0%, #16a34a 100%);
}

.leg-sidebar__nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 10px;
  list-style: none;
  margin: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--leg-border) transparent;
}
.leg-sidebar__nav::-webkit-scrollbar { width: 6px; }
.leg-sidebar__nav::-webkit-scrollbar-thumb {
  background: var(--leg-border);
  border-radius: 3px;
}

.leg-sidebar__item {
  margin-bottom: 2px;
}
.leg-sidebar__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: var(--leg-radius);
  color: var(--leg-text);
  text-decoration: none;
  font-size: 0.87rem;
  font-weight: 600;
  transition: all var(--leg-transition);
  position: relative;
  border: 1px solid transparent;
  line-height: 1.25;
}
.leg-sidebar__link:hover {
  background: rgba(22, 163, 74, 0.08);
  color: var(--leg-primary-dark);
  border-color: rgba(22, 163, 74, 0.15);
  transform: translateX(2px);
}
:root[data-theme="dark"] .leg-sidebar__link {
  color: var(--leg-text);
}
:root[data-theme="dark"] .leg-sidebar__link:hover {
  background: rgba(108, 178, 82, 0.15);
  color: #a7d88e;
  border-color: rgba(108, 178, 82, 0.25);
}
.leg-sidebar__link.is-active {
  background: var(--leg-surface-alt);
  color: var(--leg-primary-dark);
  border-color: var(--leg-border);
  box-shadow: none;
  position: relative;
}
.leg-sidebar__link.is-active::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 18%;
  bottom: 18%;
  width: 3px;
  background: var(--leg-primary);
  border-radius: 0 2px 2px 0;
}
.leg-sidebar__link.is-active:hover {
  background: var(--leg-surface-alt);
  color: var(--leg-primary-dark);
  transform: translateX(0);
}
:root[data-theme="dark"] .leg-sidebar__link.is-active {
  background: rgba(108, 178, 82, 0.1);
  color: #a7d88e;
  border-color: rgba(108, 178, 82, 0.2);
}
:root[data-theme="dark"] .leg-sidebar__link.is-active:hover {
  background: rgba(108, 178, 82, 0.15);
  color: #a7d88e;
}

.leg-sidebar__icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  flex-shrink: 0;
}

/* Admin section divider + label */
.leg-sidebar__divider {
  height: 1px;
  background: var(--leg-border);
  margin: 12px 14px 6px;
}
.leg-sidebar__section-label {
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--leg-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 20px 6px;
}
.leg-sidebar__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: #f59e0b;
  color: #fff;
  border-radius: 10px;
  font-size: 0.65rem;
  font-weight: 800;
  margin-left: auto;
  line-height: 1;
  animation: legPulse 2s infinite;
}
@keyframes legPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.1); }
}

.leg-sidebar__footer {
  border-top: 1px solid var(--leg-border);
  padding: 8px 14px;
  font-size: 0.7rem;
  color: var(--leg-text-muted);
  text-align: center;
  line-height: 1.4;
  flex-shrink: 0;
}
.leg-sidebar__footer a {
  color: var(--leg-primary);
  text-decoration: none;
  font-weight: 600;
}

/* ==========================================================================
   BACKDROP (for mobile sidebar)
   ========================================================================== */
.leg-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--leg-transition), visibility var(--leg-transition);
  z-index: 1035;
  backdrop-filter: blur(2px);
}
.leg-backdrop.is-visible {
  opacity: 1;
  visibility: visible;
}

/* ==========================================================================
   MAIN CONTENT AREA
   ========================================================================== */
.leg-main {
  min-height: calc(100vh - var(--leg-topbar-h));
  padding: 32px 36px;
  background: var(--leg-bg);
}

.leg-page-header {
  margin-bottom: 32px;
}
.leg-page-header__title {
  font-family: var(--leg-font-heading);
  font-size: var(--leg-font-size-3xl);
  font-weight: var(--leg-font-weight-extrabold);
  color: var(--leg-primary-dark);
  margin: 0 0 8px 0;
  letter-spacing: var(--leg-tracking-tight);
  line-height: var(--leg-line-height-tight);
}
:root[data-theme="dark"] .leg-page-header__title {
  color: #7dd499;
}
.leg-page-header__subtitle {
  font-size: var(--leg-font-size-lg);
  color: var(--leg-text-muted);
  margin: 0;
  font-weight: var(--leg-font-weight-regular);
  line-height: var(--leg-line-height-snug);
}

.leg-hero {
  background: var(--leg-gradient);
  border-radius: 10px;
  padding: 40px 36px;
  color: #fff;
  margin-bottom: 36px;
  box-shadow: var(--leg-shadow-lg);
  position: relative;
  overflow: hidden;
}
.leg-hero::before {
  content: "";
  position: absolute;
  top: -50%;
  right: -10%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, transparent 70%);
  pointer-events: none;
}
.leg-hero h1 {
  font-family: var(--leg-font-heading);
  font-size: var(--leg-font-size-4xl);
  font-weight: var(--leg-font-weight-extrabold);
  margin: 0 0 12px 0;
  position: relative;
  z-index: 1;
  color: #fff;
  letter-spacing: var(--leg-tracking-tight);
  line-height: var(--leg-line-height-tight);
}
.leg-hero p {
  font-size: var(--leg-font-size-lg);
  margin: 0;
  opacity: 0.95;
  max-width: 720px;
  position: relative;
  z-index: 1;
  color: #fff;
  line-height: var(--leg-line-height-relaxed);
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 1199px) {
  :root { --leg-sidebar-w: 260px; }
}

@media (max-width: 991px) {
  body.leg-app { padding-left: 0; }

  .leg-topbar { left: 0; }
  .leg-topbar__burger { display: inline-flex; }

  .leg-sidebar {
    transform: translateX(-100%);
    box-shadow: var(--leg-shadow-lg);
  }
  .leg-sidebar.is-open { transform: translateX(0); }

  .leg-main { padding: 24px 20px; }
  .leg-hero { padding: 28px 22px; }
  .leg-hero h1 { font-size: 1.6rem; }
  .leg-hero p { font-size: 0.95rem; }
  .leg-page-header__title { font-size: 1.5rem; }
}

@media (max-width: 575px) {
  :root {
    --leg-sidebar-w: 86vw;
    --leg-topbar-h: 56px;
  }

  .leg-main { padding: 18px 14px; }
  .leg-hero { padding: 22px 18px; border-radius: 8px; }
  .leg-hero h1 { font-size: 1.35rem; }
  .leg-topbar { padding: 0 14px; }
  .leg-topbar__title { font-size: 0.85rem; }
  .leg-topbar__action { width: 36px; height: 36px; }
}

/* Utility to hide scroll when sidebar open on mobile */
body.leg-no-scroll { overflow: hidden; }
