/* PingFang HK font */
@font-face {
    font-family: 'PingFang HK';
    src: url('../fonts/PingFangHK-Regular.otf') format('opentype');
    font-weight: 400;
    font-style: normal;
}
@font-face {
    font-family: 'PingFang HK';
    src: url('../fonts/PingFangHK-Semibold.otf') format('opentype');
    font-weight: 600;
    font-style: normal;
}

:root {
    --color-bg: #101720;
    --color-surface: #17212d;
    --color-surface-raised: #1d2937;
    --color-surface-muted: #222f3e;
    --color-border: #2c3a4b;
    --color-border-strong: #40536a;
    --color-text: #e7edf5;
    --color-text-muted: #9aaabd;
    --color-text-dim: #708196;
    --color-accent: #5f9fcb;
    --color-accent-hover: #74b0d8;
    --color-accent-soft: rgba(95, 159, 203, 0.16);
    --color-focus: #8bc7ec;
    --color-weekend: rgba(132, 154, 180, 0.075);
    --color-danger: #ef737b;
    --color-danger-soft: rgba(239, 115, 123, 0.12);
    --shadow-raised: 0 14px 38px rgba(2, 8, 16, 0.46);
    --radius-sm: 6px;
    --radius-md: 9px;
    --radius-lg: 14px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

button,
input,
select,
textarea {
    font-family: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

body {
    font-family: 'PingFang HK', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    max-width: 100%;
    font-size: 14px;
}
body.picker-open {
    overflow: hidden;
}
body.bulk-remark-modal-open {
    overflow: hidden;
}
body.picker-open::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 99;
    background: rgba(2, 8, 16, 0.58);
}

/* --- Navbar --- */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}
.navbar-brand {
    font-weight: 600;
    font-size: 1.1rem;
    color: #fff;
}
.navbar-links a {
    color: var(--color-text-muted);
    text-decoration: none;
    margin-left: 20px;
    padding: 6px 12px;
    border-radius: 6px;
    transition: all 0.2s;
}
.navbar-links a:hover,
.navbar-links a.active {
    color: var(--color-text);
    background: var(--color-surface-muted);
}

/* --- Container --- */
.container {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 16px 24px;
}

/* --- Month Nav --- */
.month-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 12px 0 8px;
    font-size: 1.3rem;
    font-weight: 600;
    color: #fff;
}
.month-nav button {
    background: var(--color-accent);
    border: none;
    color: #fff;
    padding: 6px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}
.month-nav button:hover { background: var(--color-accent-hover); }
.roster-view-toggle {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
}
.month-nav .roster-view-toggle-btn {
    min-height: 32px;
    padding: 4px 10px;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    color: var(--color-text-muted);
    font-size: 0.78rem;
    line-height: 1;
}
.month-nav .roster-view-toggle-btn:hover {
    border-color: var(--color-border-strong);
    background: var(--color-surface-muted);
    color: var(--color-text);
}
.month-nav .roster-view-toggle-btn.is-active,
.month-nav .roster-view-toggle-btn[aria-pressed="true"] {
    border-color: var(--color-accent);
    background: var(--color-accent-soft);
    color: var(--color-text);
}
.month-nav .roster-view-toggle-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}
.roster-view-toggle-btn-five {
    display: none;
}
#view-month { order: 1; }
#view-week { order: 2; }
#view-five { order: 3; }
.nav-action-btn {
    background: var(--color-surface-muted) !important;
    border: 1px solid var(--color-border-strong) !important;
    color: var(--color-text-muted);
    padding: 4px 10px !important;
    font-size: 0.85rem !important;
    border-radius: 5px;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}
.nav-action-btn:hover {
    color: var(--color-text);
    border-color: var(--color-accent) !important;
    background: var(--color-surface-raised) !important;
}

/* Gantt collapse state */
.gantt-collapsed .gantt-row { display: none; }
.gantt-collapsed .gantt-packed-row { display: none; }

/* Gantt packed view */
.gantt-packed-row { display: none; }
.gantt-packed .gantt-packed-row { display: table-row; }
.gantt-packed .gantt-row { display: none; }
.gantt-packed-row th {
    height: 24px !important;
    padding: 2px 0 !important;
    border: none !important;
}
.gantt-packed-row .corner-cell {
    background: var(--color-bg) !important;
}
.nav-action-btn-active {
    color: var(--color-accent-hover) !important;
    border-color: var(--color-accent) !important;
}
.roster-admin-tools {
    display: contents;
}
.roster-admin-tools[hidden] {
    display: none;
}

