/* ── ACHD Planner ────────────────────────────────────────────── */
.achd-subtabs { display: inline-flex; gap: 4px; margin-right: 12px; }
.panel-title-group .achd-subtabs { margin: 0 0 0 12px; align-self: center; }
.achd-subtab {
  border: 1px solid rgba(104,137,178,0.35); background: transparent; color: var(--muted, #5a6d84);
  border-radius: 999px; padding: 4px 12px; font-size: 0.82rem; font-weight: 600; cursor: pointer;
}
.achd-subtab--on { background: var(--accent, #1565c0); border-color: transparent; color: #fff; }
/* Actions dropdown (toolbar overflow menu) */
.achd-menu-wrap { position: relative; display: inline-block; }
.achd-menu {
  position: absolute; top: calc(100% + 4px); right: 0; z-index: 50;
  min-width: 210px; padding: 6px; display: flex; flex-direction: column;
  background: var(--panel-bg, #fff); border: 1px solid rgba(104,137,178,0.35);
  border-radius: 10px; box-shadow: 0 8px 28px rgba(19,35,54,0.18);
}
.achd-menu[hidden] { display: none; }
.achd-menu-item {
  border: none; background: none; cursor: pointer; text-align: left;
  font-size: 0.85rem; padding: 7px 10px; border-radius: 6px;
  color: var(--text, #1a2535); white-space: nowrap;
}
.achd-menu-item:hover { background: rgba(21,101,192,0.08); }
.achd-hint { margin: 4px 0 10px; font-size: 0.8rem; color: var(--muted, #5a6d84); }

.achd-table-wrap { overflow: auto; max-height: calc(100vh - var(--sticky-chrome-height, 100px) - 130px); padding-bottom: 8px; min-width: 0; max-width: 100%; }

/* Same panel mechanics as the SMO/Trainee views: bounded flex column, wrapping
   toolbar — without these the wide grid inflates the panel past the viewport
   and the app's overflow-x:hidden crops it on mobile. */
#view-achd .panel { display: flex; flex-direction: column; height: 100%; min-height: 0; }
#view-achd .panel-head { justify-content: flex-start; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
#view-achd .ph-zone { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
#achdRoot { min-width: 0; max-width: 100%; }
.achd-table { border-collapse: collapse; font-size: 0.82rem; min-width: 100%; table-layout: fixed; }
/* Column widths: date + assignee sized for full names, SMO columns share the
   rest evenly. */
.achd-table th.achd-date { width: 150px; }
.achd-table th.achd-asg  { width: 150px; }
.achd-table th, .achd-table td { border: 1px solid rgba(104,137,178,0.18); padding: 3px 6px; white-space: nowrap; }
/* Vertical separators between SMO columns. The per-cell colour fills are
   opaque and cover cell borders, so the line is drawn on the fill layer
   itself (right edge of each column's fill) — always visible. */
.achd-table thead th:not(.achd-date):not(.achd-asg) { border-left: 1px solid rgba(71,85,105,0.5); }
.achd-table tbody td.achd-cell .achd-halves { border-right: 1.5px solid rgba(71,85,105,0.55); }
.achd-table th.achd-asg, .achd-table td.achd-asg {
  border-left: 2px solid rgba(104,137,178,0.6);
  border-right: 2px solid rgba(104,137,178,0.6);
}
.achd-date, .achd-asg { overflow: hidden; text-overflow: ellipsis; }
.achd-th-orient { font-size: 0.62rem; font-weight: 700; color: #9d174d; text-transform: none; letter-spacing: 0.02em; }
.achd-table thead th { position: sticky; top: 0; background: var(--panel-bg, #fff); font-size: 0.75rem; z-index: 4; }
.achd-table thead th.achd-date, .achd-table thead th.achd-wkcol { z-index: 6; }
/* Week-type bar: narrow coloured stripe, always-lettered, sticky at the left
   edge together with the date column. */
.achd-wkcol {
  position: sticky; left: 0; z-index: 3;
  width: 18px; min-width: 18px; max-width: 18px; padding: 0 !important;
  text-align: center; font-size: 0.68rem; font-weight: 800;
  background: #b9c0c8; color: #5a6470;
}
.achd-wkcol--a { background: #5b83a8; color: #eaf2f8; }
.achd-wkcol--b { background: #5f9e78; color: #ecf7f0; }
.achd-wkcol--c { background: #c19a4b; color: #faf3e3; }
.achd-wkcol--d { background: #8b6fb8; color: #f3eef9; }
.achd-date { font-weight: 600; position: sticky; left: 18px; background: var(--panel-bg, #fff); z-index: 3; }
.achd-wk { font-weight: 400; color: var(--muted, #5a6d84); font-size: 0.72rem; }
.achd-holiday { color: #b45309; font-size: 0.72rem; font-weight: 500; }
.achd-note { color: var(--muted, #5a6d84); font-size: 0.72rem; }
.achd-extra-tag {
  background: rgba(190,24,93,0.1); color: #9d174d; border-radius: 4px;
  font-size: 0.68rem; padding: 1px 5px; text-transform: uppercase; letter-spacing: 0.04em;
}
.achd-act-tag { border-radius: 4px; font-size: 0.68rem; padding: 1px 5px; font-weight: 600; }
.achd-act-tag--ep  { background: rgba(21,101,192,0.1); color: #0a5a8a; }
.achd-act-tag--ciu { background: rgba(190,24,93,0.1); color: #9d174d; }
.achd-extra-del { border: none; background: none; color: #b91c1c; cursor: pointer; font-size: 0.9rem; padding: 0 2px; }

.achd-asg { font-weight: 700; text-align: center; position: relative; }
td.achd-asg[data-achd-edit] { cursor: pointer; }
td.achd-asg[data-achd-edit]:hover { outline: 2px solid rgba(21,101,192,0.4); outline-offset: -2px; }
.achd-clear {
  position: absolute; top: 0; right: 1px; display: none;
  border: none; background: none; color: #b91c1c; cursor: pointer;
  font-size: 0.85rem; line-height: 1; padding: 1px 3px; font-weight: 700;
}
td.achd-asg:hover .achd-clear { display: block; }
.achd-asg--empty { color: var(--muted, #5a6d84); font-weight: 400; }
.achd-asg--draft { background: rgba(37,99,235,0.14); color: #1d4ed8; }
/* Roster-derived holder: name shown when the live roster already has someone
   holding the list's code all day but the plan slot is empty (derive-only). */
.achd-asg--roster { color: #475569; font-weight: 600; box-shadow: inset 0 0 0 1px rgba(100,116,139,.45); }
.achd-roster-tag { font-size: 0.6rem; font-weight: 700; color: #64748b; text-transform: uppercase; letter-spacing: .03em; }
.achd-pair { font-weight: 500; font-size: 0.75rem; color: var(--muted, #5a6d84); }

.achd-cell { text-align: center; font-size: 0.78rem; padding: 0 !important; position: relative; height: 34px; }
/* Halves fill the whole cell (absolute inset) so the background colour covers
   the full cell area even when one or both halves have no code. */
.achd-halves { position: absolute; inset: 0; display: flex; }
.achd-half { flex: 1 1 0; display: flex; align-items: center; justify-content: center; padding: 3px 2px 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.achd-half:first-child { border-right: 1px solid rgba(104,137,178,0.3); }
/* OC/PC pills overlay the bottom of the cell — they never change its height,
   so rows stay perfectly aligned whether or not badges are present. */
.achd-badges { position: absolute; bottom: 1px; left: 0; right: 0; text-align: center; line-height: 1; pointer-events: none; }
.achd-badge { font-size: 0.6rem; padding: 0 3px; }
/* Ring around the tab's list code (stroke only, no fill) — highlights who
   actually holds ACHD / CARD-C that day without touching the tier colours. */
.achd-code-hl {
  display: inline-block; border: 1.5px solid; border-radius: 4px;
  padding: 0 3px; font-weight: 700; line-height: 1.1; background: transparent;
}
.achd-code-hl--achd { border-color: #3a6b91; color: #2c5576; }
.achd-code-hl--ep   { border-color: #2f6db3; color: #2c5a94; }
.achd-code-hl--ciu  { border-color: #be185d; color: #9d174d; }
/* Allocation marker: the day's planned anaesthetist gets a ring around their
   whole grid cell in the list's activity colour — solid for the main holder,
   dashed for the pair — so the plan is traceable without leaving the grid.
   The overlay is pointer-transparent: the cell's own tooltip/interactions
   pass straight through. */
.achd-alloc {
  position: absolute; inset: 1px; z-index: 2; pointer-events: none;
  border: 2px solid; border-radius: 3px;
}
.achd-alloc--achd { border-color: #3a6b91; }
.achd-alloc--ep   { border-color: #2f6db3; }
.achd-alloc--ciu  { border-color: #be185d; }
.achd-alloc--pair { border-style: dashed; }
/* Colour semantics (soft pastel): pale green = available, pale blue = NC
   (replaceable), soft amber = PC2/PC3, soft red = PC1, stronger red = OFF /
   leave, grey = already booked clinically. */
.achd-cell--free  { background: #d9f2e4; color: #1d6a41; }
.achd-cell--nc    { background: #e4edfb; color: #3b5b9e; }
.achd-cell--pc3, .achd-cell--pc2 { background: #fbeec9; color: #92610e; }
.achd-cell--pc1   { background: #f6d5d5; color: #9c3535; }
.achd-cell--off   { background: #efb9b9; color: #862e2e; }
.achd-cell--clash { background: #eef0f2; color: #828a94; }
/* Public holiday: the whole row goes soft olive, overriding all cell colours. */
.achd-row--holiday td { background: #e6f0cd !important; color: #4d6b16; box-shadow: none; }
.achd-row--holiday .achd-half { background: transparent !important; color: #4d6b16; }
.achd-legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 0.72rem; color: var(--muted, #5a6d84); margin: 2px 0 8px; }
.achd-legend .achd-lg { display: inline-flex; align-items: center; gap: 4px; }
.achd-legend .achd-lg i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,0.12); }
.achd-cell-code { font-weight: 500; }
.achd-badge {
  display: inline-block; margin-left: 4px; border-radius: 4px; padding: 0 4px;
  font-size: 0.66rem; font-weight: 700; vertical-align: 1px;
}
.achd-badge--oc { background: rgba(21,101,192,0.15); color: #0a5a8a; }
.achd-badge--pc { background: rgba(245,158,11,0.2); color: #92400e; }
.achd-badge--orient { background: rgba(190,24,93,0.12); color: #9d174d; }

.achd-draft-banner, .achd-reconcile {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-size: 0.85rem;
}
.achd-orient {
  display: flex; flex-direction: column; gap: 6px;
  border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-size: 0.85rem;
  background: rgba(21,101,192,0.06); border: 1px solid rgba(21,101,192,0.22);
}
.achd-orient-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.achd-orient-row--done { background: rgba(16,185,129,0.1); border-radius: 6px; padding: 4px 6px; }
.achd-orient-row--miss { color: #92610e; font-size: 0.8rem; }
.achd-watch {
  display: flex; flex-direction: column; gap: 6px;
  border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-size: 0.85rem;
  background: rgba(220,38,38,0.06); border: 1px solid rgba(220,38,38,0.28);
}
.achd-skew-note { font-size: 0.78rem; color: #92610e; padding-left: 4px; }
.achd-asg--conflict { outline: 2px solid rgba(220,38,38,0.55); outline-offset: -2px; background: rgba(220,38,38,0.08); }
.achd-warn { color: #b91c1c; }
.achd-nctag { font-size: 0.7rem; font-weight: 600; color: #3b5b9e; background: #e4edfb; border-radius: 4px; padding: 0 4px; margin-left: 2px; }
.achd-pop--cover { width: 340px; }
.achd-pop-sub { font-size: 0.8rem; color: var(--muted, #5a6d84); margin-bottom: 8px; }
.achd-cover-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.achd-cover-pick { flex: 1; text-align: left; }
.achd-cover-tag { font-size: 0.7rem; border-radius: 4px; padding: 1px 6px; }
.achd-pop-warn { margin-top: 8px; font-size: 0.78rem; color: #9c3535; background: #f6d5d5; border-radius: 6px; padding: 6px 8px; }

/* Stats modal */
.achd-stats-box { max-width: 560px; width: 92vw; max-height: 86vh; display: flex; flex-direction: column; }
.achd-stats-periods { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
.achd-stats-custom input { font-size: 0.82rem; padding: 2px 4px; border: 1px solid rgba(104,137,178,0.35); border-radius: 6px; }
.achd-stats-note { font-size: 0.74rem; color: var(--muted, #5a6d84); margin-bottom: 8px; }
.achd-stats-table-wrap { overflow-y: auto; flex: 1; }
.achd-stats-table { border-collapse: collapse; width: 100%; font-size: 0.84rem; }
.achd-stats-table th, .achd-stats-table td { border: 1px solid rgba(104,137,178,0.18); padding: 4px 10px; text-align: center; }
.achd-stats-table thead th { position: sticky; top: 0; background: var(--panel-bg, #fff); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.achd-stats-table td.achd-stats-name { text-align: left; font-weight: 600; }
.achd-stats-table tfoot td { font-weight: 700; background: rgba(104,137,178,0.08); }
.achd-stats-total { font-weight: 700; }
.achd-draft-banner { background: rgba(37,99,235,0.1); border: 1px solid rgba(37,99,235,0.3); }
.achd-reconcile { background: rgba(245,158,11,0.1); border: 1px solid rgba(245,158,11,0.35); flex-direction: column; align-items: stretch; }
.achd-reconcile-head { font-weight: 700; }
.achd-reconcile-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.achd-rec-btn { padding: 2px 10px; font-size: 0.78rem; }

.achd-more { display: block; margin: 8px auto; }

/* ── Mobile ── */
@media (max-width: 768px) {
  .achd-table th, .achd-table td { padding: 2px 3px; font-size: 0.72rem; }
  .achd-table thead th { font-size: 0.68rem; }
  .achd-table th.achd-date { width: 110px; }
  .achd-table th.achd-asg  { width: 110px; }
  .achd-cell { height: 30px; font-size: 0.72rem; }
  .achd-hint, .achd-legend { font-size: 0.68rem; }
  .achd-subtabs { flex-wrap: wrap; }
  .achd-pop { width: min(92vw, 340px); }
  .achd-cfg-box, .achd-stats-box { width: 96vw; }
  .achd-table-wrap { max-height: calc(100dvh - var(--sticky-chrome-height, 100px) - 110px); }
}
.achd-empty { text-align: center; color: var(--muted, #5a6d84); padding: 24px; }
.achd-range { font-size: 0.78rem; font-weight: 600; color: var(--muted, #5a6d84); padding: 2px 2px 6px; }
.achd-month-row td {
  background: rgba(104,137,178,0.12); font-weight: 700; font-size: 0.75rem;
  letter-spacing: 0.04em; color: var(--text, #1a2535); padding: 4px 8px;
  position: sticky; left: 0;
}
.achd-row--today td { box-shadow: inset 0 0 0 1000px rgba(21,101,192,0.10); }
.achd-row--today td.achd-date { border-left: 3px solid var(--accent, #1565c0); }

/* Popups + config modal */
.achd-pop {
  position: absolute; z-index: 60; width: 280px; background: var(--panel-bg, #fff);
  border: 1px solid rgba(104,137,178,0.35); border-radius: 10px; padding: 12px;
  box-shadow: 0 8px 28px rgba(19,35,54,0.18);
}
.achd-pop-title { font-weight: 700; font-size: 0.88rem; margin-bottom: 8px; }
.achd-pop-label { display: block; font-size: 0.72rem; font-weight: 600; color: var(--muted, #5a6d84); margin: 8px 0 2px; }
.achd-pop-sel { width: 100%; font-size: 0.85rem; padding: 4px 6px; border: 1px solid rgba(104,137,178,0.35); border-radius: 6px; background: #fff; }
.achd-pop-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.achd-cfg-box { max-width: 720px; width: 92vw; max-height: 88vh; overflow-y: auto; }
.achd-cfg-hint { font-size: 0.8rem; color: var(--muted, #5a6d84); }
.achd-cfg-expl { font-size: 0.8rem; color: var(--text, #1a2535); background: rgba(104,137,178,0.08); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; }
.achd-cfg-expl p { margin: 4px 0; }
.achd-cfg-person { border: 1px solid rgba(104,137,178,0.2); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; }
.achd-cfg-person-head { display: flex; align-items: center; gap: 16px; margin-bottom: 4px; }
.achd-cfg-table { border-collapse: collapse; margin-top: 4px; }
.achd-cfg-table th { font-size: 0.68rem; font-weight: 700; color: var(--muted, #5a6d84); padding: 2px 6px; text-align: center; }
.achd-cfg-table th.achd-cfg-wk-first { border-left: 2px solid rgba(104,137,178,0.3); }
.achd-cfg-td { text-align: center; padding: 2px 6px; }
.achd-cfg-list-name { font-size: 0.78rem; font-weight: 600; text-align: left; padding-right: 10px; white-space: nowrap; }
.achd-cfg-cb { display: inline-flex; align-items: center; gap: 3px; font-size: 0.8rem; }
.achd-cfg-pool { margin-top: 14px; border-top: 1px solid rgba(104,137,178,0.2); padding-top: 10px; }
.achd-cfg-pool-title { font-weight: 700; font-size: 0.82rem; margin-bottom: 6px; }
.achd-cfg-req { margin-top: 14px; border-top: 1px solid rgba(104,137,178,0.2); padding-top: 10px; }
.achd-cfg-req-inputs { display: flex; gap: 14px; flex-wrap: wrap; }
.achd-cfg-req-inputs label { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; font-weight: 600; }
.achd-cfg-req-inputs input[type="number"] { width: 56px; padding: 3px 6px; border: 1px solid rgba(104,137,178,0.45); border-radius: 6px; font-size: 0.85rem; }
.achd-cfg-pool-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.achd-chip {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 999px;
  background: rgba(21,101,192,0.1); color: #0a5a8a; padding: 2px 8px; font-size: 0.78rem; font-weight: 600;
}
.achd-chip-x { border: none; background: none; color: inherit; cursor: pointer; font-size: 0.9rem; padding: 0; }
.achd-cfg-pool-add { display: flex; gap: 8px; align-items: center; }
.achd-cfg-pool-add .achd-pop-sel { max-width: 260px; }

/* ── Mobile day cards (≤768px) ── */
.achd-mcards { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 12px; }
.achd-mmonth {
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.04em;
  color: var(--muted, #5a6d84); margin: 14px 2px 2px; text-transform: uppercase;
}
.achd-mcard {
  background: var(--panel-bg, #fff);
  border: 1px solid rgba(104,137,178,0.25);
  border-radius: 12px;
  padding: 10px 12px 12px;
  box-shadow: 0 2px 8px rgba(19,35,54,0.08);
}
.achd-mcard--today { border-color: var(--accent, #1565c0); box-shadow: 0 0 0 2px rgba(21,101,192,0.18); }
.achd-mcard--holiday { background: #f6f8e9; }
.achd-mcard-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.achd-mwk { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; border-radius: 6px; font-size: 0.72rem; font-weight: 800; }
.achd-mdate { font-size: 0.92rem; font-weight: 700; color: var(--text, #1a2535); }
.achd-mcard-head .achd-holiday { margin-left: auto; font-size: 0.72rem; color: var(--muted, #5a6d84); }
.achd-masg {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 9px;
  background: rgba(104,137,178,0.08);
  border: 1px solid rgba(104,137,178,0.18);
  font-size: 0.92rem; font-weight: 600; color: var(--text, #1a2535);
}
.achd-masg[data-achd-edit] { cursor: pointer; }
.achd-masg.achd-asg--empty { color: var(--muted, #5a6d84); font-weight: 400; background: transparent; border-style: dashed; }
.achd-masg.achd-asg--roster { background: rgba(104,137,178,0.14); }
.achd-masg.achd-asg--draft { outline: 2px dashed rgba(21,101,192,0.45); outline-offset: -2px; }
.achd-masg.achd-asg--conflict { border-color: rgba(200,60,60,0.55); background: rgba(200,60,60,0.07); }
.achd-masg .achd-clear { margin-left: auto; font-size: 1rem; padding: 0 4px; }
@media (min-width: 769px) {
  .achd-mcards { display: none; }
}
