/* Print-only chrome: kept in the DOM for the print stylesheet but never shown
   on screen. (print.css is linked with media="print", so its own hide rule can
   only ever run while printing — this is the rule that actually hides them in
   the live view; @media print re-enables them with !important.) */
#print-header,
#print-footer {
  display: none;
}

#app-header {
  height: var(--header-h);
  background: rgba(var(--navy-800-rgb),.6);
  backdrop-filter: blur(var(--glass-blur-lg));
  -webkit-backdrop-filter: blur(var(--glass-blur-lg));
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  flex-shrink: 0;
  z-index: 100;
  position: relative;
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 1px 0 rgba(var(--ink-rgb),.03), 0 4px 24px rgba(0,0,0,.3);
  gap: 8px;
  contain: layout paint;
}

#app-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, rgba(14,165,233,.25) 20%, rgba(103,212,255,.35) 50%, rgba(14,165,233,.25) 80%, transparent 100%);
  pointer-events: none;
}

body.is-mobile.is-standalone #app-header {
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-width: 0;
}

.brand-icon {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  object-fit: contain;
  box-shadow: 0 2px 10px rgba(14,165,233,.2);
  transition: transform .3s cubic-bezier(.34,1.2,.64,1), box-shadow .3s;
}

.brand-icon:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(14,165,233,.3);
}

.brand-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-strong);
  letter-spacing: -.015em;
  line-height: 1.2;
}

.brand-text {
  min-width: 0;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(var(--ink-rgb),.04);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 4px 6px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  transition: border-color .2s, box-shadow .2s;
}

.month-nav:hover {
  border-color: var(--glass-border-h);
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

.nav-btn {
  background: none;
  border: none;
  color: rgba(var(--ink-rgb),.35);
  font-size: 18px;
  line-height: 1;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  transition: color .15s, background .15s, transform .15s;
  display: flex;
  align-items: center;
  will-change: transform;
}

.nav-btn:hover {
  background: rgba(var(--ink-rgb),.08);
  color: var(--ink-strong);
  transform: scale(1.1);
}

.nav-btn:active {
  transform: scale(.9);
}

#month-label {
  font-size: 14px;
  font-weight: 600;
  color: rgba(var(--ink-rgb),.9);
  min-width: 120px;
  text-align: center;
  letter-spacing: -.015em;
  user-select: none;
  white-space: nowrap;
}

.month-label-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: inherit;
  padding: 4px 10px;
  border-radius: 8px;
}

.month-label-btn:hover {
  background: rgba(var(--ink-rgb),.08);
}

.month-label-btn:active {
  transform: scale(0.96);
}

.month-label-caret {
  color: rgba(var(--ink-rgb),.55);
  font-size: 11px;
}

.header-actions {
  display: flex;
  gap: 5px;
  align-items: center;
}

#btn-global-undo,
#btn-global-redo,
#btn-history,
#btn-shortcuts,
#btn-print-preview,
#btn-settings {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: rgba(var(--ink-rgb),.55);
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  transition: all .2s;
  display: flex;
  align-items: center;
}

#btn-global-undo:hover,
#btn-global-redo:hover,
#btn-history:hover,
#btn-shortcuts:hover,
#btn-print-preview:hover,
#btn-settings:hover {
  background: var(--glass-bg-hover);
  border-color: var(--glass-border-h);
  color: var(--ink-strong);
  transform: translateY(-1px);
}

#btn-global-undo:active,
#btn-global-redo:active {
  transform: scale(.9);
}

#btn-global-undo:disabled,
#btn-global-redo:disabled {
  cursor: not-allowed;
}

.hbtn-divider {
  width: 1px;
  height: 24px;
  background: var(--glass-border);
  margin: 0 4px;
  flex-shrink: 0;
}

#stats-bar {
  height: var(--statsbar-h);
  background: rgba(var(--navy-800-rgb),.85);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid rgba(var(--ink-rgb),.08);
  display: flex;
  align-items: center;
  padding: 0 16px;
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  gap: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.03);
  position: relative;
  contain: layout paint;
}

#stats-bar::-webkit-scrollbar {
  display: none;
}