/* --- Legend --- */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 6px 2px 10px;
    align-items: center;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    color: #bbb;
}
.legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    display: inline-block;
}
.remark-legend-label {
    color: var(--color-text-dim);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.remark-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    min-width: 0;
    color: var(--color-text-muted);
    font-size: 0.72rem;
}
.remark-legend-item > span:last-child {
    overflow-wrap: anywhere;
}
.remark-symbol {
    display: inline-block;
    line-height: 1;
    font-weight: 700;
}
.remark-symbol-event { color: #acd2eb; }
.remark-symbol-connected { color: #6ed9c5; }
.remark-symbol-cell { color: #f2c879; }

/* --- Grid --- */
.grid-wrapper {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: auto;
    overscroll-behavior-inline: contain;
    max-height: calc(100vh - 160px);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
}

/* --- Gantt Header Bars --- */
.gantt-row th {
    height: 24px !important;
    padding: 2px 0 !important;
    border: none !important;
}
.gantt-row + tr:not(.gantt-row) th {
    border-top: 4px solid var(--color-bg) !important;
}
.gantt-label {
    font-size: 0.65rem !important;
    font-weight: 600 !important;
    white-space: nowrap;
    text-align: left !important;
    padding-left: 10px !important;
    background: var(--color-bg) !important;
    position: sticky;
    left: 0;
    z-index: 4;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gantt-label > span {
    display: inline-block;
    width: calc(100% - 34px);
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}
.gantt-bar {
    border-radius: 3px;
    font-size: 0.6rem !important;
    font-weight: 600 !important;
    text-align: center !important;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
    line-height: 24px !important;
    padding: 0 !important;
}
.gantt-text {
    display: block;
    width: 100%;
    padding: 0 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
    pointer-events: none;
}
.gantt-remark-button {
    width: 20px;
    height: 20px;
    margin: 0 4px 0 -4px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #acd2eb;
    font: inherit;
    font-size: 0.8rem;
    line-height: 20px;
    cursor: pointer;
    vertical-align: middle;
    touch-action: manipulation;
}
.gantt-remark-button:hover {
    background: var(--color-accent-soft);
}
.gantt-inline-remark {
    font-size: 0.72rem;
    font-weight: 700;
}
.gantt-empty {
    background: var(--color-bg) !important;
}
/* Gantt row drag-and-drop reorder */
.gantt-row {
    cursor: grab;
}
.gantt-row.gantt-dragging {
    opacity: 0.4;
}
.gantt-row.gantt-drop-target {
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
}
.roster-grid {
    border-collapse: collapse;
    width: 100%;
    table-layout: fixed;
    min-width: 900px;
}
.roster-grid[data-view-mode="five"],
.roster-grid[data-view-mode="week"] {
    min-width: 0;
}
.roster-grid th,
.roster-grid td {
    border: 1px solid var(--color-border);
    padding: 2px;
    text-align: center;
    min-width: 38px;
    height: 32px;
    vertical-align: middle;
    font-size: 0.8rem;
}
.roster-grid th {
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 3;
}
.roster-grid th .weekday-label {
    font-size: 0.65rem;
    color: var(--color-text-dim);
    font-weight: 400;
}
.corner-cell {
    text-align: left !important;
    padding-left: 10px !important;
    position: sticky;
    left: 0;
    z-index: 4 !important;
}
.employee-name {
    text-align: left !important;
    padding-left: 10px !important;
    white-space: nowrap;
    background: var(--color-surface) !important;
    position: sticky;
    left: 0;
    z-index: 2;
    font-weight: 600;
    color: var(--color-text);
    cursor: grab;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Employee row drag-and-drop reorder */
.emp-dragging {
    opacity: 0.4;
}
.emp-drop-target > .employee-name {
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
}
.day-cell {
    transition: background 0.15s;
    vertical-align: middle !important;
    overflow: visible;
    position: relative;
}
.day-cell.editable {
    cursor: pointer;
}
.day-cell.editable:hover {
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
}
/* Row + column crosshair highlight */
.row-highlight > td {
    background: var(--color-accent-soft) !important;
}
.row-highlight > .employee-name {
    color: #fff !important;
    border-right: 2px solid var(--color-accent);
}
.col-highlight {
    background: var(--color-accent-soft) !important;
}
.row-highlight > td.col-highlight {
    background: rgba(95, 159, 203, 0.27) !important;
}
.weekend {
    background: var(--color-weekend);
}
.drag-highlight {
    background: rgba(95, 159, 203, 0.23) !important;
}

/* --- Assignment Blocks --- */
.assignment-block {
    display: block;
    width: 90%;
    height: 10px;
    margin: 2px auto;
    border-radius: 3px;
    cursor: pointer;
    transition: filter 0.1s, box-shadow 0.1s;
    position: relative;
}
.assignment-block:hover {
    filter: brightness(1.15);
    z-index: 4;
}
.assignment-block:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
    z-index: 5;
}
.assignment-remark-indicators {
    position: absolute;
    inset: 0;
    display: block;
    overflow: hidden;
    border-radius: inherit;
    pointer-events: none;
    z-index: 2;
}
.assignment-remark-marker {
    position: absolute;
    display: block;
    pointer-events: none;
}
.assignment-remark-marker-event {
    inset: 0;
    border: 1px solid rgba(223, 240, 251, 0.92);
    border-radius: inherit;
    box-shadow: inset 0 0 0 1px rgba(18, 30, 42, 0.16);
}
.assignment-remark-marker-connected {
    right: 1px;
    bottom: 1px;
    left: 1px;
    height: 2px;
    border-radius: 999px;
    background: #6ed9c5;
    box-shadow: 0 0 0 1px rgba(10, 29, 32, 0.28);
}
.assignment-remark-marker-cell {
    top: 2px;
    right: 3px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #f2c879;
    box-shadow: 0 0 0 1px rgba(42, 30, 8, 0.5);
}
/* Pending assignment blocks (dashed border, not yet saved) */
.pending-block {
    display: block;
    width: 90%;
    height: 10px;
    margin: 2px auto;
    border-radius: 3px;
    border: 1.5px dashed rgba(255,255,255,0.5);
    opacity: 0.7;
    cursor: pointer;
}
/* Saved assignments marked for removal */
.assignment-block.pending-remove {
    opacity: 0.25;
    position: relative;
}
.assignment-block.pending-remove::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #e74c3c;
}
/* Disable pointer events on blocks during drag so elementFromPoint hits the td */
.grid-dragging .assignment-block {
    pointer-events: none;
}
/* Connected consecutive blocks — overflow to bridge cell padding + border gaps */
.block-start {
    position: relative;
    width: calc(100% + 3px);
    margin-left: 0;
    margin-right: -3px;
    border-radius: 3px 0 0 3px;
    z-index: 1;
}
.block-start .assignment-remark-marker-connected {
    right: 0;
}
.block-mid {
    position: relative;
    width: calc(100% + 6px);
    margin-left: -3px;
    margin-right: -3px;
    border-radius: 0;
    z-index: 1;
}
.block-mid .assignment-remark-marker-connected {
    right: 0;
    left: 0;
}
.block-end {
    position: relative;
    width: calc(100% + 3px);
    margin-left: -3px;
    margin-right: 0;
    border-radius: 0 3px 3px 0;
    z-index: 1;
}

/* --- Block Tooltip --- */
.block-tooltip {
    position: absolute;
    z-index: 200;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    white-space: nowrap;
    pointer-events: none;
    display: none;
    transform: translate(-50%, -100%);
    box-shadow: 0 3px 12px rgba(0,0,0,0.5);
    max-width: min(360px, calc(100vw - 24px));
}
.block-tooltip .tooltip-title {
    display: block;
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 4px;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    padding-bottom: 4px;
}
.tooltip-emp-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    font-size: 0.78rem;
    line-height: 1.5;
}
.tooltip-emp-row.tooltip-self {
    font-weight: 700;
}
.tooltip-emp-name {
    opacity: 0.95;
}
.tooltip-emp-date {
    opacity: 0.7;
    text-align: right;
}
.block-end .assignment-remark-marker-connected {
    left: 0;
}
.tooltip-remarks {
    display: grid;
    gap: 5px;
    margin-top: 7px;
    padding-top: 7px;
    border-top: 1px solid rgba(255,255,255,0.24);
    white-space: normal;
}
.tooltip-remark {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 8px;
    line-height: 1.35;
    text-align: left;
}
.tooltip-remark-label {
    font-size: 0.7rem;
    font-weight: 700;
}
.tooltip-remark-text {
    max-width: 230px;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

/* --- Event Picker --- */
.event-picker {
    position: absolute;
    width: min(430px, calc(100vw - 20px));
    max-height: min(76vh, 680px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-lg);
    padding: 12px;
    z-index: 100;
    display: none;
    box-shadow: var(--shadow-raised);
    min-width: 240px;
}
.event-picker:focus {
    outline: none;
}
.event-picker.event-picker-opening {
    pointer-events: none;
}
.event-picker [hidden] {
    display: none !important;
}
.event-picker-handle {
    display: none;
}
.event-picker-header {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--color-border);
}
.event-picker-heading {
    min-width: 0;
    flex: 1;
}
.event-picker-heading-title {
    overflow: hidden;
    color: var(--color-text);
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.event-picker-heading-meta {
    margin-top: 2px;
    color: var(--color-text-muted);
    font-size: 0.72rem;
    line-height: 1.35;
}
.event-picker-icon-btn {
    display: inline-grid;
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    place-items: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    font: inherit;
    font-size: 1.15rem;
    line-height: 1;
    touch-action: manipulation;
}
.event-picker-icon-btn:hover {
    border-color: var(--color-border);
    background: var(--color-surface-muted);
    color: var(--color-text);
}
.event-picker-columns {
    display: flex;
    width: 100%;
    min-width: 0;
    gap: 10px;
}
.event-picker-col {
    flex: 1 1 0;
    min-width: 0;
    max-width: 100%;
}
.event-picker-col > div,
#event-picker-list,
#event-picker-remove-list {
    min-width: 0;
    max-width: 100%;
}
.event-picker-col-remove {
    border-left: 1px solid var(--color-border);
    padding-left: 10px;
}
.remove-event-btn {
    opacity: 0.85;
}
.event-picker-title {
    font-size: 0.75rem;
    color: var(--color-text-dim);
    margin-bottom: 6px;
    padding: 0 4px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}
.event-picker-btn {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 7px 12px;
    margin: 3px 0;
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    font-size: 0.85rem;
    line-height: 1.35;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
    transition: opacity 0.2s;
    touch-action: manipulation;
}
.event-picker-btn:hover { opacity: 0.85; }
.cancel-btn {
    background: var(--color-surface-muted) !important;
    margin-top: 6px;
}
.remove-btn {
    background: var(--color-danger) !important;
    margin-top: 6px;
}
.picker-add-event-btn {
    margin-top: 8px;
    border: 1px solid var(--color-border-strong);
    background: var(--color-surface-muted);
    color: var(--color-text);
}

.assignment-detail {
    display: grid;
    gap: 10px;
}
.assignment-detail-event {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: var(--color-text);
    font-size: 0.88rem;
    font-weight: 600;
}
.assignment-detail-event > span:last-child {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
}
.assignment-detail-swatch,
.bulk-remark-swatch {
    width: 10px;
    height: 10px;
    flex: 0 0 10px;
    border-radius: 3px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.28);
}
.remark-section {
    padding: 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: rgba(10, 17, 25, 0.22);
}
.remark-section-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}
.remark-scope-label {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--color-text);
    font-size: 0.8rem;
    font-weight: 600;
}
.remark-scope-help {
    margin-top: 3px;
    color: var(--color-text-dim);
    font-size: 0.68rem;
    line-height: 1.35;
}
.remark-header-actions {
    display: flex;
    gap: 3px;
}
.remark-link-btn {
    padding: 4px 6px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--color-accent-hover);
    cursor: pointer;
    font: inherit;
    font-size: 0.72rem;
    white-space: nowrap;
    touch-action: manipulation;
}
.remark-link-btn:hover {
    background: var(--color-accent-soft);
}
.remark-clear-btn {
    color: #f19aa0;
}
.remark-clear-btn:hover {
    background: var(--color-danger-soft);
}
.remark-display,
.remark-empty {
    margin: 9px 0 0;
    font-size: 0.8rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}
