/* ── Reset & base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Noto Sans', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  background: #f5f5f5;
  color: #222;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
header {
  background: #1a237e;
  color: #fff;
  padding: 12px 20px;
  display: flex;
  align-items: center;
}
header h1 { font-size: 18px; font-weight: 600; flex: 1; }
header h1 span { color: #90caf9; font-weight: 400; }

#btn-logout {
  padding: 5px 14px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.30);
  color: #fff;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
#btn-logout:hover { background: rgba(255,255,255,0.25); }

/* ── Controls ───────────────────────────────────────────────────────────── */
#controls {
  background: #fff;
  border-bottom: 1px solid #ddd;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ctrl-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}
label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: #555;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
label.compare-toggle {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
  color: #333;
  cursor: pointer;
}
select, input[type="number"], input[type="text"] {
  padding: 5px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
  min-width: 120px;
}
input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.hidden { display: none !important; }

/* ── City autocomplete ──────────────────────────────────────────────────── */
.city-label { position: relative; }

.city-input-wrap { position: relative; }

#inp-city { min-width: 160px; width: 160px; }
#inp-city:focus { outline: none; border-color: #5c6bc0; box-shadow: 0 0 0 2px rgba(92,107,192,0.15); }

.city-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  min-width: 300px;
  max-height: 260px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #c5cae9;
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 500;
  /* Reset label inheritance — label has text-transform:uppercase, letter-spacing, etc. */
  text-transform: none;
  letter-spacing: normal;
  font-weight: normal;
  font-size: 13px;
  color: #222;
}
.city-dropdown.open { display: block; }

