:root {
  --nav: #0f2d4d;
  --nav-active: #105f89;
  --nav-border: #77b1d3;
  --dustin: #2f65d8;
  --katherine: #5dbb00;
  --vacation: #12a9a2;
  --holiday: #ffc928;
  --change: #7c58c9;
  --manual: #dbe7f1;
  --bg: #f5f8fb;
  --panel: #fff;
  --line: #dce4eb;
  --text: #17202a;
  --muted: #5c6b78;
  --shadow: 0 16px 38px rgba(15, 45, 77, 0.18);
  font-family: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.topbar {
  height: 56px;
  background: var(--nav);
  color: #fff;
  display: flex;
  align-items: stretch;
  position: relative;
  z-index: 80;
}
.brand {
  width: 72px;
  border: 0;
  background: #0c3856;
  color: #fff;
  display: grid;
  place-items: center;
}
.brand-mark { font-size: 34px; line-height: 1; }
.main-nav { display: flex; align-items: stretch; }
.main-nav button {
  color: #fff;
  background: transparent;
  border: 0;
  border-bottom: 4px solid transparent;
  padding: 0 20px;
  font-size: 16px;
}
.main-nav button.active {
  background: var(--nav-active);
  border-bottom-color: var(--nav-border);
  font-weight: 700;
}

.section-panel { display: none; height: calc(100vh - 56px); }
.section-panel.active { display: block; }
.app-shell {
  height: 100%;
  display: grid;
  grid-template-columns: 282px minmax(0, 1fr);
}
.sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  min-width: 0;
}
.sidebar-backdrop { display: none; }

