:root {
  --violet: #7c4dff;
  --violet-deep: #6a3df0;
  --violet-soft: #ece7ff;
  --violet-softer: #f5f2ff;
  --pink: #e84393;
  --ink: #241a3d;
  --muted: #6b6480;
  --card: #ffffff;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow-sm: 0 1px 2px rgba(36, 26, 61, .06), 0 4px 14px rgba(36, 26, 61, .06);
  --shadow-md: 0 8px 28px rgba(93, 61, 240, .14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
               "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #fbf7ff 0%, #fdf9fc 40%, #ffffff 100%);
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------------ topbar -- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid rgba(124, 77, 255, .10);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, #8f6bff, #4fc3f7 60%, #e84393);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 7px 6px; border-radius: 4px;
  background: rgba(255, 255, 255, .85);
  clip-path: polygon(0 100%, 35% 0, 50% 60%, 65% 0, 100% 100%);
}
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: -.2px; }
.lang-select { display: flex; align-items: center; gap: 8px; }
.lang-flag { font-size: 18px; line-height: 1; }
.lang-select select {
  border: 1px solid rgba(124, 77, 255, .25); background: #fff; color: var(--ink);
  border-radius: 10px; padding: 7px 10px; font-size: 13px; cursor: pointer;
}

/* ------------------------------------------------------------------- tabs --- */
.tabs {
  max-width: 980px; margin: 14px auto 0; padding: 0 18px;
  display: flex; justify-content: center;
}
.tab-switch {
  display: inline-flex; gap: 4px; padding: 4px; border-radius: 999px;
  background: rgba(124, 77, 255, .09); border: 1px solid rgba(124, 77, 255, .12);
}
.tab-btn {
  display: inline-flex; align-items: center; gap: 7px; border: none; cursor: pointer;
  font: inherit; font-size: 13.5px; font-weight: 600; color: var(--muted);
  background: none; border-radius: 999px; padding: 9px 18px;
  transition: background .14s ease, color .14s ease, box-shadow .14s ease;
}
.tab-btn:hover { color: var(--violet-deep); }
.tab-btn.active {
  color: #fff; background: linear-gradient(135deg, var(--violet), #9a6bff);
  box-shadow: 0 2px 10px rgba(93, 61, 240, .35);
}
.tab-btn svg { width: 15px; height: 15px; }

/* -------------------------------------------------------------------- page -- */
.page { max-width: 980px; margin: 0 auto; padding: 22px 18px 60px; }

