:root { --primary-color: #3498db; --secondary-color: #2ecc71; --danger-color: #e74c3c; --warning-color: #f39c12; --bg-color: #f4f7f9; --card-bg: #ffffff; --text-color: #34495e; --border-color: #e0e4e8; --header-color: #2c3e50; --pinned-color: rgba(241, 196, 15, 0.1); --pinned-border: #f1c40f; --shadow-color: rgba(40,40,80,0.07); --footer-color: #7f8c8d;}
body.dark-theme { --bg-color: #2c3e50; --card-bg: #34495e; --text-color: #ecf0f1; --border-color: #4b6584; --header-color: #ffffff; --pinned-color: rgba(241, 196, 15, 0.15); --shadow-color: rgba(0,0,0,0.2); --footer-color: #bdc3c7;}
*, *::before, *::after { box-sizing: border-box; }
body { font-family: 'Vazirmatn', sans-serif; background-color: var(--bg-color); color: var(--text-color); margin: 0; padding: 1.5rem; transition: background-color 0.3s, color 0.3s; }
.container { max-width: 1600px; margin: 0 auto; }
.header { display: flex; justify-content: center; align-items: center; margin-bottom: 1rem; position: relative; }
h1 { color: var(--header-color); text-align: center; margin: 0; }
#theme-toggle { position: absolute; right: 0; top: 50%; transform: translateY(-50%); font-size: 1.5rem; background: none; border: none; color: var(--text-color); cursor: pointer; padding: 0; width: auto; }
.card { background: var(--card-bg); border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem; box-shadow: 0 8px 20px var(--shadow-color); border: 1px solid var(--border-color); transition: background-color 0.3s, border-color 0.3s; }
details { transition: all 0.3s ease; }
summary { font-weight: 700; color: var(--primary-color); font-size: 1.4rem; cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
summary::after { content: '▼'; font-size: 0.8em; transition: transform 0.3s ease-in-out; }
details[open] summary::after { transform: rotate(180deg); }
.details-content { overflow: hidden; max-height: 0; opacity: 0; transition: max-height 0.5s ease-out, opacity 0.3s ease-out 0.1s, padding-top 0.5s ease-out; }
details[open] .details-content { max-height: 2000px; opacity: 1; padding-top: 1rem; }
.grid-layout { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.5rem; }
.grid-layout-2-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.5rem; }
.input-group { display: flex; flex-direction: column; gap: 0.5rem; }
.dynamic-item { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.predefined-block { display: grid; grid-template-columns: 80px 1fr 40px; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
input, select, button { font-family: 'Vazirmatn', sans-serif; font-size: 1rem; padding: 0.75rem; border-radius: 8px; border: 1px solid var(--border-color); background-color: var(--bg-color); color: var(--text-color); width: 100%; }
select { -webkit-appearance: none; -moz-appearance: none; appearance: none; background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e"); background-repeat: no-repeat; background-position: left 0.75rem center; background-size: 1em; }
button { cursor: pointer; color: white; border: none; transition: transform 0.2s ease, opacity 0.2s ease; }
button:hover { transform: translateY(-2px); opacity: 0.9; }
.btn-add { background-color: var(--secondary-color); margin-top: 0.5rem; }
.btn-delete { background-color: var(--danger-color); padding: 0.5rem; font-size: 0.8rem; width: auto; }
.actions { display: flex; justify-content: center; gap: 1rem; margin-top: 1.5rem; }
.main-action-btn { background-color: var(--primary-color); padding: 0.8rem 2rem; font-size: 1.2rem; }
.export-btn { background-color: #9b59b6; }
.alert-box { display: none; text-align: center; padding: 1rem; margin-bottom: 1.5rem; border-radius: 8px; font-weight: 500; }
.alert-warning { background-color: #fef5e7; color: #b9770e; border: 1px solid var(--warning-color); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.8rem; text-align: center; border-bottom: 1px solid var(--border-color); }
thead th { color: var(--primary-color); }
.editable-duration { cursor: pointer; transition: background-color 0.3s ease; border-radius: 4px; padding: 5px 0; }
.editable-duration:hover { background-color: rgba(52, 152, 219, 0.1); }
tr.pinned { background-color: var(--pinned-color); }
.pinned .editable-duration { font-weight: bold; }
.switch-container { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 28px; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(22px); }
hr { margin: 1.5rem 0; border: none; border-top: 1px solid var(--border-color); }
#loader { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); z-index: 9999; }
.spinner { position: absolute; top: 50%; left: 50%; border: 8px solid #f3f3f3; border-top: 8px solid var(--primary-color); border-radius: 50%; width: 60px; height: 60px; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: translate(-50%, -50%) rotate(0deg); } 100% { transform: translate(-50%, -50%) rotate(360deg); } }
#a4-landscape-export-container { display: none; position: absolute; left: -9999px; width: 297mm; min-height: 210mm; padding: 15mm; background: white; box-sizing: border-box; color: #333; }
#a4-landscape-export-container h1 { font-size: 24pt; color: #333; margin-bottom: 10mm; }
#a4-landscape-export-container table { width: 100%; border-collapse: collapse; font-size: 10pt; }
#a4-landscape-export-container th, #a4-landscape-export-container td { border: 1px solid #aaa; padding: 8px; text-align: right; vertical-align: top; }
#a4-landscape-export-container th { background-color: #f2f2f2; text-align: center; }
#a4-landscape-export-container .day-col { font-weight: bold; width: 8%; text-align: center; background-color: #f9f9f9; vertical-align: middle; }
#a4-landscape-export-container .plan-col { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
#a4-landscape-export-container .plan-item { background-color: #eaf2f8; border: 1px solid #bdc3c7; border-radius: 12px; padding: 5px 10px; font-size: 9pt; display: inline-block; }
footer { text-align: center; margin-top: 2rem; color: var(--footer-color); font-size: 0.9rem; transition: color 0.3s; }
/* ========================
   Priority controls styling
   ======================== */

/* کانتینر هر آیتم اولویت */
.priority-item {
  display: flex;
  align-items: center;
  justify-content: space-between; /* متن در سمت راست، کنترل‌ها در سمت چپ (rtl) */
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(240,244,255,0.9), rgba(240,244,255,0.85));
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
  font-weight: 500;
}

/* متن اولویت */
.priority-item .prio-text {
  flex: 1 1 auto;
  text-align: right;
  margin-right: 6px;
  color: var(--header-color);
  font-size: 0.98rem;
}

/* کانتینر دکمه‌ها کوچک کنار متن */
.priority-item .prio-controls {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  margin-left: 6px; /* فاصلهٔ کمی از متن */
}

/* خود دکمه‌ها — کوچک و گرد */
.priority-item .prio-controls button {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 0.72rem;
  line-height: 1;
  border-radius: 6px;
  border: 0;
  background: rgba(44,62,80,0.06);
  color: var(--header-color);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.18s, transform 0.12s;
  cursor: pointer;
}

/* افکت ها هنگام hover و active */
.priority-item .prio-controls button:hover {
  background: rgba(52,152,219,0.12);
  transform: translateY(-2px);
}
.priority-item .prio-controls button:active {
  transform: translateY(0);
  background: rgba(52,152,219,0.18);
}

/* کوچک‌تر کردن فاصله بین دکمه‌ها در صفحه‌های کوچک */
@media (max-width: 600px) {
  .priority-item .prio-controls button {
    width: 34px;
    height: 34px;
    font-size: 0.85rem;
  }
  .priority-item { padding: 10px; }
}

/* اگر می‌خواهید آیکون به‌جای متن ▲/▼ استفاده شود (اختیاری)،
   از فونت آیکون یا SVG می‌توانید استفاده کنید:
.priority-item .prio-controls button::before { content: '\25B2'; } */
/* Fix: priority item colors should follow --text-color (works for light & dark themes) */
.priority-item .prio-text {
  color: var(--text-color) !important;
}

/* Dark-theme specific tweaks */
body.dark-theme .priority-item {
  background: linear-gradient(180deg, rgba(70,85,110,0.12), rgba(44,62,80,0.08));
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}

body.dark-theme .priority-item .prio-controls button {
  background: rgba(255,255,255,0.04);
  color: var(--text-color);
}

body.dark-theme .priority-item .prio-controls button:hover {
  background: rgba(255,255,255,0.06);
}

/* If you want the control buttons to be more visible in dark mode */
body.dark-theme .priority-item .prio-controls button {
  border: 1px solid rgba(255,255,255,0.04);
}

/* Optional: slightly brighten the text on hover in dark mode for clarity */
body.dark-theme .priority-item:hover .prio-text {
  color: #ffffff; /* یا یک مقدار روشن‌تر که دوست دارید */
}
/* ---------- Section 4 scroll & details improvements ---------- */
/* اطمینان می‌دهد که محتوای بخش برنامه روزانه هنگام کمبود ارتفاع صفحه قابل اسکرول باشد */
#daily-schedule-container {
  max-height: calc(55vh); /* پیش‌فرض: تا 55% ارتفاع پنجره */
  overflow: auto;
  padding-right: 6px; /* برای ظاهر بهتر در rtl */
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.15) transparent;
}

/* وقتی داخل جزئیات باز است، کمی فضای عمودی بیشتری بده */
details[open] #daily-schedule-container {
  max-height: calc(60vh);
}

/* اگر صفحه خیلی کوتاه بود (مثلاً موبایل)، ارتفاع را بر اساس viewport کمتر کن */
@media (max-height: 700px) {
  #daily-schedule-container { max-height: calc(48vh); }
  details[open] #daily-schedule-container { max-height: calc(52vh); }
}

/* بهتر کردن scrollbar برای وب‌کیت */
#daily-schedule-container::-webkit-scrollbar { width: 10px; }
#daily-schedule-container::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.12); border-radius: 8px;
}
#daily-schedule-container::-webkit-scrollbar-track { background: transparent; }

/* اگر محتوای details خیلی طولانی بود، محتوای داخل آن هم اسکرول‌پذیر شود */
.details-content { overflow: visible; } /* default */
details[open] .details-content { overflow: hidden; } /* preserve animation */
details[open] .details-content > * {
  /* محتواهای درونی (مثل daily container) خودشان اسکرول داشته باشند */
}

/* ---------- Responsive: When screen is narrow (mobile), stack everything ---------- */
@media (max-width: 900px) {
  .grid-layout { grid-template-columns: 1fr !important; }
  .grid-layout-2-col { grid-template-columns: 1fr !important; }
  input, select, button { font-size: 0.95rem; padding: 0.6rem; }
  .header { padding: 0 0.5rem; }
  .priority-item .prio-controls button { width: 36px; height: 36px; }
  #daily-schedule-container { max-height: calc(50vh); }
}

/* ---------- Small UX tweak: smooth scroll inside details when opened ---------- */
details summary { scroll-margin-top: 10vh; } /* if you scroll to summary, leave gap */
/* =========================
   Modern A4 export styling
   ========================= */
/* =========================
   Modern A4 export styling (Improved)
   ========================= */
#a4-landscape-export-container {
  display: block;
  width: 297mm;
  min-height: 210mm;
  padding: 18mm;
  box-sizing: border-box;
  background: #ffffff;
  color: #1b2b3b;
  border-radius: 12px;
  font-family: 'Vazirmatn', sans-serif;
  position: relative;
  overflow: hidden;
}

/* Title */
#a4-landscape-export-container h1 {
  font-size: 22pt;
  margin: 0 0 14px 0;
  color: #0f2230;
  text-align: center;
}

/* Legend: horizontal scroll if overflow */
#a4-landscape-export-container .legend {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 10px 0 14px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(245,247,250,0.95);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
#a4-landscape-export-container .legend::-webkit-scrollbar { height: 8px; }
#a4-landscape-export-container .legend::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 8px; }

/* legend item */
#a4-landscape-export-container .legend .legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.9);
  border: 1px solid rgba(20,30,40,0.03);
  font-size: 10pt;
  white-space: nowrap;
}

