/* ============================================================
   PIAA Order Parser
   Warm editorial · Noto Serif TC headings + Noto Sans TC body
   Aligned with internal.daisukeagentlab.com earth tone DNA
   ui-ux-pro-max: Nature Distilled + Trust & Authority
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+TC:wght@400;600;700&family=Noto+Sans+TC:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg:           #F5F2ED;
  --surface:      #FFFFFF;
  --surface-2:    #EFEBE5;
  --border:       #E0DAD1;
  --border-hover: #BFBAB0;
  --text:         #1A1917;
  --text-muted:   #6B6560;
  --text-dim:     #8C8680;

  --accent:       #4A3F35;
  --accent-2:     #6B5A4A;   /* lighter warm brown for hover states */
  --accent-dim:   rgba(74,63,53,.06);
  --accent-hover: #3A302A;
  --accent-ring:  rgba(74,63,53,.14);

  --destructive:    #B91C1C;
  --destructive-bg: #FEF2F2;
  --success:        #047857;
  --success-bg:     #ECFDF5;
  --warning:        #92400E;
  --warning-bg:     #FEF3C7;

  --font:       'Noto Sans TC',  -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-serif: 'Noto Serif TC', "Georgia", serif;
  --font-mono:  'JetBrains Mono','SF Mono', Menlo, Consolas, monospace;

  --radius:    6px;
  --radius-sm: 4px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 3px rgba(30,25,20,.06);
  --shadow-md: 0 1px 4px rgba(30,25,20,.06), 0 4px 16px rgba(30,25,20,.05);
  --shadow-lg: 0 4px 16px rgba(30,25,20,.10), 0 1px 4px rgba(30,25,20,.06);

  --ease-out: cubic-bezier(0.0, 0.0, 0.2, 1);

  /* ── legacy aliases ── */
  --color-primary:        var(--text);
  --color-secondary:      var(--text-muted);
  --color-tertiary:       var(--text-dim);
  --color-accent:         var(--accent);
  --color-surface:        var(--surface);
  --color-surface-muted:  var(--surface-2);
  --color-border:         var(--border);
  --color-background:     var(--bg);
  --color-destructive:    var(--destructive);
  --color-destructive-bg: var(--destructive-bg);
  --color-success:        var(--success);
  --color-warning:        var(--warning);
  --color-warning-bg:     var(--warning-bg);
  --space-1:4px; --space-2:8px;  --space-3:12px;
  --space-4:16px; --space-5:20px; --space-6:24px;
  --space-8:32px; --space-10:40px; --space-12:48px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

/* ── Page entrance ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  animation: fadeUp 320ms var(--ease-out) both;
}

/* Subtle grain overlay — tactile quality */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
  opacity: .028;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
}

/* ============================================================
   Header — sticky, warm backdrop-blur
   ============================================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(245,242,237,.93);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.app-header-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 40px;
  height: 62px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.app-logo {
  width: 36px;
  height: 36px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 180ms ease, border-color 180ms ease;
}
.app-logo svg {
  width: 18px; height: 18px;
  stroke: var(--accent); fill: none;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.app-title { flex: 1; min-width: 0; }
.app-title h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--text);
  line-height: 1.3;
}
.app-title-sub {
  display: block;
  font-size: 11.5px;
  font-weight: 300;
  color: var(--text-dim);
  letter-spacing: .15px;
  margin-top: 1px;
}
#status { margin-left: auto; flex-shrink: 0; }

/* ============================================================
   Layout
   ============================================================ */
.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 44px 40px 96px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Result section entrance animation ── */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
#result > * {
  animation: slideUp 260ms var(--ease-out) both;
}
#result > *:nth-child(2) { animation-delay: 60ms; }
#result > *:nth-child(3) { animation-delay: 120ms; }
#result > *:nth-child(4) { animation-delay: 160ms; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: box-shadow 200ms var(--ease-out), border-color 200ms ease, transform 200ms var(--ease-out);
}
.card:focus-within { border-color: var(--border-hover); }
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }

.card-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-2);
}
.card-header h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-body { padding: 24px; }
.card-body.no-padding { padding: 0; }

/* ============================================================
   Input
   ============================================================ */
.input-label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
}
textarea {
  width: 100%;
  min-height: 164px;
  padding: 14px 16px;
  border: 1.5px solid var(--border-hover);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text);
  background: var(--surface);
  resize: vertical;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
textarea::placeholder { color: var(--text-dim); opacity: .8; }
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.input-hint {
  margin-top: 10px;
  font-size: 12px;
  font-weight: 300;
  color: var(--text-dim);
  line-height: 1.6;
}

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

