/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  --saffron:       #E8700A;
  --saffron-deep:  #C45C00;
  --saffron-glow:  #FFAB40;
  --gold:          #D4A017;
  --gold-light:    #F2D472;
  --stone-dark:    #1A1209;
  --stone-med:     #2C1F0E;
  --stone-warm:    #3D2B14;
  --stone-border:  #5C3D1E;
  --cream:         #FDF6EC;
  --cream-dark:    #F5E8CC;
  --text-main:     #2C1A0E;
  --text-muted:    #7A5C3A;
  --text-light:    #C4A882;
  --visited:       #5A7A3A;
  --unvisited:     #B84040;
  --visited-bg:    #EEF4E8;
  --unvisited-bg:  #FAF0F0;

  --sidebar-w: 270px;
  --font-display: 'Cinzel', Georgia, serif;
  --font-body: 'Crimson Pro', Georgia, serif;
}

body {
  margin: 0;
  background: var(--cream);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.7;
  min-height: 100vh;
}

/* ── App Shell ── */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--stone-dark);
  color: var(--cream);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  border-right: 2px solid var(--stone-border);
  position: relative;
}

.sidebar::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 39px,
      rgba(212,160,23,0.04) 39px,
      rgba(212,160,23,0.04) 40px
    );
  pointer-events: none;
}

.app-title {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 18px;
  border-bottom: 1px solid var(--stone-border);
  position: sticky;
  top: 0;
  background: var(--stone-dark);
  z-index: 10;
}

.title-icon {
  font-size: 22px;
  line-height: 1;
}

.title-text {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-light);
}

.menu {
  flex: 1;
  padding: 12px 10px;
}

.menu-title {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 10px 12px;
  margin-top: 6px;
  cursor: pointer;
  border-radius: 6px;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.2s, color 0.2s;
  position: relative;
}

.menu-title:hover {
  background: var(--stone-warm);
  color: var(--gold-light);
}

.menu-icon {
  font-size: 10px;
  color: var(--saffron);
}

.dashboard-btn {
  background: rgba(232, 112, 10, 0.15);
  color: var(--saffron-glow);
  border: 1px solid rgba(232, 112, 10, 0.3);
  margin-bottom: 8px;
}

.dashboard-btn:hover {
  background: rgba(232, 112, 10, 0.25);
  color: var(--gold-light);
}

/* Category arrow */
.menu-title[data-cat]::after {
  content: '›';
  margin-left: auto;
  font-size: 16px;
  color: var(--stone-border);
  transition: transform 0.25s;
}

.menu-title[data-cat].active::after {
  transform: rotate(90deg);
  color: var(--saffron);
}

/* Submenu */
.submenu {
  display: none;
  padding: 4px 0 4px 8px;
  border-left: 2px solid var(--stone-border);
  margin-left: 12px;
  margin-bottom: 4px;
}

.submenu.open {
  display: block;
  animation: slideDown 0.2s ease;
}

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

.submenu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.15s;
}

.submenu-item:hover {
  background: var(--stone-warm);
}

.submenu-item span {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-light);
  cursor: pointer;
  transition: color 0.15s;
  flex: 1;
}

.submenu-item:hover span {
  color: var(--cream);
}

/* Custom Checkbox */
.submenu-item input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--stone-border);
  border-radius: 3px;
  cursor: pointer;
  background: transparent;
  flex-shrink: 0;
  position: relative;
  transition: border-color 0.15s, background 0.15s;
}

.submenu-item input[type="checkbox"]:checked {
  background: var(--visited);
  border-color: var(--visited);
}

.submenu-item input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 9px;
  font-weight: bold;
}

/* Visited indicator in submenu */
.submenu-item.is-visited span {
  color: #7BAD52;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 16px;
  text-align: center;
  border-top: 1px solid var(--stone-border);
  margin-top: auto;
}

.footer-om {
  font-size: 20px;
  color: var(--stone-border);
  letter-spacing: 0.1em;
  font-family: serif;
}

/* ── Main Content ── */
.main {
  flex: 1;
  overflow-y: auto;
  background: var(--cream);
  position: relative;
}

.main::before {
  content: '';
  position: fixed;
  inset: 0 0 0 var(--sidebar-w);
  background:
    radial-gradient(ellipse at 80% 0%, rgba(232,112,10,0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 20% 100%, rgba(212,160,23,0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* Loading */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 60vh;
  gap: 12px;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.loader-symbol {
  font-size: 40px;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.9); }
}

/* ── Dashboard ── */
.dashboard-wrap {
  padding: 36px 40px;
  position: relative;
  z-index: 1;
}

.page-header {
  margin-bottom: 32px;
}

.page-header h1 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-main);
  margin: 0 0 6px;
}

.page-header .subtitle {
  font-style: italic;
  color: var(--text-muted);
  font-size: 16px;
  margin: 0;
}

/* Summary row */
.summary-row {
  display: flex;
  gap: 16px;
  margin-bottom: 36px;
  flex-wrap: wrap;
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border: 1px solid var(--cream-dark);
  border-radius: 8px;
  padding: 10px 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.stat-chip .stat-num {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--saffron);
  line-height: 1;
}

.stat-chip .stat-label {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--font-display);
}

.stat-chip.visited-stat .stat-num { color: var(--visited); }
.stat-chip.unvisited-stat .stat-num { color: var(--unvisited); }

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
}