#stats-bar::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 32px;
  background: linear-gradient(90deg, transparent, rgba(var(--navy-800-rgb),.85));
  pointer-events: none;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: 100%;
  border-right: 1px solid rgba(var(--ink-rgb),.08);
  white-space: nowrap;
  cursor: default;
  transition: background .15s;
}

.stat-item:first-child {
  padding-left: 0;
}

.stat-item:last-child {
  border-right: none;
}

.stat-item:hover {
  background: rgba(14,165,233,.08);
}

.stat-item-emp {
  padding: 0 12px 0 0;
  border-right: 1px solid rgba(var(--ink-rgb),.1);
  margin-right: 4px;
  color: rgba(var(--ink-rgb),.5);
  gap: 5px;
}

.stat-label-sm {
  font-size: 10px;
  font-weight: 600;
  color: rgba(var(--ink-rgb),.4);
  letter-spacing: .04em;
}

.stat-code {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  line-height: 1.5;
  letter-spacing: .01em;
}

.stat-count {
  font-size: 13px;
  font-weight: 700;
  color: rgba(var(--ink-rgb),.85);
  font-variant-numeric: tabular-nums;
}

#stats-empty {
  font-size: 11px;
  color: rgba(var(--ink-rgb),.4);
  font-style: italic;
}

#plan-bar {
  height: 52px;
  background: rgba(59,10,0,.45);
  backdrop-filter: blur(var(--glass-blur-lg));
  -webkit-backdrop-filter: blur(var(--glass-blur-lg));
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  flex-shrink: 0;
  z-index: 95;
  position: relative;
  box-shadow: 0 2px 16px rgba(0,0,0,.3), inset 0 1px 0 rgba(251,191,36,.1);
  border-bottom: 1px solid rgba(251,191,36,.08);
  contain: layout paint;
}

#plan-bar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, rgba(251,191,36,.15) 20%, rgba(252,211,77,.35) 50%, rgba(251,191,36,.15) 80%, transparent 100%);
}

#plan-bar::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, rgba(245,158,11,.12) 30%, rgba(252,211,77,.25) 50%, rgba(245,158,11,.12) 70%, transparent 100%);
}

.plan-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.plan-bar-month {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: rgba(var(--ink-rgb),.75);
  white-space: nowrap;
  flex-shrink: 0;
}

.plan-bar-hint {
  font-size: 11.5px;
  color: rgba(var(--ink-rgb),.28);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.plan-bar-center {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.plan-bar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px 12px 0 12px; /* Remove bottom padding to maximize viewport height utilization */
}

/* UI Polish: Row highlighting style — subtle accent, similar to today-column but teal-amber */
.tr-hover {
  background: rgba(14,165,233,.045) !important;
  box-shadow: inset 4px 0 0 0 rgba(14,165,233,.0); /* transparent, accent via td-name */
}
.tr-hover .td-name {
  background: linear-gradient(90deg, rgba(14,165,233,.18) 0%, rgba(14,165,233,.08) 100%) !important;
  border-right-color: rgba(14,165,233,.22) !important;
  box-shadow: 4px 0 14px rgba(14,165,233,.10), inset 3px 0 0 rgba(14,165,233,.55) !important;
}
.tr-hover .emp-label {
  color: #0369A1 !important;
  font-weight: 600;
}

#grid-wrapper {
  width: max-content;
  max-width: 100%;
  flex: 1;
  min-height: 0;
  margin: 0 auto;
  overflow: auto;
  position: relative;
  background: rgba(var(--navy-700-rgb),.94);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg);
  padding: 8px;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(var(--ink-rgb),.1);
  contain: paint layout;
  overscroll-behavior: contain;
}

#grid-wrapper::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

#grid-wrapper::-webkit-scrollbar-track {
  background: rgba(var(--ink-rgb),.04);
  border-radius: 3px;
}

#grid-wrapper::-webkit-scrollbar-thumb {
  background: rgba(var(--ink-rgb),.22);
  border-radius: 3px;
}

#grid-wrapper::-webkit-scrollbar-thumb:hover {
  background: rgba(var(--ink-rgb),.36);
}

#grid-wrapper::-webkit-scrollbar-corner {
  background: transparent;
}

#plan-table {
  border-collapse: separate;
  border-spacing: 0;
  min-width: max-content;
}

