/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --blue:       #2563eb;
  --blue-light: #eff6ff;
  --blue-dark:  #1d4ed8;
  --green:      #16a34a;
  --green-light:#f0fdf4;
  --amber:      #d97706;
  --amber-light:#fffbeb;
  --red:        #dc2626;
  --red-light:  #fef2f2;
  --error:      #dc2626;
  --slate:      #64748b;
  --slate-light:#f1f5f9;
  --border:     #e2e8f0;
  --bg:         #f8fafc;
  --card:       #ffffff;
  --text:       #1e293b;
  --text-muted: #64748b;
  --radius:     8px;
  --shadow:     0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:  0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { overflow-x: hidden; }
html, body { height: 100%; font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }
body { overflow-x: hidden; }
button { cursor: pointer; font: inherit; color: inherit; }
input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Top Nav ───────────────────────────────────────────────────────────────── */
.topnav {
  background: var(--blue);
  color: #fff;
  padding: 0 1rem;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: .75rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
  flex-wrap: wrap;
}
.topnav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.topnav-logo { height: 28px; width: 28px; object-fit: contain; border-radius: 4px; }
.topnav-spacer { flex: 1; min-width: 0; }
.topnav-user { font-size: .85rem; opacity: .85; white-space: nowrap; }
.topnav-actions { display: flex; align-items: center; gap: .35rem; }

/* ── Health bar ────────────────────────────────────────────────────────────── */
.health-bar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 1rem;
  height: 28px;
  background: var(--slate-light);
  border-bottom: 1px solid var(--border);
  font-size: .72rem;
  font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace;
  color: var(--text-muted);
  overflow-x: auto;
  white-space: nowrap;
}
.health-stat { padding: 0 .75rem; }
.health-sep  { width: 1px; height: 14px; background: var(--border); flex-shrink: 0; }

.view-tabs { display: flex; gap: .25rem; }
.view-tab {
  padding: .35rem .75rem;
  border-radius: 6px;
  border: 1.5px solid rgba(255,255,255,.35);
  background: transparent;
  color: rgba(255,255,255,.85);
  font-size: .85rem;
  font-weight: 500;
  transition: all .15s;
}
.view-tab:hover { background: rgba(255,255,255,.15); }
.view-tab.active { background: #fff; color: var(--blue); border-color: #fff; }

.btn-ghost-white {
  padding: .35rem .75rem;
  border-radius: 6px;
  border: 1.5px solid rgba(255,255,255,.35);
  background: transparent;
  color: rgba(255,255,255,.85);
  font-size: .85rem;
  transition: all .15s;
}
.btn-ghost-white:hover { background: rgba(255,255,255,.15); }

/* ── Page content ──────────────────────────────────────────────────────────── */
.page { flex: 1; padding: 1.25rem 1rem; max-width: 1100px; width: 100%; margin: 0 auto; }

.app-footer { text-align: center; padding: .75rem 1rem 1.25rem; font-size: .75rem; color: var(--text-muted); }
.app-footer a { color: var(--text-muted); text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }

/* ── Calendar header ───────────────────────────────────────────────────────── */
.cal-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.cal-title { font-size: 1.2rem; font-weight: 700; min-width: 180px; }
.cal-legend { display: flex; gap: .85rem; flex-wrap: wrap; margin-bottom: .75rem; }
.cal-legend-item { display: flex; align-items: center; gap: .35rem; font-size: .78rem; color: var(--text-muted); }
.cal-legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.cal-legend-swatch.status-pending   { background: var(--amber); }
.cal-legend-swatch.status-confirmed { background: var(--green); }
.cal-legend-swatch.status-cancelled { background: var(--red); }
.cal-legend-swatch.status-completed { background: var(--slate); }
.btn-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--card);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  transition: all .15s;
}
.btn-icon:hover { background: var(--slate-light); }
.btn-today {
  padding: .35rem .85rem;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--card);
  font-size: .85rem;
  font-weight: 500;
  transition: all .15s;
}
.btn-today:hover { background: var(--slate-light); }

