:root {
  --red: #0b2146;
  --red-dark: #071a36;
  --gold: #f2a52b;
  --gold-soft: #fde6b7;
  --ink: #24282f;
  --muted: #69717d;
  --paper: #fffdf9;
  --canvas: #f3f5f7;
  --line: #dfe3e8;
  --blue: #2459a8;
  --green: #178258;
  --danger: #c82d3a;
  --shadow: 0 14px 38px rgba(18, 31, 49, .10);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; min-height: 100%; }
body { min-height: 100vh; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, a, summary, label { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
img { max-width: 100%; }
input, textarea, select {
  width: 100%;
  border: 1px solid #cfd5dc;
  border-radius: 6px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
textarea { resize: vertical; line-height: 1.75; min-height: 190px; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(36, 89, 168, .12); }
input[type="checkbox"], input[type="radio"], input[type="color"], input[type="file"] { width: auto; }
label { display: grid; gap: 7px; color: #343942; font-size: .9rem; font-weight: 700; min-width: 0; }
button { border: 0; }

.button {
  min-height: 42px;
  padding: 10px 17px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.button.primary { color: white; background: var(--red); }
.button.primary:hover { background: #102f61; }
.button.secondary { color: var(--red); background: white; border-color: #bfc8d4; }
.button.secondary:hover { border-color: var(--red); background: #f8fafc; }
.button:disabled { cursor: wait; opacity: .62; }
.button.full { width: 100%; }

.alert { margin-bottom: 18px; padding: 12px 14px; border-radius: 6px; font-size: .9rem; line-height: 1.5; }
.alert.error { color: #8d1e29; background: #fff1f2; border: 1px solid #efc3c8; }
.alert.success { color: #12633f; background: #edf9f3; border: 1px solid #b9dfcc; }

/* Authentication */
.auth-page { background: #eef1f4; }
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(390px, 43%) 1fr; }
.auth-brand {
  position: relative;
  overflow: hidden;
  padding: clamp(52px, 7vw, 108px);
  background: #fffaf0;
  border-left: 12px solid var(--red);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.auth-brand::after { content: ""; position: absolute; inset: 0 0 auto; height: 9px; background: var(--red); border-bottom: 4px solid var(--gold); }
.brand-rule { width: 58px; height: 5px; background: var(--red); box-shadow: 66px 0 0 var(--gold); margin-bottom: 30px; }
.brand-logo.app-brand-logo { width: 138px; height: 138px; object-fit: contain; margin-bottom: 22px; filter: drop-shadow(0 8px 18px rgba(11,33,70,.12)); }
.brand-kicker, .eyebrow { margin: 0 0 9px; color: var(--blue); font: 800 .74rem/1.2 Arial, sans-serif; }
.auth-brand h1 { margin: 0; color: var(--red-dark); font-size: clamp(2rem, 4vw, 3.4rem); line-height: 1.16; }
.brand-copy { max-width: 540px; margin: 22px 0 0; color: #4c5562; font-size: 1.06rem; line-height: 1.8; }
.brand-footer { margin-top: 54px; padding-top: 17px; border-top: 1px solid #ddd4c3; color: var(--muted); font-size: .84rem; }
.auth-panel { display: grid; place-items: center; padding: 36px; background: #f7f8fa; }
.auth-card { width: min(430px, 100%); padding: 36px; background: white; border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 8px; }
.auth-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 20px; margin-bottom: 26px; }
.auth-heading span { color: var(--red-dark); font-size: 1.42rem; font-weight: 800; }
.auth-heading small { color: var(--muted); font: 700 .68rem/1 Arial, sans-serif; }
.form-stack { display: grid; gap: 17px; }
.auth-switch { margin: 22px 0 0; text-align: center; color: var(--muted); font-size: .88rem; }
.auth-switch a { color: var(--blue); font-weight: 800; text-decoration: none; }
.captcha-row { display: grid; grid-template-columns: 1fr 150px 42px; gap: 9px; align-items: center; }
.captcha-row img { display: block; border: 1px solid #d7dce1; border-radius: 6px; }
.icon-button { width: 42px; height: 42px; border: 1px solid #cfd5dc; border-radius: 6px; background: white; color: var(--blue); font-size: 1.2rem; cursor: pointer; }

/* App shell */
.workspace-page { background: var(--canvas); }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 246px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #0a1d3b;
  color: white;
  display: flex;
  flex-direction: column;
  z-index: 4;
}
.sidebar-brand {
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 0 8px 21px;
  border-bottom: 1px solid rgba(255,255,255,.14);
  text-decoration: none;
}
.sidebar-brand img { width: 46px; height: 46px; object-fit: contain; filter: drop-shadow(0 4px 8px rgba(0,0,0,.2)); }
.sidebar-brand span { font-size: .9rem; font-weight: 800; line-height: 1.45; }
.sidebar nav { display: grid; gap: 6px; padding: 24px 0; }
.nav-item { display: flex; align-items: center; gap: 11px; min-height: 44px; padding: 10px 12px; color: #c9d2df; text-decoration: none; border-radius: 6px; font-size: .9rem; }
.nav-item:hover { color: white; background: rgba(255,255,255,.08); }
.nav-item.active { color: #0a1d3b; background: var(--gold); font-weight: 800; }
.nav-icon { width: 24px; height: 24px; flex: 0 0 24px; display: grid; place-items: center; border: 1px solid currentColor; border-radius: 4px; font-size: .7rem; font-weight: 800; }
.sidebar-user { margin-top: auto; padding: 17px 8px 0; border-top: 1px solid rgba(255,255,255,.14); display: grid; gap: 5px; }
.sidebar-user span { color: #9eacc0; font-size: .73rem; line-height: 1.45; overflow-wrap: anywhere; }
.text-button { padding: 8px 0 0; color: #ffc966; background: transparent; cursor: pointer; text-align: left; font-size: .82rem; }
.workspace { min-width: 0; max-width: 1500px; width: 100%; margin-inline: auto; padding: 32px clamp(24px, 3.4vw, 52px) 58px; }
.workspace-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 24px; padding-bottom: 20px; border-bottom: 1px solid #d5dbe2; }
.workspace-header h1, .document-toolbar h1 { margin: 0; color: var(--red-dark); font-size: clamp(1.65rem, 2.5vw, 2.25rem); line-height: 1.25; }
.workspace-statuses { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.status-badge { flex: none; padding: 8px 11px; border-radius: 5px; background: #eaf5ef; color: var(--green); border: 1px solid #b9dfcc; font-size: .75rem; font-weight: 800; }
.status-badge.ai-ready { background: #edf4ff; color: #124f93; border-color: #bfd4ed; }
.status-badge.local-mode { background: #fff7e4; color: #7b5207; border-color: #ead29a; }
.generation-form { display: grid; gap: 22px; }
.editor-panel, .preview-panel, .history-panel, .admin-section, .pdf-viewer-panel, .document-summary {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 7px 22px rgba(22, 36, 55, .055);
}
.editor-panel { padding: 24px; display: grid; gap: 17px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-width: 0; }
.section-heading > div { display: flex; align-items: center; gap: 10px; min-width: 0; }
.section-heading h2 { margin: 0; color: var(--red-dark); font-size: 1.12rem; }
.section-heading > span, .section-heading a { color: var(--muted); font-size: .76rem; text-decoration: none; }
.section-heading a { color: var(--blue); font-weight: 800; }
.step-number { width: 30px; height: 25px; display: inline-grid; place-items: center; border-radius: 4px; color: var(--red-dark); background: var(--gold-soft); font: 800 .7rem Arial, sans-serif; }

/* Template choice */
.brand-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(245px, 1fr)); gap: 12px; }
.brand-option {
  position: relative;
  min-height: 82px;
  grid-template-columns: 6px 64px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 0;
  border: 1px solid #d9dee5;
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
  overflow: hidden;
}
.brand-option:has(input:checked) { border-color: var(--brand-primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand-primary) 14%, transparent); }
.brand-option input { position: absolute; opacity: 0; pointer-events: none; }
.brand-swatch { align-self: stretch; display: grid; grid-template-rows: 2fr 1fr; }
.brand-swatch i:first-child { background: var(--brand-primary); }
.brand-swatch i:last-child { background: var(--brand-accent); }
.brand-option-logo { width: 64px; height: 48px; display: grid; place-items: center; padding: 4px; background: #fafafa; border: 1px solid #edf0f3; }
.brand-option-logo img { display: block; width: 100%; height: 100%; object-fit: contain; }
.brand-option-copy { display: grid; gap: 5px; min-width: 0; }
.brand-option-copy strong { color: #252a31; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-option-copy small { color: var(--muted); font-size: .7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-option > b { align-self: start; padding: 4px 6px; border-radius: 4px; color: var(--brand-primary); background: color-mix(in srgb, var(--brand-primary) 9%, white); font-size: .64rem; }
.empty-template-access { min-height: 92px; display: grid; place-content: center; gap: 7px; padding: 18px; text-align: center; border: 1px dashed #b9c3cf; background: #f8fafc; color: var(--muted); }
.empty-template-access strong { color: var(--red-dark); font-size: .9rem; }
.empty-template-access span { font-size: .74rem; }

.generator-grid { display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(355px, .88fr); gap: 22px; align-items: start; }
.source-panel { min-width: 0; }
.field-grid { display: grid; grid-template-columns: 1.25fr .75fr; gap: 14px; }
.field-grid.three { grid-template-columns: minmax(210px, 1.3fr) minmax(150px, .7fr) minmax(150px, .65fr); }
.upload-zone {
  position: relative;
  min-height: 104px;
  place-items: center;
  align-content: center;
  gap: 4px;
  padding: 16px;
  border: 1px dashed #aeb8c4;
  border-radius: 7px;
  background: #f8fafc;
  text-align: center;
  cursor: pointer;
}
.upload-zone:hover, .upload-zone.dragging { border-color: var(--blue); background: #f1f6fd; }
.upload-zone input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.upload-zone strong { font-size: .88rem; color: var(--red-dark); }
.upload-zone small { color: var(--muted); font-size: .72rem; font-weight: 400; }
.upload-icon { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--blue); font-size: 1rem; }
.editor-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.privacy-note { color: var(--muted); font-size: .72rem; }

/* Live document preview */
.preview-panel {
  --doc-primary: #d6001c;
  --doc-accent: #c89a3c;
  --doc-paper: #fff7e8;
  position: sticky;
  top: 22px;
  overflow: hidden;
}
.preview-masthead {
  min-height: 92px;
  display: grid;
  grid-template-columns: 1.15fr .9fr auto;
  gap: 13px;
  align-items: center;
  padding: 17px;
  border-top: 7px solid var(--doc-primary);
  border-bottom: 3px solid var(--doc-accent);
  background: #fff;
}
.preview-logo-wrap { min-width: 0; height: 40px; display: flex; align-items: center; }
.preview-logo-wrap img { max-width: 132px; max-height: 38px; object-fit: contain; }
.preview-masthead > div:nth-child(2) { padding-left: 13px; border-left: 1px solid #d9dde2; display: grid; gap: 4px; }
.preview-masthead small { color: var(--doc-primary); font: 700 .52rem Arial, sans-serif; }
.preview-masthead strong { color: var(--ink); font-size: .82rem; overflow-wrap: anywhere; }
.preview-masthead > span { padding: 6px 8px; color: white; background: var(--doc-primary); border-radius: 4px; font-size: .62rem; font-weight: 800; white-space: nowrap; }
.preview-body { min-height: 444px; padding: 30px; background: var(--doc-paper); border-left: 8px solid var(--doc-primary); }
.preview-index { display: inline-grid; place-items: center; width: 37px; height: 27px; color: white; background: var(--doc-primary); border-radius: 4px; font-weight: 800; font-size: .78rem; }
.preview-kicker { margin: 17px 0 4px !important; color: var(--doc-primary) !important; font-size: .68rem !important; font-weight: 800; }
.preview-body h2 { margin: 0 0 9px; color: var(--doc-primary); font-size: 1.52rem; line-height: 1.3; }
.preview-body p { color: #68717c; font-size: .8rem; line-height: 1.75; }
.preview-card-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 27px 0; }
.preview-card-row i { height: 80px; border: 1px solid color-mix(in srgb, var(--doc-accent) 55%, white); border-top: 5px solid var(--doc-primary); background: white; border-radius: 5px; }
.preview-card-row i:nth-child(2) { border-top-color: #176f91; }
.preview-card-row i:nth-child(3) { border-top-color: #178258; }
.preview-table-lines { border: 1px solid color-mix(in srgb, var(--doc-accent) 55%, white); background: white; }
.preview-table-lines i { display: block; height: 38px; border-bottom: 1px solid color-mix(in srgb, var(--doc-accent) 35%, white); }
.preview-table-lines i:first-child { height: 30px; background: var(--doc-primary); }
.preview-table-lines i:last-child { border-bottom: 0; }
.preview-note { padding: 10px 17px; text-align: right; color: var(--muted); background: #fff; font-size: .65rem; }

/* Tables and records */
.history-panel { margin-top: 22px; padding: 23px 24px; }
.table-scroll { margin-top: 17px; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 760px; font-size: .82rem; }
.data-table th { padding: 11px 12px; color: white; background: var(--red); text-align: left; font-size: .74rem; white-space: nowrap; }
.data-table td { padding: 12px; border-bottom: 1px solid #e5e8ec; vertical-align: middle; }
.data-table tbody tr:nth-child(even) { background: #fafbfc; }
.data-table td > strong, .data-table td > small { display: block; }
.data-table td > small { margin-top: 4px; color: var(--muted); font-size: .68rem; }
.template-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; }
.state { display: inline-block; padding: 5px 7px; border-radius: 4px; font-size: .67rem; font-weight: 800; }
.state.ready { color: #146743; background: #e9f6ef; }
.state.processing { color: #7a5811; background: #fff5db; }
.state.failed { color: #9c2631; background: #fff0f1; }
.row-actions { display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.row-actions a, .row-actions button { color: var(--blue); background: none; font-size: .75rem; font-weight: 800; text-decoration: none; cursor: pointer; padding: 0; }
.row-actions form { display: inline; }
.row-actions form:last-child button { color: var(--danger); }
.empty-state { margin-top: 17px; min-height: 128px; display: grid; place-items: center; align-content: center; gap: 7px; color: var(--muted); border: 1px dashed #cbd2da; background: #fafbfc; text-align: center; }
.empty-state strong { color: #3d444e; font-size: .9rem; }
.empty-state span { font-size: .75rem; }

/* Admin */
.admin-workspace { max-width: 1450px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 13px; margin-bottom: 22px; }
.stats-grid > div { position: relative; min-height: 116px; padding: 19px; background: #fff; border: 1px solid var(--line); border-top: 4px solid var(--blue); border-radius: 7px; }
.stats-grid > div:nth-child(2) { border-top-color: var(--green); }
.stats-grid > div:nth-child(3) { border-top-color: var(--gold); }
.stats-grid > div:nth-child(4) { border-top-color: var(--red); }
.stats-grid span, .stats-grid small { display: block; color: var(--muted); font-size: .7rem; }
.stats-grid strong { display: block; margin: 5px 0 3px; color: var(--red-dark); font-size: 1.65rem; }
.admin-section { padding: 24px; margin-bottom: 22px; scroll-margin-top: 18px; }
.settings-row { margin-top: 18px; display: grid; grid-template-columns: minmax(280px, 1fr) 220px auto; align-items: end; gap: 16px; }
.toggle-field { min-height: 60px; grid-template-columns: 42px 1fr; align-items: center; padding: 9px 13px; border: 1px solid #dbe0e6; border-radius: 6px; }
.toggle-field > input { position: absolute; opacity: 0; }
.toggle-control { width: 38px; height: 22px; padding: 2px; border-radius: 12px; background: #b9c0c9; transition: background .2s; }
.toggle-control::after { content: ""; display: block; width: 18px; height: 18px; border-radius: 50%; background: white; box-shadow: 0 1px 4px rgba(0,0,0,.18); transition: transform .2s; }
.toggle-field input:checked + .toggle-control { background: var(--green); }
.toggle-field input:checked + .toggle-control::after { transform: translateX(16px); }
.toggle-field > span:last-child { display: grid; gap: 3px; }
.toggle-field small { color: var(--muted); font-size: .68rem; font-weight: 400; }
.input-suffix { position: relative; display: block; }
.input-suffix input { padding-right: 42px; }
.input-suffix i { position: absolute; top: 50%; right: 12px; transform: translateY(-50%); color: var(--muted); font-style: normal; font-size: .75rem; }
.create-user-row { margin-top: 18px; display: grid; grid-template-columns: 1fr 1fr 180px auto; align-items: end; gap: 13px; padding-bottom: 20px; border-bottom: 1px solid #e2e6eb; }
.create-template-access { min-width: 0; grid-column: 1 / -1; margin: 3px 0 0; padding: 0; border: 0; }
.create-template-access legend { width: 100%; margin-bottom: 9px; color: #303844; font-size: .74rem; font-weight: 800; }
.create-template-access legend small { margin-left: 7px; color: var(--muted); font-size: .66rem; font-weight: 400; }
.permission-checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px; }
.permission-check { position: relative; min-width: 0; min-height: 54px; display: grid; grid-template-columns: 20px minmax(0, 1fr); grid-template-rows: auto auto; align-content: center; column-gap: 9px; padding: 9px 11px; border: 1px solid #d8dee6; border-left: 4px solid var(--permission-color); background: #fff; cursor: pointer; }
.permission-check input { position: absolute; opacity: 0; pointer-events: none; }
.permission-check > span { grid-row: 1 / 3; align-self: center; width: 18px; height: 18px; display: grid; place-items: center; border: 1px solid #aeb8c4; background: #fff; }
.permission-check > span::after { content: ""; width: 8px; height: 4px; border: solid white; border-width: 0 0 2px 2px; transform: rotate(-45deg) translate(1px, -1px); opacity: 0; }
.permission-check input:checked + span { border-color: var(--permission-color); background: var(--permission-color); }
.permission-check input:checked + span::after { opacity: 1; }
.permission-check strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #303844; font-size: .73rem; }
.permission-check small { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .62rem; font-weight: 400; }
.account-table-wrap { margin-top: 0; }
.account-table { min-width: 1000px; table-layout: fixed; }
.account-table th:nth-child(1) { width: 21%; }
.account-table th:nth-child(2) { width: 9%; }
.account-table th:nth-child(3) { width: 10%; }
.account-table th:nth-child(4) { width: 13%; }
.account-table th:nth-child(5) { width: 16%; }
.account-table th:nth-child(6) { width: 14%; }
.account-table th:nth-child(7) { width: 17%; }
.access-summary { display: inline-block; margin-bottom: 3px; padding: 3px 6px; color: var(--blue); background: #edf4fb; border-radius: 4px; font-size: .65rem; font-weight: 800; }
.access-summary.all { color: var(--green); background: #eaf7f2; }
.access-summary.none { color: var(--danger); background: #fff0f1; }
.permission-manager { margin-top: 18px; border-top: 1px solid #e1e6eb; }
.permission-manager-head { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.permission-manager-head strong { color: var(--red-dark); font-size: .82rem; }
.permission-manager-head span, .permission-empty { color: var(--muted); font-size: .7rem; }
.permission-editor-row { display: grid; grid-template-columns: 145px minmax(280px, 1fr) auto; align-items: center; gap: 14px; padding: 13px 0; border-top: 1px solid #edf0f3; }
.permission-account { min-width: 0; display: grid; gap: 4px; }
.permission-account strong { overflow: hidden; text-overflow: ellipsis; color: #303844; font-size: .78rem; }
.permission-account small { color: var(--muted); font-size: .64rem; }
.permission-checks.compact { display: flex; flex-wrap: wrap; gap: 7px; }
.permission-checks.compact .permission-check { min-height: 40px; grid-template-rows: 1fr; grid-template-columns: 18px minmax(110px, auto); padding: 7px 9px; }
.permission-checks.compact .permission-check > span { grid-row: auto; width: 16px; height: 16px; }
.permission-checks.compact .permission-check strong { font-size: .68rem; }
.permission-empty { padding: 15px 0; border-top: 1px solid #edf0f3; }
.muted-text { color: var(--muted); font-size: .72rem; }
.precision-tools { margin-top: 17px; border: 1px solid #dce1e7; border-radius: 6px; background: #fafbfc; }
.precision-tools summary { padding: 13px 15px; color: var(--blue); font-size: .8rem; font-weight: 800; cursor: pointer; }
.precision-tools form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; align-items: end; gap: 13px; padding: 0 15px 15px; }

/* Template editor */
.new-brand-editor { margin-top: 19px; padding: 20px; border: 1px solid #dce1e7; background: #fafbfc; border-radius: 7px; }
.brand-editor-head { display: flex; justify-content: space-between; align-items: center; gap: 18px; padding-bottom: 16px; border-bottom: 1px solid #e0e4e9; }
.brand-editor-head > div { display: grid; gap: 4px; }
.brand-editor-head strong { color: var(--red-dark); }
.brand-editor-head span { color: var(--muted); font-size: .72rem; }
.brand-editor-grid { display: grid; grid-template-columns: 190px minmax(400px, 1fr) 250px; gap: 18px; align-items: stretch; padding-top: 18px; }
.logo-drop { position: relative; height: 100%; min-height: 242px; place-items: center; align-content: center; gap: 7px; padding: 14px; text-align: center; border: 1px dashed #aeb8c4; border-radius: 6px; background: white; cursor: pointer; }
.logo-drop > input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.logo-drop strong { font-size: .78rem; color: var(--blue); }
.logo-drop small { color: var(--muted); font-size: .66rem; font-weight: 400; }
.logo-preview { width: 132px; height: 84px; display: grid; place-items: center; padding: 8px; border: 1px solid #e0e4e8; background: #fff; }
.logo-preview b { color: #abb2bb; letter-spacing: 0; }
.logo-preview img { width: 100%; height: 100%; object-fit: contain; grid-area: 1/1; }
.brand-fields { display: grid; grid-template-columns: repeat(4, minmax(100px, 1fr)); gap: 12px; align-content: start; }
.brand-fields label:nth-child(-n+4) { grid-column: span 2; }
.brand-fields .full-field { grid-column: 1 / -1; }
.color-field { grid-template-columns: 1fr; }
.color-field input { width: 100%; height: 39px; padding: 3px; cursor: pointer; }
.color-field code { color: var(--muted); font: 600 .62rem Arial, sans-serif; }
.mini-pdf-preview {
  --mini-primary: #c41230;
  --mini-accent: #c8a45c;
  --mini-paper: #fffdf8;
  min-height: 300px;
  display: grid;
  grid-template-rows: 64px 1fr 28px;
  overflow: hidden;
  border: 1px solid #d9dee4;
  background: var(--mini-paper);
  box-shadow: 0 8px 20px rgba(23, 35, 53, .09);
}
.mini-pdf-preview > div { display: grid; grid-template-columns: 54px 1fr 7px; align-items: center; gap: 8px; padding: 9px; border-top: 5px solid var(--mini-primary); border-bottom: 2px solid var(--mini-accent); background: white; }
.mini-pdf-preview > div span { width: 50px; height: 32px; display: grid; place-items: center; color: #a4abb4; border: 1px solid #e0e4e9; font: 700 .5rem Arial; }
.mini-pdf-preview > div span img { width: 100%; height: 100%; object-fit: contain; }
.mini-pdf-preview > div b { font-size: .66rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-pdf-preview > div i { width: 7px; height: 28px; background: var(--mini-primary); }
.mini-pdf-preview main { padding: 18px; }
.mini-pdf-preview main small { color: var(--mini-primary); font: 700 .45rem Arial; }
.mini-pdf-preview main strong { display: block; margin: 9px 0 6px; color: var(--mini-primary); font-size: .95rem; }
.mini-pdf-preview main p { margin: 0; color: #727983; font-size: .54rem; }
.mini-pdf-preview main section { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 20px; }
.mini-pdf-preview main section i { height: 49px; background: white; border: 1px solid color-mix(in srgb, var(--mini-accent) 60%, white); border-top: 4px solid var(--mini-primary); }
.mini-pdf-preview footer { padding: 8px; color: #7b818a; background: white; text-align: right; font-size: .42rem; }
.saved-brands { display: grid; gap: 10px; margin-top: 17px; }
.saved-brand { position: relative; border: 1px solid #dce1e7; border-left: 5px solid var(--profile-primary); border-radius: 6px; background: white; }
.saved-brand summary { min-height: 72px; display: grid; grid-template-columns: 96px minmax(170px, 1fr) 100px auto; align-items: center; gap: 14px; padding: 11px 15px; cursor: pointer; list-style: none; }
.saved-brand summary::-webkit-details-marker { display: none; }
.saved-brand-logo { width: 96px; height: 44px; display: grid; place-items: center; padding: 4px; background: #fafafa; border: 1px solid #eceff2; }
.saved-brand-logo img { width: 100%; height: 100%; object-fit: contain; }
.saved-brand summary > span:nth-child(2) { display: grid; gap: 5px; }
.saved-brand summary strong { color: var(--red-dark); font-size: .86rem; }
.saved-brand summary small { color: var(--muted); font-size: .7rem; }
.saved-brand summary > i { height: 9px; background: linear-gradient(90deg, var(--profile-primary) 0 65%, var(--profile-accent) 65%); }
.saved-brand summary > b { color: var(--profile-primary); font-size: .66rem; }
.saved-brand-form { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)); gap: 12px; padding: 18px 15px; border-top: 1px solid #e3e7eb; background: #fafbfc; }
.saved-brand-form > label:nth-child(5), .saved-brand-form > label:nth-child(6) { grid-column: span 2; }
.check-field { display: flex; align-items: center; gap: 8px; min-height: 42px; }
.check-field input { accent-color: var(--blue); }
.saved-brand-actions { display: flex; justify-content: flex-end; align-items: end; }
.delete-brand-form { position: absolute; right: 16px; bottom: 20px; }
.delete-brand-form button { color: var(--danger); background: transparent; font-size: .72rem; font-weight: 800; cursor: pointer; }

/* PDF result */
.document-workspace { max-width: none; }
.document-toolbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 22px; margin-bottom: 20px; }
.document-toolbar > div:first-child { min-width: 0; }
.document-toolbar h1 { overflow-wrap: anywhere; }
.document-toolbar > div:first-child > span { display: block; margin-top: 7px; color: var(--muted); font-size: .78rem; }
.back-link { display: inline-block; margin-bottom: 16px; color: var(--blue); font-size: .78rem; font-weight: 800; text-decoration: none; }
.toolbar-actions { display: flex; gap: 9px; }
.document-layout { display: grid; grid-template-columns: minmax(660px, 1fr) 300px; gap: 19px; align-items: start; }
.pdf-viewer-panel { overflow: hidden; background: #4a4f57; }
.pdf-viewer-panel iframe { display: block; width: 100%; height: calc(100vh - 170px); min-height: 680px; border: 0; }
.document-summary { position: sticky; top: 22px; padding: 22px; }
.summary-label { display: inline-block; padding: 5px 7px; color: var(--red-dark); background: var(--gold-soft); border-radius: 4px; font-size: .68rem; font-weight: 800; }
.document-summary > p { color: #4e5661; font-size: .82rem; line-height: 1.8; }
.document-summary dl { margin: 20px 0; }
.document-summary dl div { padding: 11px 0; border-bottom: 1px solid #e4e7eb; }
.document-summary dt { color: var(--muted); font-size: .66rem; }
.document-summary dd { margin: 5px 0 0; color: #30363e; font-size: .78rem; font-weight: 700; overflow-wrap: anywhere; }
.document-disclaimer { margin: 22px -22px -22px; padding: 13px 22px; color: var(--muted) !important; background: #f7f8fa; font-size: .66rem !important; }

@media (max-width: 1180px) {
  .generator-grid { grid-template-columns: 1fr; }
  .preview-panel { position: static; max-width: 720px; width: 100%; justify-self: center; }
  .brand-editor-grid { grid-template-columns: 170px 1fr; }
  .mini-pdf-preview { grid-column: 1 / -1; width: 260px; justify-self: center; }
  .document-layout { grid-template-columns: 1fr; }
  .document-summary { position: static; }
}

@media (max-width: 980px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { min-height: 330px; padding: 48px 36px 38px; }
  .brand-rule, .brand-footer { display: none; }
  .brand-logo.app-brand-logo { width: 94px; height: 94px; margin-bottom: 12px; }
  .auth-panel { padding: 28px 18px 48px; }
  .app-shell { grid-template-columns: 86px minmax(0, 1fr); }
  .sidebar { padding-inline: 11px; }
  .sidebar-brand { display: block; padding: 0 8px 20px; }
  .sidebar-brand img { width: 48px; height: 48px; margin-inline: auto; }
  .sidebar-brand span, .nav-item { font-size: 0; }
  .nav-item { justify-content: center; }
  .nav-icon { font-size: .7rem; }
  .sidebar-user strong, .sidebar-user span, .text-button { font-size: .65rem; overflow-wrap: anywhere; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-row { grid-template-columns: 1fr 180px; }
  .settings-row .button { grid-column: 1 / -1; justify-self: end; }
  .create-user-row { grid-template-columns: repeat(2, 1fr); }
  .permission-editor-row { grid-template-columns: 120px minmax(240px, 1fr); }
  .permission-editor-row .button { grid-column: 2; justify-self: end; }
  .precision-tools form { grid-template-columns: repeat(2, 1fr); }
  .saved-brand-form { grid-template-columns: repeat(2, 1fr); padding-bottom: 62px; }
}

@media (max-width: 700px) {
  .app-shell { display: block; }
  .sidebar { position: sticky; width: 100%; height: auto; padding: 10px 14px; flex-direction: row; align-items: center; gap: 10px; }
  .sidebar-brand { display: flex; min-height: 44px; padding: 0; border: 0; }
  .sidebar-brand img { width: 38px; height: 38px; margin: 0; }
  .sidebar-brand span { display: none; }
  .sidebar nav { margin-left: auto; padding: 0; display: flex; gap: 4px; }
  .nav-item { min-height: 38px; padding: 7px; }
  .sidebar-user { display: none; }
  .workspace { padding: 22px 14px 42px; }
  .workspace-header { align-items: flex-start; }
  .workspace-statuses { max-width: 180px; }
  .field-grid, .field-grid.three { grid-template-columns: 1fr; }
  .brand-picker { grid-template-columns: 1fr; }
  .editor-panel, .history-panel, .admin-section { padding: 18px; }
  .preview-masthead { grid-template-columns: 1fr auto; }
  .preview-masthead > div:nth-child(2) { display: none; }
  .editor-actions, .brand-editor-head, .document-toolbar { align-items: stretch; flex-direction: column; }
  .editor-actions .button, .brand-editor-head .button { width: 100%; }
  .privacy-note { text-align: center; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .settings-row, .create-user-row, .precision-tools form { grid-template-columns: 1fr; }
  .create-template-access { grid-column: auto; }
  .permission-editor-row { grid-template-columns: 1fr; align-items: stretch; }
  .permission-editor-row .button { grid-column: auto; width: 100%; }
  .permission-checks.compact { display: grid; grid-template-columns: 1fr 1fr; }
  .settings-row .button { grid-column: auto; width: 100%; }
  .brand-editor-grid { grid-template-columns: 1fr; }
  .logo-drop { min-height: 170px; }
  .brand-fields { grid-template-columns: 1fr 1fr; }
  .brand-fields label:nth-child(-n+4), .brand-fields .full-field { grid-column: 1 / -1; }
  .mini-pdf-preview { grid-column: auto; }
  .saved-brand summary { grid-template-columns: 76px 1fr auto; }
  .saved-brand summary > i { display: none; }
  .saved-brand-form { grid-template-columns: 1fr; }
  .saved-brand-form > label:nth-child(5), .saved-brand-form > label:nth-child(6) { grid-column: auto; }
  .saved-brand-actions .button { width: 100%; }
  .document-toolbar { align-items: flex-start; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .button { flex: 1; }
  .pdf-viewer-panel iframe { min-height: 560px; height: 72vh; }
  .captcha-row { grid-template-columns: 1fr 42px; }
  .captcha-row img { grid-row: 2; grid-column: 1; }
}

@media (max-width: 430px) {
  .auth-card { padding: 25px 20px; }
  .auth-brand { min-height: 300px; padding-inline: 25px; }
  .auth-brand h1 { font-size: 1.85rem; }
  .stats-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; }
  .section-heading > span { display: none; }
  .brand-fields { grid-template-columns: 1fr; }
  .brand-fields label:nth-child(-n+4), .brand-fields .full-field { grid-column: auto; }
  .mini-pdf-preview { width: 100%; }
  .saved-brand summary { grid-template-columns: 62px 1fr; }
  .saved-brand summary > b { grid-column: 2; }
  .create-template-access legend small { display: block; margin: 4px 0 0; }
  .permission-manager-head { align-items: flex-start; flex-direction: column; gap: 4px; padding-block: 12px; }
  .permission-checks, .permission-checks.compact { grid-template-columns: 1fr; }
  .toolbar-actions { flex-direction: column; }
}
