/* ── Design tokens ─────────────────────────────────────────── */
:root {
  --bg:          #faf8f4;
  --surface:     #f0eee9;
  --card-bg:     #fff;
  --border:      rgba(0,0,0,.1);
  --border-soft: #e6e2db;
  --divider:     #eeeae3;
  --shadow:      0 2px 10px rgba(0,0,0,.06);
  --shadow-lg:   0 18px 50px rgba(0,0,0,.22);
  --blue:        #2a78d6;
  --blue-light:  #eef2f7;
  --blue-border: #cfdcea;
  --text:            #2a2620;
  --text-secondary:  #4a453d;
  --text-tertiary:   #8a857c;
  --muted:       #6a655c;
  --faint:       #a29c92;
  --faintest:    #b5afa4;
  --red:         #b23c3c;
  --red-light:   #faf0ed;
  --red-border:  #e8d6d6;
  --hover-tint:    rgba(0,0,0,.03);
  --hover-tint-strong: rgba(0,0,0,.08);
  --weekend-tint:  rgba(0,0,0,.025);
  --selected-tint: #f0f5fc;
  --inverse-bg:  #2a2620;
  --radius:      9px;
  --radius-sm:   6px;
  --radius-pill: 999px;
  --sidebar-w:   242px;
  --topbar-h:    54px;
}

html[data-theme="dark"] {
  --bg:          #1c1b19;
  --surface:     #24221f;
  --card-bg:     #2a2825;
  --border:      rgba(255,255,255,.14);
  --border-soft: #38352f;
  --divider:     #38352f;
  --shadow:      0 2px 10px rgba(0,0,0,.35);
  --shadow-lg:   0 18px 50px rgba(0,0,0,.55);
  --blue:        #5b9ce6;
  --blue-light:  #1c2b3d;
  --blue-border: #2f4a68;
  --text:            #ece8e0;
  --text-secondary:  #d8d3c8;
  --text-tertiary:   #9a948a;
  --muted:       #b8b2a6;
  --faint:       #8a857c;
  --faintest:    #6f6a60;
  --red:         #e0685f;
  --red-light:   #3a2320;
  --red-border:  #5c332f;
  --hover-tint:    rgba(255,255,255,.05);
  --hover-tint-strong: rgba(255,255,255,.1);
  --weekend-tint:  rgba(255,255,255,.035);
  --selected-tint: #1c2b3d;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; font-size: 112.5%; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  min-height: 100%;
}
a { color: var(--blue); }
button, input, select, textarea { font: inherit; }
table { border-collapse: collapse; width: 100%; }

/* ── Utilities ──────────────────────────────────────────────── */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ── Auth pages (login / register / inactive) ───────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.auth-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 40px;
  width: 100%;
  max-width: 400px;
}
.auth-card h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.auth-card .subtitle {
  font-size: .875rem;
  color: var(--faint);
  margin-bottom: 28px;
}
.auth-card .alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  margin-bottom: 16px;
}
.auth-card .alert-error {
  background: var(--red-light);
  border: 1px solid var(--red-border);
  color: var(--red);
}
.auth-card .alert-success {
  background: #edf7ed;
  border: 1px solid #c3e6c3;
  color: #2d6b2d;
}

/* ── Form fields ────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--faint);
  font-family: ui-monospace, Menlo, monospace;
  margin-bottom: 6px;
}
.form-group input:not(.chip-select-input),
.form-group select,
.form-group textarea {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: .9375rem;
  transition: border-color .15s;
}
.form-group input:not(.chip-select-input):focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(42,120,214,.12);
}
.form-group textarea { resize: vertical; min-height: 80px; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--muted);
  font-size: .8125rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface); border-color: #b8b2a8; }
.btn-primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.btn-primary:hover { background: #2268bd; border-color: #2268bd; }
.btn-danger {
  background: var(--card-bg);
  border-color: var(--red-border);
  color: var(--red);
}
.btn-danger:hover { background: var(--red-light); }
.btn-full { width: 100%; justify-content: center; padding: 10px 14px; font-size: .9375rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:disabled:hover { background: var(--card-bg); border-color: var(--border-soft); }
.btn-primary:disabled:hover { background: var(--blue); border-color: var(--blue); }

/* ── Links under auth forms ─────────────────────────────────── */
.auth-footer {
  margin-top: 20px;
  text-align: center;
  font-size: .875rem;
  color: var(--faint);
}
.auth-footer a { color: var(--blue); text-decoration: none; font-weight: 500; }
.auth-footer a:hover { text-decoration: underline; }

