:root {
    --bg: #eef2f6;
    --panel: #ffffff;
    --text: #16202a;
    --muted: #5d6b78;
    --line: #d7dee6;
    --shadow: 0 18px 40px rgba(22, 32, 42, 0.08);
    --radius: 18px;
    --header-gap: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}

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

html,
body,
.app-shell,
.workspace,
.page-panel,
.a4-ratio,
.drawing-layer,
.drawing-layer-full,
.drawing-canvas,
.page-image {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.drawing-canvas {
    touch-action: none;
}

.app-shell {
    max-width: 768px;
    margin: 0 auto;
    padding: 18px;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    background: var(--panel);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}

.app-header h1 {
    margin: 8px 0 6px;
    font-size: 28px;
}

.app-header p {
    margin: 0;
    color: var(--muted);
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.btn {
    border: 0;
    border-radius: 12px;
    padding: 12px 16px;
    min-height: 48px;
    cursor: pointer;
}

.btn-primary {
    background: #111827;
    color: #fff;
}

.btn-secondary {
    background: #dfe6ec;
    color: #16202a;
}

.app-main {
    display: block;
}

.app-main--stacked .workspace {
    width: 100%;
}

.workspace {
    background: var(--panel);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
}

.page-panel {
    display: block;
    margin-bottom: 26px;
}

.page-panel:last-child {
    margin-bottom: 0;
}

.page-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin: 0 auto 10px;
    width: min(100%, 900px);
}

.page-toolbar-title {
    font-weight: 700;
    color: #24313c;
}

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

.btn-small {
    min-height: 40px;
    padding: 9px 12px;
    border-radius: 10px;
}

.a4-ratio {
    position: relative;
    width: min(100%, 900px);
    aspect-ratio: 210 / 297;
    margin: 0 auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
}

.page-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    user-select: none;
}

.field-layer,
.drawing-layer,
.signature-layer {
    position: absolute;
    inset: 0;
}

.field {
    position: absolute;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field span {
    font-size: 0.84rem;
    font-weight: 700;
    color: #24313c;
    background: rgba(255,255,255,0.72);
    padding: 2px 6px;
    border-radius: 8px;
    width: fit-content;
    backdrop-filter: blur(2px);
	visibility: hidden;
}

.field .checkbox-row span {
	visibility: visible !important;
}

.field input[type="text"],
.field input[type="date"] {
    min-height: 30px;
    border: 1px solid rgba(17,24,39,0.15);
    border-radius: 0px;
    background: rgba(255,255,255,0.85);
    padding: 0px;
}

.field input[type="checkbox"] {
    width: 11px;
    height: 11px;
    margin-top: 2px;
}

.drawing-layer {
    left: 5%;
    right: 5%;
    bottom: 3%;
}

.drawing-layer-full {
    top: 5%;
    left: 5%;
    right: 5%;
    bottom: 4.1%;
    height: auto !important;
}

.signature-layer {
    left: 54%;
    right: 5%;
    bottom: 5%;
    top: auto;
    height: 10%;
}

.drawing-label {
    position: absolute;
    top: -30px;
    left: 0;
    padding: 4px 8px;
    border-radius: 8px;
    background: rgba(255,255,255,0.78);
    font-size: 13px;
    font-weight: 700;
    color: #24313c;
}

.drawing-canvas {
    width: 100%;
    height: 100%;
    display: block;
    border: 2px dashed rgba(17,24,39,0.25);
    border-radius: 14px;
    background: rgba(255,255,255,0.03);
    touch-action: none;
}

.signature-canvas {
    border-style: solid;
    background: rgba(255,255,255,0.22);
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    min-width: 240px;
    max-width: 360px;
    padding: 14px 16px;
    border-radius: 14px;
    background: #111827;
    color: #fff;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transform: translateY(14px);
    transition: opacity .2s ease, transform .2s ease;
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 980px) {
    .app-main {
        grid-template-columns: 1fr;
    }

    .page-nav {
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .page-tab {
        flex: 1 1 120px;
    }

    .app-header {
        flex-direction: column;
    }
}

.field-checkbox-group {
    margin: 0;
    padding: 0;
    border: 0;
}

.field-checkbox-group legend {
    font-size: 13px;
    font-weight: 700;
    color: #24313c;
    background: rgba(255,255,255,0.72);
    padding: 2px 6px;
    border-radius: 8px;
    width: fit-content;
    backdrop-filter: blur(2px);
    margin-bottom: 6px;
	display: none;
}

.checkbox-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 6.5px;
    align-items: center;
}

.checkbox-chip {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    min-height: 42px;
    white-space: nowrap;
}

.checkbox-chip input {
    width: 20px;
    height: 20px;
    margin: 0;
}

@media (max-width: 900px) {
    .app-header, .page-toolbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-toolbar-actions, .header-actions {
        width: 100%;
    }

    .checkbox-row {
        flex-wrap: wrap;
    }
}
