:root {
  --bg: #f2f6f3;
  --surface: #ffffff;
  --surface-2: #f5f8f6;
  --border: #e0e8e3;
  --text: #14261c;
  --muted: #5f7168;
  --primary: #1f7a54;        /* sage green */
  --primary-dark: #155e40;
  --primary-soft: #d9efe4;
  --preferred: #15803d;
  --preferred-soft: #dcfce7;
  --available: #2563eb;
  --available-soft: #dbeafe;
  --unavailable: #dc2626;
  --unavailable-soft: #fee2e2;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --gap: #c2410c;
  --gap-soft: #ffedd5;
  --shadow: 0 1px 2px rgba(16, 40, 28, .06), 0 8px 24px rgba(16, 40, 28, .07);
  --radius: 12px;
}

/* role accent colors */
.role-physician { --rc: #1f7a54; --rc-soft: #d9efe4; }
.role-pa        { --rc: #2563eb; --rc-soft: #dbeafe; }
.role-ma        { --rc: #9333ea; --rc-soft: #f3e8ff; }
.role-xr_tech   { --rc: #b45309; --rc-soft: #fef3c7; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5; -webkit-font-smoothing: antialiased;
}

/* ---- Top bar ---- */
.topbar { display: flex; align-items: center; gap: 20px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; color: var(--primary-dark); }
.logo { font-size: 20px; }
.topnav { display: flex; gap: 4px; margin-left: 12px; }
.topnav button { border: none; background: transparent; color: var(--muted); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600; }
.topnav button.active { background: var(--primary-soft); color: var(--primary-dark); }
.topnav button:hover:not(.active) { background: var(--surface-2); color: var(--text); }
.userchip { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); }
.userchip strong { color: var(--text); }

/* ---- Layout ---- */
.app { max-width: 1240px; margin: 0 auto; padding: 24px; }
.loading { text-align: center; color: var(--muted); padding: 80px 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; margin: 0 0 4px; }
.page-head p { margin: 0; color: var(--muted); font-size: 14px; }

/* ---- Auth ---- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { background: var(--surface); width: 100%; max-width: 440px; border-radius: 16px; box-shadow: var(--shadow); padding: 32px; border: 1px solid var(--border); }
.auth-card .logo-lg { font-size: 40px; text-align: center; display: block; }
.auth-card h1 { text-align: center; font-size: 21px; margin: 8px 0 2px; color: var(--primary-dark); }
.auth-card .sub { text-align: center; color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.tabs { display: flex; background: var(--surface-2); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.tabs button { flex: 1; border: none; background: transparent; padding: 9px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 6px; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; font-size: 14px; font-family: inherit; background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: none; border-radius: 9px; padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer; background: var(--primary); color: #fff; text-decoration: none; }
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn.block { width: 100%; margin-top: 18px; padding: 12px; }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.error-msg { color: var(--unavailable); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---- Cards / toolbar ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-body { padding: 18px; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.legend .dot { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; border: 1px solid rgba(0,0,0,.06); }
.swatch.preferred { background: var(--preferred-soft); border-color: var(--preferred); }
.swatch.available { background: var(--available-soft); border-color: var(--available); }
.swatch.unavailable { background: var(--unavailable-soft); border-color: var(--unavailable); }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 13px; }

/* ---- Week / grid ---- */
.week { margin-bottom: 18px; }
.week-head { display: flex; align-items: center; gap: 10px; margin: 0 2px 8px; }
.week-head h3 { font-size: 14px; margin: 0; }
.week-head .range { color: var(--muted); font-size: 13px; }
.lock-badge { font-size: 12px; font-weight: 700; color: var(--amber); background: var(--amber-soft); padding: 2px 8px; border-radius: 20px; }

/* staff availability: 7 columns of day cells */
.availgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.availgrid .dayhead { font-size: 12px; font-weight: 700; color: var(--muted); padding: 2px; text-align: center; }
.availgrid .dayhead.today { color: var(--primary); }
.daycell { border: 1px solid var(--border); border-radius: 10px; min-height: 72px; padding: 8px; cursor: pointer; background: var(--surface-2); display: flex; flex-direction: column; gap: 4px; position: relative; }
.daycell .dnum { font-weight: 700; font-size: 15px; }
.daycell .state { font-size: 12px; font-weight: 700; }
.daycell .note { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.daycell[data-pref="preferred"] { background: var(--preferred-soft); border-color: var(--preferred); }
.daycell[data-pref="preferred"] .state { color: var(--preferred); }
.daycell[data-pref="available"] { background: var(--available-soft); border-color: var(--available); }
.daycell[data-pref="available"] .state { color: var(--available); }
.daycell[data-pref="unavailable"] { background: var(--unavailable-soft); border-color: var(--unavailable); }
.daycell[data-pref="unavailable"] .state { color: var(--unavailable); }
.daycell.locked { cursor: not-allowed; opacity: .6; }
.daycell:hover:not(.locked) { box-shadow: 0 2px 8px rgba(0,0,0,.08); }

/* ---- Save bar ---- */
.savebar { position: sticky; bottom: 0; margin-top: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 18px; display: flex; align-items: center; gap: 14px; }
.savebar .dirty { color: var(--amber); font-weight: 600; font-size: 14px; }
.savebar .clean { color: var(--muted); font-size: 14px; }

/* ---- Admin board ---- */
.boardgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.boardhead { font-size: 12px; font-weight: 700; color: var(--muted); text-align: center; padding: 2px; }
.boardcell { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); padding: 8px; min-height: 128px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.boardcell:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.boardcell .bc-top { display: flex; align-items: center; justify-content: space-between; }
.boardcell .dnum { font-weight: 700; }
.cov { font-size: 11px; font-weight: 800; padding: 1px 7px; border-radius: 20px; }
.cov.ok { background: var(--ok-soft); color: var(--ok); }
.cov.gap { background: var(--gap-soft); color: var(--gap); }
.slot { font-size: 12px; display: flex; gap: 5px; align-items: baseline; }
.slot .rl { font-weight: 800; font-size: 10px; letter-spacing: .02em; color: var(--rc, var(--muted)); min-width: 26px; text-transform: uppercase; }
.slot .names { color: var(--text); }
.slot .empty { color: var(--gap); font-weight: 600; }
.boardcell.locked { opacity: .7; }
.gaplist { margin-top: auto; font-size: 11px; color: var(--gap); }

/* role pill */
.rolepill { font-size: 11px; font-weight: 800; padding: 1px 8px; border-radius: 20px; background: var(--rc-soft, var(--surface-2)); color: var(--rc, var(--muted)); border: 1px solid transparent; }

/* ---- Tables ---- */
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.data th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.pill { font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 20px; display: inline-block; }
.pill.on { background: var(--preferred-soft); color: var(--preferred); }
.pill.off { background: var(--unavailable-soft); color: var(--unavailable); }
.pill.admin { background: var(--primary-soft); color: var(--primary-dark); }

/* ---- Modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16,40,28,.5); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: var(--surface); border-radius: 14px; padding: 22px; width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 4px; }
.modal .row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.pref-btn { flex: 1; min-width: 92px; padding: 10px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); font-weight: 700; cursor: pointer; }
.pref-btn.preferred.sel { background: var(--preferred-soft); border-color: var(--preferred); color: var(--preferred); }
.pref-btn.available.sel { background: var(--available-soft); border-color: var(--available); color: var(--available); }
.pref-btn.unavailable.sel { background: var(--unavailable-soft); border-color: var(--unavailable); color: var(--unavailable); }
.modal .actions { display: flex; justify-content: space-between; margin-top: 18px; gap: 8px; }

/* day editor role groups */
.rolegroup { margin-top: 14px; }
.rolegroup h4 { margin: 0 0 8px; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.rolegroup .req { font-size: 11px; color: var(--muted); font-weight: 600; }
.person { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 9px; margin-bottom: 6px; }
.person .pname { font-weight: 600; }
.person .pavail { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 20px; }
.pavail.preferred { background: var(--preferred-soft); color: var(--preferred); }
.pavail.available { background: var(--available-soft); color: var(--available); }
.pavail.unavailable { background: var(--unavailable-soft); color: var(--unavailable); }
.pavail.none { background: var(--surface-2); color: var(--muted); }
.person .pnote { font-size: 11px; color: var(--muted); font-style: italic; }
.person.assigned { border-color: var(--primary); background: var(--primary-soft); }
.person .grow { flex: 1; }
.cov-summary { margin-top: 4px; padding: 10px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; }
.cov-summary.ok { background: var(--ok-soft); color: var(--ok); }
.cov-summary.gap { background: var(--gap-soft); color: var(--gap); }

/* ---- Toast ---- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #14261c; color: #fff; padding: 12px 20px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); z-index: 200; max-width: 90vw; }
.toast.err { background: #b91c1c; }

/* ---- notifications bell ---- */
.bell { position: relative; border: 1px solid var(--border); background: var(--surface); border-radius: 9px; padding: 6px 10px; cursor: pointer; font-size: 15px; }
.bell:hover { background: var(--surface-2); }
.bell .badge { position: absolute; top: -6px; right: -6px; background: var(--unavailable); color: #fff; font-size: 10px; font-weight: 800; border-radius: 20px; padding: 1px 6px; }
.notif { padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; margin-bottom: 6px; font-size: 14px; }
.notif.unread { background: var(--primary-soft); border-color: var(--primary); }

/* ---- my schedule cards ---- */
.shiftlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.shiftcard { display: flex; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 14px; }
.sc-date { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 62px; background: var(--primary-soft); color: var(--primary-dark); border-radius: 10px; padding: 8px; }
.sc-dow { font-size: 12px; font-weight: 700; text-transform: uppercase; }
.sc-day { font-size: 15px; font-weight: 800; }
.sc-body { display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.sc-time { font-weight: 700; }
.sc-mates { font-size: 13px; color: var(--text); }
.card-body.empty { text-align: center; padding: 32px; }
.card-body.empty p { margin: 6px 0; }

/* ---- board summary / autofill ---- */
.summary { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.sumcard { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; }
.sumcard .sumnum { font-size: 22px; font-weight: 800; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; }
.sumcard.good { color: var(--ok); } .sumcard.good .sumnum { background: var(--ok-soft); }
.sumcard.warn { color: var(--gap); } .sumcard.warn .sumnum { background: var(--gap-soft); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 20px; border: 1px solid var(--gap); background: var(--gap-soft); color: var(--gap); cursor: pointer; }
.chip:hover { filter: brightness(0.97); }
.conflict-banner { background: var(--amber-soft); color: var(--amber); border: 1px solid var(--amber); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 13px; font-weight: 600; }

/* ---- publish ---- */
.pub-badge { font-size: 12px; font-weight: 800; color: var(--primary-dark); background: var(--primary-soft); padding: 2px 9px; border-radius: 20px; }
.boardcell.pub { border-color: var(--primary); }
.person.conflict { border-color: var(--unavailable); background: var(--unavailable-soft); }
.rowbtns { display: flex; gap: 6px; flex-wrap: wrap; }
.temppw { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 20px; font-weight: 700; letter-spacing: .06em; background: var(--surface-2); border: 1px dashed var(--border); border-radius: 10px; padding: 14px; text-align: center; margin: 10px 0; user-select: all; }

/* ---- quick-assign ---- */
.quick-banner { display: flex; align-items: center; gap: 10px; background: var(--primary-soft); color: var(--primary-dark); border: 1px solid var(--primary); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; font-weight: 600; }
.boardcell.quickmode { cursor: copy; }
.boardcell.quickmode:hover { outline: 2px dashed var(--primary); }
.boardcell.quick-on { outline: 3px solid var(--primary); background: var(--primary-soft); }

.grid-scroll { overflow-x: auto; }
@media (max-width: 820px) {
  .availgrid, .boardgrid { min-width: 780px; }
  .userchip .email { display: none; }
  .shiftlist { grid-template-columns: 1fr; }
}