/* ── Top bar (calendar + admin pages) ───────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
  height: var(--topbar-h);
  flex: none;
}
.topbar-title {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
}
.topbar-spacer { flex: 1; }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--inverse-bg);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8125rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  flex: none;
  text-decoration: none;
}

/* ── Dropdown menu ──────────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  z-index: 100;
  width: 200px;
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(0,0,0,.16);
  padding: 6px;
  display: none;
}
.dropdown-menu.open { display: block; }
.dropdown-menu-header {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 8px 10px;
}
.dropdown-menu-header .avatar { width: 30px; height: 30px; font-size: .75rem; }
.dropdown-menu-header .user-info { min-width: 0; }
.dropdown-menu-header .user-name {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--text);
}
.dropdown-menu-header .user-email {
  font-size: .6875rem;
  color: var(--faint);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dropdown-divider { height: 1px; background: var(--divider); margin: 4px -6px; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  text-align: left;
}
.dropdown-item:hover { background: var(--surface); }
.dropdown-item.danger { color: #b0503a; }
.dropdown-item.danger:hover { background: var(--red-light); }
.dropdown-item-icon { width: 18px; text-align: center; color: var(--text-tertiary); }

/* ── Admin shell ────────────────────────────────────────────── */
.admin-shell {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}
.admin-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}
.admin-sidebar {
  width: var(--sidebar-w);
  flex: none;
  border-right: 1px solid var(--border-soft);
  background: var(--bg);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: calc(100vh - var(--topbar-h));
}
.admin-main {
  flex: 1;
  min-width: 0;
  padding: 28px 32px;
  background: var(--card-bg);
  overflow-y: auto;
}
.admin-sidebar-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--blue);
  text-decoration: none;
  cursor: pointer;
}
.admin-sidebar-link:hover { background: var(--blue-light); }
.admin-sidebar-link.active {
  background: var(--blue-light);
  color: var(--text);
  font-weight: 600;
}
.admin-sidebar-link .icon { width: 18px; text-align: center; }
.admin-sidebar-divider { height: 1px; background: var(--divider); margin: 4px 2px 8px; }
.admin-sidebar-label {
  font-size: .5938rem;
  font-weight: 600;
  font-family: ui-monospace, Menlo, monospace;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 2px 8px 8px;
}
.admin-sidebar-cal-select {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 9px 11px;
  background: var(--card-bg);
  cursor: pointer;
  margin: 0 2px 6px;
}
.admin-sidebar-cal-select:hover { border-color: #b8b2a8; }
.admin-sidebar-cal-select select {
  border: none;
  background: transparent;
  font-size: .875rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  appearance: none;
  flex: 1;
}
.admin-sidebar-cal-select select:focus { outline: none; }
.admin-sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 7px;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
}
.admin-sidebar-nav-item:hover { background: var(--surface); }
.admin-sidebar-nav-item.active {
  background: var(--blue-light);
  color: var(--text);
  font-weight: 600;
}
.admin-sidebar-nav-item .icon { width: 18px; text-align: center; color: var(--faint); }
.admin-sidebar-nav-item.active .icon { color: #5b7fa6; }
.admin-sidebar-nav-count {
  margin-left: auto;
  font-size: .6875rem;
  font-weight: 500;
  font-family: ui-monospace, Menlo, monospace;
  color: var(--faintest);
}
.admin-sidebar-nav-item.active .admin-sidebar-nav-count { color: #8aa0b8; }

/* ── Page header (admin main area) ─────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.page-header-text h2 { font-size: 1.125rem; font-weight: 700; color: var(--text); }
.page-header-text p { font-size: .8125rem; color: var(--faint); margin-top: 4px; }
.page-header-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.search-input {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  padding: 8px 12px;
  background: var(--card-bg);
  font-size: .8125rem;
  color: var(--faintest);
}
.search-input input {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: .8125rem;
  width: 160px;
}
.search-input input:focus { outline: none; }
.search-input input::placeholder { color: var(--faintest); }

/* ── Data table ─────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  padding: 9px 10px 9px 4px;
  border-bottom: 1px solid var(--divider);
  font-size: .5938rem;
  font-weight: 600;
  font-family: ui-monospace, Menlo, monospace;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--faint);
  white-space: nowrap;
}
.data-table th:first-child { padding-left: 4px; }
.data-table th.actions-col { width: 76px; }
.data-table td {
  padding: 11px 10px 11px 4px;
  border-bottom: 1px solid var(--divider);
  font-size: .8125rem;
  color: var(--muted);
  vertical-align: top;
}
.data-table td:first-child { padding-left: 4px; }
.data-table td.name-cell { font-size: .8125rem; font-weight: 600; color: var(--text); }
.data-table td.actions-cell { padding: 8px 4px 8px 10px; white-space: nowrap; }
.data-table tr:last-child td { border-bottom: none; }
.data-table-footer {
  font-size: .71875rem;
  color: var(--faintest);
  margin-top: 14px;
}

/* ── Row action icon buttons ────────────────────────────────── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: var(--card-bg);
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: .875rem;
  text-decoration: none;
  transition: background .12s;
}
.icon-btn:hover { background: var(--surface); }
.icon-btn.danger { border-color: var(--red-border); color: var(--red); }
.icon-btn.danger:hover { background: var(--red-light); }
.icon-btn-group { display: inline-flex; gap: 6px; }

/* ── Pill badges ────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: .6875rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-admin {
  background: var(--blue-light);
  border: 1px solid var(--blue-border);
  color: #3a6ea5;
}
.badge-user {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  color: var(--text-tertiary);
}
.badge-active { background: #edf7ed; border: 1px solid #c3e6c3; color: #2d6b2d; }
.badge-inactive { background: #fff5e6; border: 1px solid #f0d9b5; color: #8a5c00; }
.badge-cal {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  padding: 2px 9px;
  font-size: .6875rem;
  font-weight: 500;
  color: var(--muted);
}
.badge-group { display: inline-flex; flex-wrap: wrap; gap: 5px; }

/* ── Colour swatch ──────────────────────────────────────────── */
.colour-swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  flex: none;
  vertical-align: middle;
}

/* ── Colour picker (preset palette + "no colour") ─────────────── */
.colour-picker { display: grid; grid-template-columns: repeat(8, 28px); gap: 8px; }
.colour-swatch-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  position: relative;
}
.colour-swatch-btn:hover { opacity: .85; }
.colour-swatch-btn.selected {
  border-color: var(--card-bg);
  box-shadow: 0 0 0 2px var(--text);
}
.colour-swatch-btn.no-colour {
  background: var(--card-bg);
  border-color: var(--border-soft);
}
.colour-swatch-btn.no-colour.selected { border-color: var(--text); }
.colour-swatch-btn.no-colour::after {
  content: '';
  position: absolute;
  left: 5px;
  right: 5px;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: var(--red);
  border-radius: 2px;
  transform: rotate(-45deg);
}