/* modern table wrapper */
#a4-landscape-export-container .export-table-wrap {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(20,30,40,0.06);
  box-shadow: 0 6px 20px rgba(18, 38, 63, 0.06);
}

/* table */
#a4-landscape-export-container table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 10.5pt;
  direction: rtl; /* ensure RTL rendering */
}

/* header */
#a4-landscape-export-container thead th {
  padding: 12px 14px;
  background: linear-gradient(180deg, #fbfdff, #f1f6fb);
  color: #0b2940;
  font-weight: 700;
  border-bottom: 1px solid rgba(20,30,40,0.06);
}

/* rounded corners for top header cells */
#a4-landscape-export-container thead th:first-child { border-top-right-radius: 12px; }
#a4-landscape-export-container thead th:last-child { border-top-left-radius: 12px; }

/* body cells */
#a4-landscape-export-container tbody td {
  padding: 12px 14px;
  vertical-align: middle;
  border-bottom: 1px solid rgba(20,30,40,0.04);
  text-align: right;
  color: #21323e;
}

/* alternating subtle background for rows */
#a4-landscape-export-container tbody tr:nth-child(odd) td { background: #ffffff; }
#a4-landscape-export-container tbody tr:nth-child(even) td { background: #fbfdff; }

/* day column */
#a4-landscape-export-container .day-col {
  width: 9%;
  font-weight: 700;
  text-align: center;
  color: #0f2230;
  border-left: 1px solid rgba(20,30,40,0.03);
}