.mini-panel {
  border-bottom: 1px solid var(--line);
  padding: 16px 7px 12px;
}
.mini-header {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  align-items: center;
  gap: 4px;
  padding: 0 8px 8px;
  font-size: 16px;
}
.mini-header span { text-align: center; font-weight: 700; }
.mini-arrow, .icon-btn {
  border: 0;
  background: transparent;
  font-size: 32px;
  line-height: 1;
  color: #000;
  border-radius: 6px;
}
.mini-arrow:hover, .icon-btn:hover { background: #eaf3f8; }
.mini-weekdays,
.mini-calendar { display: grid; grid-template-columns: repeat(7, 1fr); }
.mini-weekdays span { text-align: center; font-size: 13px; padding: 6px 0; }
.mini-day {
  min-height: 34px;
  border: 1px solid #f5f5f5;
  background: #fff;
  font-size: 13px;
  padding: 3px 4px;
  position: relative;
  color: #111;
}
.mini-day.other-month { opacity: .45; }
.mini-day .mini-date {
  color: #06162a;
  font-weight: 700;
  position: relative;
  z-index: 1;
}
.mini-day.selected .mini-date,
.mini-day.today .mini-date {
  color: #fff;
  background: #0e78a8;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
}
.mini-day.has-events::after {
  content: "";
  position: absolute;
  bottom: 4px;
  left: 50%;
  width: 5px;
  height: 5px;
  transform: translateX(-50%);
  background: #111;
  border-radius: 50%;
}

.sidebar-section,
.sidebar-toggle,
.sidebar-reset {
  border-bottom: 1px solid var(--line);
  padding: 16px 14px 16px 18px;
}
.side-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.side-section-title h2 { margin: 0; font-size: 15px; }
.link-button,
.sidebar-reset button {
  border: 0;
  background: #e8f2f8;
  color: #0a5b7e;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}
.sidebar-reset button { width: 100%; padding: 8px; }
.calendar-source-list { display: grid; gap: 10px; }
.source-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20px;
  gap: 10px;
  align-items: center;
}
.source-row label,
.source-static {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
  font-size: 14px;
}
.source-row span,
.source-static span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.source-row small,
.source-static small {
  color: var(--muted);
  display: block;
  font-size: 11px;
  line-height: 1.2;
}
.color-picker {
  position: relative;
  width: 18px;
  height: 18px;
  display: inline-block;
  justify-self: end;
  cursor: pointer;
  background: transparent;
}
.color-picker:focus-within { outline: none; }
.color-chip {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--pick-color);
  display: block;
  transition: transform .12s ease, opacity .12s ease;
}
.color-picker:hover .color-chip,
.color-picker:focus-within .color-chip { transform: scale(1.08); }
.source-color {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  padding: 0;
  border: 0;
}
.sidebar-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
}
.switch {
  width: 44px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  background: #d3d8dc;
  padding: 2px;
}
.switch span {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #fff;
  transition: transform .15s ease;
}
.switch[aria-pressed="true"] { background: #0e78a8; }
.switch[aria-pressed="true"] span { transform: translateX(20px); }

.calendar-workspace {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.toolbar-row {
  min-height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(190px, 1fr);
  gap: 14px;
  align-items: center;
  padding: 0 12px 0 18px;
}
.toolbar-left,
.toolbar-center,
.view-tools { display: flex; align-items: center; gap: 8px; }
.toolbar-center { justify-content: center; }
.toolbar-center h1 {
  margin: 0;
  min-width: 190px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
}
.view-tools { justify-content: flex-end; }
.primary-btn,
.outline-btn,
.text-btn {
  border-radius: 5px;
  padding: 8px 12px;
  border: 1px solid #0177ab;
  background: #fff;
  color: #006fa7;
  font-weight: 700;
}
.primary-btn { background: #0079ad; color: #fff; border-color: #0079ad; }
.text-btn { border: 0; background: transparent; padding: 7px 6px; }
#agendaToggle.active { background: #0079ad; color: #fff; }
.relative { position: relative; }
.menu-popover,
.filter-popover {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 9px;
  z-index: 50;
  min-width: 220px;
  padding: 8px;
}
.menu-popover button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px;
  border-radius: 6px;
}
.menu-popover button:hover { background: #eef6fb; }
.filter-popover { width: 260px; }
.filter-popover h3 { margin: 8px 8px 10px; font-size: 16px; }
.filter-popover label { display: block; padding: 7px 8px; font-size: 14px; }
.filter-popover p { margin: 8px; color: var(--muted); font-size: 12px; line-height: 1.35; }

.calendar-card { flex: 1; min-height: 0; background: #fff; overflow: hidden; }
.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  height: 30px;
  align-items: end;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.weekday-row span { text-align: center; font-size: 14px; padding-bottom: 5px; }
.view-panel { display: none; height: calc(100% - 30px); overflow: auto; }
.view-panel.active { display: block; }
.month-grid {
  min-height: 100%;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: minmax(122px, 1fr);
}
.day-cell {
  position: relative;
  border-right: 1px solid #e2e8ee;
  border-bottom: 1px solid #e2e8ee;
  background: #fff;
  min-width: 0;
  overflow: hidden;
}
.day-cell.other-month { color: #a6afb7; background: #fbfdfe; }
.day-cell.selected { box-shadow: inset 0 0 0 2px rgba(14, 120, 168, .28); }
.day-cell.today .day-number span {
  background: #0e78a8;
  color: #fff;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
}
.custody-bar {
  position: absolute;
  top: 0;
  left: 2px;
  right: 2px;
  height: 4px;
  display: flex;
  gap: 2px;
}
.bar-segment.dustin { background: var(--dustin); }
.bar-segment.katherine { background: var(--katherine); }
.why-day {
  position: absolute;
  top: 6px;
  left: 4px;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.88);
  color: #0d5e80;
  font-weight: 700;
  display: none;
}
.day-cell:hover .why-day { display: block; }
.day-number {
  position: absolute;
  top: 10px;
  right: 9px;
  font-size: 14px;
  border: 0;
  background: transparent;
}
.day-events {
  padding: 30px 4px 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.event {
  position: relative;
  min-height: 20px;
  border: 1px solid #d8dee5;
  border-left-width: 3px;
  border-radius: 4px;
  padding: 2px 19px 2px 4px;
  background: #fff;
  color: #000;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.event.transition { border-left-color: #0e78a8; background: #fff; border-color: transparent; padding-left: 0; font-weight: 700; }
.event.change { border-left-color: var(--change); background: #efe9ff; }
.event.holiday { border-left-color: var(--holiday); background: color-mix(in srgb, var(--holiday) 18%, white); }
.event.vacation { border-left-color: var(--vacation); background: color-mix(in srgb, var(--vacation) 16%, white); }
.event.manual { border-left-color: #9badbd; background: #f7f9fb; }
.event.external { --event-color: #f5b16d; border-left-color: var(--event-color); background: color-mix(in srgb, var(--event-color) 18%, white); }
.icon-people { color: #bf2633; padding-left: 4px; }
.icon-sync { color: #7b8790; padding-left: 2px; }
.why-event {
  position: absolute;
  right: 2px;
  top: 2px;
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 50%;
  background: #e7f1f7;
  color: #0d5e80;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
.more-link { color: #122638; font-size: 12px; padding: 2px 4px; border: 0; background: transparent; }

.agenda-view { padding: 18px; }
.agenda-date {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 18px rgba(15, 45, 77, .08);
  margin-bottom: 16px;
  overflow: hidden;
}
.agenda-date h2 {
  margin: 0;
  padding: 14px 16px;
  background: #f5f9fc;
  border-bottom: 1px solid var(--line);
  font-size: 17px;
}
.agenda-row {
  display: grid;
  grid-template-columns: 110px 145px 1fr 28px;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid #eef2f5;
  align-items: start;
  font-size: 14px;
}
.agenda-row small { color: var(--muted); }
.source-chip { border-radius: 999px; padding: 3px 8px; font-size: 12px; font-weight: 700; background: #e8eef3; }
.source-chip.custody { background: #e3ecff; color: #1d4da4; }
.source-chip.external { background: #fff0df; color: #9a5200; }
.source-chip.manual { background: #edf2f6; }
.source-chip.holiday { background: color-mix(in srgb, var(--holiday) 18%, white); }
.source-chip.change { background: #efe9ff; color: #4f2fa6; }
.source-chip.vacation { background: color-mix(in srgb, var(--vacation) 16%, white); color: #0a6864; }

.spaces-page { padding: 0; height: calc(100vh - 56px); overflow: hidden; }
.spaces-frame-host { width: 100%; height: 100%; margin: 0; border: 0; background: #fff; }
.spaces-iframe { width: 100%; height: 100%; border: 0; background: #fff; }

.eyebrow { margin: 0 0 5px; color: #0b6f99; text-transform: uppercase; letter-spacing: .08em; font-size: 12px; font-weight: 700; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(13, 26, 41, .45);
  display: grid;
  place-items: center;
  z-index: 100;
}
.modal {
  width: min(760px, calc(100vw - 40px));
  max-height: calc(100vh - 54px);
  overflow: hidden;
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.small-modal { width: min(520px, calc(100vw - 40px)); }
.modal-header { display: flex; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 22px; }
.modal-close { border: 0; background: transparent; font-size: 30px; line-height: 1; }
.modal-body { padding: 18px 20px; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 700; color: #22313f; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px 11px; background: #fff; }
.field textarea { min-height: 96px; resize: vertical; }
.form-note { margin: 0 0 14px; color: var(--muted); line-height: 1.4; }
.result-card { border-left: 6px solid var(--katherine); background: #eaf8dc; padding: 14px 16px; border-radius: 8px; }
.result-card.dustin { border-left-color: var(--dustin); background: #e3ecff; }
.result-card.katherine { border-left-color: var(--katherine); background: #eaf8dc; }
.stack, .audit-grid { display: grid; gap: 8px; }
.stack-row { display: grid; grid-template-columns: 170px 120px 1fr; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; align-items: center; }
.status { justify-self: start; border-radius: 999px; padding: 3px 8px; font-size: 12px; font-weight: 700; }
.status.win { background: #dff3ce; color: #2f6900; }
.status.override { background: #ffe8e8; color: #9e1b1b; }
.status.none { background: #edf2f6; color: #52616f; }
.audit-grid { grid-template-columns: repeat(2, 1fr); }
.audit-grid div, .notice { background: #f7fafc; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.audit-grid span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 250px minmax(0, 1fr); }
  .toolbar-row { grid-template-columns: 1fr; height: auto; padding: 10px; }
  .toolbar-left, .toolbar-center, .view-tools { justify-content: center; }
}

@media (max-width: 820px) {
  body { overflow-x: hidden; }
  .topbar { height: 52px; position: sticky; top: 0; }
  .brand { width: 56px; }
  .brand-mark { font-size: 28px; }
  .main-nav { min-width: 0; flex: 1; }
  .main-nav button { flex: 1 1 0; min-width: 0; padding: 0 10px; font-size: 15px; }
  .section-panel, .spaces-page { height: calc(100vh - 52px); }
  .app-shell { display: block; position: relative; height: 100%; }
  .sidebar {
    position: fixed;
    top: 52px;
    left: 0;
    bottom: 0;
    width: min(310px, calc(100vw - 40px));
    z-index: 70;
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 0 18px 38px rgba(15, 45, 77, .22);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 52px 0 0 0; display: block; border: 0; background: rgba(13, 26, 41, .35); z-index: 65; }
  .calendar-workspace { height: 100%; min-width: 0; }
  .toolbar-row { grid-template-columns: 1fr; height: auto; gap: 10px; padding: 10px; }
  .toolbar-left, .toolbar-center, .view-tools { min-width: 0; flex-wrap: wrap; }
  .toolbar-left { justify-content: space-between; }
  .toolbar-center { justify-content: center; }
  .toolbar-center h1 { min-width: 145px; font-size: 16px; }
  .view-tools { justify-content: space-between; }
  .outline-btn, .primary-btn, .text-btn { padding: 8px 10px; font-size: 14px; }
  .weekday-row { height: 26px; }
  .weekday-row span { font-size: 11px; padding-bottom: 4px; }
  .month-grid { grid-auto-rows: minmax(88px, 1fr); }
  .day-number { top: 6px; right: 6px; font-size: 12px; }
  .day-cell.today .day-number span { min-width: 20px; height: 20px; }
  .day-events { padding: 24px 2px 2px; gap: 2px; }
  .event { font-size: 10px; min-height: 18px; padding-right: 15px; }
  .event:nth-child(n+3):not(.more-link) { display: none; }
  .why-event { width: 14px; height: 14px; font-size: 10px; }
  .why-day { width: 18px; height: 18px; top: 4px; left: 3px; font-size: 11px; }
  .mini-panel { padding: 12px 6px 10px; }
  .mini-header { font-size: 15px; }
  .mini-day { min-height: 32px; font-size: 12px; padding: 3px 2px; }
  .agenda-view { padding: 10px; }
  .agenda-date h2 { font-size: 15px; padding: 12px; }
  .agenda-row { grid-template-columns: 1fr; gap: 6px; padding: 10px 12px; }
  .modal { width: min(96vw, 760px); max-height: calc(100vh - 20px); }
  .modal-header, .modal-body, .modal-actions { padding-left: 14px; padding-right: 14px; }
  .modal-actions { flex-wrap: wrap; justify-content: stretch; }
  .modal-actions button { flex: 1 1 100%; }
  .form-grid { grid-template-columns: 1fr; }
}


/* v12 mobile and agenda cleanup */
.agenda-row {
  position: relative;
}

.agenda-row .why-event {
  position: static;
  justify-self: end;
  align-self: center;
}

@media (max-width: 820px) {
  .filter-popover {
    position: fixed;
    left: 10px;
    right: 10px;
    top: 118px;
    width: auto;
    min-width: 0;
    max-width: none;
    max-height: calc(100vh - 136px);
    overflow: auto;
    z-index: 90;
  }

  .agenda-view .why-event {
    display: none;
  }

  .agenda-row {
    grid-template-columns: 84px 1fr;
    align-items: center;
  }

  .agenda-row > span:nth-child(3) {
    grid-column: 1 / -1;
  }

  .agenda-row > span:nth-child(4),
  .agenda-row > button:nth-child(4) {
    display: none;
  }
}