.th-corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 50;
  width: var(--name-w);
  min-width: var(--name-w);
  background: rgba(var(--navy-700-rgb),.9);
  backdrop-filter: blur(var(--glass-blur));
  border-right: 1px solid rgba(var(--ink-rgb),.06);
  border-bottom: 1px solid rgba(14,165,233,.2);
}

.th-corner-inner {
  height: 58px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(var(--ink-rgb),.25);
}

.th-day {
  position: sticky;
  top: 0;
  z-index: 30;
  width: var(--cell-w);
  min-width: var(--cell-w);
  max-width: var(--cell-w);
  border-right: 1px solid rgba(var(--ink-rgb),.04);
  border-bottom: 1px solid rgba(14,165,233,.2);
  text-align: center;
  vertical-align: bottom;
  user-select: none;
}

.th-day.is-fri {
  border-right: 1px solid rgba(var(--ink-rgb),.12) !important;
}

.th-day-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 4px 2px 5px;
  height: 58px;
}

.d-kw {
  font-family: var(--font-mono);
  font-size: 7px;
  font-weight: 500;
  letter-spacing: .04em;
  min-height: 10px;
  line-height: 1;
  opacity: .5;
}

.d-num {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
}

.d-dow {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  margin-top: 2px;
}

.d-hol {
  font-size: 7px;
  margin-top: 2px;
  max-width: 48px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.th-day.wd {
  background: rgba(22,42,70,.85);
  color: rgba(255,255,255,.92);
}

.th-day.we {
  background: rgba(30,42,60,.8);
  color: rgba(255,255,255,.62);
}

.th-day.hol {
  background: rgba(61,42,0,.8);
  color: #FCD34D;
}

.th-day.today {
  outline: 2px solid rgba(14,165,233,.5);
  outline-offset: -2px;
  z-index: 31;
}

.td-name {
  position: sticky;
  left: 0;
  z-index: 20;
  width: var(--name-w);
  min-width: var(--name-w);
  height: var(--row-h);
  background: rgba(var(--navy-700-rgb), 0.96);
  backdrop-filter: blur(8px);
  border-right: 1px solid rgba(var(--ink-rgb), 0.08);
  border-bottom: 1px solid rgba(var(--ink-rgb), 0.08);
  padding: 0 10px 0 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  box-shadow: 4px 0 12px rgba(0, 0, 0, 0.04);
}

tr:hover .td-name {
  background: rgba(14,165,233,.12);
  border-right-color: rgba(14,165,233,.25);
}

/* Role-band structure: a firm divider separates each role group so the grid
   reads as distinct sections (Leitung · FÄ · AÄ · weitere) instead of one
   undifferentiated block. The first row of a band carries the heavier rule. */
.tr-band-start .td-name,
.tr-band-start .td-cell {
  border-top: 2px solid rgba(var(--ink-rgb), 0.22);
}
.tr-band-start:first-child .td-name,
.tr-band-start:first-child .td-cell {
  border-top: none;
}
/* Subtle per-band tint on the sticky name column for at-a-glance grouping. */
tr[data-band="lead"] .td-name { background: rgba(14, 165, 233, 0.10); }
tr[data-band="fa"]   .td-name { background: rgba(168, 85, 247, 0.08); }
tr[data-band="aa"]   .td-name { background: rgba(34, 197, 94, 0.07); }
tr[data-band="lead"]:hover .td-name,
tr[data-band="fa"]:hover .td-name,
tr[data-band="aa"]:hover .td-name { background: rgba(14, 165, 233, 0.16); }

.emp-label {
  flex: 1;
  font-size: 12.5px;
  font-weight: 500;
  color: rgba(var(--ink-rgb),.88);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color .1s;
  line-height: 1.3;
}

tr:hover .emp-label {
  color: var(--accent);
}

.emp-pos-tag {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  letter-spacing: .03em;
  line-height: 1.5;
  white-space: nowrap;
  opacity: .9;
  transition: opacity .1s;
}

tr:hover .emp-pos-tag {
  opacity: 1;
}

.emp-profile-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

tr:hover .emp-profile-icon {
  opacity: 1;
  transform: scale(1);
}

.emp-profile-icon:hover {
  color: var(--blue-600);
  background: rgba(14, 165, 233, 0.1);
  border-radius: 50%;
}

.td-cell {
  width: var(--cell-w);
  min-width: var(--cell-w);
  max-width: var(--cell-w);
  height: var(--row-h);
  border-right: 1px solid rgba(var(--ink-rgb),.08);
  border-bottom: 1px solid rgba(var(--ink-rgb),.08);
  cursor: pointer;
  position: relative;
  vertical-align: top;
  transition: filter .12s, box-shadow .15s, transform 0.1s;
  outline: none;
}

.td-cell:hover {
  filter: brightness(.97);
  box-shadow: inset 0 0 0 1px rgba(14,165,233,.22), inset 0 0 10px rgba(14,165,233,.08);
  background-image: linear-gradient(180deg, rgba(14,165,233,.06), rgba(14,165,233,.01));
  z-index: 5;
}

.td-cell:active {
  transform: scale(0.97);
  z-index: 6;
}

.td-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 5;
}