/* plan item chip */
#a4-landscape-export-container .plan-item {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 6px 8px 6px 0;
  padding: 8px 12px;
  border-radius: 14px;
  background: rgba(246,251,255,0.95);
  box-shadow: 0 1px 4px rgba(12,24,40,0.04);
  border: 1px solid rgba(20,30,40,0.03);
  font-size: 10pt;
  min-height: 36px;
}

/* subject badge (circle) */
#a4-landscape-export-container .subject-badge {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  border: 1px solid rgba(255,255,255,0.6);
}

/* label inside chip */
#a4-landscape-export-container .plan-label {
  color: #0f2230;
  font-weight: 600;
}

/* small footer note bottom-right */
#a4-landscape-export-container .export-footer {
  position: absolute;
  right: 18mm;
  bottom: 10mm;
  font-size: 8.5pt;
  color: #6b7280;
  opacity: 0.95;
}

/* print-friendly: remove shadows for printing */
@media print {
  #a4-landscape-export-container { box-shadow: none; border: none; }
  #a4-landscape-export-container .legend { box-shadow: none; }
}
/* =========================
   A4 export — higher-contrast chips
   ========================= */

/* افزایش کنتراست کلی */
#a4-landscape-export-container {
  color: #0f2530; /* تیره‌تر از قبل */
}

