/* Nepali Calendar — Dark + Gold theme with Light Mode support */
@import url('https://fonts.googleapis.com/css2?family=Mukta:wght@400;500;600;700;800&family=Inter:wght@400;500;600&display=swap');

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

/* ─── Dark theme (default) ───────────────────────────── */
:root {
  --bg:         #0d1117;
  --surface:    #161b27;
  --surface-2:  #1e2535;
  --surface-3:  #252d40;
  --border:     #2a3145;
  --border-2:   #3a4460;
  --gold:       #f59e0b;
  --gold-bright:#fbbf24;
  --gold-dim:   #92400e;
  --gold-bg:    rgba(245, 158, 11, .10);
  --gold-bg-2:  rgba(245, 158, 11, .18);
  --red:        #ef4444;
  --red-bg:     rgba(239, 68, 68, .12);
  --red-border: rgba(239, 68, 68, .30);
  --text:       #e2e8f0;
  --text-muted: #64748b;
  --text-dim:   #94a3b8;
  --sat:        #f87171;
  --shadow:     0 4px 24px rgba(0, 0, 0, .5);
  --shadow-sm:  0 2px 8px  rgba(0, 0, 0, .35);
  --radius:     12px;
  --radius-sm:  8px;
}

/* ─── Light theme (system preference) ───────────────── */
@media (prefers-color-scheme: light) {
  :root {
    --bg:         #f1f5f9;
    --surface:    #ffffff;
    --surface-2:  #f8fafc;
    --surface-3:  #f1f5f9;
    --border:     #e2e8f0;
    --border-2:   #cbd5e1;
    --gold:       #b45309;
    --gold-bright:#d97706;
    --gold-dim:   #fef3c7;
    --gold-bg:    rgba(180, 83, 9, .08);
    --gold-bg-2:  rgba(180, 83, 9, .15);
    --red:        #dc2626;
    --red-bg:     rgba(220, 38, 38, .08);
    --red-border: rgba(220, 38, 38, .22);
    --text:       #0f172a;
    --text-muted: #64748b;
    --text-dim:   #334155;
    --sat:        #dc2626;
    --shadow:     0 4px 24px rgba(0, 0, 0, .10);
    --shadow-sm:  0 2px 8px  rgba(0, 0, 0, .07);
  }
}

html { background: var(--bg); }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ─── Preloader ──────────────────────────────────────── */
#cal-preloader {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .4s ease, transform .4s ease;
}

#cal-preloader.pl-done {
  opacity: 0;
  transform: scale(.98);
  pointer-events: none;
}

.pl-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
  width: 260px;
}

.pl-icon {
  font-size: 2.8rem;
  line-height: 1;
  animation: pl-pulse 1.8s ease-in-out infinite;
}
@keyframes pl-pulse {
  0%, 100% { opacity: 1;   transform: scale(1); }
  50%       { opacity: .65; transform: scale(.93); }
}

.pl-title {
  font-family: 'Mukta', sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: .01em;
}

.pl-bar-wrap {
  width: 100%;
  height: 4px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}

#pl-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  border-radius: 99px;
  transition: width .45s cubic-bezier(.4, 0, .2, 1);
}

.pl-msg {
  font-family: 'Mukta', sans-serif;
  font-size: 1rem;
  color: var(--text-dim);
  text-align: center;
  min-height: 1.4em;
  transition: opacity .2s;
}

.pl-sub {
  font-size: .72rem;
  color: var(--text-muted);
  letter-spacing: .06em;
  text-transform: uppercase;
}

/* ─── Root Layout ────────────────────────────────────── */
#nep-cal-root {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-areas:
    "sidebar main"
    "holidays main";
  gap: 1.25rem;
  max-width: 1060px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  align-items: start;
}

/* ─── Sidebar ─────────────────────────────────────────── */
#cal-sidebar {
  grid-area: sidebar;
  position: sticky;
  top: 1.25rem;
}

/* ─── Today Card ─────────────────────────────────────── */
#today-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.tc-inner {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .85rem;
  align-items: start;
}