/* ── Month grid ────────────────────────────────────────────────────────────── */
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
  box-shadow: var(--shadow);
}
.month-dow {
  padding: .5rem .25rem;
  text-align: center;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--slate-light);
  border-bottom: 1.5px solid var(--border);
}
.month-cell {
  min-height: 90px;
  padding: .4rem .35rem .3rem;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
  position: relative;
}
.month-cell:nth-child(7n) { border-right: none; }
.month-cell:hover { background: var(--blue-light); }
.month-cell.other-month .day-num { color: #c8d0dc; }
.month-cell.today .day-num {
  background: var(--blue);
  color: #fff;
  border-radius: 50%;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
}
.month-cell.selected { background: var(--blue-light); }
.day-num { font-size: .85rem; font-weight: 600; margin-bottom: .25rem; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; }
.day-bookings { display: flex; flex-direction: column; gap: 2px; }
.day-chip {
  font-size: .7rem;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--blue-light);
  color: var(--blue-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.day-chip.status-confirmed  { background: var(--green-light); color: var(--green); }
.day-chip.status-completed  { background: var(--slate-light); color: var(--slate); }
.day-chip.status-cancelled  { background: var(--red-light); color: var(--red); text-decoration: line-through; }
.day-chip.status-pending    { background: var(--amber-light); color: var(--amber); }
.day-more { font-size: .7rem; color: var(--text-muted); padding-left: 2px; }

/* ── Week view ─────────────────────────────────────────────────────────────── */
.week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: .5rem;
}
.week-col {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow .12s, border-color .12s;
}
.week-col:hover { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-light); }
.week-col-header {
  padding: .5rem;
  text-align: center;
  background: var(--slate-light);
  border-bottom: 1.5px solid var(--border);
}
.week-col:hover .week-col-header { background: var(--blue-light); }
.week-col-header.today { background: var(--blue); color: #fff; }
.week-dow { font-size: .72rem; font-weight: 600; color: var(--text-muted); }
.week-col-header.today .week-dow { color: rgba(255,255,255,.8); }
.week-date { font-size: 1.1rem; font-weight: 700; }
.week-bookings { padding: .4rem; display: flex; flex-direction: column; gap: 4px; min-height: 60px; }
.week-chip {
  font-size: .72rem;
  padding: 3px 6px;
  border-radius: 5px;
  background: var(--blue-light);
  color: var(--blue-dark);
  cursor: pointer;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity .15s;
}
.week-chip:hover { opacity: .8; }
.week-chip.status-confirmed { background: var(--green-light); color: var(--green); }
.week-chip.status-completed { background: var(--slate-light); color: var(--slate); }
.week-chip.status-cancelled { background: var(--red-light); color: var(--red); text-decoration: line-through; }
.week-chip.status-pending   { background: var(--amber-light); color: var(--amber); }
.week-add { font-size: .75rem; color: var(--text-muted); padding: 0 .4rem .4rem; }
.week-add button { background: none; border: none; color: var(--blue); font-size: .75rem; padding: 0; cursor: pointer; }
.week-add button:hover { text-decoration: underline; }

/* ── Day view ──────────────────────────────────────────────────────────────── */
.day-view-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.day-view-title { font-size: 1.2rem; font-weight: 700; }
/* ── Day time grid ─────────────────────────────────────────────────────────── */
.day-time-grid {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--card);
}
.time-slot {
  display: flex;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}
.time-slot:last-child { border-bottom: none; }
.time-label {
  width: 58px;
  min-width: 58px;
  padding: .55rem .45rem;
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
  border-right: 1px solid var(--border);
  background: var(--slate-light);
  line-height: 1.2;
  user-select: none;
}
.time-slot-bookings {
  flex: 1;
  padding: .35rem .5rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  min-width: 0;
}
.time-slot--empty { opacity: .55; }
.time-slot--empty .time-slot-bookings { background: repeating-linear-gradient(135deg, transparent, transparent 6px, rgba(0,0,0,.015) 6px, rgba(0,0,0,.015) 12px); }
.time-slot--now .time-label { color: var(--blue); font-weight: 700; background: var(--blue-light); }
.time-slot--now { border-left: 3px solid var(--blue); }
.time-slot--unscheduled .time-label { color: var(--text-muted); font-style: italic; }
.day-closed-notice {
  font-size: .82rem;
  color: var(--amber);
  background: var(--amber-light);
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
  padding: .4rem .75rem;
  margin-bottom: .65rem;
}

.booking-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem .75rem;
  cursor: pointer;
  transition: all .15s;
  box-shadow: var(--shadow);
}
.booking-card:hover { border-color: var(--blue); box-shadow: var(--shadow-md); }
.booking-card--assigned { border: 2px solid var(--blue); box-shadow: 0 0 0 3px rgba(59,130,246,.12); }
.booking-card--assigned:hover { box-shadow: 0 0 0 3px rgba(59,130,246,.25), var(--shadow-md); }

