/* 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;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'PingFang HK', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
    background: #1a1a2e;
    color: #e0e0e0;
    min-height: 100vh;
    font-size: 14px;
}

/* --- Navbar --- */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: #16213e;
    border-bottom: 1px solid #2a2a4a;
}
.navbar-brand {
    font-weight: 600;
    font-size: 1.1rem;
    color: #fff;
}
.navbar-links a {
    color: #7a8ba8;
    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: #fff;
    background: #2a2a4a;
}

/* --- Container --- */
.container { padding: 16px 24px; }

/* --- Month Nav --- */
.month-nav {
    display: flex;
    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: #4a90d9;
    border: none;
    color: #fff;
    padding: 6px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
}
.month-nav button:hover { background: #5ba0e9; }
.nav-action-btn {
    background: #2a2a4a !important;
    border: 1px solid #444 !important;
    color: #8899aa;
    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: #fff;
    border-color: #4a90d9 !important;
    background: #333 !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: #1a1a2e !important;
}
.nav-action-btn-active {
    color: #4a90d9 !important;
    border-color: #4a90d9 !important;
}

/* --- Legend --- */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 8px 0 12px;
}
.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;
}

/* --- Grid --- */
.grid-wrapper {
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 160px);
    border-radius: 8px;
    border: 1px solid #2a2a4a;
}

/* --- 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 #1a1a2e !important;
}
.gantt-label {
    font-size: 0.65rem !important;
    font-weight: 600 !important;
    white-space: nowrap;
    text-align: left !important;
    padding-left: 10px !important;
    background: #1a1a2e !important;
    position: sticky;
    left: 0;
    z-index: 4;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gantt-bar {
    border-radius: 3px;
    font-size: 0.6rem !important;
    font-weight: 600 !important;
    text-align: center !important;
    white-space: nowrap;
    overflow: visible;
    position: relative;
    line-height: 24px !important;
    padding: 0 !important;
}
.gantt-text {
    white-space: nowrap;
    font-weight: 600;
    pointer-events: none;
}
.gantt-empty {
    background: #1a1a2e !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 #4a90d9;
    outline-offset: -2px;
}
.roster-grid {
    border-collapse: collapse;
    width: 100%;
    table-layout: fixed;
    min-width: 900px;
}
.roster-grid th,
.roster-grid td {
    border: 1px solid #2a2a4a;
    padding: 2px;
    text-align: center;
    min-width: 38px;
    height: 32px;
    vertical-align: middle;
    font-size: 0.8rem;
}
.roster-grid th {
    background: #16213e;
    color: #8899aa;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 3;
}
.roster-grid th .weekday-label {
    font-size: 0.65rem;
    color: #667;
    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: #16213e !important;
    position: sticky;
    left: 0;
    z-index: 2;
    font-weight: 600;
    color: #ccc;
    cursor: grab;
}
/* Employee row drag-and-drop reorder */
.emp-dragging {
    opacity: 0.4;
}
.emp-drop-target > .employee-name {
    outline: 2px solid #4a90d9;
    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 #4a90d9;
    outline-offset: -2px;
}
/* Row + column crosshair highlight */
.row-highlight > td {
    background: rgba(74, 144, 217, 0.15) !important;
}
.row-highlight > .employee-name {
    color: #fff !important;
    border-right: 2px solid #4a90d9;
}
.col-highlight {
    background: rgba(74, 144, 217, 0.15) !important;
}
.row-highlight > td.col-highlight {
    background: rgba(74, 144, 217, 0.30) !important;
}
.weekend {
    background: rgba(255, 255, 255, 0.03);
}
.drag-highlight {
    background: rgba(74, 144, 217, 0.2) !important;
}

/* --- Assignment Blocks --- */
.assignment-block {
    display: block;
    width: 90%;
    height: 8px;
    margin: 2px auto;
    border-radius: 3px;
    cursor: pointer;
    transition: transform 0.1s;
}
.assignment-block:hover {
    transform: scaleY(1.5);
}
/* Pending assignment blocks (dashed border, not yet saved) */
.pending-block {
    display: block;
    width: 90%;
    height: 8px;
    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-mid {
    position: relative;
    width: calc(100% + 6px);
    margin-left: -3px;
    margin-right: -3px;
    border-radius: 0;
    z-index: 1;
}
.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);
}
.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;
}

