:root {
    --ink: #17231d;
    --muted: #66736c;
    --forest: #164f3a;
    --forest-dark: #0f3b2b;
    --mint: #dcebe3;
    --paper: #fffef9;
    --sand: #f3f0e8;
    --line: #d9ded9;
    --danger: #a43f35;
    --shadow: 0 18px 50px rgba(25, 48, 37, .12);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: #f7f8f5; }
a { color: var(--forest); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.2rem, 5vw, 4.7rem); line-height: .98; letter-spacing: -.04em; }
h2 { font-family: Georgia, "Times New Roman", serif; font-size: 2.4rem; }

.app-header { min-height: 82px; padding: 14px clamp(20px, 5vw, 72px); display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,252,.94); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand strong { font-family: Georgia, serif; font-size: 1.35rem; }
.brand small { color: var(--muted); font-size: .72rem; letter-spacing: .04em; }
.brand-mark { width: 44px; height: 44px; border-radius: 14px 14px 14px 4px; display: inline-grid; place-items: center; background: var(--forest); color: white; font-family: Georgia, serif; font-weight: 700; font-size: 1.15rem; box-shadow: 0 8px 18px rgba(22,79,58,.22); }
.brand-mark.large { width: 66px; height: 66px; font-size: 1.55rem; margin-bottom: 20px; }
.app-header nav { display: flex; gap: 20px; align-items: center; }
.app-header nav > a { text-decoration: none; font-weight: 650; color: var(--ink); }
.app-header form { margin: 0; }
.app-main { min-height: calc(100vh - 82px); }

