/*
 * 登入、材料主檔與系統後台共用視覺。
 * 材料頁沿用 Admin 後台的淺灰背景、白色卡片、留白與輕量邊框，不使用 Excel 格線。
 */

:root {
  color-scheme: light;
  --ink: #1f2933;
  --muted: #637083;
  --line: #d6dde5;
  --line-strong: #aeb8c4;
  --page: #f3f5f7;
  --panel: #ffffff;
  --soft: #f7f9fb;
  --brand: #1f4e78;
  --brand-dark: #173b5b;
  --brand-soft: #e8f0f7;
  --warn: #b55b28;
  --bad: #a53030;
  --good: #176b4d;
  --shadow: 0 3px 16px rgba(28, 42, 56, .07);
}

* { box-sizing: border-box; }
html { background: var(--page); }
body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font-family: "Microsoft JhengHei", "Segoe UI", Arial, sans-serif;
}
h1, h2, h3, h4, p { margin-top: 0; }
button, input, select, textarea { font: inherit; }
button {
  min-height: 40px;
  padding: 8px 15px;
  border: 1px solid #8793a0;
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { background: #eef2f5; }
button.primary {
  border-color: var(--brand);
  color: #fff;
  background: var(--brand);
}
button.primary:hover:not(:disabled) { background: var(--brand-dark); }
button.warn { border-color: var(--warn); color: #fff; background: var(--warn); }
button:disabled { opacity: .45; cursor: not-allowed; }
input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #9da8b4;
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
}
textarea { resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(31, 78, 120, .14);
  border-color: var(--brand);
}
label {
  display: block;
  margin-bottom: 5px;
  color: #344252;
  font-size: 13px;
  font-weight: 700;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.eyebrow {
  margin: 0 0 4px;
  color: #617184;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .16em;
}
.section-note, .field-help { color: var(--muted); font-size: 13px; }

/* 共用頁首與 Session 身分。 */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  gap: 20px;
  padding: 12px 32px;
  border-bottom: 1px solid #cbd3dc;
  background: rgba(255, 255, 255, .97);
  box-shadow: 0 1px 8px rgba(25, 38, 52, .05);
}
.site-header h1 { margin: 0; font-size: 23px; }
.identity { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.user-label { color: var(--muted); font-size: 12px; }
.role-badge {
  padding: 4px 9px;
  border-radius: 999px;
  color: #254966;
  background: var(--brand-soft);
  font-size: 12px;
}
.quiet-button, .logout-button { min-height: 35px; padding: 6px 11px; }

/* 材料查詢頁。 */
.materials-main {
  display: grid;
  gap: 12px;
  width: min(1840px, 100%);
  margin: 0 auto;
  padding: 14px 32px 36px;
}
.material-card {
  padding: 21px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.action-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.action-card h2 { margin-bottom: 6px; font-size: 21px; }
.action-card .section-note { margin: 0; }
.top-actions { justify-content: flex-end; }
.search-card {
  padding: 14px 16px;
  overflow-x: auto;
}
.search-toolbar {
  display: grid;
  grid-template-columns: 150px 250px 76px repeat(6, max-content);
  gap: 8px;
  align-items: end;
  min-width: max-content;
}
.search-toolbar button { padding-inline: 12px; }
.status-search select { padding-inline: 7px 24px; }
.result-card { padding: 0; overflow: hidden; }
.result-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 17px 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.filter-summary {
  margin: 0 0 8px;
  color: #374658;
  font-size: 14px;
  line-height: 1.6;
}
.result-count { margin: 0; color: var(--brand); font-size: 14px; font-weight: 750; }
.material-table-wrap {
  max-height: 70vh;
  overflow: auto;
  background: #fff;
}
table { width: 100%; border-collapse: collapse; }
.material-table { min-width: 1920px; }
th, td {
  padding: 11px 10px;
  border-bottom: 1px solid #e1e6eb;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}
th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: #314255;
  background: #edf2f6;
  font-weight: 750;
  white-space: nowrap;
}
.material-table th:first-child, .material-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 62px;
  text-align: center;
  background: inherit;
}
.material-table th:first-child { z-index: 3; background: #edf2f6; }
.material-table tbody tr { cursor: pointer; transition: background .12s ease; }
.material-table tbody tr:nth-child(even) { background: #fafbfc; }
.material-table tbody tr:hover { background: #edf5fb; }
td.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.description-cell {
  width: 310px;
  max-width: 310px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.spec-cell { min-width: 250px; }
.spec-cell small {
  display: block;
  margin-top: 3px;
  color: var(--brand);
}
.empty-row { padding: 34px; color: var(--muted); text-align: center !important; }

/* 進階篩選抽屜。 */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(13, 23, 33, .42);
}
.drawer-backdrop[hidden] { display: none; }
.detail-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 41;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(620px, 94vw);
  height: 100vh;
  background: #fff;
  box-shadow: -16px 0 40px rgba(20, 31, 44, .2);
  transform: translateX(104%);
  transition: transform .2s ease;
}
.detail-drawer.open { transform: translateX(0); }
.drawer-head, .drawer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 21px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 21px; }
.drawer-foot { border-top: 1px solid var(--line); border-bottom: 0; }
.drawer-body { padding: 20px; overflow: auto; background: #f8fafb; }
.filter-section {
  margin-bottom: 14px;
  padding: 17px;
  border: 1px solid var(--line);
  background: #fff;
}
.filter-section h3 { margin-bottom: 12px; font-size: 15px; }
.filter-section .field-help { margin: -5px 0 12px; }
.choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.choice {
  display: flex;
  align-items: center;
  min-height: 38px;
  gap: 8px;
  margin: 0;
  padding: 7px 9px;
  border: 1px solid #d8dee5;
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
  cursor: pointer;
}
.choice:hover { border-color: #8ca5bb; background: #f4f8fb; }
.choice input { width: 16px; min-height: 16px; margin: 0; }
.range-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.accordion-list { display: grid; gap: 8px; }
.accordion-list details { border: 1px solid #d8dee5; background: #fff; }
.accordion-list summary {
  padding: 11px 12px;
  color: #33475b;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}
.characteristic-options { padding: 0 11px 12px; }
.icon-button {
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  border-color: transparent;
  color: #536172;
  background: transparent;
  font-size: 25px;
}

/* Dialog 與材料分區表單。 */
dialog {
  width: min(1080px, 94vw);
  max-height: 92vh;
  padding: 0;
  border: 0;
  border-radius: 10px;
  box-shadow: 0 22px 70px rgba(19, 31, 44, .26);
}
dialog::backdrop { background: rgba(10, 18, 28, .5); }
.material-dialog { width: min(1380px, 96vw); }
.import-dialog { width: min(760px, 94vw); }
.modal-head, .modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.modal-head strong { font-size: 19px; }
.modal-foot { border-top: 1px solid var(--line); border-bottom: 0; }
.modal-body { max-height: 72vh; padding: 18px 20px; overflow: auto; background: #f5f7f9; }
.material-form-body { display: grid; gap: 15px; }
.notice {
  margin: 0;
  padding: 11px 13px;
  border: 1px solid #d4dfeb;
  border-radius: 7px;
  color: #36546f;
  background: #edf5fb;
  font-size: 13px;
}
.form-card {
  padding: 18px;
  border: 1px solid var(--line);
  background: #fff;
}
.card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-heading h3 { margin: 0; font-size: 16px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}
.basic-grid { grid-template-columns: repeat(5, minmax(150px, 1fr)); }
.two-card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.repeat-list { display: grid; gap: 9px; }
.repeat-row {
  display: grid;
  grid-template-columns: 38px 170px minmax(240px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid #dce2e8;
  background: #fafbfc;
}
.row-number {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  margin-bottom: 5px;
  border-radius: 50%;
  color: #fff;
  background: var(--brand);
  font-size: 12px;
  font-weight: 750;
}
.danger-outline { border-color: #bd6c6c; color: #9d3030; }
.parameter-group + .parameter-group {
  margin-top: 18px;
  padding-top: 17px;
  border-top: 1px solid #e0e5ea;
}
.parameter-group h4 { margin-bottom: 12px; color: #405266; font-size: 14px; }
.parameter-grid { grid-template-columns: repeat(4, minmax(155px, 1fr)); }
.span-2 { grid-column: span 2; }
.import-steps { margin: 0 0 18px; padding-left: 22px; color: #4b5c6d; line-height: 1.8; }
.import-preview {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  background: #fff;
}
.preview-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.preview-metrics > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 12px;
  background: #edf3f7;
}
.preview-metrics span { color: var(--muted); font-size: 12px; }
.preview-metrics strong { font-size: 24px; }
.preview-metrics .has-error { color: var(--bad); background: #faeaea; }
.import-preview > p { margin: 13px 0 0; }
.error-list {
  max-height: 240px;
  margin-top: 12px;
  padding: 10px;
  overflow: auto;
  border-left: 3px solid var(--bad);
  background: #fff7f7;
}
.error-list p { margin: 0 0 9px; font-size: 13px; }
.error-list p:last-child { margin: 0; }
.audit {
  max-height: 420px;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* 登入頁。 */
.login-panel {
  width: min(420px, calc(100% - 28px));
  margin: 54px auto 0;
  padding: 24px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: var(--shadow);
}
.login-panel form { display: grid; gap: 14px; }
.login-panel button.primary { border-color: #176f6b; background: #176f6b; }

/* 系統後台，保留既有元件與權限流程。 */
.button-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.admin-page { background: var(--page); }
.admin-header { border-bottom: 1px solid #c9d0d8; }
.admin-main {
  display: grid;
  gap: 22px;
  width: min(1680px, 100%);
  margin: 0 auto;
  padding: 24px 32px 42px;
}
.admin-section { padding: 22px; border: 1px solid #cfd6dd; background: #fff; box-shadow: var(--shadow); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-heading h2 { margin: 0; font-size: 20px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; }
.metric-card { display: flex; flex-direction: column; gap: 12px; min-height: 112px; padding: 18px; border-left: 4px solid var(--brand); background: #f7f9fb; }
.metric-card span { color: #56616d; font-size: 13px; }
.metric-card strong { font-size: 32px; font-variant-numeric: tabular-nums; }
.overview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.admin-subpanel { min-width: 0; border: 1px solid #d8dee5; }
.admin-subpanel h3 { margin: 0; padding: 14px 16px; border-bottom: 1px solid #d8dee5; font-size: 15px; }
.admin-table-wrap { width: 100%; overflow: auto; }
.admin-table { min-width: 800px; }
.admin-subpanel .admin-table { min-width: 560px; }
.admin-table th { position: static; border: 1px solid #cdd4dc; background: #edf1f5; }
.admin-table td { border: 1px solid #d9dee4; }
.admin-table tr:hover td { background: #f7fafc; }
.admin-table .deleted-row td { color: #7b838b; background: #f4f4f4; }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; min-width: 310px; }
.table-actions button { min-height: 32px; padding: 4px 9px; font-size: 12px; }
.account-state, .result-badge { display: inline-flex; padding: 3px 8px; border-radius: 999px; background: #eceff2; font-size: 12px; }
.account-state.active, .result-badge.ok { color: #126143; background: #dff3e9; }
.result-badge.failed { color: #922f2f; background: #f8e3e3; }
.filter-form { display: grid; grid-template-columns: 1fr 160px 160px 1fr 150px auto; gap: 10px; align-items: end; margin-bottom: 14px; }
.compact-filter { grid-template-columns: 1.2fr 160px 160px 150px auto; }
.audit-table { min-width: 1500px; }
.audit-table details { max-width: 260px; }
.audit-table summary { cursor: pointer; color: var(--brand); }
.audit-table pre { max-height: 260px; overflow: auto; padding: 8px; background: #f4f6f8; white-space: pre-wrap; word-break: break-word; }
.user-agent-cell { max-width: 360px; word-break: break-word; }
.admin-dialog { width: min(560px, 94vw); }
.admin-form { display: grid; gap: 14px; }
.admin-form p { margin: 0; }
.form-error { min-height: 20px; color: var(--bad); font-weight: 700; }

@media (max-width: 1350px) {
  .basic-grid { grid-template-columns: repeat(3, minmax(160px, 1fr)); }
}

@media (max-width: 1000px) {
  .action-card { align-items: flex-start; flex-direction: column; }
  .top-actions { justify-content: flex-start; }
  .two-card-grid { grid-template-columns: 1fr; }
  .form-grid, .parameter-grid { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
  .overview-grid { grid-template-columns: 1fr; }
  .filter-form, .compact-filter { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
}

@media (max-width: 720px) {
  .site-header { position: static; align-items: flex-start; flex-direction: column; padding: 14px; }
  .materials-main, .admin-main { padding: 14px; }
  .material-card { padding: 16px; }
  .form-grid, .basic-grid, .parameter-grid { grid-template-columns: 1fr; }
  .choice-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .repeat-row { grid-template-columns: 32px 1fr; }
  .repeat-grow, .repeat-row button { grid-column: 2; }
  .span-2 { grid-column: span 1; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-form, .compact-filter { grid-template-columns: 1fr; }
}
