:root {
    --primary-color: #0066cc;
    --bg-color: #f5f7fa;
    --panel-bg: #ffffff;
    --border-color: #dcdfe6;
    --section-kf: #2980b9;
    --section-ds: #16a085;
}

body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    color: #333;
}

/* 申請処理中ローディングオーバーレイ */
.submit-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.55);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.submit-overlay-inner {
    background: #ffffff;
    border-radius: 12px;
    padding: 40px 56px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.submit-overlay-inner p {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #2c3e50;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner {
    width: 48px;
    height: 48px;
    border: 5px solid #dcdfe6;
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* 認証完了まで画面全体を覆い隠す全画面ブロック用レイヤー */
.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #ffffff;
    z-index: 9999; /* 画面最前面に配置 */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

header {
    background-color: #2c3e50;
    color: white;
    padding: 15px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.main-container {
    display: flex;
    flex: 1;
    padding: 25px;
    gap: 25px;
    overflow: hidden;
}

.form-panel {
    flex: 0.7;
    background: var(--panel-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 35px;
    box-shadow: 0 2px 12px 0 rgba(0,0,0,0.05);
    overflow-y: auto;
}

.preview-panel {
    flex: 1.3;
    background: var(--panel-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-shadow: 0 2px 12px 0 rgba(0,0,0,0.05);
    overflow: hidden;
    position: relative;
}

.section-title {
    font-size: 16px;
    margin: 0 0 20px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid #ccc;
}

.title-kf { color: var(--section-kf); border-image: linear-gradient(to right, var(--section-kf) 30%, #ddd 30%) 1; }
.title-ds { color: var(--section-ds); border-image: linear-gradient(to right, var(--section-ds) 30%, #ddd 30%) 1; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-sub-label {
    font-size: 11px;
    font-weight: bold;
    color: #95a5a6;
    text-align: left;
    margin-top: 15px;
    margin-bottom: 2px;
    letter-spacing: 0.5px;
    line-height: 1;
}

.field-divider {
    border: 0;
    height: 1px;
    background: #e8ecef;
    margin: 0;
}

label {
    font-weight: bold;
    font-size: 13px;
    color: #555;
}

input, select, textarea {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
}

input[readonly] {
    background-color: #f8f9fa;
    color: #6c757d;
    cursor: not-allowed;
}

input[type="date"] {
    cursor: pointer;
    font-family: inherit;
}

textarea {
    resize: vertical;
    height: 80px;
    min-height: 60px;
    font-family: inherit;
}

/* ツールバーを 595px に固定し中央寄せ（左端をプレビューと完全同期） */
.toolbar {
    display: none; 
    gap: 12px;
    background: #eaeded;
    padding: 12px;
    border-radius: 6px;
    align-items: center;
    width: 595px;
    box-sizing: border-box;
    justify-content: space-between;
    margin: 0 auto;
}

.tool-buttons-group {
    display: flex;
    gap: 8px;
}

.draggable-tool {
    padding: 8px 14px;
    background: white;
    border: 1px solid #7f8c8d;
    cursor: pointer;
    border-radius: 4px;
    font-size: 12px;
    user-select: none;
    font-weight: bold;
}

.draggable-tool:hover {
    background: #e0f0ff;
}

.btn-back-list {
    background: #7f8c8d;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
}

/* ヘッダーバーも 595px 幅に統一 */
.preview-header-bar {
    display: none;
    justify-content: flex-end;
    width: 595px;
    margin: 0 auto;
    box-sizing: border-box;
}

.btn-remove-file {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    transition: background 0.2s;
}

.btn-remove-file:hover {
    background: #c0392b;
}

.preview-content-wrapper {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    min-height: 0;
    position: relative;
    align-items: center;
    width: 100%;
}

.pdf-canvas-full {
    width: 100%;
    max-width: 610px; 
    flex: 1.4; 
    position: relative;
    overflow-x: hidden;
    overflow-y: auto; 
    display: none;
    box-sizing: border-box;
    padding-right: 5px;
}

.pdf-pages-container {
    position: relative;
    width: 595px;
    display: flex;
    flex-direction: column;
    gap: 35px;
    margin: 0 auto;
}

.pdf-page-wrapper {
    position: relative;
    width: 595px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.page-ctrl-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #34495e;
    color: white;
    padding: 10px 15px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: bold;
    width: 595px;
    box-sizing: border-box;
}

.btn-add-here {
    background: #2ecc71;
    color: white;
    border: none;
    padding: 8px 18px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    transition: background 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.btn-add-here:hover {
    background: #27ae60;
}

.pdf-page-mock {
    position: relative;
    width: 595px;
    height: 842px;
    background: #ffffff;
    border: 2px solid #333333; 
    box-sizing: border-box;
    flex-shrink: 0;
}

.pdf-render-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.upload-zone {
    width: 595px;
    flex: 1;
    border: 3px dashed #bdc3c7;
    background: #ffffff; 
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 40px;
    cursor: pointer;
    border-radius: 8px;
    margin: 0 auto;
}

.upload-icon {
    font-size: 50px;
    color: #95a5a6;
    margin-bottom: 15px;
}

.json-container {
    width: 595px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    margin: 0 auto;
    gap: 4px;
}

/* 座標サマリー（常時表示） */
.coord-summary {
    background: #1e2027;
    color: #f8f8f2;
    border-radius: 4px;
    padding: 7px 12px;
    font-size: 11px;
    font-family: monospace;
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: center;
    min-height: 30px;
}

.coord-item {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.coord-empty { color: #555; }
.coord-val   { color: #a6e22e; }

/* JSON 折りたたみ */
.json-details {
    width: 100%;
}

.json-details > summary {
    font-size: 11px;
    color: #95a5a6;
    cursor: pointer;
    user-select: none;
    padding: 3px 2px;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 4px;
}

.json-details > summary::before {
    content: '▶';
    font-size: 9px;
    transition: transform 0.15s;
}

.json-details[open] > summary::before {
    transform: rotate(90deg);
}

.json-details > summary:hover { color: #555; }

.json-output {
    background: #272822;
    color: #f8f8f2;
    padding: 12px 15px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 11px;
    white-space: pre-wrap;
    overflow-y: auto;
    margin: 4px 0 0 0;
    max-height: 220px;
}

.placed-item {
    position: absolute;
    cursor: move;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    text-align: center;
    z-index: 5; 
    user-select: none;
}

.item-sign-area {
    background-color: rgba(230, 126, 34, 0.2);
    background-image: linear-gradient(
        to bottom,
        transparent 20%,
        #d35400 20%,
        #d35400 calc(20% + 1px),
        transparent calc(20% + 1px) 80%,
        #d35400 80%,
        #d35400 calc(80% + 1px),
        transparent calc(80% + 1px)
    );
    border: 2px dashed #e67e22;
    color: #d35400;
    width: 240px;
    height: 100px;
    border-radius: 2px;
}
.item-sign { background: rgba(46, 204, 113, 0.9); border: 2px solid #2ecc71; color: #27ae60; width: 110px; height: 45px; border-radius: 2px; }
.item-seal { background: rgba(231, 76, 60, 0.9); border: 2px solid #e74c3c; color: #c0392b; width: 45px; height: 45px; border-radius: 50%; }

.item-frame {
    border: 2px dashed #8e44ad;
    background: transparent;
    cursor: move;
    z-index: 2;
    overflow: hidden;
}

.frame-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background: #8e44ad;
    cursor: se-resize;
    z-index: 3;
}

.toolbar-sep {
    display: inline-block;
    width: 1px;
    height: 24px;
    background: #aaa;
    margin: 0 4px;
    vertical-align: middle;
}

.btn-frame {
    color: #6c3483 !important;
    border-color: #8e44ad !important;
}

.btn-submit {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 16px;
    border-radius: 4px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    margin-top: auto;
    transition: background-color 0.2s, opacity 0.2s;
}

.btn-submit:disabled {
    background-color: #bdc3c7;
    cursor: not-allowed;
    opacity: 0.7;
}

.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s;
}

.modal-overlay.active {
    visibility: visible;
    opacity: 1;
}

.modal-content {
    background: white;
    padding: 25px;
    border-radius: 8px;
    width: 500px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.modal-header {
    font-size: 18px;
    font-weight: bold;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 10px;
    color: #2c3e50;
}

.modal-body {
    overflow-y: auto;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.confirm-section {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 4px;
    border-left: 4px solid #7f8c8d;
}

.confirm-title {
    font-weight: bold;
    margin-bottom: 5px;
    color: #34495e;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    border-top: 1px solid #eee;
    padding-top: 15px;
}

.btn-modal {
    padding: 10px 20px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    font-weight: bold;
}

.btn-modal-close { background: #e0e0e0; border: 1px solid #ccc; color: #333; }
.btn-modal-primary { background: #2ecc71; border: none; color: white; }
.btn-modal-primary:hover { background: #27ae60; }
.btn-modal-frame { background: #8e44ad; border: none; color: white; }
.btn-modal-frame:hover { background: #6c3483; }

/* 枠選択モーダル — カードグリッド */
.frame-picker-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    background: #fafafa;
}
.frame-picker-card:hover {
    border-color: #8e44ad;
    background: #f4eeff;
}
.frame-picker-card.selected {
    border-color: #8e44ad;
    background: #f4eeff;
    box-shadow: 0 0 0 3px rgba(142,68,173,0.25);
}
.frame-picker-preview {
    width: 200px;
    height: 100px;
    object-fit: contain;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: #fff;
}
.frame-picker-label {
    font-size: 13px;
    font-weight: bold;
    color: #6c3483;
}