/* Accessible calendar tool. Follows the site's visual language (style.css
   tokens): strong focus rings (WCAG 2.4.7), 44px touch targets, high contrast
   in both themes, and colour is never the only cue (tense is also written). */

.caltool {
  max-width: 46rem;
  margin: 1.5rem auto;
}

.caltool-head h1 {
  margin-bottom: 0.5rem;
}

.caltool-lead {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
}

.caltool-form {
  padding: 1.1rem 1.25rem 1.25rem;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
}

.caltool fieldset {
  margin: 0 0 1rem;
  padding: 0;
  border: 0;
}

.caltool legend {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
  padding: 0;
}

.caltool-radios {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.caltool-radio {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.35rem 0.9rem;
  border: 2px solid var(--border-color);
  border-radius: 999px;
  cursor: pointer;
}

.caltool-radio:has(input:checked) {
  border-color: var(--accent-color);
  font-weight: 700;
}

.caltool-radio input {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  accent-color: var(--accent-color);
}

.caltool-fields {
  display: grid;
  grid-template-columns: minmax(5rem, 1fr) minmax(10rem, 2fr) minmax(6rem, 1fr);
  gap: 0.9rem;
}

@media (max-width: 560px) {
  .caltool-fields {
    grid-template-columns: 1fr;
  }
}

.caltool-field label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.caltool-field input,
.caltool-field select {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.65rem;
  font-size: 1.05rem;
  border: 2px solid var(--text-muted);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-main);
}

.caltool-field input[aria-invalid="true"],
.caltool-field select[aria-invalid="true"] {
  border-color: #b91c1c;
}

.caltool-hint,
.caltool-tip,
.caltool-note {
  margin: 0.3rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.caltool-tip {
  margin-top: 0.75rem;
}

.caltool-field-error {
  margin: 0.35rem 0 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: #b91c1c;
}

[data-theme="dark"] .caltool-field-error {
  color: #fca5a5;
}

.caltool-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.caltool-submit {
  min-height: 44px;
  padding: 0.55rem 1.4rem;
  font-size: 1.05rem;
  font-weight: 700;
  border: 0;
  border-radius: 8px;
  background: var(--accent-color);
  color: #fff;
  cursor: pointer;
}

.caltool-submit:hover {
  background: var(--accent-hover);
}

/* Secondary action: outlined, so it does not compete with "Show the day". */
.caltool-copy {
  min-height: 44px;
  padding: 0.4rem 1.1rem;
  font: inherit;
  font-weight: 600;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
}

.caltool-copy:hover {
  border-color: var(--accent-color);
}

/* The answer in one line under the buttons; it updates while typing. */
.caltool-quick {
  margin: 0.9rem 0 0;
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  background: var(--bg-color);
  font-size: 1.1rem;
  line-height: 1.6;
}

.caltool-quick[hidden] {
  display: none;
}

/* The fields are mid-edit and no longer match this answer. */
.caltool-quick.is-stale {
  opacity: 0.6;
}

.caltool-quick a {
  color: var(--text-main);
  text-decoration: none;
}

.caltool-quick a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.caltool-quick strong {
  font-size: 1.2em;
  font-weight: 800;
}

.caltool-today {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 0.9rem;
  border: 2px solid var(--accent-color);
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-main);
}

.caltool-nav a,
.caltool-help a {
  color: var(--text-main);
}

.caltool-output:empty {
  display: none;
}

.caltool-errors,
.caltool-result {
  margin-top: 1.5rem;
  padding: 1.1rem 1.25rem 1.25rem;
  border-radius: 12px;
  background: var(--card-bg);
  box-shadow: var(--shadow-md);
}

.caltool-errors {
  border: 2px solid #b91c1c;
}

.caltool-errors h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
}

.caltool-errors ul {
  margin: 0;
  padding-inline-start: 1.25rem;
}

