/*
 * Torah Portion Widget — Sidebar Calendar Style
 * All classes prefixed tw- to avoid conflicts with the host site.
 */

/* ── CONTAINER ─────────────────────────────────────────────────────────────── */
.tw-widget {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: var(--tw-base-size, 14px);
  line-height: 1.5;
  color: var(--tw-color-text, #1a1a1a);
  background: var(--tw-color-bg, #fff);
  border: 1px solid var(--tw-color-border, #c8a870);
  border-radius: 8px;
  width: 100%;
  max-width: var(--tw-max-width, 300px);
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,0,0,0.10);
}

/* ── MONTH CALENDAR ───────────────────────────────────────────────────────── */
.tw-calendar {
  padding: 0.95em 1em 0.85em;
  background:
    linear-gradient(180deg, var(--tw-color-cal-bg, #fff8ea) 0%, var(--tw-color-bg, #fff) 100%);
  border-bottom: 1px solid var(--tw-color-cal-border, #e8d5b7);
}

.tw-calendar-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75em;
  align-items: flex-start;
  margin-bottom: 0.75em;
}

.tw-calendar-kicker {
  font-family: sans-serif;
  font-size: 0.68em;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #9a7040;
}

.tw-calendar-title {
  font-family: sans-serif;
  font-size: 1em;
  font-weight: 700;
  color: #4a2c0a;
}

.tw-calendar-head-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35em;
}

.tw-calendar-legend {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.25em;
  justify-content: flex-end;
}

.tw-legend {
  font-family: sans-serif;
  font-size: 0.6em;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 0.22em 0.4em;
  color: #4a2c0a;
  white-space: nowrap;
}

.tw-legend--regular {
  background: #efe2c8;
}

.tw-legend--special {
  background: #f0dec1;
}

.tw-legend--feast {
  background: #e7c88b;
}

.tw-calendar-weekdays,
.tw-cal-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.2em;
}

.tw-calendar-weekdays {
  margin-bottom: 0.3em;
}

.tw-calendar-weekdays span {
  font-family: sans-serif;
  font-size: 0.62em;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #9a7040;
  text-align: center;
}

.tw-calendar-weeks {
  display: flex;
  flex-direction: column;
  gap: 0.45em;
}

.tw-cal-week {
  width: 100%;
  border: 1px solid var(--tw-color-week-border, #ead8ba);
  border-radius: 10px;
  background: var(--tw-color-bg, #fff);
  padding: 0.5em 0.55em 0.6em;
  text-align: left;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.tw-cal-week:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(122, 74, 26, 0.10);
}

.tw-cal-week.is-selected {
  border-color: var(--tw-color-week-sel, #7a4a1a);
  box-shadow: 0 0 0 1px rgba(122, 74, 26, 0.18);
}

.tw-cal-week--regular {
  background: linear-gradient(180deg, #fff 0%, #fcf7ef 100%);
}

.tw-cal-week--special {
  background: linear-gradient(180deg, #fffaf0 0%, #fdf1dc 100%);
}

.tw-cal-week--feast {
  background: linear-gradient(180deg, #fff6df 0%, #f5e0ad 100%);
}

.tw-cal-day {
  font-family: sans-serif;
  font-size: 0.75em;
  line-height: 1;
  padding: 0.38em 0;
  border-radius: 6px;
  text-align: center;
  color: #5e4321;
}

.tw-cal-day.is-outside {
  color: #c5ae8a;
}

.tw-cal-day.is-today {
  font-weight: 700;
  color: #7a3d00;
}

.tw-cal-day.is-selected {
  background: rgba(74, 44, 10, 0.12);
  font-weight: 700;
}

.tw-cal-reading {
  margin-top: 0.45em;
  display: flex;
  flex-direction: column;
  gap: 0.18em;
}

.tw-cal-badge {
  align-self: flex-start;
  font-family: sans-serif;
  font-size: 0.62em;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #4a2c0a;
  background: rgba(255,255,255,0.72);
  border-radius: 999px;
  padding: 0.2em 0.55em;
}

.tw-cal-title-text {
  font-family: sans-serif;
  font-size: 0.8em;
  font-weight: 700;
  color: #3c2208;
  line-height: 1.35;
}

.tw-cal-note {
  font-family: sans-serif;
  font-size: 0.68em;
  color: #8a6336;
  line-height: 1.35;
}

/* ── HEADER ─────────────────────────────────────────────────────────────────── */
.tw-header {
  padding: 0.9em 1em 0.8em;
  background: linear-gradient(135deg, var(--tw-color-header-bg1, #4a2c0a) 0%, var(--tw-color-header-bg2, #7a4a1a) 100%);
  color: var(--tw-color-header-text, #fff);
}

.tw-week-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: sans-serif;
  font-size: 0.72em;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.75;
  margin-bottom: 0.5em;
}

.tw-toggle-btn {
  background: none;
  border: none;
  color: #9a7040;
  cursor: pointer;
  font-size: 0.75em;
  line-height: 1;
  padding: 0.15em 0.3em;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
}

.tw-toggle-btn:hover {
  color: #4a2c0a;
  background: rgba(74, 44, 10, 0.08);
}

/* ── COLLAPSED CALENDAR ──────────────────────────────────────────────────────── */
.tw-calendar--collapsed .tw-calendar-weekdays,
.tw-calendar--collapsed .tw-calendar-weeks {
  display: none;
}

.tw-calendar--collapsed {
  padding-bottom: 0.75em;
}

/* ── NAVIGATION ─────────────────────────────────────────────────────────────── */
.tw-nav {
  display: flex;
  align-items: center;
  gap: 0.25em;
  margin-bottom: 0.4em;
}

.tw-nav-btn {
  flex-shrink: 0;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  color: #fff;
  font-size: 1.4em;
  line-height: 1;
  width: 1.6em;
  height: 1.6em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  padding: 0;
}

.tw-nav-btn:hover {
  background: rgba(255,255,255,0.28);
}

.tw-nav-center {
  flex: 1;
  text-align: center;
  min-width: 0;
}

.tw-parasha {
  font-size: 0.95em;
  font-weight: bold;
  letter-spacing: 0.01em;
  line-height: 1.3;
}

.tw-nav-label {
  font-family: sans-serif;
  font-size: 0.72em;
  opacity: 0.75;
  margin-top: 0.1em;
}

.tw-meta {
  font-family: sans-serif;
  font-size: 0.75em;
  opacity: 0.82;
  display: flex;
  flex-wrap: wrap;
  gap: 0 0.6em;
}

.tw-meta span + span::before {
  content: '\00b7  ';
}

/* ── READING ROWS ───────────────────────────────────────────────────────────── */
.tw-readings {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tw-reading {
  border-bottom: 1px solid var(--tw-color-cal-border, #e8d5b7);
}

.tw-reading:last-child {
  border-bottom: none;
}

.tw-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  width: 100%;
  padding: 0.65em 1em;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  gap: 0.5em;
  transition: background 0.12s;
  font-family: inherit;
}

.tw-row:hover {
  background: var(--tw-color-row-hover, #faf5ec);
}

.tw-row[aria-expanded="true"] {
  background: var(--tw-color-row-exp, #fdf4e3);
}

.tw-row-left {
  display: flex;
  flex-direction: column;
  gap: 0.1em;
  min-width: 0;
}

.tw-row-label {
  font-family: sans-serif;
  font-size: 0.8em;
  font-weight: 700;
  color: #4a2c0a;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tw-row-sub {
  font-family: sans-serif;
  font-size: 0.72em;
  color: #9a7040;
  font-style: italic;
}

.tw-row-right {
  display: flex;
  align-items: flex-start;
  gap: 0.4em;
  flex-shrink: 0;
  max-width: 58%;
}

.tw-row-ref {
  font-family: sans-serif;
  font-size: 0.75em;
  color: #5a3a10;
  font-weight: 600;
  text-align: right;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  word-break: break-word;
  line-height: 1.35;
}

.tw-chevron {
  font-size: 1.1em;
  color: var(--tw-color-chevron, #c8a870);
  transition: transform 0.2s;
  line-height: 1;
  flex-shrink: 0;
}

.tw-row[aria-expanded="true"] .tw-chevron {
  transform: rotate(90deg);
}

/* ── EXPANDED BODY ──────────────────────────────────────────────────────────── */
.tw-body {
  padding: 0.75em 1em 0.9em;
  border-top: 1px solid var(--tw-color-cal-border, #e8d5b7);
  background: var(--tw-color-body-bg, #fdfaf5);
  max-height: none;
  overflow: visible;
}

.tw-verses {
  margin: 0 0 0.6em;
  font-size: 0.88em;
  line-height: 1.95;
  overflow-wrap: anywhere;
}

.tw-verse {
  display: inline;
}

.tw-verse sup {
  font-family: sans-serif;
  font-size: 0.65em;
  font-weight: 600;
  color: #b08040;
  margin-right: 0.1em;
  vertical-align: super;
  line-height: 0;
}

.tw-tri-block + .tw-tri-block {
  margin-top: 0.75em;
  padding-top: 0.75em;
  border-top: 1px dashed #e0c898;
}

.tw-plan-block + .tw-plan-block {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--tw-color-cal-border, #e8d5b7);
}

.tw-plan-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75em;
  margin: 0 0 0.65em;
  font-family: sans-serif;
}

.tw-plan-head strong {
  font-size: 0.8em;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #4a2c0a;
}

.tw-plan-head span,
.tw-source-link {
  font-size: 0.72em;
  color: #8a6336;
}

.tw-source-link {
  text-decoration: none;
}

.tw-source-link:hover {
  text-decoration: underline;
}

.tw-reading-head {
  margin: 0 0 0.45em;
  display: flex;
  flex-direction: column;
  gap: 0.1em;
  font-family: sans-serif;
}

.tw-reading-head strong {
  font-size: 0.78em;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #4a2c0a;
}

.tw-reading-head span {
  font-size: 0.72em;
  color: #8a6336;
}

.tw-read-more {
  display: inline-block;
  margin-top: 0.5em;
  font-family: sans-serif;
  font-size: 0.75em;
  color: #7a3d00;
  text-decoration: none;
}

.tw-read-more:hover {
  text-decoration: underline;
}

.tw-empty {
  font-family: sans-serif;
  font-size: 0.82em;
  color: #9a7040;
  font-style: italic;
  margin: 0;
}

/* ── NT SUB-TABS ─────────────────────────────────────────────────────────────── */
.tw-nt-sub {
  border-top: 1px solid #ede0c8;
}

.tw-nt-sub:first-child {
  border-top: none;
}

.tw-nt-sub-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.55em 0.9em;
  background: #fdf8f0;
  border: none;
  cursor: pointer;
  text-align: left;
  font-family: sans-serif;
  gap: 0.5em;
  transition: background 0.12s;
}

.tw-nt-sub-btn:hover {
  background: #f7efe0;
}

.tw-nt-sub-btn[aria-expanded="true"] {
  background: #f3e8d4;
}

.tw-nt-sub-label {
  font-size: 0.78em;
  font-weight: 700;
  color: #4a2c0a;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.tw-nt-sub-ref {
  font-size: 0.72em;
  color: #7a5030;
  font-weight: 600;
  flex: 1;
  text-align: right;
  padding-right: 0.4em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tw-nt-chevron {
  font-size: 1em;
  color: #c8a870;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.tw-nt-sub-btn[aria-expanded="true"] .tw-nt-chevron {
  transform: rotate(90deg);
}

.tw-nt-sub-body {
  padding: 0.6em 0.9em 0.75em;
  background: #fdfaf5;
}

.tw-nt-ref-list {
  list-style: none;
  margin: 0 0 0.5em;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3em;
}

.tw-nt-ref-link {
  font-family: sans-serif;
  font-size: 0.8em;
  font-weight: 600;
  color: #5a3a10;
  text-decoration: none;
  display: inline-block;
  padding: 0.15em 0;
}

.tw-nt-ref-link:hover {
  color: #7a3d00;
  text-decoration: underline;
}

.tw-nt-ref-source {
  font-family: sans-serif;
  font-size: 0.68em;
  color: #b09070;
  margin: 0.4em 0 0;
}

.tw-nt-ref-source a {
  color: #7a5030;
  text-decoration: none;
}

.tw-nt-ref-source a:hover {
  text-decoration: underline;
}

/* ── FOOTER ─────────────────────────────────────────────────────────────────── */
.tw-footer {
  padding: 0.5em 1em;
  background: var(--tw-color-body-bg, #faf6f0);
  border-top: 1px solid var(--tw-color-cal-border, #e8d5b7);
  font-family: sans-serif;
  font-size: 0.7em;
  color: #b09070;
  text-align: center;
}

.tw-footer a {
  color: #7a5030;
  text-decoration: none;
}

.tw-footer a:hover {
  text-decoration: underline;
}

/* ── LOADING ─────────────────────────────────────────────────────────────────── */
.tw-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5em 1em;
  font-family: sans-serif;
  font-size: 0.85em;
  color: #9a8060;
  gap: 0.75em;
}

.tw-loading p { margin: 0; }

.tw-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--tw-color-cal-border, #e8d5b7);
  border-top-color: var(--tw-color-week-sel, #7a3d00);
  border-radius: 50%;
  animation: tw-spin 0.8s linear infinite;
}

@keyframes tw-spin { to { transform: rotate(360deg); } }

/* ── ERROR ───────────────────────────────────────────────────────────────────── */
.tw-widget--error {
  padding: 1.25em 1em;
  font-family: sans-serif;
  font-size: 0.85em;
  text-align: center;
  color: #7a3d00;
}

.tw-widget--error a { color: #7a3d00; }

@media (max-width: 480px) {
  .tw-calendar-head {
    flex-direction: column;
  }

  .tw-calendar-legend {
    justify-content: flex-start;
  }

  .tw-row-right {
    max-width: 52%;
  }
}