/* --- Event Picker --- */
.event-picker {
    position: absolute;
    background: #16213e;
    border: 1px solid #4a90d9;
    border-radius: 8px;
    padding: 8px;
    z-index: 100;
    display: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
    min-width: 180px;
}
.event-picker-footer { display: none; }
.event-picker-columns {
    display: flex;
    gap: 8px;
}
.event-picker-col {
    flex: 1;
    min-width: 150px;
}
.event-picker-col-remove {
    border-left: 1px solid #2a2a4a;
    padding-left: 8px;
}
.remove-event-btn {
    opacity: 0.85;
}
.event-picker-title {
    font-size: 0.75rem;
    color: #667;
    margin-bottom: 6px;
    padding: 0 4px;
}
.event-picker-btn {
    display: block;
    width: 100%;
    padding: 7px 12px;
    margin: 3px 0;
    border: none;
    border-radius: 5px;
    color: #fff;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    font-size: 0.85rem;
    transition: opacity 0.2s;
}
.event-picker-btn:hover { opacity: 0.85; }
.cancel-btn {
    background: #444 !important;
    margin-top: 6px;
}
.remove-btn {
    background: #e74c3c !important;
    margin-top: 6px;
}

/* --- Toast --- */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 200;
    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: #4a90d9;
}
.btn:hover { opacity: 0.85; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-primary { background: #4a90d9; }
.btn-secondary { background: #555; }
.btn-danger { background: #e74c3c; }
.btn-success { background: #2ecc71; }

/* --- Form Card --- */
.form-card {
    background: #16213e;
    border: 1px solid #2a2a4a;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}
.form-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}
.form-row label {
    min-width: 100px;
    color: #8899aa;
    font-size: 0.85rem;
}
.form-row input[type="text"],
.form-row input[type="color"] {
    padding: 6px 10px;
    border: 1px solid #2a2a4a;
    border-radius: 4px;
    background: #1a1a2e;
    color: #e0e0e0;
    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: #8899aa;
    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 #2a2a4a;
    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: #16213e;
    color: #8899aa;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
}
.data-table td { font-size: 0.9rem; }
.data-table .actions { display: flex; gap: 6px; }
.inactive-row { opacity: 0.4; }
.color-swatch {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    vertical-align: middle;
}
.picker-empty {
    color: #667;
    font-size: 0.8rem;
    padding: 8px;
}
.picker-divider {
    height: 1px;
    background: #2a2a4a;
    margin: 6px 0;
}

/* --- GCal Sync Button --- */
.gcal-sync-btn {
    position: fixed;
    bottom: 16px;
    right: 16px;
    background: #2a2a4a;
    color: #667;
    border: 1px solid #333;
    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: #aab;
    border-color: #4a90d9;
}
.ooo-toggle-btn {
    position: fixed;
    bottom: 16px;
    right: 80px;
    background: #2a2a4a;
    color: #556;
    border: 1px solid #333;
    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: #aab;
    border-color: #555;
}
.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: #4a90d9;
    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: #2a2a4a;
    color: #aab;
    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: #16213e;
    border: 1px solid #2a2a4a;
    border-radius: 8px;
    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 #2a2a4a;
    border-radius: 4px;
    background: #1a1a2e;
    color: #e0e0e0;
    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: #16213e;
    border: 1px solid #2a2a4a;
    border-radius: 12px;
    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: #16213e;
    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: #2a2a4a !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: #2a2a4a;
    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: #1a1a2e;
    margin: 0;
}
.login-card {
    background: #16213e;
    border: 1px solid #2a2a4a;
    border-radius: 12px;
    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: #667;
    font-size: 0.85rem;
    text-align: center;
    margin: 0 0 24px 0;
}
.login-field {
    margin-bottom: 16px;
}
.login-field label {
    display: block;
    color: #8899aa;
    font-size: 0.85rem;
    margin-bottom: 6px;
}
.login-field input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #2a2a4a;
    border-radius: 6px;
    background: #1a1a2e;
    color: #e0e0e0;
    font-family: inherit;
    font-size: 0.95rem;
    box-sizing: border-box;
}
.login-field input:focus {
    outline: none;
    border-color: #4a90d9;
}
.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: #667;
    font-size: 0.75rem;
    margin: 4px 0 12px;
}
.login-back-link {
    display: block;
    text-align: center;
    color: #4a90d9;
    font-size: 0.85rem;
    margin-top: 16px;
    text-decoration: none;
}
.login-back-link:hover {
    color: #5ba0e9;
}

/* --- OOO/SOOO/SL 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/SL picker buttons */
.ooo-picker-btn {
    background: #2a2a4a !important;
    color: #e74c3c !important;
    border: 1px solid #e74c3c !important;
}
.ooo-picker-btn:hover {
    background: #3a3a5a !important;
}
.ooo-picker-btn.ooo-active {
    background: #e74c3c !important;
    color: #fff !important;
}
/* OOO tooltip */
.ooo-tooltip {
    position: absolute;
    z-index: 200;
    background: #2a2a4a;
    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 #e74c3c;
}

.navbar-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px 8px;
}

/* --- Mobile (events page + wizard) --- */
@media (max-width: 640px) {
    .container { padding: 10px 12px; }

    /* Navbar hamburger */
    .navbar { padding: 10px 16px; flex-wrap: wrap; }
    .navbar-toggle { display: block; }
    .navbar-links { display: none; flex-direction: column; width: 100%; margin-top: 8px; gap: 4px; }
    .navbar-links.open { display: flex; }
    .navbar-links a { margin-left: 0; padding: 10px 12px; border-radius: 6px; display: block; }
    .navbar-links form { margin-left: 0; margin-top: 4px; }
    .navbar-links form button { width: 100%; padding: 10px; font-size: 0.85rem; }
    #current-user { margin-left: 0 !important; padding: 10px 12px; display: block; }

    /* Page header stacks vertically */
    .page-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .page-header-actions { flex-wrap: wrap; }
    .page-header-actions .btn { flex: 1; text-align: center; }

    /* Event table: hide Color + Status columns, make Actions wrap */
    #event-table th:nth-child(1),
    #event-table td:nth-child(1),
    #event-table th:nth-child(4),
    #event-table td:nth-child(4) { display: none; }
    #event-table th:nth-child(5),
    #event-table td:nth-child(5) { width: auto; }
    .data-table th, .data-table td { padding: 8px; }
    .data-table .actions { flex-wrap: wrap; gap: 4px; }
    .btn-sm { padding: 6px 10px; }

    /* Wizard full-width */
    .xuanfei-wizard, .form-card { padding: 12px; }
    .wizard-day-grid { grid-template-columns: repeat(5, 1fr); }
    .wizard-nav { justify-content: space-between; }
    .wizard-nav .btn { flex: 1; text-align: center; }
    .form-row { flex-wrap: wrap; }
    .form-row label { min-width: unset; width: 100%; }
    .form-row input[type="text"] { width: 100%; }

    /* History panel past-month buttons full width */
    .hist-past-btn { flex: 1; text-align: center; }

    /* Mode buttons full width */
    .mode-btn { width: 100%; padding: 14px; font-size: 1rem; }
}

/* Native sick leave has an independent label and picker state. */
.ooo-overlay.sl-overlay { background: rgba(31, 104, 113, 0.55); color: #d8fbff; }
.ooo-picker-btn.sl-picker-btn { color: #83e3e9 !important; border-color: #83e3e9 !important; }
.ooo-picker-btn.sl-picker-btn.ooo-active { background: #236b73 !important; color: #fff !important; }
.ooo-picker-btn:disabled { opacity: 0.45; cursor: not-allowed; }


/* Roster date views: retain the existing theme and monthly desktop layout. */
.roster-nav { flex-wrap: wrap; gap: 12px; }
.roster-view-toggle {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border: 1px solid #2a2a4a;
    border-radius: 8px;
    background: #16213e;
}
.roster-nav .roster-view-toggle-btn {
    min-height: 34px;
    padding: 5px 10px;
    border: 1px solid transparent;
    background: transparent;
    color: #a7b7c9;
    font-size: 0.8rem;
}
.roster-nav .roster-view-toggle-btn[aria-pressed="true"] {
    border-color: #4a90d9;
    background: #244368;
    color: #fff;
}
.roster-nav button:disabled { opacity: 0.5; cursor: not-allowed; }
.roster-nav button:focus-visible,
.grid-wrapper:focus-visible { outline: 2px solid #6bb6ff; outline-offset: 2px; }
.grid-wrapper {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overscroll-behavior-inline: contain;
}
.grid-wrapper[aria-busy="true"] { pointer-events: none; opacity: 0.65; }
.roster-grid[data-view-mode="week"] {
    min-width: calc(var(--roster-name-width, 100px) + var(--roster-day-count, 7) * 28px);
}
.employee-name { overflow: hidden; text-overflow: ellipsis; }

/* Match the reference's compact phone controls and scrolling table. */
@media (max-width: 640px), (max-width: 900px) and (pointer: coarse) {
    body { -webkit-text-size-adjust: 100%; }
    .container {
        padding: 6px max(10px, env(safe-area-inset-right))
            calc(8px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    }
    .navbar { position: relative; padding: 3px 10px; flex-wrap: wrap; }
    .navbar-brand { font-size: .88rem; line-height: 1.25; }
    .navbar-toggle { display: block; width: 34px; min-height: 34px; padding: 0; font-size: 1.2rem; }
    .navbar-links { display: none; flex-direction: column; width: 100%; margin-top: 6px; gap: 4px; }
    .navbar-links.open {
        display: flex; position: absolute; top: 100%; right: 10px; z-index: 300;
        width: min(260px, calc(100vw - 20px)); max-height: calc(100dvh - 52px);
        margin-top: 2px; padding: 6px; overflow-y: auto;
        border: 1px solid #344565; border-radius: 8px; background: #16213e;
        box-shadow: 0 8px 24px #0006;
    }
    .navbar-links a { margin-left: 0; padding: 8px 10px; min-height: 34px; display: block; font-size: .85rem; }
    #current-user { margin-left: 0 !important; padding: 8px 10px; }
    .navbar-links form { margin-left: 0 !important; }
    .navbar-links form button { width: 100%; min-height: 34px; }
    .roster-nav button { touch-action: manipulation; }
    .roster-nav {
        display: grid; grid-template-columns: 30px minmax(0, 1fr) 30px auto;
        align-items: center; gap: 4px; padding: 0 0 6px; font-size: .8rem;
    }
    .roster-nav .roster-view-toggle {
        grid-column: 4; grid-row: 1; gap: 1px; padding: 2px; border-radius: 6px;
    }
    .roster-nav .roster-view-toggle-btn {
        flex: 0 0 auto; min-height: 30px; padding: 3px 6px;
        font-size: .75rem; line-height: 1.2; border-radius: 4px;
    }
    .roster-nav > #prev-month,
    .roster-nav > #next-month {
        grid-row: 1; width: 30px; min-width: 30px; min-height: 34px;
        padding: 0; font-size: .9rem; border-radius: 5px;
    }
    .roster-nav > #prev-month { grid-column: 1; }
    .roster-nav > #next-month { grid-column: 3; }
    .roster-nav #month-label {
        grid-column: 2; grid-row: 1; min-width: 0;
        text-align: center; font-size: .75rem; line-height: 1.3;
        overflow-wrap: anywhere;
    }
    .roster-nav > .nav-action-btn { display: none; }
    .grid-wrapper { -webkit-overflow-scrolling: touch; }
    .roster-grid .gantt-row,
    .roster-grid .gantt-packed-row { display: none !important; }
    #grid-head > .roster-day-header > th {
        top: 0 !important;
        border-top: 1px solid #2a2a4a !important;
    }
    .roster-grid[data-view-mode="month"] {
        min-width: calc(var(--roster-name-width, 100px) + var(--roster-day-count, 31) * 40px);
    }
    .roster-grid th,
    .roster-grid td { height: 42px; padding: 2px; }
    .roster-grid .weekday-label { font-size: 0.58rem; }
    .employee-name,
    .corner-cell { padding-left: 6px !important; }
    .employee-name { font-size: 0.72rem !important; }
    .assignment-block { min-height: 14px; margin-top: 2px; margin-bottom: 2px; }
    .assignment-block:hover { transform: none; }
    .roster-grid .row-highlight > .employee-name { background: #233451 !important; }
    .block-tooltip {
        max-width: calc(100vw - 16px);
        max-height: calc(100dvh - 32px);
        overflow: hidden;
        white-space: normal;
        overflow-wrap: anywhere;
        font-size: 0.75rem;
        padding: 8px;
    }
    .event-picker {
        max-width: calc(100vw - 16px);
        max-height: calc(100dvh - 32px);
        overflow: hidden;
    }
    .event-picker-columns {
        flex-wrap: wrap;
        max-height: calc(100vh - 112px);
        max-height: calc(100dvh - 112px);
        overflow: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
    .event-picker-col { min-width: 0; flex-basis: 130px; }
    .event-picker-btn { min-height: 44px; }
    .event-picker-columns .cancel-btn { display: none; }
    .event-picker-footer {
        display: block;
        margin-top: 8px;
        padding-top: 8px;
        border-top: 1px solid #344565;
    }
    .event-picker-footer .cancel-btn {
        margin: 0;
        background: #344565 !important;
        border: 1px solid #7186a6;
        color: #e0e8f5;
        text-align: center;
        font-weight: 600;
    }
    .task-panel { padding: 10px; }
    .task-panel-header { flex-wrap: wrap; gap: 6px; }
    .task-actions { flex-wrap: wrap; }
    .task-actions .btn { min-height: 44px; }
    .gcal-sync-btn,
    .ooo-toggle-btn { min-height: 40px; bottom: max(8px, env(safe-area-inset-bottom)); }
    .gcal-sync-btn { right: max(12px, env(safe-area-inset-right)); }
    .ooo-toggle-btn { right: 92px; }
    .toast-container { top: auto; bottom: max(58px, env(safe-area-inset-bottom)); max-width: calc(100vw - 24px); pointer-events: none; }
}

.roster-grid[data-view-mode="week"] .gantt-row { cursor: default; }

/* Browser-local display preference; default hidden even before scripts run. */
html:not(.show-roster-admin-tools) #btn-ooo-toggle,
html:not(.show-roster-admin-tools) #btn-gcal-sync,
.display-settings-open #btn-ooo-toggle,
.display-settings-open #btn-gcal-sync { display: none !important; }
.display-settings { max-width: 760px; padding-top: 24px; }
.display-settings h1 { margin-bottom: 24px; }
.display-settings h2 { font-size: 1.15rem; margin-bottom: 16px; }
.display-settings-option { display: flex; gap: 12px; align-items: center; line-height: 1.5; }
.display-settings-option input { width: 20px; height: 20px; flex-shrink: 0; }
.display-settings p { color: #a8b5c5; line-height: 1.6; margin: 16px 0 24px; }
.display-settings a { color: #80baff; }

/* Event inspection uses the same sheet on touch and keyboard. */
.event-details-open { overflow: hidden; }
.event-details {
    position: fixed; inset: auto 0 0; margin: 0 auto;
    width: min(100%, 560px); max-width: 100%; max-height: min(85dvh, 760px);
    padding: 0; border: 1px solid #3e5274; border-bottom: 0;
    border-radius: 16px 16px 0 0; background: #16213e; color: #edf3ff;
    box-shadow: 0 -8px 40px #0006; overflow: hidden;
}
.event-details[open] { display: flex; flex-direction: column; }
.event-details::backdrop { background: #070c19b3; }
.event-details-header, .event-details-actions {
    flex-shrink: 0; padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
}
.event-details-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid #344565; }
.event-details-header h2 { margin: 0; font-size: 1.1rem; }
.event-details button { min-height: 44px; cursor: pointer; touch-action: manipulation; }
.event-details-close { padding: 8px 14px; border: 1px solid #5a7197; border-radius: 8px; background: #24365b; color: #fff; font: inherit; }
.event-details-content { padding: 16px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); overflow-y: auto; overscroll-behavior: contain; overflow-wrap: anywhere; }
.event-details-context { margin: 0 0 8px; font-weight: 600; line-height: 1.5; }
.event-details-scope { margin: 0 0 18px; color: #b9c8df; font-size: .82rem; line-height: 1.5; }
.event-details-event { border-top: 1px solid #344565; padding: 16px 0 4px; }
.event-details-name { font-size: 1.08rem; line-height: 1.45; margin: 0 0 4px; }
.event-details-company { margin: 0 0 6px; color: #a8d4ff; }
.event-details-month { margin: 0 0 12px; color: #b9c8df; font-size: .8rem; }
.event-details-people-title { margin: 16px 0 8px; font-size: .85rem; color: #c3d0e5; }
.event-details-people { list-style: none; padding: 0; margin: 0; }
.event-details-people li { padding: 10px 8px; border-radius: 6px; }
.event-details-selected-person { background: #24365b; }
.event-details-person-name, .event-details-person-dates { display: block; line-height: 1.5; }
.event-details-person-dates { color: #b9c8df; font-size: .82rem; }
.event-details-actions { border-top: 1px solid #344565; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.event-details-actions:has(button[hidden]) { display: none; }
.event-details-actions button { width: 100%; }
.event-details button:focus-visible, .has-event-details:focus-visible { outline: 2px solid #8bc8ff; outline-offset: -3px; }

/* Keep the mobile key outside the table's native two-axis scroll area. */
.mobile-roster-legend { display: none; }
@media (max-width: 640px), (max-width: 900px) and (pointer: coarse) {
    .mobile-roster-legend:not([hidden]) {
        display: flex;
        flex-direction: column;
        flex-wrap: nowrap;
        gap: 0;
        height: clamp(64px, 16vh, 120px);
        height: clamp(64px, 16dvh, 120px);
        min-width: 0;
        margin-bottom: 8px;
        padding: 8px 10px;
        border: 1px solid #344565;
        border-radius: 8px;
        background: #16213e;
        overflow: hidden;
    }
    .roster-legend-heading {
        display: flex; align-items: center; justify-content: space-between;
        flex: 0 0 auto; gap: 8px; margin-bottom: 5px;
    }
    #roster-legend-title {
        margin: 0;
        color: #a8bddd;
        font-size: .72rem;
        font-weight: 600;
        line-height: 1.35;
    }
    .roster-legend-scroll-area { position: relative; flex: 1 1 auto; min-height: 0; }
    #roster-legend-items {
        height: 100%;
        min-height: 0;
        margin: 0;
        padding: 0 3px 0 0;
        list-style: none;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
    /* This rail stays visible even when the device hides its native scrollbar. */
    #roster-legend-items { scrollbar-width: none; }
    #roster-legend-items::-webkit-scrollbar { display: none; }
    .roster-legend-cues { display: flex; align-items: center; gap: 4px; }
    .roster-legend-auto-toggle {
        display: grid; place-items: center; min-width: 24px; height: 22px; padding: 0 4px;
        border: 1px solid #4c6b94; border-radius: 6px; color: #bee1ff; background: #243b5d;
        font-family: inherit; font-size: .7rem; cursor: pointer;
    }
    .roster-legend-auto-toggle:focus-visible { outline: 2px solid #8bc8ff; outline-offset: 2px; }
    .roster-legend-scroll-hint {
        flex-shrink: 0; padding: 1px 6px; border: 1px solid #4c6b94; border-radius: 10px;
        color: #bee1ff; background: #243b5d; font-size: .65rem; line-height: 1.3;
    }
    .has-scroll-overflow #roster-legend-items { padding-right: 12px; }
    .roster-legend-scroll-track {
        position: absolute; top: 2px; right: 0; bottom: 2px; width: 4px;
        border-radius: 4px; background: #3a506e; pointer-events: none;
    }
    .roster-legend-scroll-thumb {
        position: absolute; top: 0; left: 0; width: 100%;
        height: var(--legend-thumb-height); transform: translateY(var(--legend-thumb-offset));
        border-radius: inherit; background: #8dc9fa;
    }
    .roster-legend-scroll-area::before, .roster-legend-scroll-area::after {
        content: ''; display: none; position: absolute; left: 0; right: 9px; height: 12px;
        pointer-events: none;
    }
    .roster-legend-scroll-area::before { top: 0; background: linear-gradient(#16213e, transparent); }
    .roster-legend-scroll-area::after { bottom: 0; background: linear-gradient(transparent, #16213e); }
    .roster-legend-scroll-area.can-scroll-up::before,
    .roster-legend-scroll-area.can-scroll-down::after { display: block; }
    #roster-legend-items:focus-visible { outline: 2px solid #6bb6ff; outline-offset: -2px; }
    .mobile-roster-legend .legend-item {
        align-items: flex-start;
        gap: 8px;
        padding: 3px 0 6px;
        color: #e0e8f5;
        font-size: .78rem;
        line-height: 1.4;
    }
    .mobile-roster-legend .legend-swatch {
        flex: 0 0 14px;
        margin-top: 2px;
        border: 1px solid #ffffff40;
    }
    .roster-legend-label { min-width: 0; overflow-wrap: anywhere; white-space: normal; }
    .roster-legend-label > span, .roster-legend-label small { display: block; }
    .roster-legend-label small { margin-top: 2px; color: #a8bddd; font-size: .68rem; }
    .roster-legend-empty { padding: 3px 0; color: #a8bddd; font-size: .75rem; line-height: 1.4; }
    @media (max-height: 500px) {
        .mobile-roster-legend:not([hidden]) {
            height: clamp(48px, 14vh, 64px);
            height: clamp(48px, 14dvh, 64px);
            padding-top: 5px;
            padding-bottom: 5px;
            flex-direction: row;
            gap: 10px;
        }
        .roster-legend-heading {
            flex: 0 0 86px;
            flex-direction: column;
            align-items: flex-start;
            justify-content: center;
            gap: 3px;
            margin-bottom: 0;
        }
    }
}

/* Management pages share the roster's compact controls without changing its grid. */
.management-panel-title { margin: 0 0 12px; color: #fff; font-size: 1rem; }
.management-page button:focus-visible,
.management-page input:focus-visible,
.management-page select:focus-visible,
#settings-back:focus-visible,
.login-back-link:focus-visible { outline: 2px solid #8bc8ff; outline-offset: 2px; }

@media (max-width: 640px), (max-width: 900px) and (pointer: coarse) {
    .navbar-links a { overflow-wrap: anywhere; }
    .management-page { min-width: 0; }
    .management-page .page-header { gap: 8px; margin-bottom: 10px; align-items: stretch; }
    .management-page .page-header h2 { font-size: 1.1rem; line-height: 1.4; }
    .management-page .page-header-actions { width: 100%; flex-wrap: wrap; gap: 6px; }
    .management-page .page-header-actions .btn { flex: 1 1 auto; }
    .management-page #btn-gcal-link { margin-left: 0 !important; }
    .management-page .btn {
        min-width: 0; min-height: 38px; padding: 7px 10px; font-size: .8rem;
        line-height: 1.3; white-space: normal; overflow-wrap: anywhere; touch-action: manipulation;
    }
    .management-page .month-nav { gap: 8px; padding: 0; font-size: 1rem; justify-content: space-between; }
    .management-page .month-nav button { min-width: 38px; min-height: 38px; padding: 5px 10px; touch-action: manipulation; }
    .management-page #evt-month-label { text-align: center; flex: 1; min-width: 0; }
    .management-page input[type="text"],
    .management-page input[type="number"],
    .management-page select { min-width: 0 !important; max-width: 100%; min-height: 38px; font-size: 16px !important; }
    .management-page input[type="checkbox"] { width: 18px; height: 18px; flex-shrink: 0; }
    .management-page .event-search { gap: 6px !important; }
    .management-page .event-search input { flex: 1 1 0 !important; }

    /* Keep real table markup on desktop; show each mobile record with its column labels. */
    #employee-table, #event-table { display: block; width: 100%; min-width: 0; }
    #employee-table thead, #event-table thead {
        position: absolute; width: 1px; height: 1px; padding: 0;
        overflow: hidden; clip-path: inset(50%); white-space: nowrap;
    }
    #employee-table tbody, #event-table tbody {
        display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
        align-items: start; gap: 10px; min-width: 0;
    }
    #employee-table tr, #event-table tr {
        display: block; min-width: 0; padding: 4px;
        border: 1px solid #344565; border-radius: 8px; background: #16213e;
    }
    #employee-table td, #event-table td,
    #event-table td:nth-child(1), #event-table td:nth-child(4) {
        display: block; position: relative; width: auto !important; min-width: 0; min-height: 32px;
        padding: 7px 6px 7px 82px; border-bottom: 1px solid #2a3652;
        font-size: .82rem; line-height: 1.45; white-space: normal;
        overflow: visible; overflow-wrap: anywhere; text-overflow: clip;
    }
    #employee-table td::before, #event-table td::before {
        content: attr(data-label); position: absolute; top: 8px; left: 6px; width: 68px;
        color: #a2b5cd; font-size: .7rem; font-weight: 600; line-height: 1.5;
    }
    #employee-table td:last-child, #event-table td:last-child { border-bottom: 0; }
    #employee-table td:empty, #event-table td:empty { display: none; }
    .management-page .data-table .btn { margin: 2px 2px 2px 0; min-height: 34px; padding: 6px 8px !important; font-size: .75rem !important; }
    .management-page .inactive-row { opacity: .7; }
    .management-page .skill-tag { max-width: 100%; font-size: .72rem; white-space: normal; overflow-wrap: anywhere; }

    /* These remain inline panels. Only their content scrolls; actions stay in view. */
    .management-page .management-panel[style*="block"] {
        display: flex !important; flex-direction: column; min-width: 0;
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        padding: 10px; margin-bottom: 10px; scroll-margin-top: 10px; overflow: hidden;
    }
    .management-panel > h3, .management-panel > .wizard-steps { flex-shrink: 0; }
    .management-panel > h3 { font-size: .95rem; line-height: 1.4; margin-bottom: 10px; }
    .management-panel > .management-panel-body {
        flex: 1 1 auto; min-height: 0; min-width: 0; overflow-y: auto;
        overscroll-behavior-y: contain; scrollbar-gutter: stable; padding-right: 4px;
    }
    .management-panel > .form-actions, .management-panel > .wizard-nav {
        flex: 0 0 auto; flex-wrap: wrap; gap: 6px; margin-top: 8px;
        padding-top: 8px; border-top: 1px solid #344565; background: #16213e;
    }
    .management-panel > .form-actions .btn, .management-panel > .wizard-nav .btn { flex: 1 1 72px; }
    .management-panel #btn-delete-employee { flex-basis: 100%; margin-left: 0 !important; }
    .management-panel .form-row { min-width: 0; gap: 6px; margin-bottom: 10px; }
    .management-panel .form-row > label:not(.checkbox-label) { width: 100%; font-size: .8rem; }
    .management-panel .form-row .checkbox-label { width: auto; min-height: 34px; margin-right: 8px; }
    .management-panel .form-row input[type="text"], .management-panel .form-row select { width: 100%; flex: 1 1 100%; }
    .management-panel .skill-check-grid { width: 100%; min-width: 0; gap: 4px; }
    .management-panel .skill-check-grid label {
        width: 100%; min-width: 0; min-height: 36px; padding: 5px 4px;
        align-items: flex-start; line-height: 1.5; overflow-wrap: anywhere;
    }
    .management-panel .skill-check-grid input { margin-top: 2px; }
    .management-panel .wizard-steps { gap: 6px; margin-bottom: 10px; }
    .management-panel .wizard-step-dot { width: 24px; height: 24px; }
    .management-panel .wizard-day-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
    .management-panel .wizard-day-btn { min-width: 0; min-height: 40px; touch-action: manipulation; }
    .management-panel .mode-btn { min-height: 44px; padding: 10px; font-size: .9rem; }
    .management-panel .skill-list-item {
        display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center;
        gap: 4px; padding: 6px 0; border-bottom: 1px solid #2a3652;
    }
    .management-panel .skill-list-item .skill-tag { margin: 0; font-size: .78rem !important; }
    .management-panel .skill-list-item .btn { font-size: .75rem !important; padding: 6px 8px !important; }
    .management-panel .history-filters { gap: 6px !important; }
    .management-panel #history-search { flex: 1 1 100% !important; }
    .management-panel .hist-past-btn { flex: 1 1 60px; }
    .management-panel #history-list label { padding: 9px 0 !important; align-items: flex-start !important; border-bottom: 1px solid #2a3652; }
    .management-panel #history-list .color-swatch { width: 14px; height: 14px; flex-shrink: 0; margin-top: 3px; }
    .management-panel .history-record-text { min-width: 0; line-height: 1.5; overflow-wrap: anywhere; }

    .display-settings { padding-top: 14px; overflow-wrap: anywhere; }
    .display-settings h1 { font-size: 1.25rem; margin-bottom: 16px; }
    .display-settings h2 { font-size: 1rem; margin-bottom: 12px; }
    .display-settings-option { align-items: flex-start; gap: 10px; }
    .display-settings-option input { margin-top: 2px; }
    .display-settings p { margin: 14px 0; font-size: .85rem; }
    .display-settings #settings-back { display: inline-flex; align-items: center; min-height: 44px; }

    .login-body {
        min-height: 100vh; min-height: 100dvh; padding: 12px;
        padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
            max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    }
    .login-card { min-width: 0; padding: 22px 18px; margin: auto; overflow-wrap: anywhere; }
    .login-title { font-size: 1.3rem; }
    .login-subtitle { margin-bottom: 18px; line-height: 1.5; color: #a2b5cd; }
    .login-field { margin-bottom: 12px; }
    .login-field input { min-height: 44px; font-size: 16px; }
    .login-field label { color: #b4c4d8; }
    .password-hint { line-height: 1.5; color: #a2b5cd; }
    .login-back-link { min-height: 40px; padding: 10px; margin-top: 8px; }
}
