/*!
 * jd-calendar.css — internal Jalali datepicker.
 *
 * Contains TWO things:
 *   1. the field wrapper styles (.jd-field / .jd-label / .jd-input / .jd-error)
 *      — these used to live in jd-bridge.css, which is no longer enqueued;
 *   2. the popover itself (.jdcp), which is portalled to <body>.
 *
 * The popover is `display:none` by default and only `display:block` while it
 * carries `.active`. That rule is the whole fix for "the calendar never
 * closes": removing `.active` has to actually hide it.
 *
 * Palette: navy #102a71 · gold #f5c400 · cream #fffdf0
 */

.jd-field { margin-bottom: 16px; }

.jd-label {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
  color: #102a71;
}

.jd-input { min-height: 40px; }
.jd-input:focus { border-color: #102a71; box-shadow: 0 0 0 2px rgba(16, 42, 113, .15); }

.jd-field.is-bad .jd-input { border-color: #d63638; background: #fdf3f3; }

.jd-error {
  margin: 8px 0 0;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.7;
  color: #8a1f1a;
  background: #fdf3f3;
  border: 1px solid #f3c2c2;
  border-radius: 6px;
}

.jd-error[hidden] { display: none; }

/* ------------------------------------------------------------------ popover */

.jdcp {
  position: absolute;
  z-index: 100099;
  width: 316px;
  max-width: calc(100vw - 16px);
  padding: 12px;
  border-radius: 14px;
  background: #fffdf0;
  border: 1px solid rgba(16, 42, 113, .18);
  box-shadow: 0 18px 48px -12px rgba(0, 24, 64, .35);
  direction: rtl;
  text-align: right;
  font-family: inherit;
  box-sizing: border-box;
  display: none;
  user-select: none;
}

.jdcp,
.jdcp * { box-sizing: border-box; }

.jdcp.active { display: block; }

.jdcp-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 32px;
}

.jdcp-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #102a71;
  cursor: pointer;
  transition: background .15s ease;
}

.jdcp-close:hover { background: rgba(16, 42, 113, .08); }
.jdcp-close:focus-visible { outline: 2px solid #f5c400; outline-offset: 2px; }

.jdcp-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.jdcp-navbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: rgba(16, 42, 113, .08);
  color: #102a71;
  cursor: pointer;
  transition: background .15s ease;
}

.jdcp-navbtn:hover { background: #f5c400; }
.jdcp-navbtn:focus-visible { outline: 2px solid #f5c400; outline-offset: 2px; }

.jdcp-title {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  color: #102a71;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s ease;
}

.jdcp-title::after {
  content: '\25BE';
  font-size: 10px;
  line-height: 1;
  color: rgba(16, 42, 113, .55);
}

.jdcp-title:hover { background: rgba(16, 42, 113, .08); }
.jdcp-title:focus-visible { outline: 2px solid #f5c400; outline-offset: 2px; }

/* ------------------------------------------------------------ year grid */

.jdcp-years { display: none; }

.jdcp.years .jdcp-years {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 8px;
  max-height: 264px;
  overflow-y: auto;
  padding-inline-end: 2px;
}

.jdcp.years .jdcp-weekdays,
.jdcp.years .jdcp-days { display: none; }

.jdcp-year {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 4px;
  border: 0;
  border-radius: 10px;
  background: rgba(16, 42, 113, .06);
  color: #102a71;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s ease;
}

.jdcp-year:hover { background: rgba(245, 196, 0, .28); }
.jdcp-year:focus-visible { outline: 2px solid #f5c400; outline-offset: 2px; }

.jdcp-weekdays,
.jdcp-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.jdcp-weekdays { margin-top: 8px; }

.jdcp-weekday {
  display: block;
  padding: 4px 0;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: #102a71;
}

.jdcp-days { margin-top: 2px; }

.jdcp-day {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #102a71;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background .15s ease;
}

.jdcp-day:hover { background: rgba(245, 196, 0, .28); }
.jdcp-day:focus-visible { outline: 2px solid #f5c400; outline-offset: -2px; }

.jdcp-selected {
  background: #f5c400;
  color: #102a71;
  font-weight: 700;
}

.jdcp-blank { visibility: hidden; }

.jdcp-foot {
  display: flex;
  justify-content: center;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(16, 42, 113, .1);
}

.jdcp-today {
  padding: 7px 16px;
  border: 0;
  border-radius: 10px;
  background: rgba(16, 42, 113, .08);
  color: #102a71;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s ease;
}

.jdcp-today:hover { background: #f5c400; }
.jdcp-today:focus-visible { outline: 2px solid #f5c400; outline-offset: 2px; }

@media (max-width: 640px) {
  .jdcp {
    width: auto;
    left: 8px !important;
    right: 8px;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .jdcp *,
  .jdcp-close,
  .jdcp-navbtn,
  .jdcp-day,
  .jdcp-today { transition: none !important; }
}
