:root {
    --tp-cyan: #00ced1;
    --tp-cyan-dark: #1db9c3;
    --tp-ink: #333333;
    --tp-muted: #666666;
    --bg: #ffffff;
    --surface: #ffffff;
    --ink: #333333;
    --muted: #666666;
    --line: rgba(0, 0, 0, 0.1);
    --line-strong: rgba(0, 0, 0, 0.15);
    --primary: #00ced1;
    --primary-hover: #1db9c3;
    --primary-soft: rgba(0, 206, 209, 0.08);
    --primary-glow: rgba(0, 206, 209, 0.25);
    --danger: #c0392b;
    --success: #1db9c3;
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 8px 24px rgba(0, 206, 209, 0.12);
    --radius: 12px;
    --topbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    font-family: 'Inter', "Segoe UI", system-ui, sans-serif;
    color: var(--ink);
    background: var(--bg);
}

button, input, select, textarea {
    font: inherit;
}

.hidden { display: none !important; }

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
}

.brand-copy {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.brand-app {
    font-size: 1rem;
    font-weight: 700;
    color: var(--tp-ink);
}

.brand.compact .brand-app { font-size: 0.92rem; }

.brand-by {
    font-size: 0.72rem;
    color: var(--tp-muted);
    letter-spacing: 0.02em;
}

.brand-by strong {
    color: var(--tp-cyan);
    font-weight: 600;
    text-transform: lowercase;
}

.page-layout { display: block; width: 100%; }

.page-layout.has-ads {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 20px;
}

.page-layout--editor {
    display: flex;
    flex: 1;
    min-height: 0;
    align-items: stretch;
}

.ad-rail {
    display: none;
    width: 160px;
    flex-shrink: 0;
    padding: 16px 0;
    position: sticky;
    top: 16px;
    align-self: flex-start;
    min-height: 600px;
}

.ad-slot--bottom.ad-strip,
.ad-slot.ad-strip {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid var(--line);
}

.ad-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 250px;
    padding: 16px;
    border: 2px dashed rgba(0, 206, 209, 0.45);
    border-radius: 12px;
    background: rgba(0, 206, 209, 0.05);
    color: var(--tp-muted);
    font-size: 0.78rem;
    text-align: center;
}

@media (min-width: 1280px) {
    .ad-rail { display: block; }
}

@media (max-width: 1279px) {
    .ad-slot--side_left.ad-rail,
    .ad-slot--side_right.ad-rail { display: none; }
}

body.view-landing { background: #ffffff; }

body.view-landing .page-layout--landing {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 16px;
}

.landing { min-height: 100vh; width: 100%; }

.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 1rem clamp(1.25rem, 4vw, 3rem);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 50;
}

.nav-actions { display: flex; gap: 12px; margin-left: auto; }

.nav-btn {
    padding: 9px 16px;
    border-radius: 8px;
    font-size: 0.92rem;
    cursor: pointer;
    background: transparent;
    text-decoration: none;
    display: inline-block;
}

.nav-btn.ghost {
    border: 0;
    color: var(--tp-muted);
}

.nav-btn.ghost:hover { color: var(--tp-cyan); }

.landing-main {
    max-width: 720px;
    margin: 0 auto;
    padding: 3rem 24px 5rem;
    text-align: center;
    position: relative;
}

.landing-main::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 20%, rgba(0, 206, 209, 0.06) 0%, transparent 65%);
    pointer-events: none;
}

.landing-main h1 {
    position: relative;
    z-index: 1;
    margin: 0;
    font-size: clamp(1.75rem, 4vw, 2.35rem);
    font-weight: 700;
    line-height: 1.2;
}

.landing-sub {
    position: relative;
    z-index: 1;
    margin: 14px auto 36px;
    max-width: 520px;
    color: var(--tp-muted);
    font-size: 1.05rem;
    line-height: 1.5;
}

.upload-card {
    position: relative;
    z-index: 1;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    padding: 8px;
    border: 1px solid var(--line);
}

.file-input-hidden {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 5;
}

