:root {
  --bg: #eef3fa;
  --ink: #0a2a44;
  --ink-soft: #3b5d7c;
  --line: #d9e5f2;
  --line-soft: #e8eff8;
  --brand: #1f6dc6;
  --brand-dark: #17539a;
  --head: #e7eef8;
  --result: #d6f0e4;
  --result-ink: #005b3e;
  --warn: #b4531b;
  --danger: #b3261e;
  --radius: 22px;
}

* { box-sizing: border-box; }

/* 元素自己的 display 會蓋掉瀏覽器內建的 [hidden]，這裡強制拉回來 */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 24px 14px 60px;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.card {
  max-width: 1180px;
  margin: 0 auto;
  background: #fff;
  border-radius: 28px;
  box-shadow: 0 18px 40px -14px rgba(0, 30, 60, 0.22);
  padding: 24px 22px 28px;
}

/* ---------------------------------------------------------- 標題 */
.head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
}
.title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  border-left: 6px solid var(--brand);
  padding-left: 14px;
}
.sub {
  margin: 4px 0 0 20px;
  font-size: 13.5px;
  color: var(--ink-soft);
}
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------- 表單 */
.toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; color: var(--ink-soft); font-weight: 600; }

input[type=text], input[type=number], input[type=password], select {
  font: inherit;
  color: var(--ink);
  background: #f8fbff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  background: #fff;
}

/* ---------------------------------------------------------- 表格 */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fafcff;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  background: var(--head);
  color: #1a3d60;
  font-weight: 600;
  padding: 10px 8px;
  border-bottom: 2px solid #c9d9ec;
  text-align: center;
  white-space: nowrap;
  font-size: 13px;
}
th i { display: block; font-style: normal; font-weight: 400; font-size: 11px; opacity: 0.7; }
td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line-soft);
  text-align: center;
  background: #fff;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }

#calcTable { min-width: 780px; }
#calcTable .col-no { width: 52px; }
#calcTable .col-unit { width: 92px; }
#calcTable .col-del { width: 44px; }
#calcTable input, #calcTable select { text-align: center; padding: 7px 6px; }
#calcTable td.num input { width: 82px; }

.out {
  display: inline-block;
  min-width: 74px;
  padding: 6px 10px;
  border-radius: 30px;
  background: #f2f8ff;
  color: #003e6b;
  font-variant-numeric: tabular-nums;
}
.out.result {
  background: var(--result);
  color: var(--result-ink);
  font-weight: 700;
}
.out.flag { box-shadow: inset 0 0 0 1.5px #e2b07a; }

.row-index { font-weight: 600; color: var(--ink-soft); }
.mini-flag {
  display: block;
  font-size: 10.5px;
  color: var(--warn);
  margin-top: 2px;
  white-space: nowrap;
}

.icon-btn {
  border: none;
  background: #fdeceb;
  color: var(--danger);
  border-radius: 50%;
  width: 28px; height: 28px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.icon-btn:hover { background: #f8d7d5; }

/* ---------------------------------------------------------- 按鈕 */
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.spacer { flex: 1 1 auto; }

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid var(--line);
  background: #f1f6fd;
  color: #1a4b75;
  border-radius: 40px;
  padding: 9px 18px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { background: #e4eefb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: #fff; }
.btn.small { padding: 7px 14px; font-size: 13px; }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------------------------------------------------------- 注意事項 */
.notes {
  margin-top: 22px;
  background: #f7fbff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 20px 18px;
}
.notes.plain {
  margin-top: 0;
  background: transparent;
  border: none;
  padding: 0;
}
.notes.plain .notes-view { font-size: 14px; }

.notes-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.notes-head h2 { margin: 0; font-size: 15px; }
.notes-head .hint { margin: 0; flex: 1 1 200px; }
.notes-actions { display: flex; gap: 6px; }

.notes-view { font-size: 13.5px; color: var(--ink-soft); line-height: 1.6; }
.notes-view h3 {
  margin: 14px 0 6px;
  font-size: 13.5px;
  color: var(--brand-dark);
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}
.notes-view h3:first-child { margin-top: 0; }
.notes-view ul { margin: 0; padding-left: 18px; display: grid; gap: 3px; }

.notes-edit {
  width: 100%;
  font: inherit;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  resize: vertical;
}
.notes-edit:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.notes-edit[hidden] { display: none; }

/* ---------------------------------------------------------- 規則 */
.rules {
  background: #f2f7fe;
  border-radius: 16px;
  padding: 14px 18px;
}
.rules ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: 13.5px; color: var(--ink-soft); }
.rule-note { margin: 10px 0 0; font-size: 13px; color: var(--ink-soft); }

/* ---------------------------------------------------------- 彈窗 */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 25, 45, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
.overlay[hidden] { display: none; }
.modal {
  background: #fff;
  border-radius: 24px;
  width: 100%;
  max-width: 940px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: #fff; z-index: 1;
  border-radius: 24px 24px 0 0;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 18px 22px 24px; }
.lead { margin: 0 0 12px; color: var(--ink-soft); font-size: 14px; }

.search-row { display: flex; gap: 8px; margin-bottom: 14px; }
.search-row input { flex: 1 1 auto; }

.panel { border-top: 1px solid var(--line-soft); padding-top: 18px; margin-top: 18px; }
.panel:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.panel h3 { margin: 0 0 6px; font-size: 15px; }
.hint { margin: 0 0 12px; font-size: 13px; color: var(--ink-soft); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }

.msg { margin: 10px 0 0; font-size: 13px; min-height: 18px; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--result-ink); }
.empty { color: var(--ink-soft); font-size: 13.5px; margin-top: 14px; }
.table-wrap.slim table { min-width: 640px; }

/* ---------------------------------------------------------- Toast */
.toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translateX(-50%);
  background: #0a2a44;
  color: #fff;
  padding: 11px 22px;
  border-radius: 40px;
  font-size: 14px;
  z-index: 100;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}
.toast[hidden] { display: none; }
.toast.err { background: var(--danger); }

/* ---------------------------------------------------------- 手機 */
@media (max-width: 600px) {
  body { padding: 14px 8px 48px; }
  .card { padding: 18px 14px 22px; border-radius: 22px; }
  .title { font-size: 19px; }
  .modal-body { padding: 16px 14px 20px; }
  .modal-head { padding: 14px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------------------------------------------------------- 列印 */
@media print {
  body { background: #fff; padding: 0; }
  .card { box-shadow: none; max-width: none; padding: 0; }
  .head-actions, .actions, .overlay, .toast, .col-del { display: none !important; }
  .notes-actions, .notes-edit { display: none !important; }
  .notes { border: none; background: transparent; padding-left: 0; }
  #calcTable { min-width: 0; font-size: 12px; }
  input, select { border: none !important; background: transparent !important; }
  .table-wrap { overflow: visible; }
}