.hero {
  background: linear-gradient(160deg, #efe7ff 0%, #f7e9f5 55%, #fbeef6 100%);
  border-radius: var(--radius-lg); padding: 34px 26px 26px; text-align: center;
  box-shadow: var(--shadow-sm);
}
.hero-title {
  margin: 0 0 12px; font-size: 34px; letter-spacing: -.5px;
  background: linear-gradient(90deg, #7c4dff, #e84393);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub { margin: 0 auto; max-width: 640px; color: var(--muted); font-size: 14px; line-height: 1.75; }
.notice {
  margin: 18px auto 0; max-width: 640px; display: flex; gap: 10px; align-items: flex-start;
  background: #fff5f7; border: 1px solid #ffd7e3; color: #9c2340;
  border-radius: var(--radius-md); padding: 11px 14px; font-size: 12.5px; line-height: 1.65;
  text-align: left;
}
.notice-icon { font-size: 15px; }

/* ---------------------------------------------------------------- regions --- */
.region-card {
  margin-top: 18px; background: var(--card); border-radius: var(--radius-lg);
  padding: 16px; box-shadow: var(--shadow-sm);
}
.region-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.region-btn {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 13px 8px; border: none; cursor: pointer; border-radius: var(--radius-md);
  background: var(--violet-softer); color: var(--ink); font-size: 13px;
  transition: transform .12s ease, background .12s ease, box-shadow .12s ease;
}
.region-btn:hover { background: var(--violet-soft); transform: translateY(-1px); }
.region-btn .flag { font-size: 20px; line-height: 1; }
.region-btn[aria-pressed="true"] {
  background: linear-gradient(135deg, var(--violet), #9a6bff);
  color: #fff; box-shadow: var(--shadow-md);
}

/* -------------------------------------------------------------- categories -- */
.category-bar { margin-top: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 9px; }
.chip {
  border: none; cursor: pointer; border-radius: 999px; padding: 8px 15px;
  background: var(--violet-soft); color: var(--violet-deep); font-size: 12.5px; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--violet); color: #fff; }

/* ------------------------------------------------------------------- list --- */
.list-wrap { margin-top: 16px; }
.search-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.search-row input {
  flex: 1; border: 1px solid rgba(124, 77, 255, .22); border-radius: var(--radius-md);
  padding: 11px 14px; font-size: 13.5px; background: #fff; color: var(--ink);
}
.search-row input:focus { outline: 2px solid rgba(124, 77, 255, .35); }
.count { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

.doc-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.doc-item {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  min-height: 132px; text-align: left; overflow: hidden;
  background: #fff; border: 1px solid rgba(124, 77, 255, .12); border-radius: var(--radius-md);
  padding: 16px 16px 14px; cursor: pointer; font: inherit; color: inherit;
  transition: box-shadow .14s ease, transform .14s ease, border-color .14s ease;
}
/* a thin band of the company's own brand colour, so each card reads as that utility */
.doc-item::before {
  content: ""; position: absolute; inset: 0 auto auto 0; width: 100%; height: 3px;
  background: var(--brand, var(--violet)); opacity: .85;
}
.doc-item:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: rgba(124, 77, 255, .3); }
.doc-item:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }
.doc-icon {
  display: grid; place-items: center; width: 38px; height: 38px; font-size: 19px;
  border-radius: 11px; background: var(--violet-softer); color: var(--violet-deep);
}
.doc-main { min-width: 0; }
.doc-title { display: block; font-size: 14.5px; font-weight: 650; margin-bottom: 4px; letter-spacing: -.1px; }
.doc-desc { display: block; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.doc-meta { display: flex; gap: 6px; align-items: center; margin-top: auto; }
.tag {
  font-size: 11px; padding: 4px 9px; border-radius: 999px;
  background: var(--violet-softer); color: var(--violet-deep); white-space: nowrap;
}
.tag.fake { background: #fff2f5; color: #b0304d; }

/* -------------------------------------------------------------- resources --- */
.resource-card {
  margin-top: 26px; background: #fff; border-radius: var(--radius-lg);
  padding: 18px 16px; box-shadow: var(--shadow-sm);
}
.resource-card h2 { margin: 0 0 12px; font-size: 16px; }
.resource-list { display: flex; flex-direction: column; gap: 9px; }
.resource-item {
  display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink);
  background: var(--violet-softer); border-radius: var(--radius-md); padding: 12px 14px;
  font-size: 13px; transition: background .12s ease;
}
.resource-item:hover { background: var(--violet-soft); }

.footer { max-width: 980px; margin: 0 auto; padding: 22px 18px 40px; color: var(--muted); font-size: 12px; line-height: 1.7; text-align: center; }

/* ------------------------------------------------------------------ modal --- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(36, 26, 61, .45); }
.modal-panel {
  position: relative; width: min(760px, calc(100vw - 32px)); max-height: 86vh; overflow: auto;
  background: #fff; border-radius: var(--radius-lg); padding: 24px; box-shadow: var(--shadow-md);
}
.modal-close {
  position: absolute; top: 12px; right: 14px; border: none; background: none;
  font-size: 24px; cursor: pointer; color: var(--muted); line-height: 1;
}
.modal h3 { margin: 0 0 4px; font-size: 19px; }
.modal .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 16px; }

/* Sample reader: same frame styling as the generator preview, but wider. */
.modal-panel { width: min(1080px, calc(100vw - 32px)); }
.reader-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }


/* Generated bill shown inside the modal. */
.specimen { position: relative; border: 1px solid #e4e0ee; border-radius: 12px; padding: 22px; overflow: hidden; }
.specimen h4 { margin: 0 0 2px; font-size: 17px; }
.specimen table { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 12.5px; }
.specimen td { padding: 7px 6px; border-bottom: 1px solid #efecf6; }
.specimen td:last-child { text-align: right; }
.specimen .total td { font-weight: 700; border-top: 2px solid #d9d3e8; }



/* -------------------------------------------------------------- generator --- */
.generator-section { display: flex; flex-direction: column; gap: 16px; }
.gen-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.gen-title { margin: 0 0 6px; font-size: 26px; letter-spacing: -.4px; }
.gen-sub { margin: 0; max-width: 560px; color: var(--muted); font-size: 13.5px; line-height: 1.7; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  border: 1px solid rgba(124, 77, 255, .22); background: #fff; color: var(--violet-deep);
  border-radius: 10px; padding: 8px 12px; font: inherit; font-size: 12.5px; cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.icon-btn:hover { background: var(--violet-softer); border-color: rgba(124, 77, 255, .4); }

.card { background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
/* min-width: 0 on the children stops the fixed-width bill sheet from pushing
   the grid wider than the page (grid items default to min-width: auto). */
.gen-layout { display: grid; grid-template-columns: minmax(320px, 420px) minmax(0, 1fr); gap: 16px; align-items: start; }
.gen-layout > * { min-width: 0; }

/* form */
.gen-form { padding: 8px 18px 18px; }
.field-set { border: none; margin: 0; padding: 16px 0 4px; border-bottom: 1px solid #f0ecfa; }
.field-set:last-of-type { border-bottom: none; }
.field-set legend {
  padding: 0; font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--violet-deep);
}
.fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-wide { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink); }
.field input[type="text"], .field input[type="number"], .field input[type="date"],
.field textarea, .field select {
  border: 1px solid rgba(124, 77, 255, .22); background: #fff; color: var(--ink);
  border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 13.5px; width: 100%;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.field textarea { font-family: inherit; resize: vertical; line-height: 1.6; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px rgba(124, 77, 255, .16);
}
.field input::placeholder, .field textarea::placeholder { color: #a99fc4; }
.hint { margin: 0; font-size: 11.5px; color: var(--muted); line-height: 1.55; }
.derived {
  margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--violet-softer);
  font-size: 12px; color: #4b3f6b; line-height: 1.75;
}
.derived b { font-weight: 650; color: var(--ink); }

/* usage slider */
.usage-row { display: flex; align-items: center; gap: 12px; }
.usage-row input[type="range"] { flex: 1; accent-color: var(--violet); }
.usage-out {
  min-width: 96px; text-align: right; font-variant-numeric: tabular-nums;
  font-size: 13px; font-weight: 650; color: var(--violet-deep);
}

/* submit + live estimate */
.gen-submit { display: flex; align-items: center; gap: 14px; padding-top: 18px; flex-wrap: wrap; }
.btn-primary {
  border: none; cursor: pointer; font: inherit; font-size: 14px; font-weight: 650; color: #fff;
  background: linear-gradient(135deg, var(--violet), #9a6bff); border-radius: 11px;
  padding: 12px 20px; box-shadow: var(--shadow-md);
  transition: transform .12s ease, filter .12s ease;
}
.btn-primary:hover { transform: translateY(-1px); filter: saturate(1.1); }
.btn-primary:active { transform: translateY(0) scale(.985); }
/* the submit button carries a refresh glyph; it spins once per click */
#genButton { display: inline-flex; align-items: center; gap: 9px; }
#genButton svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2.1;
  stroke-linecap: round; stroke-linejoin: round; }
#genButton.is-busy svg { animation: spin .45s ease; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #genButton.is-busy svg { animation: none; } }
/* the hint belongs to the button, so it sits under the whole row rather than
   colliding with the estimate baseline next to it */
.gen-submit-hint { margin: 10px 0 0; }
.btn-secondary {
  border: 1px solid rgba(124, 77, 255, .28); background: #fff; color: var(--violet-deep);
  cursor: pointer; font: inherit; font-size: 13.5px; font-weight: 600;
  border-radius: 11px; padding: 11px 16px; transition: background .12s ease;
}
.btn-secondary:hover { background: var(--violet-softer); }
.estimate { margin: 0; font-size: 13px; color: var(--muted); }
.estimate strong { display: block; font-size: 21px; font-weight: 700; color: var(--ink); letter-spacing: -.3px; }

/* live preview */
.gen-preview { padding: 16px; position: sticky; top: 84px; }
.preview-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.preview-head h3 { margin: 0; font-size: 15px; }
.preview-meta { font-size: 12px; color: var(--muted); text-align: right; }
/* The bill page is a fixed 210mm sheet, so the frame scales it down instead of
   clipping it: the preview shows the whole page width at any pane width. */
.preview-frame { background: #faf8ff; border: 1px solid #ece6fb; border-radius: var(--radius-md); overflow: hidden; }
/* The bill is a fixed 210mm sheet; scale it into the pane instead of clipping it. */
.preview-frame iframe { display: block; border: 0; background: #fff; transform-origin: top left;
                        width: 794px; height: 1123px;
                        transform: scale(var(--bill-scale, .85)); }
.reader-frame { overflow: hidden; }
.reader-frame iframe { height: calc(1123px * var(--bill-scale, .85)); }
.gen-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

@media (max-width: 980px) {
  .gen-layout { grid-template-columns: 1fr; }
  .gen-preview { position: static; }
}

@media (max-width: 720px) {
  .region-grid { grid-template-columns: repeat(2, 1fr); }
  .hero-title { font-size: 27px; }
  .doc-meta { display: none; }
  .fields { grid-template-columns: 1fr; }
  .tab-switch { width: 100%; }
  .tab-btn { flex: 1; justify-content: center; padding: 9px 10px; }
  .doc-list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
