:root {
  /* Ysgol Bro Taf brand */
  --brand: #404042;        /* charcoal — primary UI colour */
  --brand-dark: #2b2b2d;
  --accent: #df0a15;       /* brand red — used sparingly */
  --grey: #868690;
  --bg: #f6f6f7;
  --card: #ffffff;
  --text: #2d2d31;
  --muted: #868690;
  --border: #e3e3e6;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

/* Header: clean white bar with a thin red brand line */
header.bar {
  background: var(--card);
  color: var(--text);
  border-bottom: 2px solid var(--accent);
  padding: 10px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
header.bar a { color: var(--brand); }
header.bar .hleft { display: flex; align-items: center; gap: 12px; }
header.bar .hlogo { height: 40px; width: 40px; }
header.bar .brand {
  font-weight: 700; font-size: 1.05rem; text-decoration: none;
  color: var(--brand-dark); display: block; line-height: 1.25;
}
header.bar .strap { color: var(--grey); font-size: 0.7rem; letter-spacing: 0.02em; display: block; }
header.bar .hright { display: flex; gap: 14px; align-items: center; font-size: 0.85rem; flex-wrap: wrap; }
header.bar .hright a { text-decoration: none; font-weight: 600; }
header.bar .hright a:hover { color: var(--accent); }
header.bar .who { color: var(--muted); }

/* App shell: left navigation + content */
.shell { display: flex; align-items: stretch; min-height: calc(100vh - 65px); }
.sidenav {
  flex: 0 0 225px;
  display: flex; flex-direction: column;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
}
.snav-spacer { flex: 1 1 auto; }
.snav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 4px;
  border-radius: 10px; border-left: 3px solid transparent;
  color: var(--brand-dark); font-weight: 600; font-size: 0.9rem;
  text-decoration: none;
}
a.snav-item:hover { background: #f0f0f2; }
.snav-item.active { background: #ececee; border-left-color: var(--accent); }
.snav-item.disabled { color: var(--muted); cursor: default; }
.snav-item .soon {
  margin-left: auto; background: #ececee; color: var(--muted);
  border-radius: 99px; padding: 1px 8px; font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.shell .content { flex: 1 1 auto; min-width: 0; }
@media (max-width: 900px) {
  .shell { display: block; min-height: 0; }
  .sidenav {
    display: flex; gap: 6px; padding: 8px 12px;
    border-right: none; border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .snav-item { margin-bottom: 0; white-space: nowrap; border-left: none; }
  .snav-item.active { box-shadow: inset 0 -2px 0 var(--accent); }
}

/* Breadcrumbs */
.crumbs {
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  font-size: 0.82rem; margin-bottom: 14px;
}
.crumbs a {
  color: var(--muted); text-decoration: none; font-weight: 500;
  padding: 4px 11px; border-radius: 99px;
  transition: background 0.12s, color 0.12s;
}
.crumbs a:hover { background: #ececee; color: var(--brand-dark); }
.crumbs .here {
  color: var(--brand-dark); font-weight: 600;
  padding: 4px 11px; border-radius: 99px; background: #ececee;
}
.crumbs .sep { color: #c5c5ca; display: flex; align-items: center; }

main.page { max-width: 1000px; margin: 0 auto; padding: 24px 20px 60px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
h2 { color: var(--brand-dark); margin: 0 0 12px; font-size: 1.15rem; }
label { display: block; font-weight: 600; margin: 10px 0 4px; font-size: 0.9rem; }
input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--grey); }
button.primary {
  background: var(--brand); color: #fff; border: none; border-radius: 8px;
  padding: 10px 20px; font: inherit; font-weight: 600; cursor: pointer; margin-top: 12px;
}
button.primary:hover { background: var(--brand-dark); }
button.primary:disabled { opacity: 0.5; cursor: default; }
button.small {
  background: #ececee; color: var(--brand-dark); border: none; border-radius: 7px;
  padding: 6px 12px; font: inherit; font-size: 0.83rem; font-weight: 600; cursor: pointer;
}
button.small:hover { background: #e0e0e3; }
.error { color: #b42318; background: #fef3f2; border: 1px solid #fecdca; padding: 10px 12px; border-radius: 8px; margin: 10px 0; }
.ok { color: var(--brand-dark); background: #f0f0f2; border: 1px solid var(--grey); padding: 10px 12px; border-radius: 8px; margin: 10px 0; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* Filter bar (dashboard) */
.filterbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin: 0 0 16px;
}
.fpill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card); color: var(--brand-dark);
  border: 1px solid var(--border); border-radius: 99px;
  padding: 5px 12px; font: inherit; font-size: 0.8rem; font-weight: 600;
  cursor: pointer; transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.fpill:hover { border-color: var(--grey); }
.fpill.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.fpill .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.fdiv { width: 1px; align-self: stretch; background: var(--border); margin: 2px 8px; }

/* Map list */
.maplist { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
a.mapcard {
  display: block; position: relative; background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; text-decoration: none; color: var(--text);
  border-left: 3px solid var(--border);
}
a.mapcard:hover { border-color: var(--grey); border-left-color: var(--accent); }
a.mapcard .mapdel {
  position: absolute; top: 8px; right: 8px;
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 0.9rem; font-weight: 600;
  width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
a.mapcard .mapdel:hover { color: var(--accent); background: #fdf1f2; }
a.mapcard .t { padding-right: 26px; }
a.mapcard .t { font-weight: 700; color: var(--brand-dark); margin-bottom: 4px; }
.badge {
  display: inline-block; background: #ececee; color: var(--brand-dark);
  border-radius: 99px; padding: 2px 10px; font-size: 0.75rem; font-weight: 600; margin-right: 6px;
}
.badge.team { display: inline-flex; align-items: center; gap: 6px; }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* Chip pickers (create-map form) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; min-height: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: #ececee; color: var(--brand-dark);
  border-radius: 99px; padding: 3px 6px 3px 11px; font-size: 0.8rem; font-weight: 600;
}
.chip button {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 0.75rem; font-weight: 700;
  width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.chip button:hover { color: var(--accent); background: #fdf1f2; }

/* Drag & drop zone (create-map form) */
.dropzone {
  display: flex; align-items: center; gap: 14px;
  border: 1.5px dashed #c9c9ce; border-radius: 12px;
  background: #fafafb; color: var(--grey);
  padding: 14px 18px; margin-top: 6px;
  cursor: pointer; user-select: none;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.dropzone:hover { border-color: var(--grey); color: var(--brand); }
.dropzone.drag { border-color: var(--accent); background: #fdf6f6; color: var(--brand-dark); }
.dropzone .dz-text { font-size: 0.9rem; color: var(--text); }
.dropzone .dz-text .dz-browse { color: var(--accent); font-weight: 600; text-decoration: underline; }
.dropzone .dz-hint { font-size: 0.75rem; color: var(--muted); margin-top: 1px; }
.dz-file {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--card); padding: 10px 14px; margin-top: 6px;
  font-size: 0.88rem;
}
.dz-file .dz-fn { font-weight: 600; color: var(--brand-dark); word-break: break-all; }
.dz-file button {
  margin-left: auto; background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 0.9rem; font-weight: 600;
  width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.dz-file button:hover { color: var(--accent); background: #fdf1f2; }

/* Branded confirmation popup */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(45, 45, 49, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadein 0.15s ease-out;
}
.modal {
  background: var(--card); border-radius: 14px;
  max-width: 440px; width: 100%;
  padding: 22px 24px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.25);
  border-top: 3px solid var(--accent);
  animation: pop 0.16s ease-out;
}
.modal h3 { margin: 0 0 8px; color: var(--brand-dark); font-size: 1.05rem; }
.modal p { margin: 0 0 18px; color: var(--muted); font-size: 0.9rem; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
button.danger {
  background: var(--accent); color: #fff; border: none; border-radius: 7px;
  padding: 8px 18px; font: inherit; font-size: 0.88rem; font-weight: 600; cursor: pointer;
}
button.danger:hover { background: #c00912; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }

/* Staff table */
table.staff { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
table.staff th, table.staff td { border-bottom: 1px solid var(--border); padding: 8px 8px; text-align: left; }
table.staff select { width: auto; padding: 5px 8px; }

/* Chat (map page) */
.split { display: flex; gap: 18px; align-items: flex-start; }
.chatcol { flex: 1 1 640px; min-width: 0; }
.sidecol { flex: 0 0 300px; }
@media (max-width: 900px) { .split { flex-direction: column-reverse; } .sidecol { width: 100%; flex: none; } }
#chat {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  height: calc(100vh - 220px); min-height: 420px; overflow-y: auto; padding: 16px;
}
.msg { border-radius: 12px; padding: 12px 16px; margin-bottom: 12px; max-width: 94%; overflow-wrap: break-word; }
.user { background: var(--brand); color: #fff; margin-left: auto; white-space: pre-wrap; }
.assistant { background: #f7f7f8; border: 1px solid var(--border); }
.assistant h1, .assistant h2, .assistant h3 { color: var(--brand-dark); margin-top: 0.8em; }
.assistant table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 0.9rem; }
.assistant th, .assistant td { border: 1px solid var(--border); padding: 6px 9px; text-align: left; vertical-align: top; }
.assistant th { background: #ececee; }
.assistant pre { background: #f0f0f2; padding: 10px; border-radius: 8px; overflow-x: auto; }
.status { color: var(--muted); font-size: 0.85rem; font-style: italic; margin: 0 0 12px 4px; }
.options { margin: -2px 0 14px; display: flex; flex-direction: column; gap: 8px; max-width: 94%; }
.options button {
  text-align: left; background: #fff; border: 1.5px solid var(--grey); color: var(--brand-dark);
  border-radius: 10px; padding: 9px 14px; font: inherit; cursor: pointer;
}
.options button:hover { border-color: var(--accent); background: #fdfbfb; }
.msgtools { margin: -6px 0 14px 4px; }
.msgtools button {
  background: none; border: none; color: var(--muted); font-size: 0.8rem;
  cursor: pointer; padding: 2px 8px 2px 0; text-decoration: underline;
}
.msgtools button:hover { color: var(--accent); }
#inputBar { display: flex; gap: 10px; margin-top: 12px; }
#inputBox { flex: 1; resize: none; max-height: 140px; }
.spinner {
  display: inline-block; width: 14px; height: 14px; margin-right: 7px;
  border: 2px solid #d9d9dc; border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.filecard {
  display: flex; align-items: center; gap: 10px; background: var(--card);
  border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px;
  margin-bottom: 8px; cursor: pointer; user-select: none;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.filecard:hover {
  border-color: var(--grey);
  box-shadow: 0 3px 10px rgba(0,0,0,0.07);
  transform: translateY(-1px);
}
.filecard .ficon {
  flex: 0 0 34px; height: 34px; border-radius: 9px;
  background: #f0f0f2; color: var(--brand);
  display: flex; align-items: center; justify-content: center;
}
.filecard:hover .ficon { background: #eaeaec; }
.filecard .fmeta { min-width: 0; }
.filecard .fn { font-weight: 600; color: var(--brand-dark); font-size: 0.88rem; line-height: 1.3; }
.filecard .kind { color: var(--muted); font-size: 0.74rem; }
.filecard .filedel {
  margin-left: auto; flex: 0 0 auto;
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 0.9rem; font-weight: 600;
  width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.filecard .filedel:hover { color: var(--accent); background: #fdf1f2; }
