:root {
  color-scheme: dark;
  --bg: #12121a;
  --bg-sunk: #0d0d14;
  --card: #1b1b28;
  --card-2: #21212f;
  --line: #2a2a3d;
  --line-2: #3a3a55;
  --accent: #8ef0d3;
  --accent-2: #8be9fd;
  --text: #eaeaf2;
  --muted: #8888a0;
  --danger: #ff8a94;
  --warn: #ffcf7a;
  --ok: #8ef0d3;
  --radius: 14px;
  --font: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'JetBrains Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  padding: 28px 16px 48px;
  line-height: 1.5;
}

.wrap { width: 100%; max-width: 1120px; margin: 0 auto; }

/* ---------- language switch ---------- */
.topbar { display: flex; justify-content: flex-end; margin-bottom: -8px; }
.langs { display: inline-flex; background: var(--bg-sunk); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.langs button {
  background: none; border: none; color: var(--muted); font: inherit; font-size: .82rem; font-weight: 600;
  padding: 4px 12px; border-radius: 999px; cursor: pointer; transition: .15s;
}
.langs button:hover { color: var(--text); }
.langs button[aria-pressed="true"] { background: var(--card-2); color: var(--accent); }

/* ---------- header ---------- */
header { display: flex; align-items: center; gap: 14px; justify-content: center; }
header img { width: 52px; height: 52px; border-radius: 13px; }
h1 { font-size: 1.65rem; letter-spacing: -0.01em; }
h1 span { color: var(--accent); }
.tag { color: var(--muted); text-align: center; margin: 8px 0 18px; font-size: .95rem; }
.feat {
  display: flex; gap: 18px; flex-wrap: wrap; justify-content: center;
  color: var(--muted); font-size: .85rem; margin-bottom: 22px;
}
.feat b { color: var(--text); font-weight: 600; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; margin-bottom: 16px;
}
.card h2 {
  font-size: .95rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 600; margin-bottom: 14px;
}

/* ---------- mode switch ---------- */
.modes { display: flex; gap: 6px; background: var(--bg-sunk); padding: 5px; border-radius: 11px; margin-bottom: 16px; }
.modes button {
  flex: 1; background: none; border: none; color: var(--muted); font: inherit; font-weight: 600;
  padding: 9px 10px; border-radius: 8px; cursor: pointer; transition: .15s; font-size: .92rem;
}
.modes button:hover { color: var(--text); }
.modes button[aria-pressed="true"] { background: var(--card-2); color: var(--accent); box-shadow: 0 1px 0 #0006; }
.modes small { display: block; font-weight: 400; font-size: .72rem; color: var(--muted); margin-top: 1px; }

/* ---------- drop zone ---------- */
.drop {
  border: 2px dashed var(--line-2); border-radius: 12px; padding: 34px 16px; text-align: center;
  cursor: pointer; transition: .18s; background: transparent;
  width: 100%; color: inherit; font: inherit; display: block;
}
.drop:hover, .drop.over { border-color: var(--accent); background: #1e2430; }
.drop:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.drop .big { font-size: 2.1rem; line-height: 1; }
.drop .lead { margin-top: 8px; font-weight: 600; }
.drop .hint { color: var(--muted); margin-top: 6px; font-size: .85rem; }
kbd {
  background: var(--bg-sunk); border: 1px solid var(--line-2); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 6px; font: 600 .78rem var(--mono); color: var(--text);
}

/* ---------- controls ---------- */
.row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; align-items: center; }
select, input[type="text"] {
  background: var(--bg-sunk); color: var(--text); border: 1px solid #33334a;
  border-radius: 8px; padding: 9px 11px; font: inherit; font-size: .92rem; min-width: 120px;
}
select:focus-visible, input:focus-visible, button:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button {
  background: var(--accent); color: #0f1c17; font-weight: 700; border: none; border-radius: 8px;
  padding: 10px 20px; cursor: pointer; font: inherit; font-weight: 700; font-size: .95rem; transition: .15s;
}
button:hover:not(:disabled) { filter: brightness(1.08); }
button:disabled { opacity: .42; cursor: not-allowed; }
button.ghost { background: var(--card-2); color: var(--text); font-weight: 500; border: 1px solid var(--line); }
button.ghost:hover:not(:disabled) { border-color: var(--line-2); }
button.link { background: none; border: none; color: var(--accent-2); padding: 4px 6px; font-weight: 500; text-decoration: underline; }
.grow { flex: 1; }

/* ---------- progress ---------- */
.bar { background: var(--bg-sunk); border-radius: 8px; height: 10px; overflow: hidden; margin-top: 14px; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .35s; }
.status { color: var(--muted); font-size: .88rem; margin-top: 8px; min-height: 1.2em; }
.status.err { color: var(--danger); }

/* ---------- queue ---------- */
.queue { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.queue li {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--bg-sunk); border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; transition: .15s;
}
.queue li:hover { border-color: var(--line-2); }
.queue li[aria-selected="true"] { border-color: var(--accent); background: #1a2028; }
.queue .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.queue .st { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.queue .st.done { color: var(--ok); }
.queue .st.error { color: var(--danger); }
.queue .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); flex: none; }
.queue .dot.busy { background: var(--accent-2); animation: pulse 1.1s infinite; }
.queue .dot.done { background: var(--ok); }
.queue .dot.error { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button {
  background: none; border: none; border-bottom: 2px solid transparent; color: var(--muted);
  padding: 8px 12px; font-weight: 600; font-size: .9rem; border-radius: 0;
}
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- result ---------- */
textarea {
  width: 100%; min-height: 320px; background: var(--bg-sunk); color: var(--text);
  border: 1px solid #33334a; border-radius: 10px; padding: 14px;
  font: inherit; font-size: .93rem; line-height: 1.6; resize: vertical;
}
.md-preview {
  background: var(--bg-sunk); border: 1px solid #33334a; border-radius: 10px;
  padding: 18px; min-height: 320px; max-height: 640px; overflow: auto; font-size: .93rem;
}
.md-preview h1, .md-preview h2, .md-preview h3 { margin: 14px 0 8px; line-height: 1.3; }
.md-preview h1 { font-size: 1.3rem; } .md-preview h2 { font-size: 1.12rem; } .md-preview h3 { font-size: 1rem; }
.md-preview p, .md-preview ul, .md-preview ol { margin: 8px 0; }
.md-preview ul, .md-preview ol { padding-left: 22px; }
.md-preview code { font-family: var(--mono); background: #00000055; padding: 1px 5px; border-radius: 4px; font-size: .88em; }
.md-preview table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: .9em; }
.md-preview th, .md-preview td { border: 1px solid var(--line-2); padding: 7px 10px; text-align: left; }
.md-preview th { background: #ffffff0a; }
.pages { display: flex; flex-direction: column; gap: 12px; max-height: 640px; overflow: auto; }
.pages section { background: var(--bg-sunk); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.pages h3 { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; margin-bottom: 8px; }
.pages pre { white-space: pre-wrap; word-break: break-word; font: inherit; font-size: .9rem; }

/* ---------- invoice ---------- */
.inv-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; background: #8ef0d31a; color: var(--accent);
  border: 1px solid #8ef0d344; border-radius: 999px; padding: 5px 13px; font-size: .88rem; font-weight: 600;
}
.chip.low { background: #ffcf7a1a; color: var(--warn); border-color: #ffcf7a44; }
.conf { font-size: .78rem; color: var(--muted); font-weight: 500; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
.field input, .field select { width: 100%; min-width: 0; }
.field.total input { font-weight: 700; color: var(--accent); font-size: 1.02rem; }
.items { width: 100%; border-collapse: collapse; margin-top: 18px; font-size: .9rem; }
.items th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line);
}
.items td { padding: 8px 10px; border-bottom: 1px solid #ffffff0d; vertical-align: top; }
.items td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.items tr:last-child td { border-bottom: none; }
.notice { border-radius: 9px; padding: 10px 13px; font-size: .87rem; margin-top: 12px; display: flex; gap: 9px; }
.notice.warn { background: #ffcf7a12; border: 1px solid #ffcf7a33; color: var(--warn); }
.notice.err { background: #ff8a9412; border: 1px solid #ff8a9433; color: var(--danger); }
.notice.ok { background: #8ef0d312; border: 1px solid #8ef0d333; color: var(--ok); }
.notice ul { margin: 0; padding-left: 18px; }

/* ---------- drive ---------- */
.drive-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.who { display: flex; align-items: center; gap: 9px; font-size: .9rem; color: var(--muted); }
.who img { width: 26px; height: 26px; border-radius: 50%; }
.who b { color: var(--text); font-weight: 600; }

.drive-section { margin-top: 16px; }
.drive-section h3 {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 600; margin-bottom: 9px;
}
/* Selectable cards rather than a row of bare ticks: the choice is the point,
   and a bare checkbox next to grey text reads as decoration. */
.drive-opts { display: flex; gap: 9px; flex-wrap: wrap; }
.drive-opts label {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--bg-sunk); border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 13px; font-size: .87rem; color: var(--muted); transition: .15s;
}
.drive-opts label:hover { border-color: var(--line-2); color: var(--text); }
.drive-opts label:has(input:checked) { border-color: #8ef0d355; background: #8ef0d310; color: var(--text); }
.drive-opts label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.drive-opts .why { color: var(--warn); font-size: .78rem; }
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

/* ---------- saved results ---------- */
.saved { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.saved-doc { background: var(--bg-sunk); border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; }
.saved-doc .top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.saved-doc .nm { font-weight: 600; font-size: .9rem; color: var(--text); }
.saved-doc .path { color: var(--muted); font-size: .82rem; }
.saved-doc .path b { color: var(--text); font-weight: 500; }
.tick { color: var(--ok); font-weight: 700; }
.chips { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
/* Inline-flex so the focus ring hugs the link instead of drawing a full-width
   box across the card. */
.chip-link {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 11px; font-size: .83rem; color: var(--accent-2);
  text-decoration: none; transition: .15s;
}
.chip-link:hover { border-color: var(--accent); color: var(--accent); }
.chip-link .ico { font-size: .95em; }
.saved-doc .bar { margin-top: 8px; height: 6px; }

/* ---------- layout ---------- */
.split { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }
.hidden { display: none !important; }
footer { color: #555570; font-size: .8rem; text-align: center; margin-top: 28px; }
footer a { color: #6b6b8a; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