/* ── Modal (native <dialog>) ────────────────────────────────── */
dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0;
  max-width: 520px;
  width: 90vw;
  margin: auto; /* the global reset's margin:0 would otherwise override the UA
                   stylesheet's dialog:modal{margin:auto} centering rule */
  background: var(--card-bg);
  color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid var(--divider);
}
.modal-header h3 { font-size: .9375rem; font-weight: 700; color: var(--text); }
.modal-close {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: none; background: transparent;
  color: var(--text-tertiary); font-size: 1.0625rem; cursor: pointer;
}
.modal-close:hover { background: var(--surface); }
.modal-body { padding: 20px 18px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 13px 18px;
  border-top: 1px solid var(--divider);
  background: var(--bg);
  border-radius: 0 0 var(--radius) var(--radius);
}
.modal-footer-left { margin-right: auto; display: flex; gap: 8px; }

/* ── Notification toast ─────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--inverse-bg);
  color: #fff;
  font-size: .875rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}
#toast.show { opacity: 1; }
#toast.show.has-action { pointer-events: auto; }
.toast-undo-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: .875rem;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

/* ── Item modal (New / Edit calendar item) — matches Claude Design
   wireframes 2a/2b/2c: left rail + two-pane body ──────────────── */
.item-modal { max-width: 568px; border-radius: 12px; }
.item-locked-notice {
  font-size: .8125rem;
  color: var(--faint);
  background: var(--bg-2, rgba(0, 0, 0, .04));
  padding: 8px 18px;
}
.item-modal-body { display: flex; max-height: 70vh; }
.item-modal-rail {
  width: 152px;
  flex: none;
  background: var(--bg);
  border-right: 1px solid var(--divider);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}
