:root {
  --teal: #0f5959;
  --cream: #fdf3e0;
  --cream-cell: #fbeed6;
  --orange: #e0973b;
  --brown: #8a5230;
  --tan: #eaca8c;
  --ink: #123;
  --muted: #b7a98c;
  --line: #004D53;

  /* Patti heights (scaled from the PDF: 3388px wide).
     Title 135px, Day 156px, Subject band 75px -> * ~0.37 */
  --h-title: 50px;
  --h-day: 58px;
  --h-band: 28px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: var(--cream);
  color: var(--ink);
}

/* ---------- Public calendar ---------- */
.cal-wrap {
  max-width: 1300px;
  margin: 0 auto;
  padding: 22px;
}

.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--teal);
  color: #fff;
  border-radius: 14px;
  padding: 0 26px;
  height: var(--h-title);
}
.cal-header h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: .3px;
  display: flex;
  align-items: center;
}
.cal-header h1::before {
  content: "";
  flex: none;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--orange);
  margin-right: 12px;
}
.cal-tagline {
  font-family: "Dancing Script", cursive;
  font-weight: 600;
  font-size: 34px;
  opacity: .95;
  white-space: nowrap;
}
.cal-logo {
  height: calc(var(--h-title) - 10px);
  width: auto;
  max-width: 150px;
  object-fit: contain;
  border-radius: 6px;
  display: block;
}

.cal-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 2px;
}
.cal-nav button {
  background: var(--teal);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 15px;
  cursor: pointer;
}
.cal-nav button:hover { background: #0c4a4a; }
.cal-nav #clearBtn { background: #c0392b; }
.cal-nav #clearBtn:hover { background: #a5311f; }
.cal-nav #undoBtn, .cal-nav #redoBtn { background: #0d6e6e; }
.cal-nav #undoBtn:hover, .cal-nav #redoBtn:hover { background: #0a5757; }
.cal-nav button:disabled { opacity: .4; cursor: default; box-shadow: none; transform: none; }
.cal-nav .spacer { flex: 1; }
.cal-nav .nav-sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }
.cal-select {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--teal);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
}

/* Highlight ring over the week that contains the focused date. */
.week-focus-ring {
  grid-column: 1 / 8;
  grid-row: 1 / -1;
  border: 3px solid var(--orange);
  border-radius: 6px;
  pointer-events: none;
  z-index: 2;
}
.cal-nav a {
  color: var(--teal);
  text-decoration: none;
  font-weight: 600;
}

/* Teal rounded frame around the whole calendar (like the PDF). */
.cal-frame {
  border: 3px solid var(--teal);
  border-radius: 14px;
  overflow: hidden;
  background: var(--cream);
}

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  background: var(--teal);
  color: #fff;
}
.weekday-row div {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: var(--h-day);
  padding: 0 12px;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .5px;
  overflow: hidden;
  min-width: 0;
}
.weekday-row .wd-short { display: none; }

.calendar {
  overflow: hidden;
}

.week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-top: 1px solid var(--line);
}
.week:first-child { border-top: 0; }

.week-bg { z-index: 0; }
/* Full-height vertical column separators (continuous, even through band rows). */
.col-div {
  grid-row: 1 / -1;
  border-left: 1px solid #004D53;
  z-index: 2;                 /* above the tan patti so the line stays continuous */
  pointer-events: none;
}
.date-num, .event-cell, .band { position: relative; z-index: 1; }
.band { z-index: 3; }          /* real bands sit ABOVE the line (stay solid) */

.date-num {
  grid-row: 1;
  padding: 0;
}
.date-num .num {
  display: inline-block;
  background: var(--teal);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 5px 9px;
  border-radius: 0;
}
.date-num.other .num { background: var(--muted); }
.date-num.tinted .num { background: var(--brown); }

.band {
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--h-band);
  margin: 2px 4px;
  padding: 0 10px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  line-height: 1.2;
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}

.event-cell {
  padding: 6px 10px 14px;
  min-height: 96px;
  background: transparent;
}
.event-cell.other { background: rgba(0,0,0,.015); }