/* ============================================================
   Button
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 180ms ease, color 180ms ease, box-shadow 180ms ease, transform 160ms var(--ease-out);
  letter-spacing: .05px;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 3px rgba(74,63,53,.30), 0 2px 8px rgba(74,63,53,.16);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 2px 8px rgba(74,63,53,.35), 0 4px 16px rgba(74,63,53,.18);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border-hover);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--accent);
}

.btn-copy {
  min-height: 36px;
  padding: 0 12px;
  font-size: 12px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-copy:hover:not(:disabled) {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--border-hover);
}
.btn-copy.copied { background: var(--success-bg); color: var(--success); border-color: #A7F3D0; }

/* ============================================================
   Status
   ============================================================ */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-dim);
}
.status::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.status.ok   { color: var(--success); }
.status.warn { color: var(--warning); }
.status.err  { color: var(--destructive); }
.status.busy { color: var(--accent); }
.status.busy::before { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.2; }
}

/* ============================================================
   Badge
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
}
.badge-ai { background: var(--warning-bg); color: var(--warning); border-color: #FDE68A; }

/* ============================================================
   Table
   ============================================================ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--font);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .09em;
  text-align: left;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--accent-dim); }
td.num, th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 13.5px;
}
td.sku { font-family: var(--font-mono); font-size: 13px; color: var(--text-muted); }
tr.free td { color: var(--text-dim); font-style: italic; }

/* ── Totals ── */
.totals {
  padding: 16px 24px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13.5px;
  color: var(--text-muted);
}
.totals-row .val {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--text);
}

/* Grand total — the centrepiece */
.totals-row.grand {
  margin-top: 8px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1.5px solid var(--border-hover);
  border-radius: var(--radius);
  align-items: center;
}
.totals-row.grand .label {
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.01em;
}
.totals-row.grand .val {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -.03em;
  line-height: 1;
}

/* ============================================================
   GV8 / 新高手清單
   ============================================================ */
.gv8-box { font-family: var(--font-mono); font-size: 13px; border-collapse: collapse; width: 100%; }
.gv8-box th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--font);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .09em;
  text-align: left;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.gv8-box td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
  user-select: text;
}
.gv8-box tr:last-child td { border-bottom: 0; }
.gv8-box tr:hover td { background: var(--accent-dim); }

/* ============================================================
   Notes / Warnings
   ============================================================ */
.notes ul, .warnings ul { margin: 0; padding: 0; list-style: none; }
.notes li, .warnings li {
  padding: 10px 16px 10px 32px;
  position: relative;
  font-size: 13.5px;
  font-weight: 400;
  line-height: 1.65;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.notes li:last-child, .warnings li:last-child { border-bottom: 0; }
.notes li.important { font-weight: 500; color: var(--text); }
.notes li::before {
  content: '';
  position: absolute;
  left: 14px; top: 18px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--border-hover);
}
.notes li.important::before { background: var(--accent); }

.warnings { background: var(--destructive-bg); border-color: #FECACA; }
.warnings .card-header { border-bottom-color: #FECACA; background: #FEF2F2; }
.warnings .card-header h2 { color: var(--destructive); font-family: var(--font-serif); }
.warnings li { color: #7F1D1D; }
.warnings li::before {
  content: '!';
  left: 12px; top: 11px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--destructive);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* ============================================================
   Empty / Loading
   ============================================================ */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
.empty-icon {
  width: 52px; height: 52px;
  margin: 0 auto 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: grid;
  place-items: center;
}
.empty-icon svg { width: 24px; height: 24px; stroke: var(--text-dim); fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, #E4DDD5 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
  height: 13px;
}
.skeleton.lg { height: 18px; }
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-rows { display: flex; flex-direction: column; gap: 12px; padding: 24px; }

/* ============================================================
   Mobile
   ============================================================ */
@media (max-width: 680px) {
  .app-header-inner { padding: 0 20px; }
  .container { padding: 24px 16px 64px; gap: 14px; }
  .card-body { padding: 18px; }
  .card-header { padding: 14px 18px; }
  .actions { width: 100%; }
  .btn-primary, .btn-secondary { flex: 1; }
  thead th, tbody td { padding: 9px 12px; font-size: 13px; }
  .totals { padding: 14px 18px; }
  .totals-row.grand .val { font-size: 24px; }
}

/* ============================================================
   Accessibility
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  body, body::after { animation: none; }
  #result > * { animation: none; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