.dashboard-card {
  background: white;
  border: 1px solid var(--cream-dark);
  border-radius: 12px;
  padding: 22px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.05);
  transition: box-shadow 0.2s, transform 0.2s;
}

.dashboard-card:hover {
  box-shadow: 0 6px 24px rgba(0,0,0,0.1);
  transform: translateY(-2px);
}

.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-header h2 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-main);
  margin: 0;
  text-transform: uppercase;
}

.card-counts {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.chart-box {
  height: 220px;
  position: relative;
}

/* ── Category Dashboard ── */
.cat-wrap {
  padding: 36px 40px;
  position: relative;
  z-index: 1;
}

.cat-description {
  max-width: 700px;
  font-size: 17px;
  line-height: 1.8;
  color: var(--text-muted);
  font-style: italic;
  margin: 0 0 28px;
  padding: 16px 20px;
  background: white;
  border-left: 3px solid var(--saffron);
  border-radius: 0 8px 8px 0;
}

.cat-chart-box {
  height: 340px;
  max-width: 500px;
  margin-bottom: 32px;
}

/* Temple list */
.temple-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.temple-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: white;
  border: 1px solid var(--cream-dark);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-size: 15px;
}

.temple-chip:hover {
  border-color: var(--saffron);
  box-shadow: 0 2px 8px rgba(232,112,10,0.12);
}

.temple-chip .chip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.temple-chip.visited .chip-dot   { background: var(--visited); }
.temple-chip.unvisited .chip-dot { background: var(--unvisited); }

.temple-chip .chip-name {
  font-family: var(--font-body);
  color: var(--text-main);
  flex: 1;
}

/* ── Markdown Temple Page ── */
#mainContent .md-body {
  padding: 36px 48px;
  max-width: 860px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

/* Markdown Typography */
.md-body h1 {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--stone-dark);
  margin: 0 0 4px;
  line-height: 1.3;
}

.md-body h2 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--saffron-deep);
  margin: 36px 0 14px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--cream-dark);
}

.md-body h3 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-main);
  margin: 24px 0 10px;
}

.md-body p {
  color: var(--text-main);
  font-size: 17px;
  line-height: 1.85;
  margin: 0 0 16px;
}

.md-body em {
  color: var(--text-muted);
  font-style: italic;
}

.md-body strong {
  color: var(--stone-dark);
  font-weight: 600;
}

.md-body blockquote {
  margin: 24px 0;
  padding: 16px 22px;
  border-left: 4px solid var(--saffron);
  background: rgba(232,112,10,0.05);
  border-radius: 0 8px 8px 0;
  font-style: italic;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1.7;
}

.md-body blockquote p { margin: 0; color: var(--text-muted); }

.md-body hr {
  border: none;
  border-top: 1px solid var(--cream-dark);
  margin: 36px 0;
}

.md-body ul, .md-body ol {
  padding-left: 22px;
  margin: 0 0 16px;
}

.md-body li {
  margin-bottom: 6px;
  color: var(--text-main);
}

.md-body li::marker {
  color: var(--saffron);
}

/* Tables */
.md-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0 28px;
  font-size: 15px;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 6px rgba(0,0,0,0.06);
}

.md-body thead tr {
  background: var(--stone-dark);
  color: var(--gold-light);
}

.md-body th {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 11px 16px;
  text-align: left;
}

.md-body td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--cream-dark);
  color: var(--text-main);
}

.md-body tbody tr:last-child td {
  border-bottom: none;
}

.md-body tbody tr:hover {
  background: rgba(212,160,23,0.04);
}

.md-body tbody tr td:first-child {
  font-weight: 600;
  color: var(--stone-dark);
}

/* ── Mobile Menu Button ── */
.menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1001;
  background: var(--stone-dark);
  color: var(--gold-light);
  border: 1px solid var(--stone-border);
  border-radius: 6px;
  width: 38px;
  height: 38px;
  font-size: 16px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* ── Scrollbar ── */
.sidebar::-webkit-scrollbar,
.main::-webkit-scrollbar { width: 5px; }

.sidebar::-webkit-scrollbar-track { background: var(--stone-dark); }
.sidebar::-webkit-scrollbar-thumb { background: var(--stone-border); border-radius: 3px; }

.main::-webkit-scrollbar-track { background: var(--cream); }
.main::-webkit-scrollbar-thumb { background: var(--cream-dark); border-radius: 3px; }

/* ── Sidebar Backdrop (mobile) ── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
}

.sidebar-backdrop.visible {
  display: block;
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .app {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    height: 100%;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
  }

  .sidebar.open {
    left: 0;
    box-shadow: 4px 0 20px rgba(0,0,0,0.4);
  }

  .menu-btn {
    display: flex;
  }

  .main {
    width: 100%;
    height: 100vh;
    overflow-y: auto;
  }

  .main::before {
    left: 0;
  }

  .dashboard-wrap,
  .cat-wrap {
    padding: 60px 16px 24px;
  }

  .md-body {
    padding: 60px 16px 24px;
  }

  .summary-row {
    gap: 10px;
  }

  .stat-chip {
    flex: 1;
    min-width: 80px;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 10px 12px;
    gap: 2px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .cat-chart-box {
    height: 260px;
    max-width: 100%;
  }

  .temple-list {
    grid-template-columns: 1fr;
  }
}