:root {
  /* Default: Classic Navy Blue & Red */
  --primary-color: #1a2556;
  --accent-color: #dc2626;
}

/* Mga Color Themes */
body.theme-navy {
  --primary-color: #1a2556;
  --accent-color: #dc2626;
}

body.theme-black {
  --primary-color: #111827;
  --accent-color: #dc2626;
}

body.theme-teal {
  --primary-color: #0d3b43;
  --accent-color: #dc2626;
}

body.theme-violet {
  --primary-color: #3b145a;
  --accent-color: #dc2626;
}

body.theme-green {
  --primary-color: #0e3d23;
  --accent-color: #dc2626;
}

body.theme-maroon {
  --primary-color: #4a0d16;
  --accent-color: #b45309;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: Arial, "Helvetica Neue", sans-serif;
}

body {
  background-color: #1e293b;
  display: flex;
  min-height: 100vh;
}

/* Control Panel */
.control-panel {
  width: 310px;
  background: #0f172a;
  color: #fff;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  box-shadow: 2px 0 12px rgba(0,0,0,0.5);
  z-index: 100;
  flex-shrink: 0;
}

.panel-header {
  border-bottom: 1px solid #334155;
  padding-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.back-link {
  color: #38bdf8;
  font-size: 0.82rem;
  text-decoration: none;
  font-weight: bold;
  display: inline-block;
  margin-bottom: 2px;
  transition: color 0.15s;
}

.back-link:hover {
  color: #7dd3fc;
  text-decoration: underline;
}

.control-panel h2 {
  font-size: 1.15rem;
  color: #fff;
  margin: 0;
}

.badge-a {
  display: inline-block;
  align-self: flex-start;
  background: #334155;
  color: #38bdf8;
  font-size: 0.7rem;
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 4px;
  margin-top: 2px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.control-group label {
  font-size: 0.82rem;
  color: #94a3b8;
}

.control-group input, 
.control-group select {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #475569;
  background: #1e293b;
  color: #fff;
  font-size: 0.9rem;
}

.primary-btn {
  margin-top: 8px;
  padding: 12px;
  background: var(--accent-color);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: bold;
  font-size: 0.95rem;
  cursor: pointer;
  transition: 0.15s;
}

.primary-btn:hover {
  filter: brightness(0.9);
}

/* Workspace Canvas */
.calendar-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  gap: 30px;
  overflow: auto;
}

/* Siguraduhing eksakto ang sheet sukat sa export */
.calendar-sheet {
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  box-sizing: border-box;
  padding: 16mm 6mm 6mm 6mm; /* Sapat na espasyo para sa metal tin clip */
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.size-long  { width: 8.5in; height: 13in; }
.size-short { width: 8.5in; height: 11in; }
.size-a4    { width: 210mm; height: 297mm; }
.size-a3    { width: 297mm; height: 420mm; }

/* Double Ornamental Frame na 100% Supported ng Canvas at PDF Export */
.calendar-frame {
  border: 4px solid var(--primary-color);
  padding: 4px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: #ffffff;
  /* SVG striped pattern kapalit ng repeating-linear-gradient */
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><path d="M-2,2 l4,-4 M0,8 l8,-8 M6,10 l4,-4" stroke="%231a2556" stroke-width="2.2"/></svg>');
  background-repeat: repeat;
  box-sizing: border-box;
}

/* Kapag nagpalit ng Theme, susunod ang kulay ng ornamental border */
body.theme-black .calendar-frame {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><path d="M-2,2 l4,-4 M0,8 l8,-8 M6,10 l4,-4" stroke="%23111827" stroke-width="2.2"/></svg>');
}
body.theme-teal .calendar-frame {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><path d="M-2,2 l4,-4 M0,8 l8,-8 M6,10 l4,-4" stroke="%230d3b43" stroke-width="2.2"/></svg>');
}
body.theme-violet .calendar-frame {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><path d="M-2,2 l4,-4 M0,8 l8,-8 M6,10 l4,-4" stroke="%233b145a" stroke-width="2.2"/></svg>');
}
body.theme-green .calendar-frame {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><path d="M-2,2 l4,-4 M0,8 l8,-8 M6,10 l4,-4" stroke="%230e3d23" stroke-width="2.2"/></svg>');
}
body.theme-maroon .calendar-frame {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><path d="M-2,2 l4,-4 M0,8 l8,-8 M6,10 l4,-4" stroke="%234a0d16" stroke-width="2.2"/></svg>');
}

.calendar-inner-core {
  background: #ffffff;
  border: 3px solid var(--primary-color);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

/* 1. Top Banner / Picture Space */
.banner-area {
  height: 38%;
  border-bottom: 3px solid var(--primary-color);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background: #fdfdfd;
}

.banner-area img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.banner-placeholder {
  border: 2px dashed #94a3b8;
  padding: 30px 40px;
  color: #64748b;
  font-weight: bold;
  text-align: center;
}

/* 2. Calendar Header */
.cal-header {
  display: grid;
  grid-template-columns: 160px 1fr 160px;
  height: 68px;
  border-bottom: 3px solid var(--primary-color);
  flex-shrink: 0;
}

.year-box {
  background: var(--primary-color);
  color: #ffffff;
  font-size: 3.2rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Impact", Arial Black, sans-serif;
  letter-spacing: 2px;
  line-height: 1;
}

.month-box {
  background: var(--accent-color);
  color: #ffffff;
  font-size: 3.4rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 6px;
  font-family: "Impact", Arial Black, sans-serif;
  line-height: 1;
}

/* 3. Araw ng Linggo */
.weekdays-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  border-bottom: 2px solid var(--primary-color);
  font-weight: 900;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.weekdays-row div {
  padding: 4px 0;
  border-right: 1px solid var(--primary-color);
  color: var(--primary-color);
}

.weekdays-row div:last-child {
  border-right: none;
}

.weekdays-row .sun-col {
  color: var(--accent-color);
}

/* 4. Main Grid ng mga Araw */
.days-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(5, 1fr);
  border-bottom: 2px solid var(--primary-color);
}

.cell {
  border-right: 1px solid var(--primary-color);
  border-bottom: 1px solid var(--primary-color);
  padding: 2px 4px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.cell:nth-child(7n) {
  border-right: none;
}

.cell:nth-child(n+29) {
  border-bottom: none;
}

.cell-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
}

.lunar-char {
  writing-mode: vertical-rl;
  font-size: 0.72rem;
  font-weight: bold;
  color: var(--accent-color);
  line-height: 1;
  padding-top: 2px;
}

.day-number {
  font-size: 3.8rem;
  font-weight: 900;
  line-height: 0.85;
  color: var(--primary-color);
  font-family: "Impact", Arial Black, sans-serif;
  margin-left: auto;
}

.sunday-cell .day-number,
.holiday-cell .day-number {
  color: var(--accent-color);
}

.holiday-name {
  font-size: 0.65rem;
  font-weight: bold;
  color: var(--accent-color);
  text-align: right;
  line-height: 1.1;
  margin-top: auto;
}

/* Split Box */
.split-cell {
  position: relative;
  overflow: hidden;
  padding: 0 !important;
}

.split-diagonal-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.split-diagonal-svg line {
  stroke: var(--primary-color);
}

.split-top-left {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 2.8rem;
  font-weight: 900;
  font-family: "Impact", Arial Black, sans-serif;
  line-height: 0.9;
  z-index: 2;
  color: var(--primary-color);
}

.split-bottom-right {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 2.8rem;
  font-weight: 900;
  font-family: "Impact", Arial Black, sans-serif;
  line-height: 0.9;
  z-index: 2;
  color: var(--primary-color);
}

.sunday-cell .split-top-left,
.sunday-cell .split-bottom-right {
  color: var(--accent-color);
}

/* Moon SVG Cells */
.moon-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4px 2px;
  gap: 2px;
}

.moon-title {
  font-size: 0.62rem;
  font-weight: 900;
  color: var(--accent-color);
  letter-spacing: 0.5px;
  line-height: 1;
}

.moon-svg {
  width: 30px;
  height: 30px;
  display: block;
  margin: 1px auto;
}

.moon-svg circle, 
.moon-svg path {
  stroke: var(--accent-color);
}

.moon-svg circle[fill="#dc2626"], 
.moon-svg path[fill="#dc2626"] {
  fill: var(--accent-color) !important;
}

.moon-date {
  font-size: 0.68rem;
  font-weight: 900;
  color: var(--primary-color);
  line-height: 1;
}

/* 5. Bottom Panel: Para sa A4, Long, at Short */
.bottom-panel {
  display: grid;
  grid-template-columns: 1fr 2.9fr 1fr;
  height: 154px;
  padding: 4px;
  gap: 5px;
  flex-shrink: 0;
  box-sizing: border-box;
}

.mini-cal, .holiday-box {
  border: 1.5px solid var(--primary-color);
  padding: 4px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.section-tag {
  background: var(--accent-color);
  color: #fff;
  font-weight: 900;
  text-align: center;
  padding: 2.5px 0;
  font-size: 0.72rem;
  letter-spacing: 1px;
  margin-bottom: 3px;
  flex-shrink: 0;
}

.holiday-columns-container {
  display: flex;
  flex: 1;
  gap: 12px;
  padding: 1px 4px;
  overflow: hidden;
}

.holiday-col {
  list-style: none;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin: 0;
  padding: 0;
}

.holiday-col li {
  display: flex;
  align-items: center;
  line-height: 1.2;
  white-space: nowrap;
  font-size: 0.61rem;
}

.holiday-col li b {
  color: var(--primary-color);
  width: 48px;
  flex-shrink: 0;
  display: inline-block;
  font-size: 0.61rem;
}

.holiday-col li span {
  color: #0f172a;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-title {
  font-weight: 900;
  text-align: center;
  font-size: 0.7rem;
  color: var(--primary-color);
  border-bottom: 1px solid var(--primary-color);
  padding-bottom: 2px;
  margin-bottom: 2px;
  flex-shrink: 0;
}

.mini-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-weight: 900;
  font-size: 0.58rem;
  color: var(--primary-color);
  border-bottom: 1px dashed #cbd5e1;
  padding-bottom: 2px;
  flex-shrink: 0;
}

.mini-weekdays span:first-child {
  color: var(--accent-color);
}

.mini-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 13.5px;
  text-align: center;
  font-size: 0.63rem;
  font-weight: bold;
  color: var(--primary-color);
  margin-top: 2px;
  align-items: center;
}