.tc-right {
  border-left: 1px solid var(--border);
  padding-left: .85rem;
}

.tc-date {
  font-family: 'Mukta', sans-serif;
  font-size: 4.5rem;
  font-weight: 800;
  color: var(--gold);
  line-height: 1;
  letter-spacing: -.02em;
}

.tc-month-year {
  font-family: 'Mukta', sans-serif;
  font-size: 1rem;
  color: var(--text-dim);
  margin-top: .1rem;
}

.tc-day {
  font-family: 'Mukta', sans-serif;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  margin-top: .6rem;
}

.tc-ad {
  font-size: .72rem;
  color: var(--text-muted);
  margin-top: .1rem;
}

.tc-rows {
  display: flex;
  flex-direction: column;
  gap: .45rem;
}

.tc-row {
  display: flex;
  flex-direction: column;
  gap: .05rem;
}

.tc-label {
  font-size: .58rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  font-weight: 600;
}

.tc-val {
  font-family: 'Mukta', sans-serif;
  font-size: .9rem;
  color: var(--text-dim);
  line-height: 1.3;
}

.tc-sun-row {
  display: flex;
  gap: .75rem;
  margin-top: .3rem;
}

.tc-sun-item {
  display: flex;
  align-items: center;
  gap: .3rem;
}

.tc-sun-icon { font-size: .9rem; }

.tc-sun-time {
  font-family: 'Mukta', sans-serif;
  font-size: .85rem;
  color: var(--text-dim);
}

.tc-ritu-badge {
  display: inline-block;
  font-family: 'Mukta', sans-serif;
  font-size: .7rem;
  background: var(--gold-bg);
  color: var(--gold);
  border: 1px solid rgba(180, 83, 9, .2);
  border-radius: 99px;
  padding: .12rem .5rem;
  margin-top: .5rem;
}

/* ─── Upcoming Holidays ─────────────────────────────── */
#upcoming-holidays {
  grid-area: holidays;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.uh-heading {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0 .25rem;
}

.uh-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm);
  padding: .6rem .85rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
  transition: background .15s;
}
.uh-item:hover { background: var(--surface-2); }
.uh-item.uh-today { border-left-color: var(--gold-bright); }
.uh-item.uh-soon  { border-left-color: var(--red); }

.uh-name {
  font-family: 'Mukta', sans-serif;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.uh-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
}

.uh-date {
  font-size: .72rem;
  color: var(--text-muted);
  flex: 1;
}

.uh-badge {
  font-size: .68rem;
  font-weight: 600;
  padding: .1rem .45rem;
  border-radius: 99px;
  background: var(--gold-bg);
  color: var(--gold);
  border: 1px solid rgba(180, 83, 9, .2);
  white-space: nowrap;
  flex-shrink: 0;
}
.uh-badge.badge-today { background: var(--gold-bg-2); color: var(--gold-bright); }
.uh-badge.badge-soon  { background: var(--red-bg); color: var(--red); border-color: var(--red-border); }

/* ─── Main Column ─────────────────────────────────────── */
#cal-main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  min-width: 0;
}

/* ─── Controls ───────────────────────────────────────── */
#cal-controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .65rem .85rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
}

.cal-nav-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s, border-color .15s;
  flex-shrink: 0;
  line-height: 1;
}
.cal-nav-btn:hover {
  background: var(--gold-bg);
  border-color: rgba(180, 83, 9, .35);
  color: var(--gold);
}

.cal-month-label {
  flex: 1;
  text-align: center;
  font-family: 'Mukta', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: .01em;
  min-width: 0;
}
.cal-month-label .en {
  font-family: 'Inter', sans-serif;
  font-size: .72rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: .4rem;
}

.cal-dropdowns {
  display: flex;
  gap: .4rem;
}