.event-item {
  font-size: 12.5px;
  line-height: 1.35;
  margin: 2px 0;
  color: #b25f18;
  font-weight: 400;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.event-item::before { content: "\2011 "; }
/* Topic names are bold only in the highlighted (tan) week */
.week-hl .event-item { font-weight: 700; }

.event-cell.holiday {
  background: var(--tan);
  display: flex;
  align-items: center;
  justify-content: center;
}
.event-cell.holiday .holiday-text {
  color: var(--brown);
  font-weight: 800;
  font-size: 26px;
  letter-spacing: 1px;
}

.state-msg { padding: 40px; text-align: center; color: #888; }

/* ---------- Admin ---------- */
.admin-wrap { max-width: 1000px; margin: 0 auto; padding: 24px; }
.admin-wrap h1 { color: var(--teal); }

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { margin-top: 0; color: var(--brown); font-size: 18px; }

label { display: block; font-size: 13px; font-weight: 600; margin: 10px 0 4px; color: #444; }
input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
input[type="color"] { padding: 3px; height: 42px; }
textarea { min-height: 60px; resize: vertical; }

.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > div { flex: 1; min-width: 130px; }

.btn {
  background: var(--teal); color: #fff; border: 0; border-radius: 8px;
  padding: 10px 18px; font-size: 14px; cursor: pointer; font-weight: 600;
}
.btn:hover { background: #0c4a4a; }
.btn.secondary { background: #eee; color: #333; }
.btn.danger { background: #c0392b; }
.btn.small { padding: 5px 10px; font-size: 12px; }

.month-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.month-bar .grow { flex: 1; }

table { width: 100%; border-collapse: collapse; margin-top: 10px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid #eee; font-size: 13px; vertical-align: top; }
th { color: #666; font-weight: 600; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: middle; margin-right: 6px; border: 1px solid #0002; }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.topbar a { color: var(--teal); }
.toast {
  position: fixed; bottom: 20px; right: 20px; background: #222; color: #fff;
  padding: 12px 18px; border-radius: 8px; opacity: 0; transition: opacity .25s;
  pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; }
.hidden { display: none !important; }
.muted-text { color: #888; font-size: 13px; font-weight: 400; }

.img-row { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.img-preview {
  height: 46px; max-width: 200px; object-fit: contain;
  background: var(--teal); border-radius: 6px; padding: 4px 8px;
}

/* ---------- Login screen ---------- */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f5959 0%, #0b4444 100%);
  padding: 20px;
  z-index: 40;
}
.login-box {
  background: #fff;
  width: 100%;
  max-width: 380px;
  border-radius: 16px;
  padding: 34px 30px 30px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  text-align: left;
}
.login-badge {
  width: 62px; height: 62px;
  margin: 0 auto 14px;
  background: var(--teal);
  color: #fff;
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px; letter-spacing: 1px;
}
.login-box h2 { margin: 0; text-align: center; color: var(--teal); font-size: 22px; }
.login-sub { margin: 4px 0 18px; text-align: center; color: #999; font-size: 13px; }
.login-box label { margin-top: 14px; }
.login-box input { padding: 11px 13px; }
.login-btn { width: 100%; margin-top: 20px; padding: 12px; font-size: 15px; }
.login-msg { min-height: 18px; margin: 10px 0 0; font-size: 13px; color: #c0392b; }

/* ---------- Admin interactive week view ---------- */
.wk-day { cursor: pointer; transition: background .12s; }
.wk-day:hover { background: rgba(15,89,89,.08); }
.wk-band { cursor: pointer; }
.wk-band:hover { filter: brightness(1.08); outline: 2px solid #0004; }

.wmodal {
  position: fixed; inset: 0; z-index: 60; padding: 16px;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
}
.wmodal-box {
  background: #fff; border-radius: 14px; padding: 22px;
  width: 100%; max-width: 470px; max-height: 90vh; overflow: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.wmodal-box h3 { margin: 0 0 6px; color: var(--brown); }
.wmodal-box hr { border: 0; border-top: 1px solid #eee; margin: 14px 0; }
.topic-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.topic-row input[type="text"] { flex: 1; min-width: 150px; width: auto; }
.topic-row input[type="color"] { width: 46px; }

/* "Weeks" dropdown label in the nav */
.nav-label { align-self: center; font-weight: 700; color: var(--teal); font-size: 14px; margin-left: 4px; }

/* Band patti (coloured strip like a real band) with an inline name box,
   shown in every empty week so you can name & add a band right there. */
.add-band-strip {
  position: relative; z-index: 4;   /* sit above bands/lines so its controls always show */
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--h-band);
  margin: 2px 4px;
  padding: 3px 10px;
  border-radius: 6px;
  background: #F3DBB2;               /* tan patti */
  border: 1px solid #cbb68e;         /* fixed — not affected by line-colour changes */
  color: var(--brown);
  font-weight: 700; font-size: 13px;
}
.abs-plus {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  background: var(--brown); color: #fff; font-size: 14px; line-height: 1;
}
.add-band-strip .ab-name {
  flex: 0 1 260px; min-width: 0;
  width: auto; height: 26px; padding: 3px 9px;
  border: 1px solid #cbb68e; border-radius: 5px; font-size: 13px;
  background: #fff; color: #333;
}
.add-band-strip .ab-add {
  flex: none; padding: 4px 12px;
  background: var(--brown); color: #fff;
}
.add-band-strip .ab-add:hover { background: #6f4226; }

/* ============================================================
   Responsive — tablets & phones
   ============================================================ */

/* Tablet / small laptop */
@media (max-width: 900px) {
  .cal-wrap { padding: 16px; }
  .admin-wrap { padding: 16px; }

  .cal-header h1 { font-size: 24px; }
  .cal-tagline { font-size: 20px; }

  .event-cell { min-height: 84px; }
  .week { grid-template-rows: unset; }

  .event-cell.holiday .holiday-text { font-size: 20px; }
}

/* Phones */
@media (max-width: 600px) {
  :root {
    --h-title: auto;
    --h-day: 40px;
    --h-band: 22px;
  }

  .cal-wrap { padding: 10px; }
  .admin-wrap { padding: 10px; }

  /* Header stacks vertically and grows to fit its content */
  .cal-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 14px 16px;
    text-align: left;
  }
  .cal-header h1 { font-size: 19px; }
  .cal-header h1::before { width: 9px; height: 9px; margin-right: 8px; }
  .cal-tagline { font-size: 22px; white-space: normal; }
  .cal-logo { height: 40px; max-width: 120px; }

  /* Nav buttons wrap and shrink */
  .cal-nav { gap: 6px; margin: 12px 0; flex-wrap: wrap; }
  .cal-nav button { padding: 7px 11px; font-size: 13px; }
  .cal-nav .spacer { flex-basis: 100%; height: 0; }

  /* Calendar frame: keep the 7-col month grid but shrink everything.
     Allow horizontal scroll as a safety net if content is still wide. */
  .cal-frame { border-width: 2px; }

  .weekday-row div { font-size: 11px; padding: 0 2px; letter-spacing: 0; }
  .weekday-row .wd-full { display: none; }
  .weekday-row .wd-short { display: inline; }

  .date-num .num { font-size: 11px; padding: 3px 5px; }

  .band { font-size: 10px; margin: 1px 2px; padding: 0 4px; border-radius: 4px; }

  .event-cell { padding: 3px 4px 8px; min-height: 60px; }
  .event-item { font-size: 10px; line-height: 1.25; }

  .event-cell.holiday .holiday-text { font-size: 13px; letter-spacing: .5px; }

  /* Admin forms: one field per row for easy tapping */
  .card { padding: 14px; margin-bottom: 14px; }
  .card h2 { font-size: 16px; }
  .row { gap: 10px; }
  .row > div { flex: 1 1 100%; min-width: 0; }

  .month-bar { gap: 8px; }
  .month-bar #yearInput { width: 80px !important; }
  .month-bar .grow { flex-basis: 100%; height: 0; }

  .btn { padding: 10px 16px; }

  /* Tables scroll horizontally instead of squeezing */
  #catTable, #eventTable { display: block; overflow-x: auto; white-space: nowrap; }

  .topbar h1 { font-size: 22px; }

  .toast { left: 12px; right: 12px; bottom: 12px; text-align: center; }
}

/* Very small phones */
@media (max-width: 380px) {
  .cal-header h1 { font-size: 17px; }
  .weekday-row div { font-size: 9px; }
  .date-num .num { font-size: 10px; padding: 2px 4px; }
  .event-item { font-size: 9px; }
}
