:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --success: #15803d;
  --danger: #b91c1c;
  --soft: #eef7f6;
  --input: #ffffff;
  --table-head: #f9fafb;
  --table-cell: #ffffff;
  --shadow: 0 1px 2px rgba(15,23,42,.04);
}
html.theme-dark {
  --bg: #0b1220;
  --card: #111827;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --line: #2b3547;
  --primary: #14b8a6;
  --primary-dark: #0d9488;
  --success: #22c55e;
  --danger: #ef4444;
  --soft: #0f2f2d;
  --input: #0f172a;
  --table-head: #0f172a;
  --table-cell: #111827;
  --shadow: 0 1px 2px rgba(0,0,0,.25);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar { min-height: 60px; display: flex; align-items: center; justify-content: space-between; padding: 0 28px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand a { font-weight: 800; font-size: 20px; color: var(--text); }
.topbar nav { display: flex; gap: 20px; }
.topbar nav a { color: var(--text); font-weight: 600; }
.userbox { display: flex; gap: 14px; align-items: center; color: var(--muted); }
.theme-toggle { border: 1px solid var(--line); background: var(--input); color: var(--text); border-radius: 999px; padding: 7px 12px; cursor: pointer; font-weight: 650; }
.theme-toggle:hover { background: var(--soft); }
.page { max-width: 1440px; margin: 0 auto; padding: 28px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 18px; }
h1 { margin: 0 0 6px; font-size: 28px; }
h2 { margin: 0 0 14px; font-size: 18px; }
h3 { margin: 0 0 8px; }
p { margin: 4px 0; }
.page-head p, .hint, small, .muted { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi { padding: 18px; }
.kpi span { color: var(--muted); display: block; margin-bottom: 6px; }
.kpi strong { font-size: 24px; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--input); color: var(--text); font-weight: 650; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--soft); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.success:hover { filter: brightness(.95); }
.btn.small { min-height: 30px; padding: 5px 10px; font-size: 13px; }
.btn.large { min-height: 44px; padding: 10px 18px; font-size: 15px; }
.btn.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn.full { width: 100%; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline { display: inline; margin: 0; }
.inline-form, .toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input { min-width: 320px; }
input, textarea, select { width: 100%; min-height: 38px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--input); color: var(--text); font: inherit; }
input[type="file"] { padding: 8px; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .75; }
textarea { resize: vertical; }
label { font-weight: 650; }
.form-grid { display: grid; grid-template-columns: 170px 1fr; gap: 12px 14px; align-items: start; margin-bottom: 20px; }
.form-grid.three-col { grid-template-columns: 170px 1fr 170px 1fr 170px 1fr; }
.form-wide h2 { border-top: 1px solid var(--line); padding-top: 18px; margin-top: 18px; }
.form-wide h2:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { border-bottom: 1px solid var(--line); padding: 10px; text-align: left; vertical-align: top; }
.data-table th { background: var(--table-head); font-size: 13px; color: var(--text); white-space: nowrap; }
.data-table td { background: var(--table-cell); }
.item-table th:nth-child(2), .item-table td:nth-child(2) { min-width: 190px; }
.item-table th:nth-child(4), .item-table td:nth-child(4) { min-width: 160px; }
.empty { text-align: center; color: var(--muted); padding: 28px !important; }
.empty-title { color: var(--text); font-weight: 800; font-size: 18px; margin-bottom: 6px; }
.empty-cta .btn { margin-top: 14px; }
.status { display: inline-block; padding: 3px 9px; background: var(--soft); color: var(--primary); border-radius: 999px; font-size: 12px; font-weight: 800; }
.thumb { width: 86px; height: 86px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: var(--input); }
.thumb.big { width: 130px; height: 130px; margin-bottom: 8px; display: block; }
.no-img, .image-empty { width: 86px; height: 86px; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); display: flex; align-items: center; justify-content: center; font-size: 12px; background: var(--input); }
.image-empty { color: var(--primary); font-weight: 700; }
.size-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.size-tags span, .pdf-size { display: inline-block; background: var(--soft); border-radius: 999px; padding: 3px 8px; margin: 2px; white-space: nowrap; }
.row-actions { white-space: nowrap; }
.row-actions form { display: inline; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.preline { white-space: pre-wrap; }
.danger-zone { border-color: #fecaca; background: color-mix(in srgb, var(--card) 92%, #ef4444); }
.messages { margin-bottom: 16px; }
.message { padding: 10px 12px; border-radius: 10px; margin-bottom: 8px; border: 1px solid var(--line); }
.message.success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.message.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
html.theme-dark .message.success { background: #052e24; border-color: #065f46; color: #a7f3d0; }
html.theme-dark .message.error { background: #3b0a0a; border-color: #7f1d1d; color: #fecaca; }
.info-card { min-height: 150px; }
.mini-list { display: grid; gap: 8px; }
.mini-list a { padding: 10px; border: 1px solid var(--line); border-radius: 10px; display: flex; justify-content: space-between; align-items: center; }
.size-editor { display: grid; gap: 8px; max-width: 680px; margin: 10px 0; }
.size-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; }
.fallback-box { margin: 14px 0; color: var(--muted); }
.internal-hidden .internal-col { display: none !important; }
.quick-panel { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.quick-step { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; box-shadow: var(--shadow); }
.quick-step strong { width: 34px; height: 34px; border-radius: 999px; background: var(--soft); color: var(--primary); display: flex; align-items: center; justify-content: center; }
.quick-step b { display: block; }
.quick-step span { display: block; color: var(--muted); font-size: 13px; margin-top: 3px; }
.export-card { display: flex; align-items: center; justify-content: space-between; gap: 18px; background: linear-gradient(135deg, var(--card), var(--soft)); }
.upload-hero { display: grid; grid-template-columns: 1.1fr 360px; gap: 24px; align-items: stretch; background: var(--soft); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 22px; }
.file-drop { display: flex; flex-direction: column; gap: 8px; justify-content: center; align-items: center; min-height: 190px; border: 2px dashed var(--primary); border-radius: 16px; background: var(--card); cursor: pointer; text-align: center; padding: 22px; }
.file-drop:hover { filter: brightness(.98); }
.file-icon { width: 52px; height: 52px; border-radius: 999px; display: flex; align-items: center; justify-content: center; background: var(--primary); color: #fff; font-size: 30px; line-height: 1; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }
.image-preview-box { min-height: 260px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.preview-placeholder { color: var(--muted); border: 1px dashed var(--line); border-radius: 12px; width: 82%; height: 200px; display: flex; align-items: center; justify-content: center; }
.preview-img { width: 100%; height: 100%; max-height: 320px; object-fit: contain; background: var(--input); }
.hidden { display: none !important; }
.sticky-actions { position: sticky; bottom: 0; background: color-mix(in srgb, var(--card) 92%, transparent); border-top: 1px solid var(--line); padding: 12px 0 0; margin-top: 18px; }
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #eef7f6, #f6f7fb); }
html.theme-dark .login-body { background: linear-gradient(135deg, #0b1220, #111827); }
.login-card { width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 20px 50px rgba(15,23,42,.08); padding: 28px; }
.login-card h1 { font-size: 30px; }
.login-card label { display: block; margin-top: 14px; margin-bottom: 6px; }
.login-card button { margin-top: 16px; }
.login-card small { display: block; margin-top: 16px; line-height: 1.5; }
.print-body { background: #d1d5db; }
.print-toolbar { display: flex; gap: 10px; padding: 14px; justify-content: center; align-items: center; flex-wrap: wrap; position: sticky; top: 0; background: rgba(255,255,255,.96); border-bottom: 1px solid #e5e7eb; z-index: 9; color: #111827; }
.print-tip { color: #6b7280; font-size: 13px; }
.pdf-page { width: 210mm; min-height: 297mm; margin: 18px auto; padding: 14mm; background: #fff; color: #111827; box-shadow: 0 8px 30px rgba(0,0,0,.12); }
.pdf-page a { color: #0f766e; }
.pdf-header { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #111827; padding-bottom: 12px; margin-bottom: 14px; }
.pdf-header h1 { font-size: 24px; letter-spacing: .5px; }
.pdf-header h2 { font-size: 20px; text-align: right; margin-bottom: 8px; }
.pdf-meta { text-align: right; }
.pdf-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; border: 1px solid #d1d5db; padding: 10px; margin-bottom: 14px; }
.pdf-table { width: 100%; border-collapse: collapse; font-size: 11px; margin-top: 12px; }
.pdf-table th, .pdf-table td { border: 1px solid #cbd5e1; padding: 6px; vertical-align: top; }
.pdf-table th { background: #f3f4f6; color: #111827; }
.pdf-table td { color: #111827; }
.pdf-size { background: #f3f4f6; color: #111827; }
.pdf-thumb { width: 70px; height: 70px; object-fit: cover; }
.pdf-total { display: grid; grid-template-columns: 1fr 260px; margin-top: 14px; }
.pdf-total table { width: 100%; border-collapse: collapse; }
.pdf-total td { border: 1px solid #cbd5e1; padding: 8px; }
.pdf-total .grand td { font-weight: 800; font-size: 15px; background: #f3f4f6; }
.pdf-notes { margin-top: 18px; border-top: 1px solid #d1d5db; padding-top: 12px; white-space: pre-wrap; }
.pdf-footer { margin-top: 24px; text-align: center; color: #6b7280; }
@media (max-width: 1100px) {
  .quick-panel { grid-template-columns: 1fr; }
  .quick-step { grid-template-columns: 40px 1fr; }
  .quick-step .btn { grid-column: 2; justify-self: start; }
  .upload-hero { grid-template-columns: 1fr; }
}
@media (max-width: 1000px) {
  .grid.two, .grid.four { grid-template-columns: 1fr; }
  .form-grid, .form-grid.three-col { grid-template-columns: 1fr; }
  .toolbar input { min-width: 0; }
  .topbar { height: auto; flex-wrap: wrap; padding: 12px; gap: 10px; }
  .topbar nav { flex-wrap: wrap; }
  .page { padding: 14px; }
  .page-head, .export-card { flex-direction: column; align-items: stretch; }
}
@media print {
  @page { size: A4; margin: 8mm; }
  body { background: #fff; }
  .no-print { display: none !important; }
  .pdf-page { width: auto; min-height: auto; margin: 0; padding: 0; box-shadow: none; }
  .pdf-table { page-break-inside: auto; }
  tr { page-break-inside: avoid; page-break-after: auto; }
  .pdf-header { margin-top: 0; }
}

.workflow-tip { display: flex; align-items: center; justify-content: space-between; gap: 18px; background: linear-gradient(135deg, var(--soft), var(--card)); }
.workflow-tip h2 { margin-bottom: 6px; }
.button-stack { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.order-list-table th:last-child, .order-list-table td:last-child { min-width: 300px; }
@media (max-width: 1000px) {
  .workflow-tip { flex-direction: column; align-items: stretch; }
  .button-stack { flex-direction: column; align-items: stretch; }
  .button-stack .btn { width: 100%; }
}

/* v4 multi-image upload */
.file-drop.drag-over { background: color-mix(in srgb, var(--primary) 12%, var(--card)); transform: translateY(-1px); }
.image-preview-box.multi { align-items: stretch; justify-content: stretch; padding: 12px; overflow: auto; }
.preview-grid { width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; align-content: start; }
.preview-card { border: 1px solid var(--line); background: var(--input); border-radius: 12px; overflow: hidden; min-height: 150px; display: flex; flex-direction: column; }
.preview-card img { width: 100%; height: 118px; object-fit: cover; display: block; }
.preview-card span { color: var(--muted); font-size: 12px; padding: 7px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.existing-images { margin-top: 16px; }
.existing-image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; margin-top: 8px; }
.existing-image-card { border: 1px solid var(--line); background: var(--input); border-radius: 12px; padding: 7px; display: grid; gap: 6px; cursor: pointer; font-weight: 500; }
.existing-image-card img { width: 100%; height: 90px; object-fit: cover; border-radius: 8px; }
.existing-image-card span { display: flex; gap: 5px; align-items: center; font-size: 12px; color: var(--muted); }
.existing-image-card input { width: auto; min-height: auto; }
.thumb-grid { display: grid; grid-template-columns: repeat(2, 42px); gap: 4px; }
.thumb.small-thumb { width: 42px; height: 42px; border-radius: 8px; }
.pdf-image-grid { display: grid; grid-template-columns: repeat(2, 38px); gap: 3px; }
.pdf-image-grid .pdf-thumb { width: 38px; height: 38px; border-radius: 4px; object-fit: cover; }

/* v5 larger thumbnails + click-to-preview lightbox */
.item-table th:first-child, .item-table td:first-child { min-width: 172px; width: 172px; }
.thumb-grid { grid-template-columns: repeat(2, 72px); gap: 8px; align-items: start; }
.thumb.small-thumb { width: 72px; height: 72px; border-radius: 10px; }
.image-zoomable { cursor: zoom-in; transition: transform .12s ease, box-shadow .12s ease; }
.image-zoomable:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(15,23,42,.18); }
.existing-image-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.existing-image-card img { height: 138px; }
.preview-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.preview-card { min-height: 180px; }
.preview-card img { height: 148px; }
.image-lightbox { position: fixed; inset: 0; z-index: 9999; background: rgba(3, 7, 18, .88); display: flex; align-items: center; justify-content: center; padding: 34px; }
.image-lightbox.hidden { display: none !important; }
.image-lightbox img { max-width: min(96vw, 1280px); max-height: 88vh; object-fit: contain; border-radius: 14px; background: #fff; box-shadow: 0 20px 70px rgba(0,0,0,.45); }
.image-lightbox-close { position: fixed; right: 24px; top: 18px; width: 44px; height: 44px; border-radius: 999px; border: 1px solid rgba(255,255,255,.28); background: rgba(15,23,42,.72); color: #fff; font-size: 32px; line-height: 1; cursor: pointer; }
.image-lightbox-tip { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); color: rgba(255,255,255,.78); font-size: 13px; }
@media (max-width: 900px) {
  .item-table th:first-child, .item-table td:first-child { min-width: 140px; width: 140px; }
  .thumb-grid { grid-template-columns: repeat(2, 58px); gap: 6px; }
  .thumb.small-thumb { width: 58px; height: 58px; }
}

/* v6 larger customer PDF product images */
.pdf-table th:nth-child(2), .pdf-table td:nth-child(2) {
  width: 132px;
  min-width: 132px;
}
.pdf-image-grid {
  display: grid;
  grid-template-columns: repeat(2, 62px);
  gap: 6px;
  align-items: start;
}
.pdf-image-grid .pdf-thumb {
  width: 62px;
  height: 62px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid #e5e7eb;
}
@media print {
  .pdf-table { font-size: 10.5px; }
  .pdf-table th:nth-child(2), .pdf-table td:nth-child(2) {
    width: 124px;
    min-width: 124px;
  }
  .pdf-image-grid {
    grid-template-columns: repeat(2, 58px);
    gap: 5px;
  }
  .pdf-image-grid .pdf-thumb {
    width: 58px;
    height: 58px;
  }
}

/* v7 company header and clickable customer detail improvements */
.customer-name-link { font-weight: 800; color: var(--primary); }
.customer-name-link:hover { text-decoration: underline; }
.detail-list { display: grid; gap: 10px; }
.detail-list div { border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.detail-list div:last-child { border-bottom: none; padding-bottom: 0; }
.detail-list span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.detail-list strong { display: block; color: var(--text); font-weight: 650; line-height: 1.45; overflow-wrap: anywhere; }
.customer-contact-card { min-height: 100%; }
.pdf-header.company-header { align-items: flex-start; gap: 16px; border-bottom: 2.5px solid #111827; padding-bottom: 10px; }
.pdf-company { flex: 1 1 auto; min-width: 0; font-size: 10.5px; line-height: 1.35; }
.pdf-logo-line { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.pdf-logo { width: 118px; height: auto; display: block; border-radius: 2px; }
.pdf-company h1 { margin: 0 0 3px; font-size: 22px; letter-spacing: .2px; color: #111827; }
.pdf-tagline { color: #374151; font-weight: 650; }
.pdf-company p { margin: 2px 0; color: #111827; }
.pdf-meta { flex: 0 0 210px; }
.pdf-meta h2 { font-size: 20px; line-height: 1.15; }
@media print {
  .pdf-logo { width: 108px; }
  .pdf-company h1 { font-size: 20px; }
  .pdf-company { font-size: 10px; }
  .pdf-meta { flex-basis: 198px; }
}
