* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: "PingFang HK", "Microsoft JhengHei", sans-serif; color: #333; line-height: 1.6; }
header { background: #1a5f7a; color: #fff; padding: 1rem 2rem; display: flex; justify-content: space-between; align-items: center; }
header a { color: #fff; margin-left: 1rem; text-decoration: none; }
main { max-width: 960px; margin: 2rem auto; padding: 0 1rem; }
main section { margin-bottom: 2rem; }
footer { text-align: center; padding: 1rem; color: #777; }

.login-box { max-width: 360px; }
.login-box label { display: block; margin-bottom: 1rem; }
.login-box input { width: 100%; padding: .5rem; margin-top: .25rem; }
.login-box button { width: 100%; padding: .6rem; background: #1a5f7a; color: #fff; border: 0; cursor: pointer; }
.error { color: #c0392b; margin-bottom: 1rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.card { border: 1px solid #ddd; border-radius: 8px; padding: 1rem; text-align: center; }
.card p { font-size: 2rem; font-weight: bold; color: #1a5f7a; }

/* Admin 主頁模塊展示 */
.modules { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.25rem; margin-bottom: 2rem; }
.module-card { display: block; border: 1px solid #ddd; border-radius: 10px; padding: 1.5rem 1.25rem; text-decoration: none; color: inherit; }
a.module-card:hover { border-color: #1a5f7a; box-shadow: 0 2px 8px rgba(26, 95, 122, .15); }
.module-card h3 { color: #1a5f7a; margin-bottom: .4rem; font-size: 1.05rem; }
.module-card p { color: #55656f; font-size: .95rem; }
.module-disabled { opacity: .6; }
.module-card .badge { display: inline-block; margin-top: .75rem; padding: .15rem .6rem; border-radius: 999px; background: #eef3f5; color: #1a5f7a; font-size: .8rem; }

/* 項目管理：甘特圖 */
main.wide { max-width: 1280px; }
.gantt-wrap { overflow-x: auto; margin-bottom: 2rem; }
.gantt { border-collapse: collapse; white-space: nowrap; }
.gantt th, .gantt td { border: 1px solid #e0e0e0; padding: .3rem .4rem; font-size: .85rem; text-align: center; }
.gantt th { background: #f2f7f9; color: #1a5f7a; }
.gantt .gantt-wbs, .gantt .gantt-task, .gantt .gantt-owner { text-align: left; }
.gantt .gantt-task { min-width: 12rem; white-space: normal; }
.gantt td.bar { background: #7fb3c8; }
.gantt td.bar-done { background: #1a5f7a; }
.gantt .milestone { color: #c0392b; font-size: 1rem; }
.gantt th.today, .gantt td.today { background: #dff0f7; }
.gantt td.bar.today { background: #5a9cb8; }
.gantt td.bar-done.today { background: #14506a; }

/* 關鍵路徑 */
.gantt tr.critical-row .gantt-wbs, .gantt tr.critical-row .gantt-task { background: #fdf3e3; }
.gantt td.bar-critical { box-shadow: inset 0 0 0 2px #c0392b; }
.cp-summary { background: #fdf3e3; border: 1px solid #f0c36d; border-radius: 6px; padding: .6rem 1rem; margin-bottom: 1rem; }
.cp-node { display: inline-block; background: #fff; border: 1px solid #f0c36d; border-radius: 4px; padding: .05rem .5rem; font-weight: bold; color: #9a6b1a; }
.cp-arrow { color: #c0392b; margin: 0 .3rem; font-weight: bold; }
.cp-tag { display: inline-block; background: #c0392b; color: #fff; border-radius: 4px; padding: 0 .4rem; font-size: .8rem; white-space: nowrap; }

/* 任務管理 */
.pri { display: inline-block; border-radius: 4px; padding: .05rem .5rem; font-size: .85rem; white-space: nowrap; }
.pri-high { background: #fdecea; color: #c0392b; border: 1px solid #f5b7b1; }
.pri-medium { background: #fdf3e3; color: #9a6b1a; border: 1px solid #f0c36d; }
.pri-low { background: #eef3f5; color: #55656f; border: 1px solid #d5dee3; }
.row-overdue td { background: #fdf6f5; }
.link-btn.link-start { color: #1a5f7a; }
.link-btn.link-done { color: #2e7d32; }

/* 排班及打卡（Rostering & HR） */
.clock-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.clock-grid form { margin: 0; }
.btn-action:disabled { background: #b8c4ca; cursor: not-allowed; }
.clock-in { background: #2e7d32; }
.clock-out { background: #c0392b; }
.clock-break_out, .clock-break_in { background: #9a6b1a; }
.roster-grid td { vertical-align: top; min-width: 7rem; }
.shift-chip { display: block; color: #fff; border-radius: 4px; padding: .15rem .4rem; margin: .15rem 0; font-size: .8rem; }
.chip-del { background: rgba(255,255,255,.25); border: 0; color: #fff; border-radius: 50%; width: 16px; height: 16px; line-height: 1; cursor: pointer; font-size: .75rem; padding: 0; }
.cal-grid { table-layout: fixed; }
.cal-grid td { vertical-align: top; min-width: 8rem; min-height: 5.5rem; padding: .25rem .35rem; }
.cal-day-num { font-weight: bold; font-size: .85rem; margin-bottom: .15rem; }
.cal-outside { background: #f5f7f8; color: #9aa7ae; }
.cal-today { outline: 2px solid #1a5f7a; outline-offset: -2px; }
.cal-leave { display: block; font-size: .72rem; color: #9a6b1a; }
.check-row label.inline { display: inline-block; margin: .15rem 1rem .15rem 0; font-weight: normal; }

/* 工卡（傳統卡紙形式） */
.timecard { border: 2px solid #333; border-radius: 4px; padding: 1rem 1.25rem; margin-bottom: 2rem; background: #fff; }
.tc-head { display: flex; justify-content: space-between; margin-bottom: .75rem; line-height: 1.5; }
.tc-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tc-table th, .tc-table td { border: 1px solid #666; padding: .18rem .3rem; text-align: center; }
.tc-table th { background: #eee; }
.tc-table .tc-notes { text-align: left; font-size: .78rem; }
.tc-weekend { background: #f5f5f5; }
.tc-total td { font-weight: bold; background: #eee; }
.tc-sign { display: flex; justify-content: space-between; margin-top: .75rem; font-size: .85rem; }

@media print {
    header, .no-print { display: none !important; }
    body { background: #fff; }
    main.wide { padding: 0; max-width: none; }
    .timecard { border-radius: 0; page-break-after: always; margin-bottom: 0; }
    .timecard:last-child { page-break-after: auto; }
}

/* 表格頁（前台申請表格 + 後台客戶表格） */
.form-grid fieldset { border: 1px solid #ddd; border-radius: 8px; padding: 1rem 1.25rem; margin-bottom: 1.5rem; }
.form-grid legend { font-weight: bold; color: #1a5f7a; padding: 0 .5rem; }
.form-grid label { display: block; margin-bottom: .75rem; }
.form-grid label.inline { display: inline-block; margin-right: 1rem; margin-bottom: .25rem; font-weight: normal; }
.form-grid input[type="text"], .form-grid input[type="tel"], .form-grid input[type="email"],
.form-grid input[type="date"], .form-grid input[type="number"], .form-grid select, .form-grid textarea {
    width: 100%; padding: .5rem; margin-top: .25rem; border: 1px solid #ccc; border-radius: 4px;
}
.form-grid .field-row { margin-bottom: .75rem; }
.form-grid .field-row > span { display: block; font-weight: bold; margin-bottom: .25rem; }
.form-grid button { padding: .6rem 2rem; background: #1a5f7a; color: #fff; border: 0; border-radius: 4px; cursor: pointer; }
.form-actions a { margin-left: 1rem; }

.flash { background: #e8f5e9; border: 1px solid #a5d6a7; color: #2e7d32; padding: .75rem 1rem; border-radius: 4px; margin-bottom: 1rem; }
.badge { display: inline-block; background: #e8f5e9; border: 1px solid #a5d6a7; color: #2e7d32; border-radius: 4px; padding: .1rem .45rem; font-size: .85em; white-space: nowrap; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.search-form { display: flex; gap: .5rem; align-items: center; }
.search-form input { padding: .45rem; border: 1px solid #ccc; border-radius: 4px; }
.search-form button { padding: .45rem 1rem; background: #1a5f7a; color: #fff; border: 0; border-radius: 4px; cursor: pointer; }
.btn { display: inline-block; padding: .5rem 1rem; background: #1a5f7a; color: #fff; border-radius: 4px; text-decoration: none; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { border: 1px solid #ddd; padding: .5rem .75rem; text-align: left; }
.data-table th { background: #f2f7f9; }
.data-table .actions { white-space: nowrap; }
.data-table .actions form { display: inline; }
.link-btn { background: none; border: 0; color: #c0392b; cursor: pointer; text-decoration: underline; padding: 0; font-size: inherit; }

/* 維修主檔篩選 */
.filter-form fieldset { margin-bottom: 1.5rem; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 1rem; }

/* 可摺疊區塊（篩選查詢 / 匯出 Excel） */
.collapsible { border: 1px solid #ddd; border-radius: 8px; margin-bottom: 1.25rem; background: #fff; }
.collapsible > summary { cursor: pointer; padding: .75rem 1.25rem; font-weight: bold; color: #1a5f7a; list-style: none; user-select: none; }
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary::before { content: '▸ '; }
.collapsible[open] > summary::before { content: '▾ '; }
.collapsible > form { padding: .25rem 1.25rem 1.25rem; }

/* 維修員頁面 */
.visit-card { border: 1px solid #ddd; border-radius: 8px; padding: 1rem 1.25rem; margin-bottom: 1.25rem; background: #fff; }
.visit-card h3 { color: #1a5f7a; margin-bottom: .5rem; }
.visit-card p { margin-bottom: .5rem; }
.badge-warn { background: #fdf3e3; border-color: #f0c36d; color: #9a6b1a; }
.btn-action { display: inline-block; width: 100%; padding: .9rem; font-size: 1.1rem; font-weight: bold; background: #1a5f7a; color: #fff; border: 0; border-radius: 6px; cursor: pointer; }
.hint { color: #777; font-size: .9rem; margin-bottom: .75rem; }

/* 使用說明按鈕 + 彈窗 */
.help-btn { background: transparent; color: #fff; border: 2px solid #fff; border-radius: 50%; width: 28px; height: 28px; margin-left: 1rem; font-size: 1rem; font-weight: bold; cursor: pointer; line-height: 1; padding: 0; }
.help-btn:hover { background: #fff; color: #1a5f7a; }
.help-modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1000; align-items: center; justify-content: center; }
.help-modal.open { display: flex; }
.help-box { background: #fff; color: #333; border-radius: 8px; max-width: 560px; width: 92%; max-height: 82vh; overflow-y: auto; padding: 1.25rem 1.5rem; box-shadow: 0 4px 20px rgba(0,0,0,.3); text-align: left; }
.help-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .75rem; border-bottom: 1px solid #e3ebf0; padding-bottom: .5rem; }
.help-head h2 { font-size: 1.2rem; color: #1a5f7a; }
.help-close { background: none; border: none; font-size: 1.6rem; cursor: pointer; color: #666; line-height: 1; padding: 0 .25rem; }
.help-close:hover { color: #1a5f7a; }
.help-content h3 { margin: .75rem 0 .25rem; font-size: 1rem; color: #1a5f7a; }
.help-content ul { margin: .25rem 0 .5rem 1.25rem; }
.help-content li { margin-bottom: .3rem; }
.help-content p { margin: .25rem 0 .5rem; }
@media print { .help-btn { display: none; } }

/* 排班月曆：Drag & Drop + 直接改時間 */
.shift-chip[draggable="true"] { cursor: grab; user-select: none; }
.shift-chip.chip-dragging { opacity: .4; }
.cal-grid td.cal-drop { outline: 2px dashed #1a5f7a; outline-offset: -2px; background: #eaf4f9; }
.cal-grid td .cal-day-hint { display: block; font-size: .72rem; color: #1a5f7a; }

.chip-modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1000; align-items: center; justify-content: center; }
.chip-modal.open { display: flex; }
.chip-modal-box { background: #fff; border-radius: 8px; width: 340px; max-width: 92%; padding: 1.1rem 1.25rem; box-shadow: 0 4px 20px rgba(0,0,0,.3); }
.chip-modal-box h3 { color: #1a5f7a; font-size: 1.05rem; margin-bottom: .15rem; }
.chip-modal-box .chip-modal-sub { color: #55656f; font-size: .9rem; margin-bottom: .8rem; }
.chip-modal-box label { display: block; margin-bottom: .6rem; font-size: .92rem; }
.chip-modal-box input[type="time"] { width: 100%; padding: .45rem; margin-top: .2rem; border: 1px solid #ccc; border-radius: 4px; }
.chip-modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .4rem; }
.chip-modal-actions button { padding: .5rem 1.1rem; border: 0; border-radius: 4px; cursor: pointer; }
.chip-modal-save { background: #1a5f7a; color: #fff; }
.chip-modal-cancel { background: #e3ebf0; color: #333; }