.city-option {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 7px 10px;
  cursor: pointer;
  gap: 8px;
  border-bottom: 1px solid #f0f0f0;
}
.city-option:last-child { border-bottom: none; }
.city-option.highlighted { background: #e8eaf6; }

.city-opt-name { font-size: 13px; color: #222; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.city-opt-tz   { font-size: 11px; color: #888; flex-shrink: 0; }

.custom-toggle-wrap {
  display: flex;
  flex-direction: column;
  gap: 3px;
  /* Invisible label spacer so the link aligns with the bottom of other controls */
  padding-top: 14px;
}
.custom-link { font-size: 11px; color: #5c6bc0; text-decoration: none; white-space: nowrap; letter-spacing: normal; text-transform: none; font-weight: 500; }
.custom-link:hover { text-decoration: underline; }
button.primary {
  padding: 6px 18px;
  background: #1a237e;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}
button.primary:hover { background: #283593; }
button.primary:disabled { background: #9fa8da; cursor: default; }
#status { font-size: 12px; color: #666; align-self: center; }

/* ── Tabs ───────────────────────────────────────────────────────────────── */
#tabs {
  display: flex;
  gap: 0;
  padding: 0 20px;
  background: #fff;
  border-bottom: 2px solid #e8eaf6;
}
.tab {
  padding: 10px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #666;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.tab:hover { color: #1a237e; }
.tab.active { color: #1a237e; border-bottom-color: #1a237e; }

/* ── Views ──────────────────────────────────────────────────────────────── */
.view { padding: 16px 20px; }

/* ── Calendar legend ────────────────────────────────────────────────────── */
#calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 11px;
}
.leg-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.leg-item::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
}
.leg-item.shukla::before    { background: #e8f5e9; border: 1px solid #a5d6a7; }
.leg-item.krishna::before   { background: #ede7f6; border: 1px solid #ce93d8; }
.leg-item.pournami::before  { background: #fff9c4; border: 1px solid #f9a825; }
.leg-item.amavasya::before  { background: #37474f; }
.leg-item.festival::before  { background: #e3f2fd; border: 1px solid #42a5f5; }
.leg-item.diff::before      { background: #fff3e0; border: 1px solid #ff9800; }

/* ── Calendar grid ──────────────────────────────────────────────────────── */
#calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  background: #ccc;
  border: 1px solid #ccc;
}

/* Day-of-week header */
.cal-header {
  background: #1a237e;
  color: #fff;
  text-align: center;
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

/* Empty filler cells */
.cal-empty { background: #f0f0f0; }

/* Day cells */
.cal-cell {
  background: #fff;
  padding: 5px 6px;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  transition: box-shadow 0.1s;
}
.cal-cell:hover { box-shadow: inset 0 0 0 2px #5c6bc0; }

/* Paksha colouring */
.cal-cell.shukla   { background: #f1f8e9; }
.cal-cell.krishna  { background: #f3e5f5; }
.cal-cell.pournami { background: #fffde7; border: 1px solid #f9a825; }
.cal-cell.amavasya { background: #263238; color: #eceff1; }

/* Diff highlight in compare mode */
.cal-cell.has-diff { border: 2px solid #ff9800; }

/* Day number row */
.cell-date {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.cell-day-num {
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}
.cell-vara {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #888;
  opacity: 0.8;
}
.amavasya .cell-vara { color: #b0bec5; }

/* Panchangam lines */
.cell-line {
  font-size: 10px;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell-line.muted { color: #777; }
.amavasya .cell-line { color: #cfd8dc; }
.amavasya .cell-line.muted { color: #90a4ae; }

.cell-times {
  display: flex;
  gap: 8px;
  font-size: 10px;
  color: #555;
  margin-top: 1px;
}
.amavasya .cell-times { color: #90a4ae; }
.time-sr::before { content: '↑ '; }
.time-rahu::before { content: '☿ '; }

/* Festival badges */
.cell-festivals { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.fest-badge {
  font-size: 9px;
  background: #e3f2fd;
  color: #0d47a1;
  border-radius: 3px;
  padding: 1px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Comparison lines */
.cmp-block { display: flex; flex-direction: column; gap: 1px; margin-top: 1px; }
.cmp-row {
  display: flex;
  gap: 3px;
  font-size: 10px;
  align-items: baseline;
}
.cmp-label {
  font-size: 9px;
  font-weight: 700;
  min-width: 18px;
  color: #888;
  text-transform: uppercase;
}
.cmp-val { color: #333; }
.cmp-val.diff {
  color: #e65100;
  font-weight: 600;
  background: #fff3e0;
  border-radius: 2px;
  padding: 0 2px;
}
.amavasya .cmp-label { color: #78909c; }
.amavasya .cmp-val   { color: #cfd8dc; }
.amavasya .cmp-val.diff { background: #4e342e; color: #ffb74d; }

/* ── Table view ─────────────────────────────────────────────────────────── */
#table-wrap {
  overflow-x: auto;
}
#data-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
  background: #fff;
}
#data-table th {
  background: #1a237e;
  color: #fff;
  padding: 7px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
#data-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #eee;
  white-space: nowrap;
  vertical-align: top;
}
#data-table tr:hover td { background: #f5f5f5; }

/* Table row paksha colouring */
#data-table tr.shukla  td { background: #f1f8e9; }
#data-table tr.krishna td { background: #f3e5f5; }
#data-table tr.pournami td { background: #fffde7; }
#data-table tr.amavasya td { background: #263238; color: #eceff1; }
#data-table tr:hover td { filter: brightness(0.96); }

/* Comparison: second tradition row */
#data-table tr.cmp-row td {
  padding-top: 2px;
  padding-bottom: 5px;
  font-size: 11px;
  color: #555;
  border-bottom: 2px solid #e8eaf6;
}
#data-table tr.cmp-row.amavasya td { color: #90a4ae; }
.trad-label {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  text-transform: uppercase;
  margin-right: 4px;
}
.trad-label.primary { background: #e8eaf6; color: #1a237e; }
.trad-label.compare { background: #fce4ec; color: #880e4f; }

/* Diff highlight in table */
td.diff-cell {
  background: #fff3e0 !important;
  color: #e65100 !important;
  font-weight: 600;
}
.amavasya td.diff-cell { background: #4e342e !important; color: #ffb74d !important; }

/* Festival cell */
.fest-list { display: flex; flex-direction: column; gap: 2px; }
.tbl-fest {
  display: inline-block;
  font-size: 10px;
  background: #e3f2fd;
  color: #0d47a1;
  border-radius: 3px;
  padding: 1px 5px;
}

/* Selected cell highlight */
.cal-cell.selected {
  outline: 2px solid #5c6bc0;
  outline-offset: -2px;
  z-index: 1;
  position: relative;
}

/* ── Compare view ───────────────────────────────────────────────────────── */
#cmp-controls {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.cmp-date-label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: #555;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
input[type="date"] {
  padding: 5px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
}
#cmp-status { font-size: 12px; color: #666; align-self: center; }

#cmp-legend {
  display: flex;
  gap: 14px;
  margin-bottom: 10px;
  font-size: 11px;
  flex-wrap: wrap;
}
.cmp-leg {
  display: flex;
  align-items: center;
  gap: 5px;
}
.cmp-leg::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
}
.cmp-leg.match::before { background: #c8e6c9; border: 1px solid #81c784; }
.cmp-leg.close::before  { background: #fff9c4; border: 1px solid #f9a825; }
.cmp-leg.diff::before   { background: #ffcdd2; border: 1px solid #e57373; }
.cmp-leg.miss::before   { background: #f5f5f5; border: 1px solid #bbb; }

#cmp-table-wrap { overflow-x: auto; }

.cmp-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
  background: #fff;
  min-width: 600px;
}

.cmp-th-field {
  background: #1a237e;
  color: #fff;
  padding: 8px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  min-width: 120px;
  position: sticky;
  left: 0;
  z-index: 2;
}
.cmp-th-src {
  background: #3949ab;
  color: #fff;
  padding: 8px 14px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: pre;        /* renders \n line-breaks in textContent */
  line-height: 1.5;
  min-width: 140px;
}
.cmp-th-src.src-error { background: #6d4c41; opacity: 0.85; }

.cmp-td-field {
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #f5f5f5;
  border-bottom: 1px solid #e0e0e0;
  position: sticky;
  left: 0;
  white-space: nowrap;
}
.cmp-td-val {
  padding: 6px 14px;
  text-align: center;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid #eeeeee;
  border-left: 1px solid #eeeeee;
}
/* Reference column (AG Engine) */
.cmp-td-val.ref   { background: #e8eaf6; font-weight: 600; color: #1a237e; }
/* Match statuses for comparison columns */
.cmp-td-val.match { background: #c8e6c9; color: #1b5e20; font-weight: 500; }
.cmp-td-val.close { background: #fff9c4; color: #f57f17; font-weight: 500; }
.cmp-td-val.diff  { background: #ffcdd2; color: #b71c1c; font-weight: 600; }
.cmp-td-val.miss  { background: #f5f5f5; color: #bbb; font-style: italic; }

/* Stripe alternate field groups */
.cmp-table tbody tr:nth-child(even) .cmp-td-field { background: #eeeeee; }

/* ── Detail modal (full-page) ───────────────────────────────────────────── */
#detail-panel {
  position: fixed;
  inset: 0;
  background: #f0f2f8;
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#detail-panel.hidden { display: none; }

#dp-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 24px;
  background: #1a237e;
  color: #fff;
  flex-shrink: 0;
}
#dp-close {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 5px 14px;
  border-radius: 4px;
  flex-shrink: 0;
  white-space: nowrap;
}
#dp-close:hover { background: rgba(255,255,255,0.28); }
#dp-title-block { flex: 1; }
#dp-date-line {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}
#dp-meta-line {
  font-size: 11px;
  color: #90caf9;
  margin-top: 2px;
}

#dp-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px 32px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
  align-content: start;
}

/* ── Detail modal: sections (cards) ────────────────────────────────────── */
.dp-section {
  background: #fff;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.dp-sec-hdr {
  padding: 5px 14px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff;
  text-transform: uppercase;
}
.dp-sec-body { padding: 6px 0 8px; }

/* ── Detail panel: rows ─────────────────────────────────────────────────── */
.dp-row {
  display: flex;
  align-items: baseline;
  padding: 3px 14px;
  gap: 8px;
}
.dp-label {
  font-size: 11px;
  color: #888;
  min-width: 96px;
  flex-shrink: 0;
  font-weight: 500;
}
.dp-val {
  font-size: 12px;
  color: #222;
  font-weight: 500;
  flex: 1;
}
.dp-sub {
  font-size: 11px;
  color: #777;
  padding: 0 14px 3px 110px;
  line-height: 1.4;
}
.dp-sublabel {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #aaa;
  padding: 6px 14px 2px;
}

/* ── Slot grids (choghadiya, gowri, hora) ───────────────────────────────── */
.dp-slot-grid { padding: 0 14px 4px; }
.dp-slot-row {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  align-items: center;
  padding: 2px 0;
  font-size: 11px;
  border-radius: 3px;
}
.dp-slot-time {
  color: #666;
  font-variant-numeric: tabular-nums;
  font-size: 10px;
}
.dp-slot-name { font-weight: 500; color: #222; }
.dp-slot-rating {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1px 5px;
  border-radius: 3px;
}
.dp-hora-row .dp-slot-name { color: #1a237e; }

/* Rating colours */
.slot-good   .dp-slot-name   { color: #2E7D32; }
.slot-good   .dp-slot-rating { background: #e8f5e9; color: #2E7D32; }
.slot-bad    .dp-slot-name   { color: #B71C1C; }
.slot-bad    .dp-slot-rating { background: #ffebee; color: #B71C1C; }
.slot-neutral .dp-slot-name   { color: #546E7A; }
.slot-neutral .dp-slot-rating { background: #eceff1; color: #546E7A; }

/* ── Special yogas grid ─────────────────────────────────────────────────── */
.dp-yoga-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 4px;
  padding: 4px 14px 6px;
}
.dp-yoga-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  padding: 5px 8px;
  border-radius: 4px;
}
.yoga-active  { background: #e8f5e9; }
.yoga-inactive { background: #fafafa; }
.yoga-main {
  display: flex;
  align-items: center;
  gap: 5px;
}
.yoga-check {
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.yoga-active  .yoga-check { color: #2E7D32; }
.yoga-inactive .yoga-check { color: #ccc; }
.yoga-name { color: #444; }
.yoga-active .yoga-name { color: #1B5E20; font-weight: 600; }
.yoga-window {
  font-size: 10px;
  color: #388E3C;
  padding-left: 18px;
  font-variant-numeric: tabular-nums;
}

/* ── Festival items ─────────────────────────────────────────────────────── */
.dp-fest-item {
  padding: 6px 14px;
  border-bottom: 1px solid #f5f5f5;
}
.dp-fest-item:last-child { border-bottom: none; }
.dp-fest-name {
  font-size: 13px;
  font-weight: 600;
  color: #1a237e;
}
.dp-fest-cat {
  font-size: 10px;
  color: #888;
  margin-top: 1px;
}
.dp-fest-badge {
  display: inline-block;
  font-size: 9px;
  background: #fff3e0;
  color: #e65100;
  border-radius: 3px;
  padding: 1px 5px;
  margin-top: 2px;
  font-weight: 600;
}

