:root {
  --app-bar-height: 48px;
  --tool-rail-width: 56px;
  --mobile-tabs-height: 58px;
  color-scheme: light;
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17202a;
  background: #dfe3e7;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { overflow-x: clip; }
body { min-height: 100vh; margin: 0; background: #dfe3e7; }
button, input, select { font: inherit; }
button, .file-button, .upload-link { cursor: pointer; }
button { border: 1px solid #c8ced4; border-radius: 8px; padding: 7px 11px; color: #17202a; background: #fff; }
button:hover:not(:disabled), .file-button:hover, .upload-link:hover { background: #edf1f4; }
button:focus-visible, input:focus-visible, select:focus-visible, .file-button:focus-within { outline: 3px solid #72a7d4; outline-offset: 2px; }
button:disabled { cursor: default; opacity: .38; }
.primary { color: #fff; background: #1f5f99; border-color: #1f5f99; }
.primary:hover:not(:disabled) { background: #194f80; }
.quiet { border-color: transparent; background: transparent; }
.danger { color: #9d2520; border-color: #efc3c0; background: #fff7f6; }
.row, .compact-row { display: flex; align-items: center; gap: 8px; }
.spacer, .grow, .rail-spacer { flex: 1; }
.error { color: #b42318; min-height: 1.3rem; }

.auth-card { width: min(390px, calc(100% - 32px)); margin: 11vh auto; padding: 30px; border-radius: 18px; background: #fff; box-shadow: 0 18px 55px #23354a25; }
.auth-mark, .brand { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; color: #fff; background: #1f5f99; font-weight: 800; }
.auth-card h1 { margin: 12px 0 4px; }
.login-hint { color: #586573; }
.auth-card form { display: grid; gap: 12px; margin-top: 22px; }
label { display: grid; gap: 4px; color: #52606d; font-size: 12px; font-weight: 700; }
input, select { min-width: 0; height: 36px; border: 1px solid #c7ced5; border-radius: 7px; padding: 6px 8px; color: #17202a; background: #fff; }

.app-bar { position: fixed; z-index: 20; inset: 0 0 auto; height: var(--app-bar-height); display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid #cbd1d6; background: rgba(255,255,255,.97); box-shadow: 0 1px 8px #24313d10; }
.app-bar #documents { width: min(360px, 32vw); border: 0; font-weight: 650; }
.file-button { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: #edf1f4; font-size: 20px; }
.file-button input, .upload-link input { display: none; }
.compact { padding-inline: 8px; }
.download { white-space: nowrap; }
.account-button { border-color: transparent; white-space: nowrap; }
.account-popover { position: fixed; z-index: 30; top: 43px; right: 10px; padding: 6px; border: 1px solid #c8ced4; border-radius: 9px; background: #fff; box-shadow: 0 8px 28px #24313d30; }
.account-popover button { width: 100%; border: 0; }

.tool-rail { position: fixed; z-index: 15; inset: var(--app-bar-height) auto 0 0; width: var(--tool-rail-width); display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 8px 5px; border-right: 1px solid #c7cdd3; background: #fff; }
.rail-tool { position: relative; width: 44px; min-height: 44px; display: grid; place-items: center; gap: 0; padding: 3px; border-color: transparent; font-size: 18px; background: transparent; }
.rail-tool[aria-expanded="true"] { color: #fff; background: #1f5f99; }
.rail-tool:is(#add-input, #add-output) > span { white-space: nowrap; font-size: 13px; font-weight: 750; }
.rail-tool small { display: none; font-size: 9px; font-weight: 650; }
.zoom-tool { min-height: 32px; }
.zoom-label { width: 48px; color: #586573; font-size: 11px; text-align: center; }

.page-area { min-height: 100vh; display: flex; flex-direction: column; align-items: center; gap: 22px; margin-left: var(--tool-rail-width); padding: calc(var(--app-bar-height) + 26px) 28px 66px; background: #dfe3e7; touch-action: pan-y; transform: translateX(calc(var(--canvas-pan, 0px) + var(--panel-shift, 0px))); cursor: grab; }
.page-area.panning { cursor: grabbing; }
.pdf-page { position: relative; flex: 0 0 auto; max-width: none; background: #fff; box-shadow: 0 4px 18px #23354a35; user-select: none; }
.page-image { width: 100%; height: 100%; display: block; pointer-events: none; }
.field-layer { position: absolute; inset: 0; }
.page-number { position: absolute; z-index: 2; top: 9px; left: 11px; display: grid; place-items: center; min-width: 24px; height: 24px; border-radius: 6px; color: #52606d; background: #ffffffdf; font-size: 11px; font-weight: 700; }
.field { position: absolute; min-width: 8px; min-height: 8px; display: grid; align-content: center; border-radius: 4px; box-shadow: 0 0 0 1px #2a72ad; cursor: move; overflow: visible; touch-action: none; }
.field.output { box-shadow: 0 0 0 1px #8a55a1; }
.field.selected { outline: 3px solid #f39b25; outline-offset: 1px; z-index: 3; }
.field span { display: block; width: 100%; max-height: 100%; white-space: nowrap; overflow: hidden; }
.reference-count { position: absolute; top: calc(var(--badge-size) / -2); right: calc(var(--badge-size) / -2); display: grid; place-items: center; min-width: var(--badge-size); height: var(--badge-size); padding: 0 3px; border: 1.5px solid #fff; border-radius: 99px; color: #fff; background: #1f5f99; font: 700 calc(var(--badge-size) * .56)/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.handle { position: absolute; right: -7px; bottom: -7px; width: 12px; height: 12px; border-radius: 3px; background: #f39b25; cursor: nwse-resize; }

.overlay-panel { position: fixed; z-index: 18; top: var(--app-bar-height); bottom: 0; left: var(--tool-rail-width); width: 300px; padding: 16px; border-right: 1px solid #bbc3ca; background: #fff; box-shadow: 8px 0 28px #24313d24; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; }
.overlay-panel::-webkit-scrollbar { width: 0; }
.panel-head, .section-title { display: flex; align-items: center; gap: 8px; }
.panel-head { margin-bottom: 14px; }
.panel-head > div { display: grid; }
.panel-head small, .section-title { color: #66727e; font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.panel-head strong { font-size: 17px; }
.close-panel { margin-left: auto; border-color: transparent; font-size: 20px; }
#inspector { display: grid; gap: 9px; }
.save-look { width: 100%; margin-top: 4px; color: #fff; border-color: #1f5f99; background: #1f5f99; }
.compact-row > label { min-width: 0; }
.size-control { width: 62px; }
.color-control { width: 46px; }
.color-control input { width: 42px; padding: 3px; }
.check { display: flex; align-items: center; gap: 5px; }
.check input { width: auto; height: auto; }
.compact-row .danger { margin-left: auto; }
.compact-row button { min-height: 44px; }
.selection-hint { margin: 10px 0 16px; color: #687582; }
.panel-section { margin-top: 18px; padding-top: 15px; border-top: 1px solid #e1e5e9; }
.panel-section.first-section { margin-top: 0; padding-top: 0; border-top: 0; }
.section-title { min-height: 30px; }
.section-title button, .upload-link { margin-left: auto; padding: 5px; color: #1f5f99; border: 0; font-size: 11px; font-weight: 750; letter-spacing: 0; }
.chip-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-top: 8px; }
.empty-look { grid-column: 1 / -1; margin: 3px 0; color: #687582; font-size: 12px; }
.style, .font-chip { position: relative; min-width: 0; }
.style > button:first-child, .font-chip { width: 100%; min-height: 52px; padding: 7px; overflow: hidden; border-color: #d1d7dc; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.style > button:first-child { display: grid; align-content: center; gap: 2px; }
.style > button:first-child small { font: 10px/1.1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; opacity: .72; }
.style > button:last-child { position: absolute; top: 1px; right: 1px; padding: 1px 5px; border: 0; color: #8b3330; background: #fffffff0; }
.font-chip.selected, .style > button:first-child.selected { border: 2px solid #1f5f99; }
.page-jump { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.page-jump button { position: relative; aspect-ratio: .72; padding: 0; overflow: hidden; border-color: #ccd2d8; color: #52606d; background: #f5f7f8; font-size: 12px; font-weight: 750; }
.page-jump img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.page-jump span { position: absolute; top: 5px; left: 5px; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: #ffffffe8; pointer-events: none; }
.status-pill { position: fixed; z-index: 20; right: 17px; bottom: 15px; display: flex; gap: 7px; max-width: calc(100vw - 100px); padding: 8px 11px; border: 1px solid #c6ccd2; border-radius: 99px; color: #52606d; background: #fffffff2; box-shadow: 0 4px 15px #24313d22; font-size: 12px; }
.style-dialog { width: min(360px, calc(100% - 28px)); padding: 18px; border: 1px solid #c1c8ce; border-radius: 14px; box-shadow: 0 18px 60px #17202a55; }
.style-dialog::backdrop { background: #17202a55; backdrop-filter: blur(2px); }
.style-dialog form { display: grid; gap: 13px; }
.style-preview { min-height: 74px; display: grid; place-items: center; padding: 12px; border-radius: 9px; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 720px) {
  body.panel-open { overflow: hidden; }
  .app-bar { padding: 0 8px; }
  .brand { width: 27px; }
  .app-bar #documents { width: min(42vw, 190px); }
  .app-bar .compact { display: none; }
  .account-button { width: 34px; padding-inline: 6px; font-size: 0; }
  .account-button::after { content: "•••"; font-size: 15px; }
  .download { padding-inline: 9px; }
  .download span { display: none; }
  .tool-rail { inset: auto 0 0; width: auto; height: var(--mobile-tabs-height); flex-direction: row; justify-content: space-around; gap: 0; padding: 3px 5px; border: 0; border-top: 1px solid #c7cdd3; }
  .rail-spacer, #fit { display: none; }
  .zoom-label { display: block; width: 38px; }
  .zoom-tool { display: grid; width: 34px; }
  .rail-tool { width: 44px; min-height: 48px; font-size: 16px; }
  .rail-tool small { display: block; }
  .page-area { min-height: 100vh; gap: 14px; margin-left: 0; padding: calc(var(--app-bar-height) + 12px) 8px calc(var(--mobile-tabs-height) + 45px); }
  .overlay-panel { inset: auto 0 var(--mobile-tabs-height); width: auto; max-height: min(420px, calc(100vh - var(--app-bar-height) - var(--mobile-tabs-height))); padding: 12px 14px 16px; border: 0; border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px #24313d38; }
  .overlay-panel::before { content: ""; display: block; width: 42px; height: 4px; margin: -3px auto 10px; border-radius: 3px; background: #bdc4ca; }
  .pages-panel { max-height: 55vh; }
  .page-jump { grid-template-columns: repeat(4, 1fr); }
  .status-pill { right: 8px; bottom: calc(var(--mobile-tabs-height) + 8px); }
  .handle { width: 20px; height: 20px; right: -11px; bottom: -11px; }
}