.item-modal-rail-label {
  font: 600 10.5px/1 ui-monospace, Menlo, monospace;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 2px 8px 6px;
}
.item-rail-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: none;
  border-radius: 7px;
  background: none;
  font: 500 14px/1 system-ui, sans-serif;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
}
.item-rail-btn:hover { background: var(--surface); }
.item-rail-btn.active { background: var(--blue); color: #fff; font-weight: 600; }
.item-rail-icon { width: 18px; text-align: center; flex: none; }

.item-modal-fields {
  flex: 1;
  min-width: 0;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}
#item-program-fields, #item-event-fields { display: flex; flex-direction: column; gap: 16px; }
.item-field label:not(.radio-card) {
  display: block;
  font: 600 10.5px/1 ui-monospace, Menlo, monospace;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 6px;
}
.item-field select,
.item-field input[type="text"]:not(.chip-select-input) {
  display: block;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  background: var(--card-bg);
  color: var(--text);
  font-size: .8125rem;
}
.item-field select:focus,
.item-field input[type="text"]:not(.chip-select-input):focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(42,120,214,.12);
}
.item-field-heading { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.item-field-heading label { margin-bottom: 0; }
.item-field-count { font: 500 11px/1 system-ui, sans-serif; color: var(--faint); }

/* radio-card list: event-type picker, repeat-pattern picker */
.radio-card-list { display: flex; flex-direction: column; gap: 8px; }
.radio-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 9px 11px;
  cursor: pointer;
}
.radio-card:has(input:checked) { border-color: var(--blue); background: var(--selected-tint); }
.radio-card input[type="radio"] { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.radio-card-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid var(--faintest);
  flex: none;
  display: flex; align-items: center; justify-content: center;
}
.radio-card-dot::after { content: ''; width: 7px; height: 7px; border-radius: 50%; background: transparent; }
.radio-card input:checked ~ .radio-card-dot { border-color: var(--blue); }
.radio-card input:checked ~ .radio-card-dot::after { background: var(--blue); }
.radio-card-text { font: 600 14px/1 system-ui, sans-serif; color: var(--text); flex: none; }
.event-type-swatch { width: 13px; height: 13px; border-radius: 3px; flex: none; }
.mini-input, .mini-select {
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  padding: 7px 9px;
  background: var(--card-bg);
  font: 400 14px/1.2 system-ui, sans-serif;
  color: var(--text);
}
.mini-input { width: 44px; text-align: center; flex: none; }

