:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #dbe3ef;
  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --soft-primary: #eaf1ff;
  --danger: #b91c1c;
  --warning-bg: #fff7ed;
  --warning-line: #fdba74;
  --shadow: 0 14px 36px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-layout {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  width: 188px;
  background: #0b1b33;
  color: #fff;
  padding: 24px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-title {
  font-size: 18px;
  font-weight: 900;
  margin-bottom: 22px;
  letter-spacing: 0.03em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
}

.sidebar-nav a {
  color: #cbd5e1;
  text-decoration: none;
  font-weight: 800;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 15px;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: var(--primary);
  color: #fff;
}

.sidebar-nav a[href="admin.html"] {
  margin-top: auto;
  font-size: 13px;
  opacity: 0.5;
  background: transparent;
}

.sidebar-nav a[href="admin.html"]:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
}

.main-content {
  flex: 1;
  min-width: 0;
}

.wrap {
  width: min(1040px, calc(100% - 40px));
  margin: 0 auto;
  padding: 36px 0 56px;
}

.title {
  margin: 0 0 10px;
  font-size: 30px;
  font-weight: 950;
  letter-spacing: -0.03em;
}

.subtitle {
  margin: 0 0 24px;
  color: var(--muted);
  line-height: 1.8;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.grid,
.dynamic-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.full-span {
  grid-column: 1 / -1;
}

.field label {
  display: block;
  font-weight: 900;
  margin-bottom: 8px;
}

.field input,
.field select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 16px;
  background: #fff;
  color: var(--text);
}

.field input:focus,
.field select:focus {
  outline: 3px solid var(--soft-primary);
  border-color: var(--primary);
}

.field small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.6;
}

.actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

button,
.ghost-link {
  border: 0;
  border-radius: 12px;
  padding: 13px 20px;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  text-decoration: none;
}

button {
  background: var(--primary);
  color: #fff;
}

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

button.ghost,
.ghost-link {
  background: #e5eaf1;
  color: #0f172a;
}

button.ghost:hover,
.ghost-link:hover {
  background: #d8e0ea;
}

.notice {
  display: none;
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--warning-line);
  background: var(--warning-bg);
  color: #c2410c;
  font-weight: 800;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 20px;
  margin-top: 18px;
  color: var(--muted);
}

.meta strong {
  color: var(--text);
}

/* ================================
   表格區：Excel 凍結第一欄
================================ */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

.compare-table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  border-radius: 16px;
}

/* 提示使用者可左右滑 */
.compare-table-wrap::after {
  content: "← 左右滑動查看更多 →";
  display: none;
  padding: 8px 4px 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

.compare-table {
  width: max-content;
  min-width: 100%;
  table-layout: auto;
}

/* 所有表格文字不換行 */
th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  word-break: normal;
  overflow-wrap: normal;
  vertical-align: middle;
  background: #fff;
}

th {
  background: #f8fafc;
  font-weight: 950;
  color: var(--text);
}

td {
  text-align: right;
  font-weight: 800;
  color: var(--text);
}

/* 第一欄凍結 */
.compare-table th:first-child,
.compare-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  width: 118px;
  min-width: 118px;
  max-width: 118px;
  text-align: left;
  font-weight: 950;
  color: var(--muted);
  background: #fff;
  box-shadow: 8px 0 14px rgba(15, 23, 42, 0.08);
}

/* 表頭第一格層級最高 */
.compare-table thead th:first-child {
  z-index: 5;
  background: #f8fafc;
  color: var(--text);
}

/* 表頭其他格 */
.compare-table thead th {
  background: #f8fafc;
  text-align: center;
}

/* 右側利率欄位固定寬度，方便滑動比較 */
.compare-table th:not(:first-child),
.compare-table td:not(:first-child) {
  min-width: 150px;
  text-align: right;
}

/* 一般非 compare table */
table:not(.compare-table) {
  width: 100%;
  table-layout: fixed;
}

table:not(.compare-table) th:first-child,
table:not(.compare-table) td:first-child {
  text-align: left;
  font-weight: 900;
}

.empty {
  padding: 36px 18px;
  text-align: center;
  color: var(--muted);
  font-weight: 800;
}

/* ================================
   TOYOTA / LEXUS / 1.88 單筆結果卡片
================================ */

.result-card-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.result-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
}

.result-card-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}

.result-card-row:last-child {
  border-bottom: 0;
}

.result-card-label {
  color: var(--muted);
  font-weight: 900;
}

.result-card-value {
  font-weight: 950;
  text-align: right;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* ================================
   手機版
================================ */

@media (max-width: 860px) {
  .app-layout {
    display: block;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 12px 12px;
  }

  .sidebar-title {
    font-size: 16px;
    margin-bottom: 10px;
  }

  .sidebar-nav {
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    height: auto;
  }

  .sidebar-nav a {
    white-space: nowrap;
    font-size: 14px;
    padding: 10px 12px;
  }

  .sidebar-nav a[href="admin.html"] {
    margin-top: 0;
    margin-left: auto;
    opacity: 0.35;
    font-size: 12px;
  }

  .wrap {
    width: min(100% - 24px, 720px);
    padding: 24px 0 40px;
  }

  .title {
    font-size: 26px;
  }

  .card {
    padding: 18px;
    border-radius: 18px;
  }

  .grid,
  .dynamic-grid {
    grid-template-columns: 1fr;
  }

  .actions button,
  .actions .ghost-link {
    flex: 1;
  }

  .result-card-row {
    padding: 14px;
  }
}

@media (max-width: 768px) {
  .result-card-shell {
    padding: 12px;
  }

  .compare-table-wrap {
    overflow-x: auto;
    overflow-y: visible;
  }

  .compare-table-wrap::after {
    display: block;
  }

  .compare-table {
    width: max-content;
    min-width: 100%;
  }

  .compare-table th,
  .compare-table td {
    padding: 13px 14px;
    font-size: 15px;
    line-height: 1.45;
    white-space: nowrap;
  }

  .compare-table th:first-child,
  .compare-table td:first-child {
    width: 92px;
    min-width: 92px;
    max-width: 92px;
    padding-left: 12px;
    padding-right: 10px;
    font-size: 15px;
    white-space: nowrap;
  }

  .compare-table th:not(:first-child),
  .compare-table td:not(:first-child) {
    min-width: 132px;
    font-size: 15px;
  }

  /* 中古尊榮欄位比較多，但仍維持正常可讀字級 */
  .compare-table-zhonggu th:not(:first-child),
  .compare-table-zhonggu td:not(:first-child) {
    min-width: 112px;
    font-size: 14px;
  }

  .compare-table-zhonggu th:first-child,
  .compare-table-zhonggu td:first-child {
    width: 86px;
    min-width: 86px;
    max-width: 86px;
    font-size: 14px;
  }
}

@media (max-width: 390px) {
  .compare-table th,
  .compare-table td {
    padding: 12px 12px;
    font-size: 14px;
  }

  .compare-table th:first-child,
  .compare-table td:first-child {
    width: 84px;
    min-width: 84px;
    max-width: 84px;
    font-size: 14px;
  }

  .compare-table th:not(:first-child),
  .compare-table td:not(:first-child) {
    min-width: 122px;
    font-size: 14px;
  }

  .compare-table-zhonggu th:not(:first-child),
  .compare-table-zhonggu td:not(:first-child) {
    min-width: 106px;
    font-size: 13px;
  }

  .compare-table-zhonggu th:first-child,
  .compare-table-zhonggu td:first-child {
    width: 80px;
    min-width: 80px;
    max-width: 80px;
    font-size: 13px;
  }
}