.caltool-errors a {
  color: var(--text-main);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.caltool-result {
  border: 1px solid var(--border-color);
  border-inline-start: 6px solid var(--accent-color);
}

.caltool-result.caltool-past {
  border-inline-start-color: #64748b;
}

.caltool-result.caltool-present {
  border-inline-start-color: #15803d;
}

.caltool-result.caltool-future {
  border-inline-start-color: #1d4ed8;
}

.caltool-result h2 {
  margin: 0 0 0.6rem;
  font-size: 1.5rem;
  line-height: 1.25;
}

/* Headline: the weekday is the answer, so it is the biggest thing on screen.
   The separator stays in the accessible name ("الأحد، 31 يناير") but is not
   drawn, since weekday and date sit on separate lines. */
.caltool-weekday {
  display: block;
  font-size: clamp(2.2rem, 7vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--accent-color);
}

.caltool-present .caltool-weekday { color: #15803d; }
[data-theme="dark"] .caltool-present .caltool-weekday { color: #86efac; }
.caltool-past .caltool-weekday { color: var(--text-main); }

.caltool-sep {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.caltool-date {
  display: block;
  margin-top: 0.15rem;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* The same day in the other calendar, right under the headline. */
.caltool-converted {
  margin: -0.3rem 0 0.7rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
}

.caltool-enter {
  animation: caltool-in 0.22s ease-out;
}

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

.caltool-grid td a:focus-visible,
.caltool-grid td a:focus {
  outline: 3px solid var(--text-main);
  outline-offset: 2px;
}

.caltool-badge {
  display: inline-block;
  margin: 0 0 0.6rem;
  padding: 0.15rem 0.75rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: 0.9rem;
  font-weight: 700;
}

.caltool-past .caltool-badge { color: #475569; }
.caltool-present .caltool-badge { color: #15803d; }
.caltool-future .caltool-badge { color: #1d4ed8; }
[data-theme="dark"] .caltool-past .caltool-badge { color: #cbd5e1; }
[data-theme="dark"] .caltool-present .caltool-badge { color: #86efac; }
[data-theme="dark"] .caltool-future .caltool-badge { color: #93c5fd; }

.caltool-sentence {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  font-weight: 600;
}

.caltool-subhead {
  margin: 1.25rem 0 0.5rem;
  font-size: 1.05rem;
}

.caltool-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0.5rem 1rem;
  margin: 0;
}

.caltool-details > div {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: var(--bg-color);
}

.caltool-details dt {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.caltool-details dd {
  margin: 0;
  font-weight: 600;
}

/* The day's occasion (Ramadan, Arafah, Eid…) stands out right under the
   headline sentences; the text itself says what it is. */
.caltool-occasion {
  display: inline-block;
  margin: 0.4rem 0 0.2rem;
  padding: 0.4rem 0.85rem;
  border-radius: 10px;
  background: rgba(21, 128, 61, 0.1);
  border: 1px solid rgba(21, 128, 61, 0.45);
  color: #14532d;
  font-weight: 700;
}

[data-theme="dark"] .caltool-occasion {
  background: rgba(134, 239, 172, 0.1);
  border-color: rgba(134, 239, 172, 0.45);
  color: #bbf7d0;
}

/* "Did you mean the other calendar?" hint under the result sentences. */
.caltool-tip-mismatch {
  margin: 0.5rem 0 0;
  padding: 0.45rem 0.85rem;
  border-inline-start: 4px solid #b45309;
  background: rgba(180, 83, 9, 0.08);
  border-radius: 6px;
  font-weight: 600;
}

[data-theme="dark"] .caltool-tip-mismatch {
  border-inline-start-color: #fbbf24;
  background: rgba(251, 191, 36, 0.1);
}

.caltool-cal {
  margin-top: 0.5rem;
}

/* Reference facts: a step quieter than the answer above them. */
.caltool-cal .caltool-details dd,
.caltool-other .caltool-details dd {
  font-size: 0.95rem;
}

.caltool-intro {
  margin: 0.75rem 0 0;
  line-height: 1.8;
}

/* The other calendar, collapsed by default: its summary already states the
   matching date, so most visitors never need to open it. */
.caltool-other {
  margin-top: 1.25rem;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-color);
}

.caltool-other > summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-weight: 700;
  border-radius: 10px;
  list-style: none;
}

.caltool-other > summary::-webkit-details-marker {
  display: none;
}

/* display:flex drops the browser's disclosure triangle, so draw one. The
   empty alt text keeps it out of what screen readers announce (they already
   say "collapsed"/"expanded"). */
.caltool-other > summary::after {
  content: "\25BE";
  content: "\25BE" / "";
  margin-inline-start: auto;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}

.caltool-other[open] > summary::after {
  transform: rotate(180deg);
}

.caltool-other > summary:hover {
  color: var(--accent-color);
}

.caltool-other-body {
  padding: 0 1rem 1rem;
}

.caltool-other-body .caltool-intro {
  margin-top: 0;
}

.caltool-other-body .caltool-details {
  margin-top: 0.75rem;
}

.caltool-other-body .caltool-details > div {
  background: var(--card-bg);
}

.caltool-help-text {
  margin: 0.75rem 0 0;
  line-height: 1.8;
}

.caltool-copyrow {
  margin: 1rem 0 0;
}

/* Nearby dates: one row each for day, month and year; "previous" on the
   start side, "next" on the end side. */
.caltool-nav ul {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.caltool-nav li.is-prev {
  grid-column: 1;
}

.caltool-nav li.is-next {
  grid-column: 2;
}

.caltool-nav a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  height: 100%;
  min-height: 44px;
  box-sizing: border-box;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  text-decoration: none;
}

.caltool-nav li.is-next a {
  justify-content: flex-end;
  text-align: end;
}

.caltool-nav a:hover {
  border-color: var(--accent-color);
}

.caltool-navarrow {
  flex: none;
  font-size: 1.15rem;
  color: var(--text-muted);
}

.caltool-navtitle {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.caltool-navdate {
  display: block;
  font-weight: 600;
}

.caltool-gridwrap {
  position: relative;
  margin-top: 1.25rem;
  overflow-x: auto;
}

/* Previous/next month arrows at the two ends of the table's title. */
.caltool-gridnav {
  position: absolute;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  box-sizing: border-box;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-main);
  font-size: 1.2rem;
  text-decoration: none;
}

.caltool-gridnav:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.caltool-gridnav-prev {
  inset-inline-start: 0;
}

.caltool-gridnav-next {
  inset-inline-end: 0;
}

/* The site styles every table as a card with dark header cells and roomy
   padding; the month grid needs none of that (the padding alone squeezed the
   day links to nothing on phones). */
.caltool-grid {
  width: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  overflow: visible;
  border-collapse: separate;
  border-spacing: 4px;
  table-layout: fixed;
  text-align: center;
}

.caltool-grid th,
.caltool-grid td {
  padding: 0;
  border: 0;
  background: transparent;
  text-align: center;
}

.caltool-grid caption {
  min-height: 44px;
  padding: 0.55rem 3.25rem 0.4rem;
  font-weight: 700;
  font-size: 1.1rem;
  text-align: center;
}

.caltool-grid-hint {
  display: block;
  font-weight: 400;
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* Keyboard instructions: kept for screen readers, shown on screen only while
   a day in the grid has keyboard focus. */
.caltool-grid-keys {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.caltool-gridwrap:has(a:focus-visible) .caltool-grid-keys {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
  display: block;
  margin-top: 0.2rem;
  font-weight: 400;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.caltool-grid th {
  padding: 0.35rem 0 0.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.caltool-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  margin: 0.6rem 0 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.caltool-key {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border-radius: 4px;
  box-sizing: border-box;
}

.caltool-key-selected {
  background: var(--accent-color);
}

.caltool-key-today {
  margin-inline-start: 0.75rem;
  border: 2px solid #15803d;
}

[data-theme="dark"] .caltool-key-today {
  border-color: #4ade80;
}

.caltool-grid td a {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 3.4rem;
  margin-inline: auto;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  text-decoration: none;
  color: var(--text-main);
}

.caltool-grid td a:hover {
  border-color: var(--accent-color);
}

.caltool-grid td.is-today a {
  border: 2px solid #15803d;
  font-weight: 700;
}

[data-theme="dark"] .caltool-grid td.is-today a {
  border-color: #4ade80;
}

.caltool-grid td.is-selected a {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: #fff;
  font-weight: 700;
}

.caltool-help {
  margin-top: 2rem;
  padding: 1rem 1.25rem;
  border: 1px dashed var(--border-color);
  border-radius: 12px;
}

.caltool-help h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.caltool-help ol {
  margin: 0 0 0.5rem;
  padding-inline-start: 1.4rem;
}

/* Keep focused targets clear of the sticky site header when scrolled to.
   calendar.js measures the header and sets the variable; the fallback
   covers the usual one-row header. */
.caltool [data-caltool-focus],
.caltool-field input,
.caltool-field select {
  scroll-margin-top: var(--caltool-scroll-offset, 6.5rem);
}

/* Phones: the site header scrolls away here, and every pixel of width goes
   to the month grid. */
@media (max-width: 640px) {
  .caltool [data-caltool-focus],
  .caltool-field input,
  .caltool-field select {
    scroll-margin-top: var(--caltool-scroll-offset, 1rem);
  }

  .caltool {
    margin-bottom: 4.5rem; /* room to scroll the last lines clear of the back-to-top button */
  }

  .caltool-form,
  .caltool-errors,
  .caltool-result {
    padding-inline: 0.85rem;
  }

  .caltool-grid {
    border-spacing: 3px;
  }

  .caltool-grid th {
    font-size: 0.75rem;
  }

  .caltool-nav a {
    gap: 0.35rem;
    padding-inline: 0.5rem;
  }

  .caltool-navdate {
    font-size: 0.9rem;
  }
}

/* The narrowest phones (320–400px): tighter title and headers so the
   month title stays short and every weekday fits its column. */
@media (max-width: 400px) {
  .caltool-grid caption {
    padding-inline: 2.85rem;
    font-size: 1rem;
  }

  .caltool-grid-hint {
    font-size: 0.8rem;
  }

  .caltool-gridnav {
    width: 40px;
    height: 40px;
  }

  .caltool-grid {
    border-spacing: 2px;
  }

  .caltool-grid th {
    font-size: 0.68rem;
    letter-spacing: -0.02em;
  }

  /* Decorative only; the column and the words "السابق/التالي" already say
     which way each link goes. */
  .caltool-navarrow {
    display: none;
  }
}

.caltool [data-caltool-focus]:focus {
  outline: 3px solid var(--accent-color);
  outline-offset: 4px;
  border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
  .caltool * {
    transition: none !important;
    animation: none !important;
  }
}