/* ── Line items table ─────────────────────────────────────────────────────── */
.line-items-table { border-collapse: collapse; font-size: .85rem; }
.line-items-table th { text-align: left; padding: .3rem .5rem; font-weight: 600; font-size: .78rem; color: var(--text-muted); border-bottom: 1.5px solid var(--border); }
.line-items-table td { padding: .3rem .5rem; border-bottom: 1px solid var(--border); }
.line-items-table tfoot td { border-top: 1.5px solid var(--border); border-bottom: none; }
.li-editor-table input { background: var(--card); color: var(--text); border: 1.5px solid var(--border); border-radius: 4px; padding: .25rem .4rem; font-family: inherit; font-size: .85rem; }
.li-editor-table input:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.booking-info { min-width: 0; }
.booking-title { font-weight: 600; font-size: .9rem; margin-bottom: .15rem; }
.booking-time-tag {
  font-size: .72rem;
  font-weight: 600;
  color: var(--blue);
  background: var(--blue-light);
  border-radius: 4px;
  padding: 1px 5px;
}
.booking-meta { font-size: .78rem; color: var(--text-muted); display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.status-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.status-pending   { background: var(--amber-light); color: var(--amber); }
.status-confirmed { background: var(--green-light); color: var(--green); }
.status-completed { background: var(--slate-light); color: var(--slate); }
.status-cancelled { background: var(--red-light); color: var(--red); }
.conflict-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
  background: var(--amber-light);
  color: var(--amber);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: .5rem; }
.empty-state p { font-size: .9rem; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  border: none;
  font-weight: 600;
  font-size: .875rem;
  transition: all .15s;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { background: var(--card); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--slate-light); }
.btn-danger { background: var(--red-light); color: var(--red); border: 1.5px solid #fca5a5; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn-fab {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  border: none;
  font-size: 1.5rem;
  box-shadow: 0 4px 12px rgba(37,99,235,.4);
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
  z-index: 50;
}
.btn-fab:hover { background: var(--blue-dark); transform: scale(1.05); }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5);
  z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  overflow: hidden;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--card);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -4px 24px rgba(0,0,0,.15);
  animation: slideUp .2s ease;
  overflow: hidden;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-header {
  padding: 1rem 1.25rem .75rem;
  border-bottom: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0; /* always visible - never squished by tall body content */
}
.modal-title { font-weight: 700; font-size: 1rem; flex: 1; }
.modal-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--slate-light);
  color: var(--text-muted);
  font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 1rem 1.25rem; }
.modal-footer {
  padding: .75rem 1.25rem;
  border-top: 1.5px solid var(--border);
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
  flex-shrink: 0; /* always visible */
}

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: .85rem; position: relative; }

/* Autocomplete dropdown */
.ac-list {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: var(--card);
  border: 1.5px solid var(--blue);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 6px 18px rgba(0,0,0,.12);
  max-height: 180px;
  overflow-y: auto;
  z-index: 10;
  list-style: none;
  margin: 0; padding: .2rem 0;
}
.ac-list li {
  padding: .45rem .75rem;
  font-size: .875rem;
  cursor: pointer;
  color: var(--text);
}
.ac-list li { display: flex; flex-direction: column; }
.ac-list li:hover, .ac-list li.ac-active { background: var(--slate-light); }
.ac-list li:hover .ac-name, .ac-list li.ac-active .ac-name { color: var(--blue); }
.ac-name { font-weight: 500; }
.ac-hints { font-size: .78rem; color: var(--text-muted); margin-top: .1rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }
label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .3rem; color: var(--text); }
label .req { color: var(--red); margin-left: 2px; }
input[type="text"], input[type="email"], input[type="tel"], input[type="password"],
input[type="date"], input[type="time"], select, textarea {
  width: 100%;
  padding: .5rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-size: .875rem;
  transition: border-color .15s;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
textarea { resize: vertical; min-height: 72px; }
.form-hint { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }
.btn-link { background: none; border: none; padding: 0; color: var(--primary); font: inherit; font-size: inherit; cursor: pointer; text-decoration: underline; }
.checkbox-label { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.checkbox-label input[type="checkbox"] { width: auto; }
.conflict-warning {
  background: var(--amber-light);
  border: 1.5px solid #fcd34d;
  border-radius: var(--radius);
  padding: .6rem .85rem;
  font-size: .8rem;
  color: var(--amber);
  margin-bottom: .75rem;
  display: flex;
  gap: .5rem;
  align-items: flex-start;
}

.draft-banner {
  background: var(--blue-light);
  border: 1.5px solid var(--blue);
  border-radius: var(--radius);
  padding: .5rem .85rem;
  font-size: .82rem;
  color: var(--blue-dark);
  margin-bottom: .75rem;
  display: flex;
  align-items: center;
  gap: .75rem;
}

/* ── Admin panel ───────────────────────────────────────────────────────────── */
.admin-tabs { display: flex; gap: .25rem; margin-bottom: 1.25rem; border-bottom: 2px solid var(--border); flex-wrap: wrap; }
.admin-tab {
  padding: .5rem 1rem;
  border: none;
  background: none;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all .15s;
}
.admin-tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.admin-tab:hover { color: var(--text); }

.section-header { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; margin-top: 1.5rem; }
.section-title { font-size: 1rem; font-weight: 700; flex: 1; }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
}
.data-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  background: var(--card);
  font-size: .875rem;
}
.data-table th {
  background: var(--slate-light);
  padding: .6rem .85rem;
  text-align: left;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1.5px solid var(--border);
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.data-table td { padding: .65rem .85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--blue-light); }
.actions { display: flex; gap: .35rem; }
.drag-handle { cursor: grab; color: var(--text-muted); font-size: 1rem; padding: 0 .3rem; user-select: none; }