/* chip multi-select: Systems & Program Editors */
.chip-select { position: relative; }
.chip-select-chips-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 7px 8px;
  background: var(--card-bg);
}
.chip-select-chips-input:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(42,120,214,.12); }
.chip-select-chips { display: contents; }
.chip-select-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--selected-tint);
  border-radius: 5px;
  padding: 4px 5px 4px 9px;
  font: 600 13px/1 system-ui, sans-serif;
  color: var(--text);
}
.chip-select-chip-remove { color: #8aa8cf; font-size: 14px; cursor: pointer; line-height: 1; }
.chip-select-chip-remove:hover { color: #5b7fa6; }
.chip-select-input {
  flex: 1;
  min-width: 80px;
  border: none;
  outline: none;
  font: 400 14px/1.4 system-ui, sans-serif;
  color: var(--text);
  background: transparent;
}
.chip-select-input::placeholder { color: var(--faintest); }
.chip-select-dropdown {
  position: absolute;
  left: 0; right: 0; top: 100%;
  margin-top: 6px;
  z-index: 20;
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  box-shadow: 0 14px 34px rgba(0,0,0,.16);
  max-height: 180px;
  overflow-y: auto;
  padding: 5px;
}
.chip-select-option {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: 6px;
  font: 500 13.5px/1 system-ui, sans-serif;
  color: var(--text-secondary);
  cursor: pointer;
}
.chip-select-option:hover { background: var(--surface); }
.chip-select-option.selected { background: var(--surface); font-weight: 600; color: var(--text); }
.chip-select-option-check {
  width: 15px; height: 15px;
  border-radius: 4px;
  border: 1.5px solid var(--faintest);
  flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: #fff;
}
.chip-select-option.selected .chip-select-option-check { background: var(--blue); border-color: var(--blue); }
.chip-select-empty { padding: 10px; font-size: .75rem; color: var(--faintest); }

/* Dates: Single/Recurring segmented toggle + Starts/Ends fields */
.segmented-toggle { display: flex; padding: 3px; background: var(--surface); border-radius: 8px; gap: 3px; margin-bottom: 10px; }
.segmented-toggle-btn {
  flex: 1;
  text-align: center;
  padding: 6px 0;
  border: none;
  border-radius: 6px;
  background: none;
  font: 500 12.5px/1 system-ui, sans-serif;
  color: var(--faint);
  cursor: pointer;
}
.segmented-toggle-btn.active { background: var(--card-bg); box-shadow: 0 1px 2px rgba(0,0,0,.09); font-weight: 600; color: var(--text); }
.item-date-row { display: flex; gap: 10px; }
.item-date-field { flex: 1; }
.item-date-caption { display: block; font: 500 11.5px/1 system-ui, sans-serif; color: var(--muted); margin-bottom: 5px; }
.item-date-box { border: 1px solid var(--border-soft); border-radius: 7px; padding: 2px 11px; background: var(--card-bg); }
.item-date-box input[type="date"] {
  border: none;
  width: 100%;
  padding: 7px 0;
  font: 400 14px/1.2 system-ui, sans-serif;
  color: var(--text);
  background: transparent;
}
.item-date-box input[type="date"]:focus { outline: none; }
.item-date-box:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(42,120,214,.12); }

/* Tentative row */
.tentative-row { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.tentative-row input[type="checkbox"] { width: 16px; height: 16px; border-radius: 4px; accent-color: var(--blue); cursor: pointer; }
.tentative-label { font: 500 14px/1 system-ui, sans-serif; color: var(--text); }
.tentative-hint { font: 400 12.5px/1 system-ui, sans-serif; color: var(--faint); }

/* ── Environment pill toggles ───────────────────────────────── */
.env-pills { display:flex; flex-wrap:wrap; gap:6px; padding:2px 0; }
.env-pill { padding:4px 12px; border:1px solid var(--border-soft); border-radius:var(--radius-pill); font-size:.75rem; font-weight:500; color:var(--muted); cursor:pointer; background:var(--card-bg); transition:all .12s; }
.env-pill.on { background:var(--selected-tint); border-color:var(--blue); color:var(--text); font-weight:600; }
.env-pill.on::before { content: "\2713"; margin-right: 4px; color: var(--blue); }

/* ── Calendar toolbar (embedded in topbar) ──────────────────── */
.cal-switcher-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 7px 11px;
  background: var(--card-bg);
  font-size: .875rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  appearance: none;
  max-width: 220px;
}
.cal-switcher-btn:hover { border-color: #b8b2a8; }
.cal-switcher-wrap { position: relative; display: inline-flex; align-items: center; }
.cal-switcher-wrap::after {
  content: '▾';
  position: absolute;
  right: 11px;
  font-size: 11px;
  color: var(--faint);
  pointer-events: none;
}
.cal-switcher-wrap select { padding-right: 26px; }
.cal-divider { width: 1px; height: 22px; background: var(--border-soft); flex: none; }
.cal-nav-btns { display: flex; align-items: center; gap: 2px; }
.cal-nav-btn, .cal-today-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--card-bg);
  font-size: .75rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
}
.cal-nav-btn {
  width: 30px;
  padding: 4px 0;
  font-size: .8125rem;
  line-height: 1;
}
.cal-nav-btn:hover, .cal-today-btn:hover { background: var(--surface); border-color: #b8b2a8; }
.cal-title { font-size: 1.0625rem; font-weight: 700; color: var(--text); white-space: nowrap; }
.cal-legend { display: flex; align-items: center; gap: 5px; font-size: .6875rem; font-weight: 500; color: var(--muted); padding-right: 6px; }
.cal-legend-swatch {
  width: 13px; height: 13px; border-radius: 3px; flex: none;
  border: 1px dashed var(--faintest);
  background: repeating-linear-gradient(45deg, var(--border-soft), var(--border-soft) 3px, var(--card-bg) 3px, var(--card-bg) 5px);
}
.cal-legend-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.cal-legend-dot-new { background: #2d6b2d; }
.cal-legend-dot-edited { background: #8a5c00; }

/* ── Calendar shell ─────────────────────────────────────────── */
.cal-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.cal-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.cal-sidebar {
  width: var(--sidebar-w);
  flex: none;
  border-right: 1px solid var(--border-soft);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cal-main {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  background: var(--card-bg);
  display: flex;
  flex-direction: column;
}

/* Sidebar tabs (Programs / Filters) — rounded segmented control, matches wireframe 1a */
.sidebar-tabs {
  display: flex;
  padding: 3px;
  margin: 12px 12px 8px;
  background: var(--surface);
  border-radius: 8px;
  gap: 3px;
  flex-shrink: 0;
}
.sidebar-tab-btn {
  flex: 1;
  text-align: center;
  padding: 7px 0;
  border: none;
  border-radius: 6px;
  background: none;
  font: 700 11.5px/1 ui-monospace, Menlo, monospace;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  cursor: pointer;
}
.sidebar-tab-btn.active { background: var(--card-bg); box-shadow: 0 1px 2px rgba(0,0,0,.09); color: var(--text); }
.sidebar-tab-panel { display: none; flex: 1; min-height: 0; overflow-y: auto; padding: 4px 0 10px; flex-direction: column; }
.sidebar-tab-panel.active { display: flex; }

/* Sidebar section labels and item rows */
.sidebar-section-label {
  font-size: .5625rem;
  font-weight: 700;
  font-family: ui-monospace, Menlo, monospace;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--faintest);
  padding: 10px 14px 4px;
}
.sidebar-section-header { display: flex; align-items: center; justify-content: space-between; padding-right: 10px; }
.sidebar-section-header .sidebar-section-label { padding-right: 0; }
.sidebar-select-all { display: flex; align-items: center; gap: 5px; }
.sidebar-select-all-btn {
  font-size: .6875rem; color: var(--blue); background: none; border: none;
  cursor: pointer; padding: 0; font-family: inherit;
}
.sidebar-select-all-btn:hover { text-decoration: underline; }
.sidebar-check-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  cursor: pointer;
  user-select: none;
}
.sidebar-check-item:hover { background: var(--hover-tint); }
.sidebar-check-item input[type=checkbox] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.sidebar-cb {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--faintest);
  border-radius: 4px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sidebar-check-item input:checked ~ .sidebar-cb {
  background: var(--sw-colour, var(--blue));
  border-color: var(--sw-colour, var(--blue));
}
.sidebar-check-item input:checked ~ .sidebar-cb::after {
  content: '\2713';
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}
.sidebar-check-label {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-dot {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* Program row: swatch + name on one line, "last item {date}" below */
.sidebar-prog-check { align-items: flex-start; }
.sidebar-prog-check .sidebar-cb { margin-top: 1px; }
.sidebar-prog-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sidebar-prog-name-row { display: flex; align-items: center; gap: 7px; min-width: 0; }
.sidebar-prog-lastitem {
  font: 400 11.5px/1.3 system-ui, sans-serif;
  color: var(--faint);
  margin-top: 3px;
}
.sidebar-prog-editors {
  font: 400 11.5px/1.3 system-ui, sans-serif;
  color: var(--faint);
  margin-top: 3px;
}
/* Program row wrapper (label + hover actions) */
.sidebar-prog-row { display:flex; align-items:center; padding-right:6px; }
.sidebar-prog-row .sidebar-check-item { flex:1; min-width:0; padding-right:2px; }
.sidebar-prog-row:hover { background:var(--hover-tint); }
.sidebar-prog-row:hover .sidebar-check-item { background:transparent; }

/* Hover-reveal edit/delete buttons on program & project rows */
.sidebar-row-actions { display:none; align-items:center; gap:1px; flex-shrink:0; }
.sidebar-prog-row:hover .sidebar-row-actions,
.sidebar-project-row:hover .sidebar-row-actions { display:flex; }
.sidebar-row-btn {
  display:inline-flex; align-items:center; justify-content:center;
  width:26px; height:26px; padding:0; border:none; border-radius:4px;
  background:none; cursor:pointer; font-size:1rem; color:var(--faint);
}
.sidebar-row-btn:hover { background:var(--hover-tint-strong); color:var(--muted); }
.sidebar-row-btn.danger:hover { background:var(--red-light); color:var(--red); }

/* Per-program "+ Add project" link */
.sidebar-add-proj-btn {
  display:block; width:100%; padding:3px 14px 5px 36px;
  font-size:.75rem; color:var(--blue); background:none; border:none;
  cursor:pointer; text-align:left;
}
.sidebar-add-proj-btn:hover { text-decoration:underline; }

.sidebar-project-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 8px 6px 36px;
}
.sidebar-project-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.sidebar-project-label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-project-owner {
  font: 400 11.5px/1.3 system-ui, sans-serif;
  color: var(--faintest);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 2px 14px 0;
  padding: 8px;
  border: 1px dashed var(--faintest);
  border-radius: 7px;
  font: 600 12.5px/1 system-ui, sans-serif;
  color: var(--text-tertiary);
  background: none;
  cursor: pointer;
}
.sidebar-add-btn:hover { border-color: var(--blue); color: var(--blue); }
.sidebar-add-btn-icon { font-size: 14px; }
.sidebar-divider { height: 1px; background: var(--divider); margin: 8px 12px; }

/* Calendar grid area */
.cal-grid { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; padding: 10px; }
.cal-grid-inner { flex: 1; min-height: 0; display: flex; flex-direction: column; border: 1px solid var(--border-soft); border-radius: 6px; overflow: hidden; background: var(--card-bg); }
.cal-grid-header { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--surface); border-bottom: 1px solid var(--border-soft); flex: none; }
/* overflow-y is a last-resort safety net: layoutWeekRows() sizes rows to fit
   without it, but if content is too dense to fit even truncated, this keeps
   the excess reachable by scrolling instead of silently clipped away. */
#cal-grid-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; }
.cal-weekday {
  padding: 5px 8px;
  font: 600 11px/1 ui-monospace, Menlo, monospace;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  text-align: center;
}
.cal-weekday:nth-child(1), .cal-weekday:nth-child(7) { background: var(--weekend-tint); }
/* Height is assigned per-row by layoutWeekRows() in calendar.js, which
   equalises rows while growing any row that needs more space to show its
   (wrapped) text and shrinking the rest — down to their own content height. */
.cal-week-row { position: relative; border-bottom: 1px solid var(--divider); }
.cal-week-row:last-child { border-bottom: none; }
.cal-week-bg { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-day-cell { border-right: 1px solid var(--divider); padding: 5px 7px; cursor: pointer; user-select: none; }
.cal-day-cell:last-child { border-right: none; }
.cal-day-cell:nth-child(1), .cal-day-cell:nth-child(7) { background: var(--weekend-tint); }
.cal-day-cell:hover { background: var(--hover-tint); }
.cal-day-cell.range-preview,
.cal-day-cell.range-preview:hover {
  background: var(--blue-light);
  box-shadow: inset 0 0 0 1px var(--blue-border);
}
.cal-day-num { font: 600 13px/1 ui-sans-serif, system-ui, sans-serif; color: var(--text-secondary); display: block; }
.cal-day-num.muted { color: var(--faintest); }
.cal-day-num.today { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; background: var(--blue); color: #fff; }
.cal-events-layer {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 22px;
  gap: 3px;
  padding: 26px 6px 8px;
  box-sizing: border-box;
  pointer-events: none;
}
.cal-event-bar {
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: normal;
  overflow-wrap: break-word;
  padding: 3px 6px;
  font: 500 12px/1.3 ui-sans-serif, system-ui, sans-serif;
  border-radius: 3px;
  box-sizing: border-box;
  cursor: pointer;
  pointer-events: auto;
  position: relative;
  user-select: none;
}
/* Fallback when even one-line-per-lane rows can't all fit the visible area:
   collapse back to single-line, ellipsis-truncated bars (layoutWeekRows()
   in calendar.js toggles this class on #cal-grid-body). */
.cal-grid-truncate .cal-event-bar { white-space: nowrap; text-overflow: ellipsis; }
.cal-event-bar.tentative { color: var(--text-secondary); border-style: dashed; border-width: 1px; }
.cal-event-bar.dragging { opacity: .55; }
.cal-event-badge {
  display: inline-flex;
  align-items: center;
  flex: none;
  padding: 0 4px;
  margin-right: 4px;
  border-radius: 3px;
  font: 700 9px/1.4 ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .02em;
}
.cal-event-badge-new { background: #2d6b2d; color: #fff; }
.cal-event-badge-edited { background: #8a5c00; color: #fff; }
.cal-event-lock { display: inline-flex; align-items: center; flex: none; margin-right: 4px; font-size: 10px; }
#cal-grid-body.dragging-active .cal-event-bar { pointer-events: none; }
.cal-event-resize-handle {
  position: absolute;
  top: 0; bottom: 0;
  width: 6px;
  cursor: ew-resize;
}
.cal-event-resize-handle.left { left: 0; }
.cal-event-resize-handle.right { right: 0; }
body.cal-resize-cursor, body.cal-resize-cursor * { cursor: ew-resize !important; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .admin-sidebar { display: none; }
  .admin-main { padding: 16px; }
  .auth-card { padding: 24px 20px; }
  .cal-sidebar { display: none; }
}