.remark-display {
    color: var(--color-text);
}
.remark-empty {
    color: var(--color-text-dim);
    font-style: italic;
}
.remark-editor {
    display: block;
    width: 100%;
    min-height: 92px;
    margin-top: 9px;
    resize: vertical;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    padding: 8px 9px;
    background: var(--color-bg);
    color: var(--color-text);
    font: inherit;
    font-size: 0.82rem;
    line-height: 1.45;
}
.remark-editor:focus {
    border-color: var(--color-focus);
    outline: 2px solid rgba(139, 199, 236, 0.22);
    outline-offset: 1px;
}
.remark-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 7px;
    margin-top: 8px;
}
.remark-edit-actions .btn {
    padding: 6px 11px;
    font-size: 0.75rem;
}
.assignment-detail-secondary {
    padding-top: 3px;
    border-top: 1px solid var(--color-border);
}
.btn-danger-subtle {
    border-color: rgba(239, 115, 123, 0.38) !important;
    background: var(--color-danger-soft) !important;
    color: #f29ba1 !important;
}
.btn-danger-subtle:hover {
    border-color: var(--color-danger) !important;
    background: rgba(239, 115, 123, 0.19) !important;
}
.bulk-remark-summary {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    min-width: 0;
    max-width: 100%;
    gap: 6px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--color-border);
    overflow: hidden;
}
.bulk-remark-row {
    display: flex;
    align-items: center;
    min-width: 0;
    max-width: 100%;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: rgba(10, 17, 25, 0.18);
}
.bulk-remark-row-content {
    min-width: 0;
    max-width: 100%;
    flex: 1;
}
.bulk-remark-row-title {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    color: var(--color-text);
    font-size: 0.78rem;
    font-weight: 600;
}
.bulk-remark-row-title > span:nth-child(2) {
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
}
.bulk-remark-preview {
    overflow: hidden;
    margin-top: 3px;
    color: var(--color-text-muted);
    font-size: 0.7rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
    white-space: normal;
}
.bulk-remark-count,
.bulk-remark-empty {
    margin-top: 3px;
    color: var(--color-text-dim);
    font-size: 0.68rem;
    overflow-wrap: anywhere;
}
.bulk-remark-open {
    flex: 0 0 auto;
}
.bulk-assignment-remark-modal {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: grid;
    place-items: center;
    padding: 24px;
}
.bulk-assignment-remark-modal[hidden] {
    display: none !important;
}
.bulk-assignment-remark-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 8, 16, 0.72);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    animation: bulkRemarkBackdropIn 0.16s ease-out;
}
.bulk-assignment-remark-dialog {
    position: relative;
    z-index: 1;
    display: grid;
    width: min(560px, calc(100vw - 32px));
    max-height: min(82vh, 720px);
    min-width: 0;
    gap: 12px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 18px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-lg);
    background: var(--color-surface-raised);
    box-shadow: 0 24px 70px rgba(2, 8, 16, 0.72);
    animation: bulkRemarkDialogIn 0.18s ease-out;
}
.bulk-assignment-remark-dialog:focus {
    outline: none;
}
.bulk-assignment-remark-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--color-border);
}
.bulk-assignment-remark-header h2 {
    margin: 2px 0 0;
    color: var(--color-text);
    font-size: 1.05rem;
    line-height: 1.3;
}
.bulk-assignment-remark-eyebrow {
    color: var(--color-text-dim);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.bulk-assignment-remark-event {
    padding: 9px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: rgba(10, 17, 25, 0.22);
}
.bulk-assignment-remark-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
    margin: 0;
}
.bulk-assignment-remark-stats > div {
    min-width: 0;
    padding: 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface-muted);
}
.bulk-assignment-remark-stats dt {
    overflow-wrap: anywhere;
    color: var(--color-text-dim);
    font-size: 0.66rem;
    line-height: 1.25;
}
.bulk-assignment-remark-stats dd {
    margin: 3px 0 0;
    color: var(--color-text);
    font-size: 1rem;
    font-weight: 700;
}
.bulk-assignment-remark-help,
.bulk-assignment-remark-warning {
    margin: 0;
    overflow-wrap: anywhere;
    font-size: 0.75rem;
    line-height: 1.45;
}
.bulk-assignment-remark-help {
    color: var(--color-text-muted);
}
.bulk-assignment-remark-warning {
    padding: 8px 9px;
    border: 1px solid rgba(242, 200, 121, 0.38);
    border-radius: var(--radius-sm);
    background: rgba(242, 200, 121, 0.09);
    color: #f4d89d;
}
.remark-editor-label {
    color: var(--color-text);
    font-size: 0.78rem;
    font-weight: 600;
}
.bulk-cell-remark-editor {
    margin-top: 0;
}
.bulk-assignment-remark-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
.bulk-assignment-remark-actions .btn {
    min-width: 0;
    overflow-wrap: anywhere;
    white-space: normal;
}
@keyframes bulkRemarkBackdropIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes bulkRemarkDialogIn {
    from { opacity: 0; transform: translateY(8px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* --- Toast --- */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 400;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 10px 18px;
    border-radius: 6px;
    color: #fff;
    font-size: 0.85rem;
    animation: fadeIn 0.3s, fadeOut 0.3s 3.7s;
}
.toast-warn { background: #e67e22; }
.toast-info { background: #3498db; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* --- Page Header --- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}
.page-header h2 {
    color: #fff;
    font-size: 1.3rem;
}
.page-header-actions {
    display: flex;
    gap: 8px;
}

/* --- Buttons --- */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    transition: opacity 0.2s;
    color: #fff;
    background: var(--color-accent);
}
.btn:hover { opacity: 0.85; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-primary { background: var(--color-accent); }
.btn-secondary { background: var(--color-surface-muted); }
.btn-danger { background: var(--color-danger); }
.btn-success { background: #2ecc71; }

/* --- Form Card --- */
.form-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 16px;
}
.form-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}
.form-row label {
    min-width: 100px;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}
.form-row input[type="text"],
.form-row input[type="color"] {
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.85rem;
}
.form-row input[type="text"] { flex: 1; }
.form-row input[type="color"] { width: 50px; height: 32px; padding: 2px; }
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    min-width: auto !important;
}
.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* --- Data Table --- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.data-table th,
.data-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Event table column widths */
#event-table th:nth-child(1),
#event-table td:nth-child(1) { width: 60px; }
#event-table th:nth-child(4),
#event-table td:nth-child(4) { width: 80px; }
#event-table th:nth-child(5),
#event-table td:nth-child(5) { width: 240px; overflow: visible; }
.data-table th {
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
}
.data-table td { font-size: 0.9rem; }
.table-cell-value {
    min-width: 0;
    overflow-wrap: anywhere;
}
/* Keep table cells in table layout; flex only their inner action content. */
.table-cell-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}
#employee-table .employee-skill-list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 4px;
}
#employee-table .employee-skill-list .skill-tag {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
}
#employee-table .employee-skill-list .skill-tag,
#employee-table .table-cell-actions > * {
    max-width: 100%;
}
.inactive-row { opacity: 0.4; }
.color-swatch {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    vertical-align: middle;
}
.picker-empty {
    color: var(--color-text-dim);
    font-size: 0.8rem;
    padding: 8px;
}
.bulk-month-event-hint {
    margin-bottom: 7px;
    padding: 7px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    background: var(--color-accent-soft);
    font-size: 0.72rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}