.override-note { font-size: .68rem; font-weight: 600; color: var(--amber, #b45309); background: #fef3c7; border-radius: 3px; padding: 1px 4px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.week-col-header .override-note { font-size: .65rem; }
.data-table tr.row-muted td { color: var(--text-muted); opacity: .65; }
.log-entity-link { color: var(--blue); text-decoration: none; font-weight: 500; }
.log-entity-link:hover { text-decoration: underline; }

.month-cell.day-closed { opacity: 0.45; background: repeating-linear-gradient(135deg, transparent, transparent 4px, rgba(0,0,0,.04) 4px, rgba(0,0,0,.04) 8px); }
.month-cell.day-closed .day-chip { opacity: 0.7; }
.week-col.day-closed { opacity: 0.5; background: repeating-linear-gradient(135deg, transparent, transparent 4px, rgba(0,0,0,.03) 4px, rgba(0,0,0,.03) 8px); }

.day-toggles { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .25rem; }
.day-toggle { display: flex; align-items: center; gap: .3rem; padding: .3rem .6rem; border: 1.5px solid var(--border); border-radius: 6px; cursor: pointer; font-size: .85rem; user-select: none; }
.day-toggle input { accent-color: var(--primary); }
tr.dragging { opacity: 0.4; }
tr[data-field-id] { cursor: default; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .72rem; font-weight: 600; }
.badge-admin { background: var(--blue-light); color: var(--blue); }
.badge-user  { background: var(--slate-light); color: var(--slate); }
.badge-req   { background: var(--red-light); color: var(--red); }
.badge-opt   { background: var(--slate-light); color: var(--slate); }
.badge-cal    { background: #d1fae5; color: #065f46; }
.badge-system { background: #ede9fe; color: #5b21b6; }

.chip-field  { opacity: .75; font-size: .75em; }

/* ── WYSIWYG email template editor ────────────────────────────────────────── */
.wysiwyg-toolbar {
  display: flex;
  align-items: center;
  gap: .25rem;
  flex-wrap: wrap;
  padding: .35rem .5rem;
  background: var(--slate-light);
  border: 1.5px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}
.wysiwyg-toolbar button[data-cmd] {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 4px;
  padding: .2rem .55rem;
  cursor: pointer;
  font-size: .82rem;
  min-width: 30px;
  line-height: 1.4;
  color: var(--text);
}
.wysiwyg-toolbar button[data-cmd]:hover { background: var(--slate-light); }
.wysiwyg-toolbar select { font-size: .8rem; padding: .2rem .3rem; border-radius: 4px; border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer; }
.wysiwyg-editor {
  border: 1.5px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 1rem 1.1rem;
  min-height: 180px;
  background: var(--card);
  color: var(--text);
  font-family: sans-serif;
  font-size: .9rem;
  line-height: 1.65;
  outline: none;
  overflow-y: auto;
}
.wysiwyg-editor:focus { border-color: var(--primary); }
.toolbar-sep { width: 1px; height: 18px; background: var(--border); margin: 0 .15rem; flex-shrink: 0; }

/* ── Multiselect field ─────────────────────────────────────────────────────── */
.multiselect-group {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  padding: .5rem .6rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.multiselect-group .checkbox-label {
  font-size: .9rem;
  margin: 0;
}

/* ── Login ─────────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--bg);
}
.login-card {
  background: var(--card);
  border-radius: 12px;
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-md);
  border: 1.5px solid var(--border);
}
.login-brand { text-align: center; margin-bottom: 1.75rem; }
.login-logo { font-size: 2rem; margin-bottom: .4rem; }
.login-brand h1 { font-size: 1.4rem; font-weight: 700; }
.login-brand p { font-size: .85rem; color: var(--text-muted); margin-top: .2rem; }
.error-msg {
  background: var(--red-light);
  color: var(--red);
  border: 1.5px solid #fca5a5;
  border-radius: var(--radius);
  padding: .6rem .85rem;
  font-size: .85rem;
  margin-bottom: 1rem;
}

/* ── Toast ─────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 5rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  z-index: 500;
  pointer-events: none;
}
.toast {
  padding: .6rem 1rem;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: fadeIn .2s ease;
  pointer-events: all;
  max-width: 280px;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.toast-success { background: #166534; color: #fff; }
.toast-error   { background: var(--red); color: #fff; }

/* ── Change password view ──────────────────────────────────────────────────── */
.change-pw-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.change-pw-card {
  background: var(--card);
  border-radius: 12px;
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-md);
  border: 1.5px solid var(--border);
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  /* Nav: CSS Grid - brand+actions on row 1, tabs on row 2.
     Grid is more reliable than flex-wrap ordering for preventing overflow. */
  .topnav {
    display: grid;
    grid-template-areas: "brand actions" "tabs tabs";
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    padding: .45rem .75rem .3rem;
    gap: .2rem .4rem;
    min-height: auto;
    width: 100%;
    box-sizing: border-box;
  }
  .topnav-brand {
    grid-area: brand;
    font-size: .95rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topnav-spacer { display: none; }
  .topnav-user   { display: none; }
  .topnav-actions {
    grid-area: actions;
    display: flex;
    align-items: center;
    gap: .25rem;
  }
  .view-tabs {
    grid-area: tabs;
    display: flex;
    padding-bottom: .2rem;
  }
  .view-tabs .view-tab { flex: 1; text-align: center; padding: .32rem .2rem; font-size: .8rem; }

  /* Icon-only action buttons */
  #nav-logout, #nav-admin, #nav-cpw {
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
    flex-shrink: 0;
  }
  #nav-logout::after { content: '↩'; font-size: .95rem; }
  #nav-admin::after  { content: '⚙'; font-size: .95rem; }
  #nav-cpw::after    { content: '🔒'; font-size: .85rem; }

  /* Calendar */
  .week-grid { grid-template-columns: 1fr; }
  .week-col { display: flex; gap: .5rem; }
  .week-col-header { min-width: 70px; border-bottom: none; border-right: 1.5px solid var(--border); }
  .week-bookings { flex-direction: row; flex-wrap: wrap; }
  .month-cell { min-height: 60px; }
  .day-chip { display: none; }
  .day-num-with-dot::after {
    content: '•';
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--blue);
    font-size: .9rem;
  }

  /* Forms */
  .form-row { grid-template-columns: 1fr; }

  /* Modal - explicit width cap + x-scroll prevention */
  .modal {
    max-height: 96vh;
    max-height: 96dvh;
    max-width: 100vw;
    border-radius: 12px 12px 0 0;
  }
  .modal-body  { padding: .85rem 1rem; overflow-x: hidden; }
  .modal-footer { padding: .6rem 1rem; }

  /* Admin */
  .data-table { font-size: .8rem; }
  .data-table th, .data-table td { padding: .45rem .55rem; }
  .page { padding: .85rem .75rem; }
}

@media (max-width: 480px) {
  .topnav-brand .topnav-name { display: none; }
  .month-dow { font-size: .65rem; padding: .35rem .1rem; }
  .month-cell { padding: .25rem .15rem; }
  .day-num { font-size: .75rem; width: 22px; height: 22px; }
  .cal-header { gap: .35rem; }
  .cal-title { font-size: 1rem; min-width: 0; }
}

/* Prevent any single form element from escaping its container */
input, select, textarea { max-width: 100%; }

/* ── Dark mode ─────────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:         #0f172a;
  --card:       #1e293b;
  --text:       #e2e8f0;
  --text-muted: #94a3b8;
  --border:     #334155;
  --slate-light:#263248;
  --blue-light: #1e3a5f;
  --green-light:#0a2e18;
  --amber-light:#1c0f02;
  --red-light:  #1c0505;
  --shadow:     0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-md:  0 4px 6px rgba(0,0,0,.4), 0 2px 4px rgba(0,0,0,.25);
}

/* Status chips -- need explicit bg+text since light-variant vars are now very dark */
[data-theme="dark"] .day-chip                  { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .day-chip.status-confirmed { background: #0a2e18; color: #86efac; }
[data-theme="dark"] .day-chip.status-completed { background: #263248; color: #94a3b8; }
[data-theme="dark"] .day-chip.status-cancelled { background: #2d0909; color: #fca5a5; }
[data-theme="dark"] .day-chip.status-pending   { background: #1c0f02; color: #fcd34d; }

[data-theme="dark"] .week-chip                  { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .week-chip.status-confirmed { background: #0a2e18; color: #86efac; }
[data-theme="dark"] .week-chip.status-completed { background: #263248; color: #94a3b8; }
[data-theme="dark"] .week-chip.status-cancelled { background: #2d0909; color: #fca5a5; }
[data-theme="dark"] .week-chip.status-pending   { background: #1c0f02; color: #fcd34d; }

[data-theme="dark"] .status-pending   { background: #1c0f02; color: #fcd34d; }
[data-theme="dark"] .status-confirmed { background: #0a2e18; color: #86efac; }
[data-theme="dark"] .status-completed { background: #263248; color: #94a3b8; }
[data-theme="dark"] .status-cancelled { background: #2d0909; color: #fca5a5; }

[data-theme="dark"] .booking-time-tag { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .conflict-badge   { background: #1c0f02; color: #fcd34d; }

/* Badges */
[data-theme="dark"] .badge-admin  { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge-user   { background: #263248; color: #94a3b8; }
[data-theme="dark"] .badge-req    { background: #2d0909; color: #fca5a5; }
[data-theme="dark"] .badge-opt    { background: #263248; color: #94a3b8; }
[data-theme="dark"] .badge-cal    { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .badge-system { background: #2e1065; color: #c4b5fd; }

/* Hardcoded border/bg overrides */
[data-theme="dark"] .override-note      { background: #1c0f02; color: #fcd34d; }
[data-theme="dark"] .day-closed-notice  { border-color: #92400e; }
[data-theme="dark"] .conflict-warning   { border-color: #92400e; }
[data-theme="dark"] .error-msg          { border-color: #7f1d1d; }
[data-theme="dark"] .modal-overlay      { background: rgba(0,0,0,.7); }
[data-theme="dark"] .btn-danger:hover   { background: #7f1d1d; }

/* Calendar cell overrides */
[data-theme="dark"] .month-cell.other-month .day-num { color: #334155; }
[data-theme="dark"] .month-cell:hover,
[data-theme="dark"] .month-cell.selected { background: #1a2d45; }
[data-theme="dark"] .month-cell.day-closed {
  background: repeating-linear-gradient(135deg, transparent, transparent 4px, rgba(255,255,255,.02) 4px, rgba(255,255,255,.02) 8px);
}
[data-theme="dark"] .week-col.day-closed {
  background: repeating-linear-gradient(135deg, transparent, transparent 4px, rgba(255,255,255,.02) 4px, rgba(255,255,255,.02) 8px);
}
[data-theme="dark"] .time-slot--empty .time-slot-bookings {
  background: repeating-linear-gradient(135deg, transparent, transparent 6px, rgba(255,255,255,.02) 6px, rgba(255,255,255,.02) 12px);
}

/* Misc */
[data-theme="dark"] .data-table tr:hover td { background: #1a2d45; }

/* Legend swatches: use lighter pastels so small boxes are visible on dark bg */
[data-theme="dark"] .cal-legend-swatch.status-pending   { background: #fcd34d; }
[data-theme="dark"] .cal-legend-swatch.status-confirmed { background: #86efac; }
[data-theme="dark"] .cal-legend-swatch.status-cancelled { background: #fca5a5; }
[data-theme="dark"] .cal-legend-swatch.status-completed { background: #cbd5e1; }