.td-cell.we {
  background-color: rgba(var(--ink-rgb),.05);
}

.td-cell.hol {
  background-color: rgba(245,158,11,.07);
}

.td-cell.today {
  box-shadow: inset 0 0 0 2px rgba(14,165,233,.85), inset 0 0 16px rgba(14,165,233,.22);
  background-image: linear-gradient(180deg, rgba(14,165,233,.08), rgba(14,165,233,.02));
  z-index: 2;
}

.td-cell.multi-selected {
  box-shadow: inset 0 0 0 2px rgba(245,158,11,.9), inset 0 0 10px rgba(245,158,11,.2);
  background-image: linear-gradient(180deg, rgba(245,158,11,.08), rgba(245,158,11,.02));
}

.td-cell.is-fri {
  border-right: 1px solid rgba(var(--ink-rgb),.16) !important;
}

.cell-inner {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 3px;
}

.cell-assign {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
  word-break: break-all;
  max-width: 100%;
}

.cell-assign-rbn {
  font-size: 9.5px !important;
  font-weight: 700 !important;
  white-space: nowrap !important;
  word-break: normal !important;
  letter-spacing: -0.01em;
}

.td-cell.empty-wd .cell-inner::after {
  content: '';
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--gray-200);
  transition: background .12s, transform 0.15s;
  flex-shrink: 0;
}

.td-cell.empty-wd:hover .cell-inner::after {
  background: var(--gray-300);
  transform: scale(1.5);
}

.td-cell.auto-f-rest .cell-assign {
  color: rgba(var(--ink-rgb),.4);
  font-weight: 500 !important;
  font-style: italic;
  letter-spacing: .03em;
}

.td-cell.auto-f-rest::after {
  content: '';
  position: absolute;
  bottom: 1px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 2px;
  border-radius: 1px;
  background: rgba(71,85,105,0.18);
  pointer-events: none;
}

.cell-duty {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 8px;
  font-weight: 800;
  padding: 1px 3.5px;
  border-radius: 3px;
  line-height: 1.3;
  letter-spacing: .02em;
  pointer-events: none;
}

.cell-duty[draggable="true"] {
  pointer-events: auto;
  cursor: grab;
}

.cell-duty[draggable="true"]:active {
  cursor: grabbing;
}

/* Drop target feedback for native drag & drop of duty badges */
.td-cell.drag-over {
  box-shadow: inset 0 0 0 2px var(--accent);
  background-color: var(--accent-dim);
}

.cell-wish {
  position: absolute;
  bottom: 1px;
  left: 1px;
  font-size: 6px;
  font-weight: 900;
  padding: 0.5px 2.5px;
  border-radius: 2px;
  line-height: 1.3;
  pointer-events: none;
  letter-spacing: .02em;
  z-index: 1;
}

.cell-wish.wish-NO_DUTY {
  background: #FEE2E2;
  color: #991B1B;
}

.cell-wish.wish-BD_WISH {
  background: #FEE2E2;
  color: #B91C1C;
}

.cell-wish.wish-HG_WISH {
  background: #E0F2FE;
  color: #0369A1;
}