.picker-divider {
    height: 1px;
    background: #2a2a4a;
    margin: 6px 0;
}

/* --- GCal Sync Button --- */
.gcal-sync-btn {
    position: fixed;
    bottom: 16px;
    right: 16px;
    background: var(--color-surface-muted);
    color: var(--color-text-dim);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 5px 10px;
    font-family: inherit;
    font-size: 0.7rem;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
    display: none;
    z-index: 10;
}
.gcal-sync-btn:hover {
    color: var(--color-text);
    border-color: var(--color-accent);
}
.ooo-toggle-btn {
    position: fixed;
    bottom: 16px;
    right: 80px;
    background: var(--color-surface-muted);
    color: var(--color-text-dim);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.7rem;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
    z-index: 10;
    opacity: 0.5;
}
.ooo-toggle-btn:hover {
    opacity: 0.9;
    color: var(--color-text);
    border-color: var(--color-border-strong);
}
.ooo-toggle-btn.active {
    opacity: 0.8;
    color: #e8a735;
    border-color: #e8a735;
    background: #2a2a3a;
}

/* --- Loading Overlay --- */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(26, 26, 46, 0.5);
    z-index: 500;
    display: none;
    cursor: none;
}
.loading-overlay.active {
    display: block;
}
.loading-cursor {
    position: fixed;
    z-index: 501;
    display: none;
    pointer-events: none;
    align-items: center;
    gap: 10px;
}
.loading-cursor.active {
    display: flex;
}
.loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}
.loading-text {
    font-size: 0.8rem;
    color: #ccc;
    white-space: nowrap;
    line-height: 1.3;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Skill Tags --- */
.skill-tag {
    display: inline-block;
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 3px;
    margin: 1px 2px;
}
.skill-check-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.skill-check-grid label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: #bbb;
    min-width: auto !important;
    cursor: pointer;
}
.skills-panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    margin-bottom: 16px;
}
.skills-panel h3 {
    color: #fff;
    font-size: 1rem;
    margin: 0 0 10px;
}
.skill-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 0.85rem;
    color: #ccc;
}
.skill-list-item input[type="text"] {
    padding: 3px 8px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.8rem;
    width: 140px;
}

