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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 12px;
  background: #f0f2f5;
  color: #333;
}

/* ── Layout constants ─────────────────────────────────────── */
:root {
  --day-label-w: 44px;
  --kid-label-w: 68px;
  --row-h: 45px;
  /* school zone: 390min * 2.5px = 975px, afternoon zone: 270min * 3.5px = 945px */
  --timeline-w: 1920px;
}

/* ── Page wrapper ─────────────────────────────────────────── */
#app {
  padding: 24px 20px 40px;
}

.schedule-scroll {
  overflow-x: auto;
}

.page-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #f0f2f5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 16px;
  row-gap: 8px;
  padding-bottom: 8px;
  margin-bottom: 4px;
}

h1 {
  font-size: 20px;
  font-weight: 700;
  color: #444;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

h2 {
  font-size: 13px;
  font-weight: 400;
  color: #888;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

/* ── View toggle ──────────────────────────────────────────── */
.view-toggle {
  display: flex;
  flex-shrink: 0;
  border: 1px solid #b0bcc8;
  border-radius: 6px;
  overflow: hidden;
  background: #e4e9ee;
}

.view-btn {
  padding: 5px 14px;
  font-size: 11px;
  font-weight: 600;
  border: none;
  border-right: 1px solid #b0bcc8;
  background: transparent;
  color: #666;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.03em;
}

.view-btn:last-child { border-right: none; }

.view-btn:hover:not(.active) { background: #d4dce4; }

.view-btn.active {
  background: #2c3e50;
  color: #fff;
}

/* ── Kid filter ───────────────────────────────────────────── */
.kid-filter {
  display: flex;
  flex-shrink: 0;
  border: 1px solid #b0bcc8;
  border-radius: 6px;
  overflow: hidden;
  background: #e4e9ee;
}

.kid-btn {
  padding: 5px 14px;
  font-size: 11px;
  font-weight: 600;
  border: none;
  border-right: 1px solid #b0bcc8;
  background: transparent;
  color: #999;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.03em;
  text-decoration: line-through;
}

.kid-btn:last-child { border-right: none; }

.kid-btn:hover:not(.active) { background: #d4dce4; }

.kid-btn.active {
  background: var(--kid-color);
  color: var(--kid-text-color, rgba(0,0,0,0.75));
  text-decoration: none;
}

/* ── Schedule container ───────────────────────────────────── */
#schedule {
  display: inline-block;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  /* overflow: hidden intentionally omitted — it would break sticky label positioning */
}

/* ── Time header ──────────────────────────────────────────── */
.time-header {
  display: flex;
  align-items: flex-end;
  height: 32px;
  background: #2c3e50;
  color: #ecf0f1;
  border-bottom: 2px solid #1a252f;
}

.header-spacer {
  min-width: calc(var(--day-label-w) + var(--kid-label-w));
  flex-shrink: 0;
  border-right: 1px solid #3d5166;
  position: sticky;
  left: 0;
  z-index: 10;
  background: #2c3e50;
}

.header-timeline {
  position: relative;
  width: var(--timeline-clip-w, var(--timeline-w));
  height: 100%;
  flex-shrink: 0;
  overflow: hidden;
}

.header-timeline-inner {
  position: absolute;
  top: 0;
  left: var(--timeline-offset, 0px);
  width: var(--timeline-w);
  height: 100%;
}

.hour-tick {
  position: absolute;
  bottom: 4px;
  transform: translateX(-50%);
  font-size: 14px;
  font-weight: 600;
  color: #bdc3c7;
  user-select: none;
}

.hour-tick-first { transform: translateX(0); }
.hour-tick-last  { transform: translateX(-100%); }

.hour-tick::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 1px;
  height: 4px;
  background: #4a6278;
  transform: translateX(-50%);
}

.hour-tick-first::after { left: 0;    transform: none; }
.hour-tick-last::after  { left: 100%; transform: translateX(-100%); }

.half-tick {
  position: absolute;
  bottom: 2px;
  width: 1px;
  height: 3px;
  background: #3d5166;
}

/* ── Day section ──────────────────────────────────────────── */
.day-section {
  display: flex;
  align-items: stretch;
  border-top: 1px solid #96a2ae;
}

/* Remove top border from the first day section (which follows the time header) */
.time-header + .day-section {
  border-top: none;
}

/* Highlight the current day */
.day-today {
  border-top: 1px solid #e53935 !important;
  border-bottom: 1px solid #e53935;
}

/* Suppress the redundant top border on the section immediately after today */
.day-today + .day-section {
  border-top: none;
}

.day-label {
  min-width: var(--day-label-w);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
  background: #2c3e50;
  border-right: 1px solid #1a252f;
  letter-spacing: 0.05em;
  flex-shrink: 0;
  position: sticky;
  left: 0;
  z-index: 8;
}

.kids-rows {
  flex: 1;
}

/* ── Kid row ──────────────────────────────────────────────── */
.kid-row {
  display: flex;
  align-items: stretch;
  height: var(--row-h);
  border-bottom: 1px solid #b4bece;
}

.kid-row:last-child {
  border-bottom: none;
}

.kid-label {
  min-width: var(--kid-label-w);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding-left: 8px;
  font-weight: 600;
  font-size: 11px;
  color: #555;
  background: #f7f8fa;
  border-right: 1px solid #a8bacb;
  white-space: nowrap;
  position: sticky;
  left: var(--day-label-w);
  z-index: 6;
}

/* ── Timeline ─────────────────────────────────────────────── */
.timeline-clip {
  position: relative;
  width: var(--timeline-clip-w, var(--timeline-w));
  height: 100%;
  flex-shrink: 0;
  overflow: hidden;
}

.timeline {
  position: absolute;
  top: 0;
  left: var(--timeline-offset, 0px);
  width: var(--timeline-w);
  height: 100%;
  background: #D6DCE4;
}

.grid-line-hour {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: #96a2ae;
  z-index: 0;
}

.grid-line-half {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: #b8c2cc;
  z-index: 0;
}

/* ── Shared pair: two kid rows + spanning school overlay ──── */
.shared-pair {
  position: relative;
}

/* School overlay sits on top of both kid rows, aligned with the timeline */
.school-overlay {
  position: absolute;
  top: 0;
  left: var(--kid-label-w);
  width: var(--timeline-clip-w, var(--timeline-w));
  height: calc(2 * var(--row-h));
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}

/* Blocks inside the overlay span the full 2-row height, shifted with the timeline */
.school-overlay .block {
  top: 3px;
  height: calc(100% - 6px);
  transform: translateX(var(--timeline-offset, 0px));
}

/* ── Blocks ───────────────────────────────────────────────── */
.block {
  position: absolute;
  top: 3px;
  height: calc(100% - 6px);
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 4px;
  overflow: hidden;
  padding: 0 4px;
  cursor: default;
  border: 1px solid rgba(0,0,0,0.12);
  box-shadow: 0 2px 4px rgba(0,0,0,0.18), 0 1px 2px rgba(0,0,0,0.12);
  user-select: none;
}

.block-time {
  font-size: 12px;
  font-weight: 400;
  line-height: 1;
  opacity: 1;
  white-space: nowrap;
}

.block {
  color: rgba(0,0,0,0.75); /* default; overridden per-kid via inline style */
}

.block-name {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.block-school .block-name {
  letter-spacing: 0.02em;
}

.block-activity .block-name {
  letter-spacing: 0;
}

/* Activity color categories */
.color-music   { background: #fff176; border-color: #f9a825; }
.color-sport   { background: #a5d6a7; border-color: #388e3c; }
.color-english { background: #90caf9; border-color: #1565c0; }
.color-other   { background: #ce93d8; border-color: #6a1b9a; }
.color-red     { background: #ef9a9a; border-color: #c62828; color: #b71c1c; }

/* ── Login overlay ────────────────────────────────────────── */
#login-overlay {
  position: fixed;
  inset: 0;
  background: #f0f2f5;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#login-overlay[hidden] { display: none; }

#login-form {
  background: #fff;
  padding: 36px 40px;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.13);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 260px;
}

#login-form h2 {
  font-size: 18px;
  font-weight: 700;
  color: #2c3e50;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

#login-form input {
  padding: 8px 12px;
  border: 1px solid #b0bcc8;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

#login-form input:focus { border-color: #2c3e50; }

#login-form button[type="submit"] {
  padding: 9px;
  background: #2c3e50;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.03em;
  margin-top: 4px;
}

#login-form button[type="submit"]:hover    { background: #3d5166; }
#login-form button[type="submit"]:disabled { opacity: 0.6; cursor: default; }

#login-error {
  font-size: 12px;
  color: #c62828;
  text-align: center;
}

/* ── Logout button ────────────────────────────────────────── */
.logout-btn {
  margin-left: auto;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid #b0bcc8;
  border-radius: 6px;
  background: #e4e9ee;
  color: #666;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.03em;
}

.logout-btn:hover {
  background: #c0392b;
  border-color: #922b21;
  color: #fff;
}

.print-btn {
  padding: 5px 9px;
  line-height: 0;
  border: 1px solid #b0bcc8;
  border-radius: 6px;
  background: #e4e9ee;
  cursor: pointer;
  transition: background 0.15s;
  color: #666;
}

.print-btn:hover { background: #d4dce4; }

/* ── Print media ──────────────────────────────────────────── */
@media print {
  .view-toggle,
  .kid-filter,
  .print-btn,
  .logout-btn      { display: none; }
  .now-line        { display: none !important; }
  @page            { size: A4 landscape; margin: 8mm; }
  body             { width: fit-content; background: #fff; }
  #app             { padding: 0; }
  .schedule-scroll { overflow: visible; }
  .block,
  .note            { box-shadow: none; }
  .day-today       { border-top: 1px solid #96a2ae !important; border-bottom: none; }
  .day-today + .day-section { border-top: 1px solid #96a2ae; }
  .timeline        { background: #fff;}
}

/* ── View modes ───────────────────────────────────────────── */
#schedule.view-school .block-activity          { display: none; }

#schedule.view-afternoon .block-school         { display: none; }
#schedule.view-afternoon .school-overlay       { display: none; }
#schedule.view-afternoon .note                 { display: none; }

/* ── Current time line ────────────────────────────────────── */
.now-line {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: #e53935;
  z-index: 5;
  pointer-events: none;
  transform: translateX(-0.5px);
}

.now-line-top::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #e53935;
}

/* ── Notes ────────────────────────────────────────────────── */
.note {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 3px;
  letter-spacing: 0.03em;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 4px rgba(0,0,0,0.18), 0 1px 2px rgba(0,0,0,0.12);
}

.note-red {
  background: #ef9a9a;
  color: #b71c1c;
  border: 1px solid #c62828;
}

/* ── Mobile ───────────────────────────────────────────────── */
@media (max-width: 600px) {
  :root {
    --day-label-w: 32px;
    --kid-label-w: 52px;
  }

  #app {
    padding: 8px 8px 16px;
  }

  h1 {
    font-size: 16px;
  }

  .page-header {
    column-gap: 8px;
    row-gap: 6px;
  }

  .view-btn,
  .kid-btn {
    padding: 10px 12px;
  }

  .logout-btn,
  .print-btn {
    padding: 10px 10px;
  }

  .block-time {
    display: none;
  }
}
