:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-soft: #eef5f1;
  --ink: #17211d;
  --muted: #63716b;
  --line: #d8dfdb;
  --primary: #176b5f;
  --primary-dark: #0f4f46;
  --accent: #b56b2a;
  --danger: #b23b3b;
  --shadow: 0 18px 45px rgba(25, 43, 36, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.shell.narrow {
  width: min(860px, calc(100% - 32px));
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.75rem, 3vw, 2.7rem);
  line-height: 1.1;
}

h2 {
  font-size: 1.15rem;
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 8px 14px;
  white-space: nowrap;
}

.topnav {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 5px;
}

.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-weight: 800;
  border-radius: 999px;
  padding: 8px 13px;
  white-space: nowrap;
}

.nav-link.active {
  background: var(--primary);
  color: #fff;
}

.workspace {
  display: grid;
  grid-template-columns: 370px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.search-workspace {
  grid-template-columns: 340px minmax(0, 1fr);
}

.panel,
.results {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 18px;
  position: sticky;
  top: 16px;
}

.field {
  display: grid;
  gap: 7px;
}

.wide {
  grid-column: 1 / -1;
}

label,
.metric span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 95, 0.15);
}

.switch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch span {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #c8d0cc;
  position: relative;
  transition: 0.18s ease;
}

.switch span::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  transition: 0.18s ease;
}

.switch input:checked + span {
  background: var(--primary);
}

.switch input:checked + span::after {
  transform: translateX(18px);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.two-actions {
  grid-template-columns: 1fr 1fr;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  min-height: 44px;
  padding: 10px 13px;
  cursor: pointer;
  font-weight: 800;
}

button:hover {
  background: var(--primary-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.secondary {
  background: var(--panel-soft);
  color: var(--primary-dark);
}

.secondary:hover {
  background: #dcebe4;
}

.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid #e3c6aa;
}

.ghost:hover {
  background: #fff5ec;
}

.results {
  padding: 18px;
  min-width: 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: 0.65fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}

.metric-grid.compact {
  grid-template-columns: 1fr 1fr;
}

.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfb;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 1.12rem;
  line-height: 1.2;
  word-break: break-word;
}

.result-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.result-toolbar p {
  color: var(--muted);
  margin-top: 4px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.88rem;
}

td {
  line-height: 1.45;
}

td a {
  color: var(--primary);
  font-weight: 800;
}

.tender-title {
  font-weight: 800;
}

.tender-id {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 3px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 34px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(18px);
  opacity: 0;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  border-radius: 8px;
  padding: 12px 16px;
  max-width: min(520px, calc(100% - 32px));
  transition: 0.18s ease;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%);
}

.toast.error {
  background: var(--danger);
}

.settings-panel {
  display: grid;
  gap: 18px;
  padding: 20px;
}

.settings-section {
  display: grid;
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.settings-section:last-of-type {
  border-bottom: 0;
  padding-bottom: 0;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.settings-grid.single {
  grid-template-columns: 1fr;
}

.settings-actions {
  grid-template-columns: 1fr 1fr;
}

.status-section .metric-grid {
  margin-bottom: 0;
}

@media (max-width: 920px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .controls {
    position: static;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding: 18px 0;
  }

  .topbar,
  .result-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topnav {
    justify-content: stretch;
    width: 100%;
  }

  .nav-link {
    flex: 1;
    text-align: center;
  }

  .status-pill,
  .result-toolbar button {
    width: 100%;
    text-align: center;
  }

  .controls,
  .metric-grid,
  .actions,
  .settings-grid,
  .metric-grid.compact {
    grid-template-columns: 1fr;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tr {
    border-bottom: 1px solid var(--line);
    padding: 12px;
  }

  td {
    border: 0;
    padding: 5px 0;
  }

  td::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    margin-bottom: 2px;
  }

  .empty::before {
    display: none;
  }
}
