* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  background: #f4f6f9; color: #2c3e50; font-size: 15px;
}

/* ---- 登入頁 ---- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #1e3a5f; }
.login-box { background: #fff; padding: 40px; border-radius: 12px; width: 360px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.login-box h1 { font-size: 24px; margin-bottom: 4px; }
.login-box .sub { color: #888; margin-bottom: 24px; }
.login-box label { display: block; margin-bottom: 14px; font-weight: bold; }
.login-box input { width: 100%; padding: 10px; margin-top: 4px; border: 1px solid #ccc; border-radius: 6px; font-size: 15px; }
.error { color: #e74c3c; margin-top: 10px; min-height: 18px; }

/* ---- 主框架 ---- */
.layout { display: flex; height: 100vh; }
.sidebar {
  width: 200px; background: #1e3a5f; color: #fff; padding: 16px 0; flex-shrink: 0;
  display: flex; flex-direction: column;
}
.sidebar .logo {
  font-size: 18px; font-weight: bold; padding: 0 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.15);
  display: flex; align-items: center; gap: 10px;
}
.sidebar .logo img { width: 42px; height: 42px; flex-shrink: 0; }
.sidebar .logo .logo-text { line-height: 1.3; }
.sidebar .logo small { font-weight: normal; font-size: 11px; color: #9fb3c8; }
/* 登入頁 logo */
.login-logo { display: block; width: 90px; margin: 0 auto 14px; }
.sidebar nav { flex: 1; margin-top: 10px; }
.sidebar a {
  display: block; color: #cdd8e3; text-decoration: none; padding: 10px 20px; font-size: 15px;
  white-space: normal; word-break: break-word; overflow: visible; line-height: 1.35;
}
.sidebar a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar a.active { background: #2e5a8f; color: #fff; border-left: 3px solid #6cb2ff; }
.sidebar .userinfo { padding: 12px 20px; border-top: 1px solid rgba(255,255,255,.15); font-size: 13px; color: #9fb3c8; }
.sidebar .userinfo a { display: inline; padding: 0; color: #6cb2ff; cursor: pointer; }

.main { flex: 1; padding: 24px; overflow: auto; }
/* 捲動條加粗，橫向拖曳條固定在畫面最下方 */
.main::-webkit-scrollbar { height: 14px; width: 12px; }
.main::-webkit-scrollbar-thumb { background: #9fb0c0; border-radius: 7px; border: 3px solid #f4f6f9; }
.main::-webkit-scrollbar-thumb:hover { background: #7e93a8; }
.main::-webkit-scrollbar-track { background: #e8edf2; }
.main h2 { margin-bottom: 16px; font-size: 22px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=text], .toolbar select { padding: 7px 10px; border: 1px solid #ccc; border-radius: 6px; }
.toolbar .spacer { flex: 1; }

/* ---- 按鈕 ---- */
.btn { padding: 7px 14px; border: 1px solid #ccc; background: #fff; border-radius: 6px; cursor: pointer; font-size: 14px; }
.btn:hover { background: #f0f4f8; }
.btn.primary { background: #2e5a8f; color: #fff; border-color: #2e5a8f; }
.btn.primary:hover { background: #244a78; }
.btn.danger { color: #e74c3c; border-color: #e74c3c; }
.btn.danger:hover { background: #fdeaea; }
.btn.small { padding: 3px 8px; font-size: 13px; }

/* ---- 表格 ---- */
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid #eef1f4; white-space: nowrap; }
th { background: #f8fafc; font-size: 14px; color: #556; position: sticky; top: 0; }
tr:hover td { background: #f6f9fc; }
/* 表格排序與篩選 */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #eef3f8; }
th .arrow { color: #2e5a8f; font-size: 11px; margin-left: 3px; }
/* 欄寬調整（Excel 式） */
th .colgrip { position: absolute; right: 0; top: 0; bottom: 0; width: 7px; cursor: col-resize; }
th .colgrip:hover, th .colgrip.active { background: #6cb2ff; }
table.fixedcols { table-layout: fixed; }
table.fixedcols th, table.fixedcols td { overflow: hidden; text-overflow: ellipsis; }
th.dragover { background: #dcebfb !important; }
.filterRow td { padding: 4px 6px; background: #fbfcfe; }
/* 可雙擊編輯的儲存格 */
td[data-edit]:hover { outline: 1px dashed #8fa8c0; outline-offset: -2px; cursor: cell; }
.filterRow input { width: 100%; min-width: 60px; padding: 3px 6px; border: 1px solid #dde3ea; border-radius: 4px; font-size: 13px; }
/* 長文字欄位：單行省略，游標懸停彈出批註框（欄高保持矮） */
td.wrap { white-space: nowrap; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.celltip {
  position: fixed; z-index: 300; display: none; pointer-events: none;
  background: #fffbe6; border: 1px solid #e0cf7a; color: #333;
  box-shadow: 0 4px 16px rgba(0,0,0,.2); border-radius: 6px;
  padding: 10px 12px; max-width: 420px; white-space: pre-wrap;
  font-size: 14px; line-height: 1.5;
}
a.link { color: #2e5a8f; cursor: pointer; text-decoration: underline; }

/* ---- 狀態標籤 ---- */
.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 13px; }
.tag.green { background: #e6f7ea; color: #1e8e3e; }
.tag.blue { background: #e8f0fe; color: #1a63c9; }
.tag.orange { background: #fef3e0; color: #c77b13; }
.tag.red { background: #fdeaea; color: #d33; }
.tag.gray { background: #eee; color: #777; }
.tag.purple { background: #f1eafd; color: #7b3ff2; }

/* ---- 統計卡 ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 24px; }
.card { background: #fff; border-radius: 10px; padding: 18px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.card .num { font-size: 30px; font-weight: bold; color: #1e3a5f; }
.card .label { color: #789; font-size: 14px; margin-top: 4px; }

/* ---- 彈窗 ---- */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: #fff; border-radius: 10px; padding: 24px; width: 480px; max-width: 94vw; max-height: 90vh; overflow-y: auto; }
.modal h3 { margin-bottom: 16px; }
.modal label { display: block; margin-bottom: 12px; font-size: 14px; color: #445; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 8px; margin-top: 4px; border: 1px solid #ccc; border-radius: 6px; font-size: 15px; font-family: inherit;
}
.modal textarea { min-height: 60px; resize: vertical; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---- 階段進度 ---- */
.stage-list { display: flex; flex-direction: column; gap: 6px; }
.stage-item { display: flex; align-items: center; gap: 10px; background: #fff; padding: 8px 12px; border-radius: 8px; border: 1px solid #e7ecf1; }
.stage-item.done { background: #eefaf1; border-color: #bfe6cb; }
.stage-item .sname { width: 160px; font-weight: bold; }
.stage-item input[type=date] { padding: 5px; border: 1px solid #ccc; border-radius: 5px; }
.stage-item input.snotes { flex: 1; padding: 5px 8px; border: 1px solid #ccc; border-radius: 5px; }

/* ---- 詳情頁區塊 ---- */
.section { background: #fff; border-radius: 10px; padding: 18px; margin-bottom: 18px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.section h3 { margin-bottom: 12px; font-size: 18px; color: #1e3a5f; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 20px; }
.kv div b { color: #789; font-weight: normal; margin-right: 6px; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; }
}

/* 列表內嵌階段下拉 */
select.stagesel {
  max-width: 210px; padding: 3px 5px; font-size: 13px;
  border: 1px solid #dde3ea; border-radius: 5px; background: #fff; cursor: pointer;
}
select.stagesel:hover { border-color: #2e5a8f; }

/* Excel 式分頁籤 */
.sheettabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 2px solid #cdd8e3; }
.sheettab {
  padding: 7px 18px; border: 1px solid #cdd8e3; border-bottom: none;
  border-radius: 8px 8px 0 0; background: #e8edf2; color: #567;
  cursor: pointer; font-size: 14px; font-weight: bold;
}
.sheettab:hover { background: #f0f4f8; }
.sheettab.active { background: #fff; color: #1e3a5f; border-color: #9fb0c0; position: relative; top: 2px; border-bottom: 2px solid #fff; }

/* 行號欄 */
th.rownum, td.rownum { width: 44px; min-width: 34px; text-align: right; color: #9ab; font-size: 12px; background: #f6f8fa; border-right: 1px solid #e8edf2; }
/* Shift 範圍選取（Excel 式計數） */
td.selcell { background: #d8e8fb !important; outline: 1px solid #6cb2ff; outline-offset: -1px; }
.selbar {
  position: fixed; right: 18px; bottom: 18px; z-index: 250; display: none;
  background: #1e3a5f; color: #dce8f5; padding: 9px 16px; border-radius: 8px;
  font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.selbar b { color: #fff; }

/* Excel 式自動篩選下拉 */
.af-wrap { display: flex; gap: 2px; align-items: center; }
.af-wrap input { flex: 1; min-width: 40px; }
.af-btn {
  border: 1px solid #dde3ea; background: #fff; border-radius: 4px;
  padding: 2px 5px; cursor: pointer; font-size: 12px; color: #678; flex-shrink: 0;
}
.af-btn:hover { border-color: #2e5a8f; color: #2e5a8f; }
.af-btn.active { background: #2e5a8f; color: #fff; border-color: #2e5a8f; }
.af-panel {
  position: fixed; z-index: 400; width: 300px; max-height: 330px;
  background: #fff; border: 1px solid #b8c4d0; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); display: flex; flex-direction: column;
}
.af-tools { padding: 8px; border-bottom: 1px solid #eef1f4; display: flex; gap: 8px; align-items: center; }
.af-tools .af-search { flex: 1; padding: 4px 8px; border: 1px solid #dde3ea; border-radius: 4px; font-size: 13px; }
.af-tools a { color: #2e5a8f; cursor: pointer; font-size: 13px; white-space: nowrap; }
.af-list { overflow-y: auto; padding: 4px 0; }
.af-list label {
  display: flex; align-items: center; gap: 7px; padding: 4px 12px;
  font-size: 14px; cursor: pointer;
}
.af-list label:hover { background: #f0f4f8; }
.af-list label span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.af-list label b { color: #2e5a8f; font-size: 13px; }

/* 行事曆表格：固定欄寬讓各日期群組對齊 */
table.agenda-tbl { table-layout: fixed; }
table.agenda-tbl td, table.agenda-tbl th { overflow: hidden; text-overflow: ellipsis; }

/* CITA 月曆 */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head { text-align: center; font-weight: bold; color: #556; padding: 6px 0; background: #f0f4f8; border-radius: 6px; font-size: 14px; }
.cal-cell { background: #fff; border: 1px solid #e7ecf1; border-radius: 8px; min-height: 92px; padding: 6px; overflow: hidden; }
.cal-empty { background: transparent; border: none; }
.cal-weekend { background: #f7f9fb; }
.cal-today { border: 2px solid #2e5a8f; background: #f2f8ff; }
.cal-daynum { font-weight: bold; color: #345; margin-bottom: 4px; font-size: 14px; }
.cal-item {
  background: #eef4fb; border-left: 3px solid #2e5a8f; border-radius: 4px;
  padding: 2px 5px; margin-bottom: 3px; font-size: 13px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-item:hover { background: #dcebfb; }
.cal-item.ok { border-left-color: #1e8e3e; background: #eefaf1; }
.cal-item.due { border-left-color: #d33; background: #fdf0f0; }


/* 付款 Excel 檢視 */
table.pex td.paycell { cursor: pointer; padding: 5px 8px; }
table.pex td.paycell:hover { background: #eef4fb; outline: 1px solid #6cb2ff; outline-offset: -1px; }
table.pex td.paycell .pd { font-size: 12px; color: #789; }
table.pex td.paycell .pa { font-weight: bold; color: #1e3a5f; }
table.pex td.paycell.empty { color: #c3ccd6; text-align: center; font-size: 16px; }
table.pex td.paycell.empty:hover { color: #2e5a8f; background: #f4f8fd; }


/* 履約 Excel 檢視 */
table.evx td.kyccell { cursor: pointer; padding: 4px 7px; }
table.evx td.kyccell:hover { background: #eef4fb; outline: 1px solid #6cb2ff; outline-offset: -1px; }
table.evx td.kyccell .kd { font-weight: bold; color: #1e3a5f; font-size: 13px; }
table.evx td.kyccell .kp { font-size: 12px; color: #1a63c9; }
table.evx td.kyccell .kc { font-size: 11px; color: #888; }
table.evx td.kyccell.pend { background: #fff8ec; }
table.evx td.kyccell.empty { color: #c3ccd6; text-align: center; font-size: 16px; }
table.evx td.kyccell.empty:hover { color: #2e5a8f; background: #f4f8fd; }