.cal-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  padding: 0 .55rem;
  height: 32px;
  font-size: .78rem;
  cursor: pointer;
  font-family: 'Mukta', sans-serif;
  transition: border-color .15s;
}
.cal-select:hover { border-color: var(--border-2); }
.cal-select:focus { outline: 2px solid var(--gold-bg-2); outline-offset: 1px; }
.cal-select option { background: var(--surface-2); color: var(--text); }

.cal-today-btn {
  background: transparent;
  border: 1px solid rgba(180, 83, 9, .35);
  border-radius: 99px;
  color: var(--gold);
  padding: 0 .8rem;
  height: 32px;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  flex-shrink: 0;
  font-family: 'Mukta', sans-serif;
}
.cal-today-btn:hover { background: var(--gold-bg); border-color: rgba(180, 83, 9, .6); }

/* ─── Week Header ────────────────────────────────────── */
.cal-week-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  padding: 0 1px;
}

.cal-week-header div {
  text-align: center;
  font-size: .62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  padding: .4rem 0;
}
.cal-week-header div:last-child { color: var(--sat); }

/* ─── Grid ───────────────────────────────────────────── */
#cal-grid {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.cal-grid-inner {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
}

.cal-cell {
  background: var(--surface);
  min-height: 80px;
  padding: .5rem .55rem .4rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: background .12s;
}
.cal-cell:hover { background: var(--surface-2); }

.cal-cell.empty {
  background: var(--bg);
  cursor: default;
  pointer-events: none;
}

.cal-cell-bs {
  font-family: 'Mukta', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.cal-cell-ad {
  font-size: .6rem;
  color: var(--text-muted);
  margin-top: .1rem;
}

.cal-cell-event {
  margin-top: auto;
  font-family: 'Mukta', sans-serif;
  font-size: .65rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  padding-top: .2rem;
}
.cal-cell-event.ev-holiday { color: var(--red); opacity: .85; }
.cal-cell-event.ev-more    { opacity: .55; }

/* ── Today ── */
.cal-cell.today {
  background: var(--gold-bg);
  outline: 1.5px solid rgba(180, 83, 9, .35);
  outline-offset: -1.5px;
}
.cal-cell.today:hover { background: var(--gold-bg-2); }
.cal-cell.today .cal-cell-bs    { color: var(--gold-bright); }
.cal-cell.today .cal-cell-ad    { color: rgba(180, 83, 9, .5); }
.cal-cell.today .cal-cell-event { color: rgba(180, 83, 9, .65); }

/* ── Holiday ── */
.cal-cell.holiday .cal-cell-bs          { color: var(--red); }
.cal-cell.today.holiday .cal-cell-bs    { color: var(--gold-bright); }

/* ── Saturday ── */
.cal-cell.saturday .cal-cell-bs          { color: var(--sat); }
.cal-cell.today.saturday .cal-cell-bs   { color: var(--gold-bright); }

/* ─── Day Popup ──────────────────────────────────────── */
#day-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

#day-popup {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  animation: slideUp .22s cubic-bezier(.22, 1, .36, 1);
  box-shadow: var(--shadow);
}
@keyframes slideUp {
  from { transform: translateY(32px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.dp-handle {
  width: 36px; height: 3px;
  background: var(--border-2);
  border-radius: 99px;
  margin: .65rem auto .1rem;
}

/* Two-column inner layout: date | panchanga | close */
.dp-inner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  padding: .75rem 1.25rem 1.5rem;
  align-items: start;
}

.dp-left { /* auto-sized to date content */ }

.dp-right {
  border-left: 1px solid var(--border);
  padding-left: 1rem;
  min-width: 0;
}

.dp-bs-date {
  font-family: 'Mukta', sans-serif;
  font-size: 3rem;
  font-weight: 800;
  color: var(--gold);
  line-height: 1;
}
.dp-month-year {
  font-family: 'Mukta', sans-serif;
  font-size: .85rem;
  color: var(--text-dim);
  margin-top: .1rem;
}
.dp-day {
  font-family: 'Mukta', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-top: .4rem;
}
.dp-ad {
  font-size: .68rem;
  color: var(--text-muted);
  margin-top: .1rem;
}

.dp-close {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 50%;
  width: 28px; height: 28px;
  cursor: pointer;
  font-size: .85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.dp-close:hover { background: var(--red-bg); color: var(--red); }

.dp-events {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  margin-bottom: .75rem;
}

.dp-event-chip {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .4rem .7rem;
  border-radius: var(--radius-sm);
  font-family: 'Mukta', sans-serif;
  font-size: .9rem;
  font-weight: 500;
}
.dp-event-chip.ev-holiday {
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: var(--red);
}
.dp-event-chip.ev-general {
  background: var(--gold-bg);
  border: 1px solid rgba(180, 83, 9, .2);
  color: var(--gold);
}

.dp-pancha-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem .75rem;
}
.dp-pancha-row { display: flex; flex-direction: column; gap: .1rem; }
.dp-pancha-label {
  font-size: .58rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  font-weight: 700;
}
.dp-pancha-val {
  font-family: 'Mukta', sans-serif;
  font-size: .9rem;
  color: var(--text-dim);
  line-height: 1.3;
}

/* ─── Loading / Error ────────────────────────────────── */
.cal-loading {
  padding: 3.5rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
}
.cal-error {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--red);
  font-size: .85rem;
}

/* ─── Responsive: Tablet (600–900px) ────────────────── */
@media (max-width: 900px) {
  #nep-cal-root {
    grid-template-columns: 1fr;
    grid-template-areas:
      "sidebar"
      "main"
      "holidays";
    gap: 1rem;
  }

  #cal-sidebar { position: static; }
  #today-card { padding: 1.1rem 1.25rem; }
  .tc-date { font-size: 3.6rem; }
}