.mini-blank {
  visibility: hidden;
}

/* ====================================================
   FIXED PRINT RULES (FIREFOX, CHROME & MOBILE COMPLIANT)
   ==================================================== */
@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
    box-sizing: border-box !important;
  }

  html, body {
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: visible !important;
  }

  .control-panel,
  .preview-pill,
  .modal-overlay {
    display: none !important;
  }

  .calendar-wrapper {
    padding: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    overflow: visible !important;
  }

  .calendar-sheet {
    box-shadow: none !important;
    margin: 0 auto !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    
    /* Pinalitan ang 100vw at 100vh na nagdudulot ng putol sa footer sa mobile at Firefox */
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    
    /* Balanced padding para iwas tapyas sa ibaba */
    padding: 12mm 6mm 4mm 6mm !important;
  }

  .calendar-sheet:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }
}

/* A3 Calibrated Adjustments */
.size-a3 { padding: 30mm 10mm 10mm 10mm; }
.size-a3 .cal-header { height: 95px; grid-template-columns: 220px 1fr 220px; }
.size-a3 .year-box { font-size: 4.8rem; }
.size-a3 .month-box { font-size: 5rem; letter-spacing: 8px; }
.size-a3 .weekdays-row { height: 38px; font-size: 1.6rem; }
.size-a3 .day-number { font-size: 5.6rem; }
.size-a3 .lunar-char { font-size: 1rem; }
.size-a3 .holiday-name { font-size: 0.9rem; }
.size-a3 .split-top-left, .size-a3 .split-bottom-right { font-size: 4rem; }
.size-a3 .moon-svg { width: 44px; height: 44px; }
.size-a3 .moon-title { font-size: 0.85rem; }
.size-a3 .moon-date { font-size: 0.95rem; }