.dropzone {
    display: block;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    border: 2px dashed rgba(0, 206, 209, 0.35);
    border-radius: 14px;
    padding: 48px 32px 36px;
    text-align: center;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.dropzone > :not(.file-input-hidden) {
    position: relative;
    z-index: 1;
    pointer-events: none;
}

.dropzone:hover,
.dropzone.dragover {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: 0 8px 20px var(--primary-glow);
}

.dropzone-icon { color: var(--tp-cyan); margin-bottom: 16px; }

.dropzone strong {
    display: block;
    font-size: 1.1rem;
    margin-bottom: 18px;
}

.btn-browse {
    display: inline-block;
    padding: 12px 28px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

.upload-hint {
    display: block;
    margin-top: 20px;
    font-size: 0.82rem;
    color: var(--tp-muted);
}

.status {
    min-height: 1.3rem;
    margin: 12px 16px 8px;
    font-size: 0.9rem;
    color: var(--tp-muted);
}

.status.error { color: var(--danger); }
.status.success { color: var(--success); }

.landing-faq {
    position: relative;
    z-index: 1;
    width: min(720px, 100%);
    margin: 2.5rem auto 0;
    text-align: left;
}

.landing-faq h2 {
    margin: 0 0 1rem;
    font-size: 1.25rem;
}

.landing-faq details {
    margin-bottom: 0.75rem;
    padding: 0.9rem 1rem;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.landing-faq summary {
    cursor: pointer;
    font-weight: 600;
}

.landing-faq p {
    margin: 0.75rem 0 0;
    color: var(--tp-muted);
    line-height: 1.55;
}

.landing-footer {
    position: relative;
    z-index: 1;
    margin-top: 2rem;
    font-size: 0.85rem;
    color: var(--tp-muted);
}

.landing-footer a {
    color: var(--tp-cyan);
    font-weight: 600;
    text-decoration: none;
}

body.view-editor {
    overflow: hidden;
    height: 100vh;
}

.editor-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #f5f7f8;
}

.editor-app .page-layout--editor { background: #f5f7f8; }

.editor-topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    height: var(--topbar-h);
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.topbar-left { justify-self: start; }
.topbar-center { justify-self: center; min-width: 0; }
.topbar-right {
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 6px;
}

.doc-title {
    font-size: 0.9rem;
    color: var(--tp-muted);
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--tp-ink);
    font-size: 0.85rem;
    cursor: pointer;
}

.topbar-btn:hover {
    background: var(--primary-soft);
    border-color: rgba(0, 206, 209, 0.35);
    color: var(--tp-cyan-dark);
}

.btn-done {
    padding: 8px 22px;
    border: 0;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    cursor: pointer;
}

.btn-done:hover {
    background: var(--primary-hover);
    box-shadow: 0 8px 20px var(--primary-glow);
}

.btn-done:disabled {
    opacity: 0.6;
    cursor: wait;
}

.editor-body {
    display: flex;
    flex: 1;
    min-height: 0;
}

.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.workspace-split {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(280px, 42%) minmax(360px, 1fr);
    gap: 16px;
    padding: 16px;
}

.pdf-pane,
.form-pane {
    min-height: 0;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.pdf-pane {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pane-head,
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.pane-head {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}

.pane-head h2,
.card h2 {
    margin: 0;
    font-size: 0.95rem;
}

.pdf-frame {
    flex: 1;
    width: 100%;
    border: 0;
    background: #eef1f2;
}

.extracted-text {
    flex: 1;
    margin: 0;
    padding: 16px;
    overflow: auto;
    white-space: pre-wrap;
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--tp-muted);
    background: #f8fbfb;
}

.text-toggle {
    border: 0;
    background: transparent;
    color: var(--tp-cyan-dark);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.form-pane {
    overflow: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.card {
    padding: 14px 16px 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
}

.badge {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--tp-cyan-dark);
    font-size: 0.68rem;
    font-weight: 600;
    vertical-align: middle;
}

.check-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--tp-muted);
}

.grid {
    display: grid;
    gap: 10px 12px;
    margin-top: 12px;
}

.grid.two { grid-template-columns: 1fr 1fr; }

.grid label,
.line-row label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--tp-muted);
    text-align: left;
}

.wide { grid-column: 1 / -1; }

input, select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--tp-ink);
    font-weight: 500;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

input.filled { background: rgba(0, 206, 209, 0.05); }

.line-row {
    display: grid;
    grid-template-columns: 1fr 88px 110px 88px 1fr 36px;
    gap: 8px;
    align-items: end;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.line-remove {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 8px;
    background: rgba(192, 57, 43, 0.08);
    color: var(--danger);
    font-size: 1.2rem;
    cursor: pointer;
}

.riepilogo {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--primary-soft);
    font-size: 0.88rem;
    color: var(--tp-ink);
}

.cambio-box {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid rgba(0, 206, 209, 0.35);
    background: var(--primary-soft);
    font-size: 0.88rem;
    color: var(--tp-ink);
    line-height: 1.45;
}

.cambio-box strong {
    display: block;
    margin-bottom: 4px;
}

.cambio-box.error {
    border-color: rgba(192, 57, 43, 0.3);
    background: rgba(192, 57, 43, 0.08);
    color: var(--danger);
}

.editor-toast {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    padding: 10px 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
    font-size: 0.88rem;
    color: var(--tp-muted);
    max-width: min(520px, 90%);
    text-align: center;
    z-index: 10;
}

.editor-toast.error {
    color: var(--danger);
    border-color: rgba(192, 57, 43, 0.3);
    background: rgba(192, 57, 43, 0.08);
}

.editor-toast.success {
    color: var(--tp-cyan-dark);
    border-color: rgba(0, 206, 209, 0.35);
    background: var(--primary-soft);
}