/* چیپ (plan-item) واضح‌تر و برجسته‌تر */
#a4-landscape-export-container .plan-item {
  background: rgba(246,250,255,0.96); /* کمی روشن‌تر اما کمتر شفاف */
  border: 1px solid rgba(20,30,40,0.06); /* حاشیه مشخص‌تر */
  box-shadow: 0 3px 10px rgba(12,24,40,0.06);
  padding: 8px 14px;
  border-radius: 14px;
  min-height: 40px;
  align-items: center;
  gap: 12px;
}

/* دایرهٔ رنگی بزرگتر و واضح‌تر */
#a4-landscape-export-container .subject-badge {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  border: 1px solid rgba(255,255,255,0.6);
  flex: 0 0 auto;
}

/* متن چیپ پررنگ و با کنتراست بیشتر */
#a4-landscape-export-container .plan-label {
  color: #08202a;
  font-weight: 700;
  font-size: 10.5pt;
  white-space: nowrap;
}

/* اگر می‌خواهید پس‌زمینه چیپ از رنگ درس مشتق شود،
   border را کمی تیره‌تر می‌کنیم تا جلوی محو شدن را بگیریم */
#a4-landscape-export-container .plan-item[data-hue] {
  /* no-op: data-hue در JS تنظیم می‌شود تا در صورت نیاز CSS تغییر کند */
}

/* legend سایهٔ ملایم و خواناتر */
#a4-landscape-export-container .legend .legend-item {
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 600;
  color: #0f2a34;
  border: 1px solid rgba(20,30,40,0.04);
}

/* footer */
#a4-landscape-export-container .export-footer {
  color: #6b7280;
  font-weight: 500;
}
/* ---------- Top subjects legend (main UI) ---------- */
.subjects-legend {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;           /* allow wrapping to next line instead of overflowing */
  padding: 10px 12px;
  margin: 16px 0;
  border-radius: 12px;
  background: rgba(250,252,255,0.9);
  border: 1px solid rgba(20,30,40,0.04);
  overflow: hidden;
  max-width: 100%;
}

/* make it scroll horizontally on very small widths */
.subjects-legend { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.subjects-legend::-webkit-scrollbar { height: 8px; }
.subjects-legend::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.08); border-radius: 6px; }

/* each chip */
.subjects-legend .legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid rgba(20,30,40,0.03);
  white-space: nowrap;
  min-height: 36px;
  font-weight: 600;
  font-size: 0.95rem;
}

/* badge circle */
.subjects-legend .legend-badge {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  border: 1px solid rgba(255,255,255,0.6);
}

/* text */
.subjects-legend .legend-text { padding-right: 4px; color: var(--header-color); }

/* responsive: on small screens increase spacing and allow wrapping more */
@media (max-width: 720px) {
  .subjects-legend .legend-chip { padding: 8px 12px; font-size: 0.9rem; }
  .subjects-legend .legend-badge { width: 16px; height: 16px; }
}
html, body {
  overflow-x: hidden;
}

#a4-landscape-export-container {
  display: none;
  position: absolute;
  left: -9999px;
  top: 0;
  max-width: 100%;
  overflow: hidden;
}
/* باکس‌های درس در خروجی PDF */