.size-a3 .bottom-panel { 
  height: 200px; 
  grid-template-columns: 1fr 3.1fr 1fr; 
  gap: 8px; 
}
.size-a3 .section-tag { font-size: 0.95rem; padding: 3.5px 0; margin-bottom: 4px; }
.size-a3 .holiday-columns-container { gap: 20px; padding: 2px 6px; }
.size-a3 .holiday-col li { font-size: 0.81rem; line-height: 1.25; }
.size-a3 .holiday-col li b { width: 66px; font-size: 0.81rem; }
.size-a3 .mini-title { font-size: 0.85rem; padding-bottom: 2px; }
.size-a3 .mini-weekdays { font-size: 0.72rem; }
.size-a3 .mini-grid { font-size: 0.78rem; grid-auto-rows: 18px; margin-top: 2px; }

/* ====================================================
   MOBILE PREVIEW ONLY (DESKTOP MASTER INTACT)
   ==================================================== */
   @media screen and (max-width: 900px) {
    body {
      flex-direction: column !important;
      min-height: auto !important;
    }
  
    .control-panel {
      width: 100% !important;
      padding: 16px !important;
    }
  
    .calendar-wrapper {
      width: 100% !important;
      padding: 16px 0 !important;
      overflow-x: hidden !important;
      display: flex !important;
      justify-content: center !important;
      align-items: flex-start !important;
    }
  
    /* Preview zoom lamang para magkasya sa screen ng phone nang hindi sinisira ang desktop CSS */
    .calendar-sheet {
      zoom: 0.42;
      margin: 0 auto !important;
    }
  }
  
  @media screen and (max-width: 480px) {
    .calendar-sheet {
      zoom: 0.36; /* Para sa mas maliliit na smartphone screens */
    }
  }

  /* Mobile preview fix lamang para sa in-upload na banner image */
  .banner-area {
    overflow: hidden !important;
    position: relative !important;
  }

  .banner-area img {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: cover !important;
    object-position: center !important;
    display: block !important;
  }


/* ====================================================
   MOBILE PRINT-ONLY OVERRIDE (Android / iOS Print Spooler)
   Hindi maaapektuhan ang Mozilla o Chrome Desktop
   ==================================================== */
   @media print and (max-width: 900px) {
    .calendar-sheet {
      /* Bahagyang bawas sa top padding para sa mobile spooler margin */
      padding: 6mm 5mm 2mm 5mm !important;
      height: 98% !important;
      max-height: 98% !important;
      overflow: hidden !important;
    }
  
    /* Bawasan ng kaunti ang banner at bottom panel sa mobile print */
    .calendar-sheet .banner-area {
      height: 34% !important;
    }
  
    .calendar-sheet .bottom-panel {
      height: 125px !important;
      padding: 2px !important;
    }
  }