.xml-dialog {
    width: min(860px, 94vw);
    max-height: 80vh;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0;
    box-shadow: var(--shadow-md);
}

.xml-dialog::backdrop { background: rgba(17, 24, 28, 0.45); }

.xml-dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
}

.xml-preview {
    margin: 0;
    padding: 16px;
    max-height: 64vh;
    overflow: auto;
    font-size: 0.78rem;
    line-height: 1.45;
    background: #f8fbfb;
}

@media (max-width: 1100px) {
    .workspace-split {
        grid-template-columns: 1fr;
        grid-template-rows: 280px 1fr;
    }

    .line-row {
        grid-template-columns: 1fr 1fr;
    }

    .line-row .wide { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
    .doc-title { max-width: 140px; }
    .brand-copy { display: none; }
    .grid.two { grid-template-columns: 1fr; }
}

.sign-split {
    grid-template-columns: minmax(360px, 1.2fr) minmax(280px, 0.8fr);
}

.sign-stage {
    position: relative;
    flex: 1;
    overflow: auto;
    background: #eef1f2;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 16px;
}

#pdfCanvas {
    display: block;
    max-width: 100%;
    height: auto;
    box-shadow: var(--shadow-sm);
    background: #fff;
}

.signature-layer {
    position: absolute;
    cursor: move;
    user-select: none;
    border: 1px dashed rgba(0, 206, 209, 0.85);
    box-sizing: border-box;
    background: transparent;
}

.signature-layer.resizing {
    cursor: nwse-resize;
}

.page-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--tp-muted);
}

.sign-upload {
    display: block;
    margin-top: 12px;
    padding: 16px;
    border: 2px dashed rgba(0, 206, 209, 0.35);
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
    font-weight: 600;
    color: var(--tp-cyan-dark);
}

.sign-upload input { display: none; }

.sign-upload:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
}

.id-grid {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin: 0 auto 20px;
    max-width: 720px;
    text-align: left;
}

.id-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.id-card h2 {
    margin: 0 0 12px;
    font-size: 1.05rem;
}

.id-preview {
    min-height: 160px;
    border-radius: 10px;
    border: 2px dashed rgba(0, 206, 209, 0.35);
    background: #f8fbfb center/contain no-repeat;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tp-muted);
    font-size: 0.88rem;
    margin-bottom: 12px;
}

.id-preview.has-image {
    border-style: solid;
    color: transparent;
}

.id-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.id-actions .btn-browse {
    padding: 10px 16px;
    cursor: pointer;
}

.id-title-field {
    position: relative;
    z-index: 1;
    display: block;
    max-width: 520px;
    margin: 4px auto 8px;
    text-align: left;
}

.id-title-field span {
    display: block;
    margin-bottom: 6px;
    font-size: 0.92rem;
    font-weight: 600;
}

.id-title-field input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
}

.id-title-field input:focus {
    outline: 2px solid rgba(0, 206, 209, 0.45);
    border-color: var(--primary);
}

#generateBtn {
    position: relative;
    z-index: 1;
    margin: 8px auto 0;
    display: inline-block;
}

.camera-dialog {
    width: min(640px, 96vw);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    background: #fff;
}

.camera-dialog::backdrop {
    background: rgba(17, 24, 28, 0.5);
}

.camera-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

#cameraVideo {
    width: 100%;
    border-radius: 10px;
    background: #111;
    max-height: 60vh;
}

.camera-actions {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 10px;
}

.crop-hint {
    margin: 0 0 8px;
    color: var(--tp-muted);
    font-size: 0.88rem;
}

.crop-wrap {
    position: relative;
    margin: 0 auto;
    overflow: hidden;
    border-radius: 10px;
    background: #111;
    touch-action: none;
    user-select: none;
}

.crop-wrap img {
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.crop-shade {
    position: absolute;
    background: rgba(17, 24, 28, 0.5);
    pointer-events: none;
}

.crop-box {
    position: absolute;
    box-sizing: border-box;
    border: 2px solid #00ced1;
    cursor: move;
    touch-action: none;
}

.crop-handle {
    position: absolute;
    width: 18px;
    height: 18px;
    background: #00ced1;
    border: 2px solid #fff;
    border-radius: 50%;
    box-sizing: border-box;
}

.crop-handle[data-handle="nw"] { top: -9px; left: -9px; cursor: nwse-resize; }
.crop-handle[data-handle="ne"] { top: -9px; right: -9px; cursor: nesw-resize; }
.crop-handle[data-handle="sw"] { bottom: -9px; left: -9px; cursor: nesw-resize; }
.crop-handle[data-handle="se"] { bottom: -9px; right: -9px; cursor: nwse-resize; }

@media (max-width: 700px) {
    .id-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .nav-actions { display: none; }
    .editor-topbar {
        grid-template-columns: auto 1fr auto;
        gap: 8px;
    }
    .topbar-btn span { display: none; }
}