/* Inline comment indicator dot — top-right corner of grid cell */
.cell-comment-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #F59E0B;
  box-shadow: 0 0 0 1px rgba(0,0,0,.25);
  pointer-events: none;
  z-index: 2;
  flex-shrink: 0;
}

/* Show tooltip on cell hover when comment dot is present */
.td-cell:hover .cell-comment-dot {
  background: #FBBF24;
  box-shadow: 0 0 0 2px rgba(251,191,36,.35);
}

/* Pin indicator — marks a cell as fixed/excluded from the Auto-Plan solver */
.cell-pin {
  position: absolute;
  top: 1px;
  left: 1px;
  font-size: 7px;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.35));
}

.td-cell.pinned {
  outline: 1.5px dashed rgba(245,158,11,.65);
  outline-offset: -1.5px;
}

/* Hard-rule conflict warning — flags cells that violate a hard rule (D-D, duty+Urlaub,
   Mehrfachbesetzung etc.), independent of whether an Auto-Plan run produced them. */
.td-cell.cell-conflict {
  box-shadow: inset 0 0 0 1.5px var(--red);
  z-index: 4;
}

.td-cell.cell-conflict:hover {
  box-shadow: inset 0 0 0 1.5px var(--red), inset 0 0 12px rgba(239,68,68,.2);
}

.cell-conflict-flag {
  position: absolute;
  top: 1px;
  right: 1px;
  font-size: 8px;
  line-height: 1;
  color: var(--red);
  pointer-events: none;
  z-index: 3;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.3));
}

.tr-stat.tr-stat-first .td-stat-lbl,
.tr-stat.tr-stat-first .td-stat-val {
  border-top: 1px solid rgba(var(--ink-rgb),.12);
}

.tr-stat .td-stat-lbl {
  position: sticky;
  left: 0;
  z-index: 20;
  background: rgba(var(--navy-700-rgb),.92);
  color: rgba(var(--ink-rgb),.6);
  backdrop-filter: blur(6px);
  height: var(--foot-h);
  padding: 0 10px;
  border-right: 1px solid rgba(var(--ink-rgb),.08);
  border-bottom: 1px solid rgba(var(--ink-rgb),.08);
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  box-shadow: 2px 0 8px rgba(0,0,0,.1);
}

.tr-stat .td-stat-val {
  background: rgba(var(--navy-700-rgb),.7);
  color: rgba(var(--ink-rgb),.3);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  vertical-align: middle;
  height: var(--foot-h);
  border-bottom: 1px solid rgba(var(--ink-rgb),.08);
  border-right: 1px solid rgba(var(--ink-rgb),.08);
  font-variant-numeric: tabular-nums;
  transition: color .12s, background .12s;
}

.td-stat-val.dim {
  color: rgba(var(--ink-rgb),.4);
  opacity: 1;
}

.td-stat-val.nz {
  color: rgba(var(--ink-rgb),.85);
}

.td-stat-val.warn {
  color: var(--red);
  background: rgba(239,68,68,.16);
  font-weight: 800;
}

.td-stat-val.today-col {
  background: var(--accent-dim);
}

.td-stat-val.is-fri {
  border-right: 1px solid rgba(var(--ink-rgb),.18) !important;
}

.stat-lbl-badge {
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.6;
  letter-spacing: .01em;
}

.stat-lbl-text {
  font-size: 10px;
  font-weight: 500;
  color: rgba(var(--ink-rgb),.5);
}

.td-empty {
  padding: 0;
  text-align: center;
}

.empty-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 52px 24px;
  color: var(--text-3);
}

.empty-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
}

.empty-hint {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-3);
}

.tr-rbn .td-name-rbn {
  background-color: #0C4A6E;
}

.tr-rbn .emp-label {
  color: #fff;
}

.td-cell.td-cell-rbn {
  background-color: #0C4A6E;
}

.td-cell-rbn .cell-assign-rbn {
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  line-height: 1.2;
}

body.plan-mode-active #app-header::after {
  background: linear-gradient(90deg, transparent 0%, rgba(245,158,11,.4) 15%, #F59E0B 35%, #FCD34D 50%, #F59E0B 65%, rgba(245,158,11,.4) 85%, transparent 100%);
  opacity: .8;
}

body.plan-mode-active #grid-wrapper {
  box-shadow: inset 0 0 0 3px rgba(245,158,11,.35);
  outline: none;
}

