:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --ink: #172026;
  --muted: #65727b;
  --line: #d7dee2;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --warn: #b45309;
  --error: #b42318;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  padding-bottom: 50px;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.app {
  width: min(1180px, calc(100vw - 32px));
  margin: 28px auto 100px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

h1, h2, p { margin: 0; }

h1 { font-size: 28px; line-height: 1.25; }
h2 { font-size: 16px; line-height: 1.3; margin-bottom: 14px; }

.topbar p { margin-top: 6px; color: var(--muted); font-size: 14px; }

.status-pill {
  min-width: 86px; text-align: center;
  padding: 8px 12px; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; color: var(--muted); font-size: 13px;
}

.workspace {
  display: grid; grid-template-columns: 320px 1fr; gap: 16px;
}

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 18px;
}

.mobile-upload { align-self: start; }

.upload-title {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.upload-title h2 { margin-bottom: 0; }
.upload-title span {
  padding: 4px 8px; border-radius: 6px;
  background: #e7f4f2; color: var(--accent-dark); font-size: 12px;
}

.primary-upload {
  display: grid; align-content: center; gap: 8px;
  min-height: 132px; padding: 22px 18px; margin-bottom: 14px;
  border: 1px dashed #5da79f; border-radius: 8px;
  background: #f2fbfa; text-align: center; cursor: pointer;
}
.primary-upload strong { color: var(--accent-dark); font-size: 18px; }
.primary-upload small, .field span { font-size: 13px; color: var(--muted); }
.primary-upload input {
  position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none;
}

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

.preview-panel { grid-column: 1 / -1; }

.preview-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; margin-bottom: 12px;
}
.preview-head p { margin-top: 5px; color: var(--muted); font-size: 13px; }

.table-wrap {
  width: 100%; overflow-x: auto;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th, td {
  border-bottom: 1px solid var(--line); border-right: 1px solid var(--line);
  padding: 6px; text-align: center;
}

th {
  position: sticky; top: 0; background: #ffd000; z-index: 1; font-weight: 700;
}

td input {
  min-height: 34px; padding: 5px 7px;
  border-color: transparent; background: #f5fff5; text-align: center;
}

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

.price-field input {
  min-height: 48px; border-color: var(--accent); font-size: 20px; font-weight: 700;
}

input, select, button { font: inherit; }

input, select {
  width: 100%; min-height: 38px; border: 1px solid #cbd5da;
  border-radius: 6px; padding: 8px 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus {
  outline: 2px solid rgba(15, 118, 110, 0.18); border-color: var(--accent);
}

.actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  justify-content: flex-start;
  overflow-x: auto;
  padding: 4px 10px calc(4px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.97);
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.04);
  min-height: unset;
}
.actions > * { flex: 0 0 auto; }
.actions #message { flex: 1 1 240px; }

button, .download {
  min-height: 32px; border-radius: 5px; padding: 0 12px; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; text-decoration: none; cursor: pointer;
  white-space: nowrap;
}
button { background: var(--accent); color: #fff; }
button.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
button:hover { background: var(--accent-dark); }
button:disabled { opacity: 0.65; cursor: wait; }

.ghost-button, .secondary, .icon-button {
  min-height: 28px; border-radius: 5px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); padding: 0 10px; font-size: 12px;
  font: inherit; display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-button { min-width: 42px; padding: 0 8px; color: var(--error); }

.download {
  background: #fff; color: var(--accent-dark); border-color: #8cc5bf;
}

.message { color: var(--muted); font-size: 14px; }
.message.error { color: var(--error); }

.hidden { display: none !important; }

.fil-pill {
  min-height: 30px; font-size: 13px; cursor: pointer; user-select: none;
}
.fil-pill:hover { border-color: var(--accent); }
.fil-drop label:hover { background: #f0f6fc; }

td.price-cell {
  position: relative; color: var(--accent); font-weight: 700; cursor: pointer;
}
td.price-cell:hover { text-decoration: underline; }

tr.filtered-out { display: none; }

/* ── 预留底部空白给固定栏 ── */
#quotePreviewWrap { padding-bottom: 60px; }
#previewPanel { padding-bottom: 60px; }
.download-inline-wrap {
  position: sticky;
  top: 12px;
  z-index: 15;
  display: flex;
  justify-content: flex-end;
  margin: 0 0 10px;
}
.download-inline-wrap button {
  min-height: 44px;
  padding: 0 18px;
  background: linear-gradient(90deg, #0f766e, #2563eb);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-weight: 800;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.28);
}

/* ── 手机端适配 ── */

@media (max-width: 860px) {
  body { padding-bottom: env(safe-area-inset-bottom); }

  .app {
    width: 100vw; margin: 0 auto 120px;
  }

  .topbar {
    flex-direction: row; flex-wrap: wrap; align-items: center;
    padding: 8px 12px; gap: 6px;
    background: #fff; border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 30;
  }

  h1 { font-size: 18px; flex: 1; }
  .topbar > div:first-child { flex: 1; }
  .topbar > div:first-child > p:not(.mobile-status) { display: none; }

  .mobile-status {
    display: block !important;
    font-size: 11px !important;
    color: var(--accent) !important;
    font-weight: 600;
  }
  .status-pill { display: none; }

  .workspace { grid-template-columns: 1fr; }

  .panel {
    padding: 10px 12px;
    border-radius: 0;
    border-left: none; border-right: none;
    margin-bottom: 6px;
  }

  .mobile-upload { order: -1; }

  .grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .preview-head { flex-direction: column; }

  table { min-width: auto; font-size: 11px; }
  th, td { padding: 3px 2px; }
  td input { min-height: 26px; font-size: 11px; padding: 2px 3px; }

  .params-panel .grid { grid-template-columns: 1fr 1fr; }

  .price-field input {
    min-height: 36px; font-size: 16px;
  }

  .primary-upload {
    min-height: 80px; padding: 12px 10px;
  }

  input, select {
    min-height: 38px; font-size: 14px;
  }

  /* 底部操作栏紧凑化 */
  .actions {
    flex-wrap: wrap;
    padding: 3px 6px calc(3px + env(safe-area-inset-bottom));
    gap: 4px;
  }
  .actions button, .actions .download {
    min-height: 30px; font-size: 11px; padding: 0 8px;
    flex: 1 1 auto;
  }
  .actions #outputMode {
    min-height: 30px; font-size: 11px;
  }
  .actions #message {
    width: 100%; text-align: center; font-size: 11px;
    order: -1; margin: 0;
  }

  #previewTable { min-width: 500px; }
  #quotePreviewTable { min-width: 400px; }

  .fil-drop {
    position: fixed !important;
    left: 8px !important; right: 8px !important;
    top: auto !important; bottom: 80px !important;
    max-height: 40vh !important;
  }

  #settingsPanel {
    left: 8px; right: 8px; width: auto; top: 50px;
  }

  #btnTop, #btnBottom {
    width: 28px !important; height: 28px !important;
    right: 6px !important; font-size: 12px !important;
  }
  #btnTop { bottom: 90px !important; }
  #btnBottom { bottom: 62px !important; }

  #quotePreviewWrap { padding-bottom: 56px; }
  #previewPanel { padding-bottom: 56px; }
}

@media (max-width: 400px) {
  .grid { grid-template-columns: 1fr; }
  .params-panel .grid { grid-template-columns: 1fr; }
}