/* --- Mode Selection Dialog --- */
.mode-dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(26, 26, 46, 0.85);
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
}
.mode-dialog-overlay.active {
    display: flex;
}
.mode-dialog {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 32px 40px;
    text-align: center;
    min-width: 320px;
}
.mode-dialog h3 {
    color: #fff;
    margin: 0 0 24px;
    font-size: 1.2rem;
}
.mode-btn {
    display: block;
    width: 100%;
    padding: 16px;
    margin: 10px 0;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    color: #fff;
    transition: transform 0.15s;
}
.mode-btn:hover { transform: scale(1.03); }
.mode-btn-xuanfei {
    background: linear-gradient(135deg, #e74c3c, #9b59b6, #e74c3c);
    background-size: 200% 200%;
    font-size: 1.6rem;
    font-weight: 700;
    padding: 24px;
    animation: xuanfei-pulse 2s ease-in-out infinite, xuanfei-bg 4s ease infinite;
    letter-spacing: 8px;
}
@keyframes xuanfei-pulse {
    0%, 100% { box-shadow: 0 0 10px rgba(231,76,60,0.3); }
    50% { box-shadow: 0 0 30px rgba(231,76,60,0.8), 0 0 60px rgba(155,89,182,0.4); }
}
@keyframes xuanfei-bg {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}
.mode-btn-normal {
    background: #333;
    font-size: 0.9rem;
    color: #999;
}

/* --- Xuanfei Wizard --- */
.xuanfei-wizard {
    border-color: #9b59b6;
}
.wizard-steps {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.wizard-step-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #2a2a4a;
    color: #667;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    transition: all 0.2s;
}
.wizard-step-dot.active {
    background: #9b59b6;
    color: #fff;
}
.wizard-step-dot.done {
    background: #2ecc71;
    color: #fff;
}
.wizard-step-panel {
    display: none;
    min-height: 80px;
}
.wizard-step-panel.active {
    display: block;
}
.wizard-step-panel h4 {
    color: #aab;
    font-size: 0.85rem;
    margin: 0 0 10px;
    font-weight: 400;
}
.wizard-nav {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    justify-content: flex-end;
}
.wizard-day-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}
.wizard-day-btn {
    padding: 6px 2px;
    border: 1px solid #2a2a4a;
    border-radius: 4px;
    background: #1a1a2e;
    color: #bbb;
    cursor: pointer;
    text-align: center;
    font-family: inherit;
    font-size: 0.75rem;
    transition: all 0.15s;
}
.wizard-day-btn:hover { border-color: #9b59b6; }
.wizard-day-btn.selected {
    background: #9b59b6;
    color: #fff;
    border-color: #9b59b6;
}
.wizard-day-btn.weekend { color: #666; }
.wizard-day-btn .day-num { font-weight: 600; font-size: 0.85rem; }
.wizard-day-btn .day-wd { font-size: 0.6rem; opacity: 0.7; }

/* --- Task Panel (Roster) --- */
.task-panel {
    background: var(--color-surface);
    border: 2px solid #9b59b6;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 12px;
    display: none;
}
.task-panel.active { display: block; }
.task-panel-header {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.task-event-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
}
.task-title {
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
}
.task-progress {
    margin-left: auto;
    font-size: 0.9rem;
    color: #9b59b6;
    font-weight: 600;
}
.task-skills {
    margin: 6px 0;
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.task-skill-tag {
    background: #9b59b6;
    color: #fff;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 3px;
}
.task-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.task-unqualified { opacity: 0.25; }
.task-divider-row td {
    background: var(--color-border) !important;
    height: 3px !important;
    padding: 0 !important;
    border: none !important;
}
.task-day-highlight {
    background: rgba(155, 89, 182, 0.12) !important;
    animation: task-col-pulse 2.5s ease-in-out infinite;
    box-shadow: inset 0 0 0 1px rgba(155, 89, 182, 0.25);
}
@keyframes task-col-pulse {
    0%, 100% { background: rgba(155, 89, 182, 0.08) !important; }
    50% { background: rgba(155, 89, 182, 0.28) !important; }
}
/* Header cells for task days */
.task-day-header-highlight {
    background: rgba(155, 89, 182, 0.3) !important;
    color: #d4a0ff !important;
    animation: task-header-pulse 2.5s ease-in-out infinite;
}
.task-day-header-highlight .weekday-label {
    color: #b07de0 !important;
}
@keyframes task-header-pulse {
    0%, 100% { background: rgba(155, 89, 182, 0.2) !important; }
    50% { background: rgba(155, 89, 182, 0.45) !important; }
}

/* --- Unqualified Cell Tooltip --- */
.task-unqualified-tooltip {
    position: absolute;
    z-index: 200;
    background: var(--color-surface-muted);
    color: #e74c3c;
    font-size: 0.78rem;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: pre-line;
    pointer-events: none;
    display: none;
    transform: translate(-50%, -100%);
    box-shadow: 0 3px 12px rgba(0,0,0,0.5);
    border: 1px solid #e74c3c;
    max-width: 220px;
    line-height: 1.4;
}

/* --- Login & Change Password Pages --- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--color-bg);
    margin: 0;
}
.login-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    box-sizing: border-box;
}
.login-title {
    color: #fff;
    font-size: 1.5rem;
    text-align: center;
    margin: 0 0 4px 0;
}
.login-subtitle {
    color: var(--color-text-dim);
    font-size: 0.85rem;
    text-align: center;
    margin: 0 0 24px 0;
}
.login-field {
    margin-bottom: 16px;
}
.login-field label {
    display: block;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    margin-bottom: 6px;
}
.login-field input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.95rem;
    box-sizing: border-box;
}
.login-field input:focus {
    outline: none;
    border-color: var(--color-focus);
}
.login-btn {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    margin-top: 8px;
}
.login-error {
    background: rgba(231, 76, 60, 0.15);
    border: 1px solid #e74c3c;
    color: #e74c3c;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 16px;
    text-align: center;
}
.login-success {
    background: rgba(46, 204, 113, 0.15);
    border: 1px solid #2ecc71;
    color: #2ecc71;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 16px;
    text-align: center;
}
.password-hint {
    color: var(--color-text-dim);
    font-size: 0.75rem;
    margin: 4px 0 12px;
}
.login-back-link {
    display: block;
    text-align: center;
    color: var(--color-accent);
    font-size: 0.85rem;
    margin-top: 16px;
    text-decoration: none;
}
.login-back-link:hover {
    color: var(--color-accent-hover);
}

/* --- OOO/SOOO Tags --- */
.has-ooo {
    cursor: not-allowed !important;
}
.ooo-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.5rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 0;
    white-space: nowrap;
    overflow: hidden;
    pointer-events: none;  /* CRITICAL: don't interfere with drag-and-select */
    z-index: 1;
}
/* OOO/SOOO picker buttons */
.ooo-picker-btn {
    background: var(--color-surface-muted) !important;
    color: var(--color-danger) !important;
    border: 1px solid var(--color-danger) !important;
}
.ooo-picker-btn:hover {
    background: var(--color-surface-raised) !important;
}
.ooo-picker-btn.ooo-active {
    background: var(--color-danger) !important;
    color: #fff !important;
}
/* OOO tooltip */
.ooo-tooltip {
    position: absolute;
    z-index: 200;
    background: var(--color-surface-muted);
    color: #ff6b6b;
    font-size: 0.78rem;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: nowrap;
    pointer-events: none;
    display: none;
    transform: translate(-50%, -100%);
    box-shadow: 0 3px 12px rgba(0,0,0,0.5);
    border: 1px solid var(--color-danger);
}

.navbar-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px 8px;
}

/* --- Mobile / iPhone Safari --- */
@media (max-width: 640px), (max-width: 900px) and (pointer: coarse) {
    body {
        -webkit-text-size-adjust: 100%;
    }
    button,
    a,
    [role="button"] {
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    input,
    select,
    textarea {
        font-size: 16px !important;
    }
    .container {
        padding: 10px max(12px, env(safe-area-inset-right))
            calc(12px + env(safe-area-inset-bottom))
            max(12px, env(safe-area-inset-left));
    }

    /* Keep the phone roster focused on range and date navigation. */
    .month-nav {
        gap: 7px;
        padding: 6px 0 4px;
        font-size: 1rem;
        white-space: nowrap;
    }
    .roster-view-toggle {
        order: 1;
        width: 100%;
        flex: 1 0 100%;
    }
    .roster-view-toggle-btn-five {
        display: block;
    }
    #view-five { order: 1; }
    #view-week { order: 2; }
    #view-month { order: 3; }
    .month-nav .roster-view-toggle-btn {
        flex: 1 1 0;
        min-width: 0;
        min-height: 44px;
        padding: 8px 6px;
        font-size: 0.82rem;
    }
    #prev-month,
    #month-label,
    #next-month {
        order: 2;
    }
    .month-nav > #prev-month,
    .month-nav > #next-month {
        width: 44px;
        min-width: 44px;
        min-height: 44px;
        padding: 0;
    }
    #month-label {
        flex: 1 1 calc(100% - 102px);
        min-width: 0;
        overflow: hidden;
        font-size: 0.92rem;
        text-align: center;
        text-overflow: ellipsis;
    }
    .month-nav > .nav-action-btn {
        display: none;
    }

    .legend {
        flex-wrap: nowrap;
        gap: 5px;
        padding: 4px 2px 8px;
    }
    .remark-legend-label {
        display: none;
    }
    .remark-legend-item {
        min-width: 0;
        flex: 1 1 0;
        gap: 3px;
        font-size: 0.68rem;
        white-space: nowrap;
    }
    .remark-legend-item > span:last-child {
        overflow-wrap: normal;
        font-size: 0;
    }
    .remark-legend-item > span:last-child::after {
        content: attr(data-mobile-label);
        font-size: 0.68rem;
    }

    .grid-wrapper {
        max-height: calc(100vh - 174px);
        max-height: calc(100dvh - 174px);
        -webkit-overflow-scrolling: touch;
    }
    .roster-grid .gantt-row,
    .roster-grid .gantt-packed-row {
        display: none !important;
    }
    #grid-head > .roster-day-header > th {
        position: sticky;
        top: 0 !important;
        border-top: 1px solid var(--color-border) !important;
    }
    .roster-grid[data-view-mode="five"],
    .roster-grid[data-view-mode="week"] {
        width: 100%;
        min-width: 100%;
    }
    .roster-grid th,
    .roster-grid td {
        height: 42px;
        padding: 2px;
    }
    .roster-grid th .weekday-label {
        font-size: 0.62rem;
    }
    .employee-name,
    .corner-cell {
        padding-left: 7px !important;
    }
    .employee-name {
        font-size: 0.72rem !important;
    }
    .assignment-block {
        min-height: 14px;
        margin-top: 2px;
        margin-bottom: 2px;
    }
    .assignment-block:hover {
        transform: none;
    }
    .assignment-remark-marker-cell {
        top: 3px;
        right: 4px;
        width: 5px;
        height: 5px;
    }
    .assignment-remark-marker-connected {
        bottom: 2px;
    }

    /* Navbar hamburger and menu are thumb-friendly. */
    .navbar {
        padding: 8px max(12px, env(safe-area-inset-right)) 8px
            max(12px, env(safe-area-inset-left));
        flex-wrap: wrap;
    }
    .navbar-toggle {
        display: block;
        width: 44px;
        min-height: 44px;
        padding: 0;
    }
    .navbar-links {
        display: none;
        flex-direction: column;
        width: 100%;
        margin-top: 6px;
        gap: 4px;
    }
    .navbar-links.open {
        display: flex;
    }
    .navbar-links a,
    #current-user {
        display: flex !important;
        min-height: 44px;
        margin-left: 0 !important;
        padding: 10px 12px !important;
        align-items: center;
        border-radius: 6px;
    }
    .navbar-links form {
        margin: 0 !important;
    }
    .navbar-links form button {
        width: 100%;
        min-height: 44px;
        padding: 10px;
        font-size: 0.85rem !important;
    }

    /* Headers, forms, and actions stack without clipped controls. */
    .page-header {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .page-header h2 {
        align-self: flex-start;
    }
    .page-header .month-nav {
        width: 100%;
        justify-content: center;
    }
    .page-header .month-nav button {
        min-width: 44px;
        min-height: 44px;
    }
    .page-header-actions,
    .form-actions,
    .task-actions {
        width: 100%;
        flex-wrap: wrap;
    }
    .page-header-actions .btn,
    .form-actions .btn,
    .task-actions .btn {
        flex: 1 1 120px;
        min-height: 44px;
        text-align: center;
    }
    .btn,
    .btn-sm {
        min-height: 44px;
        padding: 8px 12px;
    }
    .xuanfei-wizard,
    .form-card,
    .skills-panel {
        padding: 12px;
    }
    .form-row {
        align-items: stretch;
        flex-wrap: wrap;
    }
    .form-row label {
        width: 100%;
        min-width: 0;
    }
    .form-row input[type="text"],
    .form-row input[type="number"],
    .form-row select,
    #new-skill-name,
    #history-search,
    #evt-search {
        width: 100%;
        min-width: 0 !important;
        min-height: 44px;
    }
    .checkbox-label,
    .skill-check-grid label {
        width: auto;
        min-height: 44px;
        padding: 6px;
    }
    .skill-list-item {
        flex-wrap: wrap;
        padding: 7px 0;
    }
    .skill-list-item .skill-tag {
        flex: 1 1 140px;
        overflow-wrap: anywhere;
    }

    /* Management tables become labeled cards instead of clipped mini-tables. */
    .data-table {
        display: block;
        width: 100%;
        table-layout: auto;
    }
    .data-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }
    .data-table tbody {
        display: grid;
        width: 100%;
        gap: 10px;
    }
    .data-table tr {
        display: block;
        width: 100%;
        overflow: hidden;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        background: var(--color-surface);
    }
    .data-table td,
    #event-table td:nth-child(1),
    #event-table td:nth-child(4),
    #event-table td:nth-child(5) {
        display: grid !important;
        width: 100% !important;
        min-height: 42px;
        grid-template-columns: minmax(78px, 30%) minmax(0, 1fr);
        align-items: center;
        gap: 8px;
        padding: 8px 10px;
        overflow: visible;
        border-bottom: 1px solid var(--color-border);
        white-space: normal;
    }
    .data-table td:last-child {
        border-bottom: 0;
    }
    .data-table td:empty {
        display: none !important;
    }
    .data-table td::before {
        content: attr(data-label);
        color: var(--color-text-dim);
        font-size: 0.68rem;
        font-weight: 600;
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }
    .data-table .actions {
        display: grid !important;
    }
    .table-cell-actions .btn {
        flex: 1 1 92px;
        min-height: 44px;
    }

    /* Wizard and history controls remain usable in portrait. */
    .wizard-day-grid {
        grid-template-columns: repeat(5, 1fr);
    }
    .wizard-day-btn {
        min-height: 44px;
    }
    .wizard-nav {
        justify-content: space-between;
        flex-wrap: wrap;
    }
    .wizard-nav .btn,
    .hist-past-btn {
        flex: 1 1 90px;
        min-height: 44px;
        text-align: center;
    }
    .mode-dialog {
        width: calc(100vw - 24px);
        min-width: 0;
        padding: 24px 18px;
    }
    .mode-btn {
        width: 100%;
        min-height: 52px;
        padding: 14px;
        font-size: 1rem;
    }
    #history-panel label,
    #history-list .history-option {
        min-height: 44px;
        align-items: center;
        overflow-wrap: anywhere;
    }

    .login-card {
        width: calc(100% - 24px);
        padding: 24px 18px;
    }
    .login-field input,
    .login-btn {
        min-height: 44px;
    }
    .login-back-link {
        display: flex;
        min-height: 44px;
        align-items: center;
        justify-content: center;
    }
    .toast-container {
        right: max(10px, env(safe-area-inset-right));
        left: max(10px, env(safe-area-inset-left));
    }
    .toast {
        overflow-wrap: anywhere;
    }

    .gcal-sync-btn,
    .ooo-toggle-btn {
        position: static;
        flex: 1 1 44px;
        min-width: 44px;
        min-height: 44px;
        padding: 6px 8px;
    }

    /* Bulk remark confirmation becomes a Safari-safe modal bottom sheet. */
    .bulk-assignment-remark-modal {
        place-items: end stretch;
        padding: 0;
    }
    .bulk-assignment-remark-dialog {
        width: 100%;
        max-height: calc(100vh - 12px);
        max-height: calc(
            100dvh - max(12px, env(safe-area-inset-top))
        );
        padding: 14px max(14px, env(safe-area-inset-right))
            calc(14px + env(safe-area-inset-bottom))
            max(14px, env(safe-area-inset-left));
        border-right: 0;
        border-bottom: 0;
        border-left: 0;
        border-radius: 18px 18px 0 0;
        -webkit-overflow-scrolling: touch;
        animation-name: bulkRemarkSheetIn;
    }
    .bulk-assignment-remark-header {
        position: sticky;
        top: -14px;
        z-index: 2;
        margin: -2px -2px 0;
        padding: 4px 2px 10px;
        background: var(--color-surface-raised);
    }
    .bulk-assignment-remark-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    /* Roster detail popover becomes a Safari-safe bottom sheet. */
    .event-picker,
    .event-picker.event-picker-mobile {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0 !important;
        top: auto !important;
        width: 100%;
        min-width: 0;
        max-height: 82vh;
        max-height: 82dvh;
        padding: 8px max(12px, env(safe-area-inset-right))
            calc(12px + env(safe-area-inset-bottom))
            max(12px, env(safe-area-inset-left));
        border-right: 0;
        border-bottom: 0;
        border-left: 0;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -16px 42px rgba(2, 8, 16, 0.58);
    }
    .event-picker-handle {
        display: block;
        width: 42px;
        height: 4px;
        margin: 0 auto 8px;
        border-radius: 999px;
        background: var(--color-border-strong);
    }
    .event-picker-heading-title {
        display: -webkit-box;
        overflow: hidden;
        white-space: normal;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }
    .event-picker-heading-meta {
        overflow-wrap: anywhere;
    }
    .event-picker-header {
        position: sticky;
        top: -8px;
        z-index: 2;
        margin: 0 -2px 10px;
        padding: 4px 2px 10px;
        background: var(--color-surface-raised);
    }
    .event-picker-columns {
        flex-direction: column;
    }
    .event-picker-col {
        min-width: 0;
    }
    .event-picker-col-remove {
        padding-top: 10px;
        padding-left: 0;
        border-top: 1px solid var(--color-border);
        border-left: 0;
    }
    .event-picker-btn,
    .event-picker-icon-btn,
    .remark-link-btn,
    .remark-edit-actions .btn,
    .btn-danger-subtle {
        min-height: 44px;
    }
    .event-picker-icon-btn {
        width: 44px;
        flex-basis: 44px;
    }
    .remark-link-btn {
        padding-right: 10px;
        padding-left: 10px;
    }
    .remark-editor {
        min-height: 110px;
        resize: none;
    }
    .remark-edit-actions,
    .bulk-assignment-remark-actions {
        position: sticky;
        bottom: 0;
        padding-top: 8px;
        background: var(--color-surface-raised);
    }
    .remark-edit-actions .btn {
        flex: 1;
    }
    .bulk-remark-row {
        align-items: stretch;
    }
    .bulk-assignment-remark-actions {
        grid-template-columns: minmax(0, 1fr);
    }
}

@keyframes bulkRemarkSheetIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (max-width: 640px) and (max-height: 620px),
       (max-width: 900px) and (max-height: 620px) and (pointer: coarse) {
    .login-body {
        min-height: 100dvh;
        padding: 12px 0;
        align-items: flex-start;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