body.plan-mode-active .th-corner {
  background: linear-gradient(135deg, #3B1000 0%, #6B2100 100%);
}

body.plan-mode-active .th-corner-inner::after {
  content: 'PLAN';
  position: absolute;
  bottom: 4px;
  left: 14px;
  font-size: 7px;
  font-weight: 800;
  letter-spacing: .1em;
  color: #F59E0B;
  opacity: .7;
}

body.plan-mode-active .th-corner-inner {
  position: relative;
}

body.plan-mode-active .td-cell.empty-wd .cell-inner::after {
  background: rgba(245,158,11,.28) !important;
}

body.plan-mode-active .td-cell.empty-wd:hover .cell-inner::after {
  background: rgba(245,158,11,.5) !important;
}

body.plan-mode-active #stats-bar {
  border-top: 2px solid rgba(245,158,11,.25);
}

.mobile-nav {
  display: none;
}

.mobile-view {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

body.is-mobile main {
  display: none !important;
}

body.is-mobile #stats-bar {
  display: none !important;
}

body.is-mobile .mobile-view {
  display: flex !important;
  min-height: 0;
}

body.is-mobile .mobile-nav {
  display: flex !important;
  bottom: max(0px, var(--kb-inset));
}

body.is-mobile #app-header .header-actions {
  display: none !important;
}

body.is-mobile.plan-mode-active .mobile-view {
  border-top: 2px solid rgba(245,158,11,.35);
}

body.is-mobile.plan-mode-active #plan-bar {
  height: auto !important;
  min-height: 52px !important;
  padding: 8px 12px !important;
  flex-wrap: nowrap !important;
  gap: 8px !important;
  overflow-x: auto !important;
  scrollbar-width: none !important;
}

body.is-mobile.plan-mode-active #plan-bar::-webkit-scrollbar {
  display: none !important;
}

body.is-mobile .plan-bar-left {
  flex-shrink: 0 !important;
  flex: 0 0 auto !important;
}

body.is-mobile .plan-bar-center {
  flex-shrink: 0 !important;
}



@media (max-width: 1200px) {
  .brand-sub { display: none; }
  #month-label { min-width: 100px; font-size: 13px; }
  .plan-bar-hint { display: none; }
  .plan-bar-month { font-size: 11px; }
}

/* ── Manual density toggle: lets users shrink the desktop grid on demand
   (tablets, smaller windows) without waiting for a width breakpoint ── */
body.grid-density-compact {
  --name-w: 118px;
  --cell-w: 32px;
  --row-h: clamp(32px, 4vh, 44px);
}

body.grid-density-compact .emp-pos-tag,
body.grid-density-compact .emp-profile-icon {
  display: none;
}

body.grid-density-compact .cell-assign {
  font-size: 10px;
}

body.grid-density-compact .d-kw {
  display: none;
}

/* ── Tablet (601-768px): Grid stays visible, layout tightened ── */
@media (max-width: 768px) {
  :root {
    --header-h: 48px;
    --name-w: 140px;
    --cell-w: 40px;
    --row-h: clamp(36px, 4.5vh, 50px);
    --overlay-pad: 12px;
  }
  .brand-text { display: none; }
  .brand { position: absolute; left: 12px; gap: 0; }
  #app-header { justify-content: center; padding: 0 8px; }
  .month-nav { margin: 0 auto; }
  #month-label { min-width: 80px; font-size: 12px; }
  .nav-btn { padding: 4px 8px; font-size: 16px; }
  /* Header actions remain visible on tablet — only hide on phone */
  .hbtn-lbl { display: none; }
  .hbtn { padding: 6px 8px; }
  #stats-bar { padding: 0 8px; }
  .stat-item { padding: 0 8px; }
  .stat-label-sm { display: none; }
  #plan-bar { gap: 8px; padding: 0 8px; flex-wrap: nowrap; height: auto; min-height: 44px; padding-top: 4px; padding-bottom: 4px; overflow-x: auto; scrollbar-width: none; }
  #plan-bar::-webkit-scrollbar { display: none; }
  .plan-bar-left { flex: 1 1 auto; min-width: 0; gap: 6px; }
  .plan-bar-center { gap: 2px; }
  .plan-bar-right { gap: 3px; }
  #grid-wrapper { border-radius: var(--radius); padding: 6px; }
  main { padding: 8px 8px 0; }
}