.hero { min-height: 410px; padding: clamp(62px, 8vw, 110px) clamp(24px, 8vw, 130px); display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(260px, .65fr); align-items: center; gap: 40px; color: white; background: radial-gradient(circle at 77% 25%, rgba(157,199,177,.35), transparent 25%), linear-gradient(135deg, #0e3c2b, #1b5c43); overflow: hidden; }
.hero h1 { max-width: 820px; }
.hero p { max-width: 640px; font-size: 1.15rem; color: #dbe8e0; }
.eyebrow { display: block; margin-bottom: 10px; color: #6e9a84; font-size: .76rem; text-transform: uppercase; letter-spacing: .18em; font-weight: 800; }
.hero .eyebrow { color: #a9ccb9; }
.hero-art { position: relative; height: 260px; }
.paper { position: absolute; width: 180px; aspect-ratio: 210/297; border-radius: 4px; background: #fffef8; box-shadow: 0 25px 50px rgba(0,0,0,.25); }
.paper-back { right: 32px; top: 0; transform: rotate(10deg); opacity: .66; }
.paper-front { right: 76px; top: 10px; transform: rotate(-5deg); padding: 34px 25px; }
.paper-front span { display: block; height: 6px; margin-bottom: 15px; background: #d7e2dc; border-radius: 10px; }
.paper-front span:nth-child(2) { width: 72%; }
.paper-front i { display: block; width: 36px; height: 36px; margin: 45px auto 0; border-radius: 50%; background: var(--forest); position: relative; }
.paper-front i::after { content: "✓"; color: white; position: absolute; inset: 0; display: grid; place-items: center; font-style: normal; }

.catalog-section { max-width: 1280px; margin: 0 auto; padding: 70px 28px 100px; }
.section-heading, .form-toolbar, .designer-header { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 32px; }
.section-heading h2 { margin-bottom: 0; }
.search-box { width: min(360px, 100%); display: flex; align-items: center; gap: 8px; padding: 0 14px; background: white; border: 1px solid var(--line); border-radius: 13px; }
.search-box input { width: 100%; padding: 13px 0; border: 0; outline: 0; background: transparent; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 22px; }
.template-card { background: white; border: 1px solid #e4e8e4; border-radius: 22px; padding: 25px; display: grid; grid-template-columns: auto 1fr; gap: 18px; box-shadow: 0 8px 26px rgba(24,55,40,.05); transition: transform .2s, box-shadow .2s; }
.template-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.template-card .button { grid-column: 1 / -1; justify-content: space-between; }
.template-icon { width: 54px; height: 64px; border: 1px solid #bcd1c5; border-radius: 7px; display: grid; place-items: center; background: #f5faf7; color: var(--forest); font-size: 1.3rem; }
.template-content h3 { margin: 2px 0 7px; font-family: Georgia, serif; font-size: 1.35rem; }
.template-content p { color: var(--muted); min-height: 48px; }
.template-meta { display: flex; gap: 15px; color: #7c8881; font-size: .78rem; }

.button { border: 0; border-radius: 11px; padding: 11px 17px; display: inline-flex; align-items: center; justify-content: center; gap: 10px; text-decoration: none; font-weight: 750; transition: .18s; }
.button.primary { color: white; background: var(--forest); }
.button.primary:hover { color: white; background: var(--forest-dark); }
.button.subtle { color: var(--forest); background: #edf4f0; }
.button.danger { color: white; background: var(--danger); }
.button.full { width: 100%; }
.link-button { padding: 5px; border: 0; background: none; color: var(--forest); text-decoration: underline; }
.danger-text { color: var(--danger); }
.back-link { display: inline-block; margin-bottom: 12px; color: var(--muted); text-decoration: none; }

.login-shell { min-height: calc(100vh - 82px); display: grid; place-items: center; padding: 45px 20px; background: radial-gradient(circle at 20% 0, #dcebe3, transparent 30%), var(--sand); }
.login-card { width: min(460px, 100%); padding: 42px; text-align: center; background: rgba(255,255,252,.95); border: 1px solid white; border-radius: 25px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 3rem; }
.stack-form, .designer-sidebar { display: grid; gap: 15px; text-align: left; }
label { display: grid; gap: 7px; font-size: .83rem; font-weight: 750; color: #4d5b54; }
input, select, textarea { width: 100%; min-height: 43px; padding: 10px 12px; color: var(--ink); background: white; border: 1px solid #cbd3ce; border-radius: 9px; outline: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--forest); box-shadow: 0 0 0 3px rgba(22,79,58,.12); }
textarea { min-height: 85px; resize: vertical; }
.reset-form { margin: 16px 0; }
.alert { max-width: 1280px; margin: 18px auto; padding: 13px 16px; border-radius: 11px; }
.alert.error { color: #762d25; background: #f9e7e4; border: 1px solid #ebc2bd; }
.alert.success { color: #194d36; background: #e1f2e8; border: 1px solid #bdddc9; }
.alert.info { color: #305069; background: #e8f1f7; border: 1px solid #c6dbe9; }

.form-toolbar, .designer-header { max-width: 1400px; margin: 0 auto; padding: 38px 28px 24px; align-items: center; }
.form-toolbar h1, .designer-header h1 { margin-bottom: 8px; font-size: clamp(2.1rem, 4vw, 3.5rem); }
.form-toolbar p, .designer-header p { margin-bottom: 0; color: var(--muted); }
.toolbar-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.import-button { position: relative; overflow: hidden; }
.import-button input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.form-stage, .designer-workspace { padding: 35px; overflow: auto; background: #e5e9e5; }
.form-stage { display: grid; gap: 42px; }
.form-page-shell { min-width: min-content; }
.form-page-label { width: min(210mm, 92vw); margin: 0 auto 8px; color: var(--muted); font-size: .76rem; font-weight: 750; }
.form-bottom-actions { display:flex; justify-content:flex-end; gap:12px; width:min(210mm, 92vw); margin:24px auto 0; }
.filename-placeholders { display:flex; flex-wrap:wrap; gap:6px; }
.filename-placeholders button { border:1px solid var(--line); border-radius:999px; background:#fff; padding:5px 8px; color:var(--ink); font-size:.72rem; }
.filename-example { display:block; color:var(--muted); overflow-wrap:anywhere; }
.field-warning { display:block; color:#9b2c2c; font-weight:700; }
.a4-page { position: relative; width: min(210mm, 92vw); aspect-ratio: 210 / 297; margin: 0 auto; background: var(--paper); box-shadow: 0 15px 45px rgba(25,42,33,.18); }
.form-field { position: absolute; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-field > label:not(.checkbox-field) { flex: 0 0 auto; line-height: 1.2; font-size: clamp(.45rem, 1.1vw, .78rem); }
.form-field input, .form-field select, .form-field textarea { flex: 1 1 0; min-height: 0; height: auto; padding: 4px 7px; line-height: 1.25; font-size: clamp(.48rem, 1.2vw, .86rem); border-radius: 3px; }
.form-field select { padding-block: 0; line-height: normal; }
.form-field h2 { margin: 0; font-size: clamp(.8rem, 2.4vw, 1.8rem); }
.static-form-text { width: 100%; height: 100%; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; font-size: clamp(.55rem, 1.5vw, 1rem); line-height: 1.35; }
.form-field.line, .form-field.rectangle, .form-field.image { pointer-events: none; }
.form-line { width: 100%; align-self: center; margin: auto 0; display: block; min-height: 1px; }
.form-rectangle { width: 100%; height: 100%; display: block; border-style: solid; }
.form-image { width: 100%; height: 100%; display: block; object-fit: contain; }
.checkbox-field { display: flex; grid-template-columns: auto 1fr; flex-direction: row; align-items: center; gap: 9px; }
.checkbox-field input { width: 20px; height: 20px; flex: 0 0 auto; }
.checkbox-field.compact { font-size: .82rem; }
.radio-group { min-width: 0; height: 100%; margin: 0; padding: 0; border: 0; }
.radio-group legend { padding: 0; line-height: 1.2; font-size: clamp(.45rem, 1.1vw, .78rem); font-weight: 750; color: #4d5b54; }
.radio-options { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.radio-option { display: inline-flex; grid-template-columns: none; flex-direction: row; align-items: center; gap: 5px; font-size: clamp(.48rem, 1.2vw, .86rem); }
.radio-option input { flex: 0 0 auto; width: 17px; height: 17px; padding: 0; }
.signature-wrap { height: calc(100% - 22px); min-height: 54px; border: 1px solid #9eaaa3; background: white; position: relative; }
.signature-wrap canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.signature-clear { position: absolute; top: 4px; right: 4px; border: 0; border-radius: 5px; background: rgba(255,255,255,.85); color: var(--danger); font-size: .65rem; }

.designer-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); min-height: 900px; border-top: 1px solid var(--line); }
.designer-sidebar { align-content: start; padding: 25px; background: white; border-right: 1px solid var(--line); }
.designer-sidebar hr { width: 100%; border: 0; border-top: 1px solid var(--line); }
.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.tool-grid button { padding: 10px 7px; border: 1px solid #cfdbd4; border-radius: 8px; background: #f6faf7; color: var(--forest); font-size: .78rem; font-weight: 700; }
.property-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.property-grid .full { grid-column: 1 / -1; }
.text-style-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.style-toggle { min-height: 38px; padding: 7px; display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 6px; background: #f6faf7; border: 1px solid #cfdbd4; border-radius: 7px; font-size: .72rem; }
.style-toggle input { width: 16px; height: 16px; min-height: 0; padding: 0; }
.layer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.layer-actions button { padding: 8px; border: 1px solid #cfdbd4; border-radius: 7px; background: white; color: var(--forest); font-size: .75rem; }
.designer-workspace { min-width: 0; position: relative; }
.page-toolbar { width: min(210mm, 92vw); margin: 0 auto 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.page-tabs { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.page-tab, .page-add, .page-actions button { padding: 8px 11px; border: 1px solid #c8d2cc; border-radius: 8px; color: var(--forest); background: rgba(255,255,255,.8); font-size: .76rem; font-weight: 750; }
.page-tab.active { color: white; border-color: var(--forest); background: var(--forest); }
.page-add { width: 34px; padding-inline: 0; font-size: 1rem; }
.page-actions { display: flex; gap: 7px; }
.designer-hint { text-align: center; color: var(--muted); font-size: .82rem; }
.designer-page.grid-visible {
    background-color: var(--paper);
    background-image:
        linear-gradient(to right, rgba(22,79,58,.11) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(22,79,58,.11) 1px, transparent 1px);
    background-size: var(--grid-x) var(--grid-y);
}
.designer-field { position: absolute; overflow: hidden; padding: 4px 6px; display: flex; flex-direction: column; align-items: start; text-align: left; color: var(--forest); background: rgba(220,235,227,.62); border: 1px dashed #569076; touch-action: none; }
.designer-field.selected { overflow: visible; border: 2px solid var(--forest); background: rgba(192,222,205,.8); box-shadow: 0 0 0 3px rgba(22,79,58,.12); z-index: 10; }
.designer-field.selected:not(.primary-selected) { border-style: dashed; box-shadow: 0 0 0 2px rgba(22,79,58,.08); }
.designer-field small { opacity: .7; font-size: clamp(.38rem, .8vw, .62rem); }
.designer-field span { font-size: clamp(.48rem, 1.1vw, .82rem); font-weight: 700; }
.designer-field.type-line, .designer-field.type-rectangle, .designer-field.type-image { padding: 0; background: transparent; }
.designer-field.type-image img { width: 100%; height: 100%; display: block; object-fit: contain; pointer-events: none; }
.line-preview { width: 100%; height: 0; margin: auto 0; display: block; border-top-style: solid; pointer-events: none; }
.rectangle-preview { width: 100%; height: 100%; display: block; border-style: solid; pointer-events: none; }
.static-text-preview { width: 100%; height: 100%; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.3; pointer-events: none; }
.inline-text-editor { width: 100%; height: 100%; min-height: 0; resize: none; padding: 5px; color: var(--ink); background: rgba(255,255,255,.96); border: 0; border-radius: 0; font-size: clamp(.5rem, 1.2vw, .9rem); line-height: 1.3; touch-action: auto; }
.static-text-property { min-height: 150px; white-space: pre-wrap; }
.field-delete { position: absolute; top: -14px; right: -14px; width: 27px; height: 27px; display: grid; place-items: center; padding: 0; color: white; background: var(--danger); border: 2px solid white; border-radius: 50%; box-shadow: 0 3px 9px rgba(0,0,0,.2); font-size: 1rem; line-height: 1; z-index: 14; touch-action: auto; }
.resize-handle { position: absolute; width: 11px; height: 11px; background: white; border: 2px solid var(--forest); border-radius: 2px; z-index: 13; }
.resize-nw { left: -7px; top: -7px; cursor: nwse-resize; }
.resize-n { left: 50%; top: -7px; transform: translateX(-50%); cursor: ns-resize; }
.resize-ne { right: -7px; top: -7px; cursor: nesw-resize; }
.resize-e { right: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.resize-se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.resize-s { left: 50%; bottom: -7px; transform: translateX(-50%); cursor: ns-resize; }
.resize-sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.resize-w { left: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.designer-context-menu { position: fixed; z-index: 1000; min-width: 185px; padding: 6px; display: grid; gap: 2px; background: white; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.designer-context-menu button { padding: 9px 11px; text-align: left; color: var(--ink); background: transparent; border: 0; border-radius: 6px; font-size: .8rem; }
.designer-context-menu button:hover { background: #edf4f0; }
.modal-backdrop { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 24px; background: rgba(12,28,20,.58); backdrop-filter: blur(3px); }
.import-dialog { width: min(620px, 100%); max-height: 85vh; overflow: auto; padding: 28px; background: white; border-radius: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.3); }
.import-dialog h2 { margin-bottom: 10px; font-size: 2rem; }
.conflict-list { display: grid; gap: 9px; margin: 20px 0; }
.conflict-item { padding: 12px; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; background: #f7f9f6; border: 1px solid var(--line); border-radius: 10px; }
.conflict-item input { width: 20px; height: 20px; min-height: 0; }
.conflict-item strong, .conflict-item small { display: block; }
.conflict-item small { margin-top: 3px; color: var(--muted); font-weight: 400; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.asset-upload small, .muted-small { color: var(--muted); font-weight: 400; font-size: .72rem; }
.asset-library { display: grid; gap: 8px; max-height: 310px; overflow: auto; }
.asset-card { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 9px; align-items: center; padding: 7px; border: 1px solid var(--line); border-radius: 9px; background: #fafbf9; }
.asset-card img { width: 52px; height: 42px; object-fit: contain; background: white; border-radius: 5px; }
.asset-card strong, .asset-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-card strong { font-size: .75rem; }
.asset-card small { color: var(--muted); font-size: .65rem; }
.asset-card button { width: 28px; height: 28px; border: 0; border-radius: 6px; color: var(--danger); background: #f7e9e7; font-size: 1.05rem; }

.preview-page { padding-bottom: 70px; }
.pdf-preview { display: block; width: min(1000px, calc(100% - 40px)); height: 75vh; margin: 25px auto; border: 1px solid var(--line); border-radius: 12px; background: #777; }
.empty-state { max-width: 700px; margin: 80px auto; padding: 45px; text-align: center; background: white; border: 1px solid var(--line); border-radius: 20px; }
.documents-page { max-width: 1280px; margin: 0 auto; padding: 50px 28px 100px; }
.documents-heading { display:flex; justify-content:space-between; align-items:center; gap:24px; margin-bottom:28px; }
.documents-heading h1 { margin-bottom:8px; font-size:clamp(2.1rem, 4vw, 3.5rem); }
.documents-heading p { margin-bottom:0; color:var(--muted); }
.document-summary { display:grid; grid-template-columns:repeat(2, minmax(180px, 280px)); gap:16px; margin-bottom:24px; }
.document-summary article { padding:20px; display:grid; gap:4px; background:white; border:1px solid var(--line); border-radius:14px; }
.document-summary strong { font-family:Georgia, serif; font-size:1.7rem; }
.document-summary span { color:var(--muted); font-size:.8rem; }
.document-send-panel { margin-bottom:24px; padding:18px; background:white; border:1px solid var(--line); border-radius:14px; }
.document-send-panel label { max-width:520px; margin:0; }
.document-send-panel small { color:var(--muted); font-weight:400; font-size:.76rem; }
.document-table-wrap { overflow:auto; background:white; border:1px solid var(--line); border-radius:16px; }
.document-table { width:100%; border-collapse:collapse; }
.document-table th, .document-table td { padding:15px 17px; text-align:left; border-bottom:1px solid var(--line); vertical-align:middle; }
.document-table th { color:var(--muted); background:#f5f7f4; font-size:.76rem; text-transform:uppercase; letter-spacing:.05em; }
.document-table tbody tr:last-child td { border-bottom:0; }
.document-name { max-width:460px; overflow-wrap:anywhere; font-weight:700; }
.document-actions { display:flex; flex-wrap:wrap; gap:7px; }
.document-actions .button { padding:8px 11px; font-size:.75rem; white-space:nowrap; }
.settings-page { max-width:1100px; margin:0 auto; padding:50px 28px 100px; }
.settings-grid { display:grid; grid-template-columns:1fr 1fr; gap:20px; }
.settings-card { padding:25px; display:grid; align-content:start; gap:14px; background:white; border:1px solid var(--line); border-radius:17px; }
.settings-card h2 { margin-bottom:0; font-size:1.65rem; }
.settings-card p { margin-bottom:2px; color:var(--muted); }
.settings-card-wide { grid-column:1 / -1; }
.settings-fields { display:grid; grid-template-columns:1fr 1fr; gap:14px; }
.settings-actions { display:flex; flex-wrap:wrap; gap:10px; }

#blazor-error-ui { display: none; position: fixed; left: 20px; right: 20px; bottom: 20px; z-index: 100; padding: 15px; color: white; background: #7b2c25; border-radius: 10px; }
#blazor-error-ui .dismiss { float: right; color: white; background: none; border: 0; }

@media (max-width: 850px) {
    .hero { grid-template-columns: 1fr; }
    .hero-art { display: none; }
    .section-heading, .form-toolbar, .designer-header { align-items: stretch; flex-direction: column; }
    .toolbar-actions { justify-content: stretch; }
    .toolbar-actions .button { flex: 1; }
    .designer-layout { grid-template-columns: 1fr; }
    .designer-sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
    .page-toolbar { align-items: stretch; flex-direction: column; }
    .documents-heading { align-items:stretch; flex-direction:column; }
    .document-summary { grid-template-columns:1fr 1fr; }
    .settings-grid, .settings-fields { grid-template-columns:1fr; }
    .settings-card-wide { grid-column:auto; }
    .app-header nav > a:not(.admin-link) { display: none; }
}

@media print {
    .app-header, .form-toolbar, .designer-header, .toolbar-actions { display: none !important; }
}