/* ─── Responsive: Mobile (<600px) ───────────────────── */
@media (max-width: 600px) {
  #nep-cal-root {
    padding: .85rem .75rem 2.5rem;
    gap: .85rem;
  }

  /* Today card: compact date, tighter padding */
  #today-card { padding: .85rem 1rem; }
  .tc-date { font-size: 3rem; }
  .tc-month-year { font-size: .9rem; }
  .tc-day { font-size: 1.05rem; margin-top: .4rem; }
  .tc-divider { margin: .6rem 0; }

  /* Controls: label stacked above buttons */
  #cal-controls {
    padding: .55rem .7rem;
    gap: .45rem;
  }

  .cal-month-label {
    order: -1;
    width: 100%;
    font-size: 1rem;
    text-align: center;
    padding-bottom: .25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: .1rem;
  }
  /* Hide English subtitle inside label on mobile — prevents text wrap */
  .cal-month-label .en { display: none; }

  .cal-nav-btn { width: 32px; height: 32px; font-size: 1rem; }

  .cal-dropdowns { flex: 1; }
  .cal-select { height: 30px; font-size: .75rem; flex: 1; }
  .cal-today-btn { height: 30px; font-size: .72rem; padding: 0 .65rem; }

  /* Grid cells */
  .cal-cell { min-height: 54px; padding: .35rem .35rem .3rem; }
  .cal-cell-bs { font-size: .95rem; }
  .cal-cell-ad { font-size: .56rem; }
  .cal-cell-event { display: none; }

  /* Popup: full centered card on mobile */
  #day-popup-overlay {
    align-items: center;
    padding: .75rem;
  }
  #day-popup {
    border-radius: var(--radius);
    max-height: 90vh;
  }
  .dp-handle { display: none; }
  .dp-pancha-grid { grid-template-columns: 1fr; gap: .4rem; }
  .dp-bs-date { font-size: 2.5rem; }
}

/* ─── Responsive: Very small (<380px) ───────────────── */
@media (max-width: 380px) {
  .tc-date { font-size: 2.6rem; }
  .cal-cell { min-height: 46px; }
  .cal-cell-bs { font-size: .85rem; }
  .cal-cell-ad { display: none; }
  .pl-inner { width: 220px; }
  .pl-icon { font-size: 2.2rem; }
  .pl-title { font-size: 1.1rem; }
}