/* ── Phone (≤600px): Switch to mobile list view ── */
@media (max-width: 600px) {
  :root {
    --header-h: 44px;
    --name-w: 110px;
    --cell-w: 36px;
    --row-h: clamp(32px, 4.5vh, 44px);
    --foot-h: 26px;
    --overlay-pad: 10px;
  }
  .header-actions { display: none; }
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mnav-h);
    background: rgba(var(--navy-800-rgb),.9);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(var(--ink-rgb),.1);
    z-index: 1000;
    padding-bottom: var(--safe-bottom);
    padding-left: max(10px, var(--safe-left));
    padding-right: max(10px, var(--safe-right));
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 20px rgba(0,0,0,.3);
  }
  main { padding-bottom: calc(12px + var(--mnav-h)); }
  .mnav-btn {
    background: none;
    border: none;
    color: rgba(var(--ink-rgb),.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 500;
    flex: 1;
    height: 100%;
    transition: color 0.15s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
  }
  .mnav-btn:hover { color: var(--accent-lt); }
  .mnav-btn:active { transform: scale(0.92); color: var(--accent-lt); }
  .mnav-plan { position: relative; color: #FCD34D; }
  .mnav-plan-icon {
    background: rgba(251,191,36,.15);
    border: 1px solid rgba(251,191,36,.3);
    border-radius: 12px;
    width: 44px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2px;
  }
  body.plan-mode-active .mnav-plan-icon { background: #F59E0B; color: #fff; }
  .brand-icon { width: 28px; height: 28px; }
  .month-nav { padding: 3px 4px; }
  #month-label { min-width: 70px; font-size: 11px; }
  .nav-btn { padding: 4px 6px; font-size: 14px; }
  .cell-assign { font-size: 8px; }
  .cell-assign-rbn { font-size: 7.5px !important; }
  .td-name { padding: 0 4px 0 6px; }
  .emp-label { font-size: 11px; }
  .emp-pos-tag { font-size: 7.5px; padding: 1px 3px; }
  .emp-profile-icon { display: none; }
  .d-num { font-size: 12px; }
  .d-dow { font-size: 8px; }
  .d-kw { font-size: 6px; }
  .th-day-inner { height: 48px; }
  .th-corner-inner { height: 48px; font-size: 8px; }
  .plan-bar-month { display: none; }
}

/* ═══════════════════════════════════════════════════
   Day Status Stripe (Feature 3)
═══════════════════════════════════════════════════ */
.day-status-stripe {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  pointer-events: none;
  transition: background-color 0.3s ease;
  border-radius: 1px 1px 0 0;
}

/* ═══════════════════════════════════════════════════
   Keyboard Grid Navigation – Hint Bar (Feature 1)
═══════════════════════════════════════════════════ */
#grid-kbd-hint {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: 26px;
  background: rgba(14,165,233,.05);
  border-top: 1px solid rgba(14,165,233,.12);
  font-size: 10px;
  color: rgba(var(--ink-rgb),.4);
  font-family: var(--font-mono);
  flex-wrap: nowrap;
  overflow: hidden;
  flex-shrink: 0;
  user-select: none;
  letter-spacing: .01em;
}

body.grid-cell-focused #grid-kbd-hint {
  display: flex;
}

body.is-mobile #grid-kbd-hint {
  display: none !important;
}

body.plan-mode-active #grid-kbd-hint {
  background: rgba(245,158,11,.05);
  border-top-color: rgba(245,158,11,.15);
}

.kbd-hint-group {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}

.kbd-hint-sep {
  color: rgba(var(--ink-rgb),.18);
  font-size: 9px;
  flex-shrink: 0;
}

.kbd-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 14px;
  padding: 0 3px;
  background: rgba(var(--ink-rgb),.09);
  border: 1px solid rgba(var(--ink-rgb),.14);
  border-bottom-width: 2px;
  border-radius: 3px;
  font-size: 8.5px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: rgba(var(--ink-rgb),.65);
  line-height: 1;
  letter-spacing: 0;
}
