/* リセット */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Yu Gothic', sans-serif;
    background: #f5f5f5;
    color: #333;
    overflow: hidden;
}

/* ヘッダー */
.header {
    background: linear-gradient(135deg, #8B4513, #CD853F);
    color: white;
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header-left h1 {
    font-size: 20px;
    margin: 0;
}

.header-center {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-center label {
    font-weight: bold;
}

.header-center select {
    padding: 8px 15px;
    border: 2px solid white;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
    background: white;
    color: #8B4513;
}

/* ボタン */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: white;
    color: #8B4513;
}

.btn-primary:hover {
    background: #f0f0f0;
    transform: translateY(-2px);
}

.btn-secondary {
    background: #ddd;
    color: #333;
}

.btn-secondary:hover {
    background: #ccc;
}

.btn-danger {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    background: #f44336;
    color: white;
}

.btn-danger:hover {
    background: #da190b;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(244, 67, 54, 0.3);
}

/* メインコンテナ */
.main-container {
    display: flex;
    height: calc(100vh - 70px);
}

/* サイドバー */
.sidebar {
    width: 350px;
    background: white;
    border-right: 2px solid #ddd;
    padding: 20px;
    overflow-y: auto;
}

.sidebar h3 {
    font-size: 16px;
    color: #8B4513;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #f0e6d6;
}

/* カテゴリタブ */
.category-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #ddd;
}

.category-tab {
    padding: 6px 12px;
    border: 2px solid #ddd;
    border-radius: 5px;
    background: white;
    color: #666;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.category-tab:hover {
    background: #f0e6d6;
    border-color: #8B4513;
}

.category-tab.active {
    background: #8B4513;
    color: white;
    border-color: #8B4513;
}

/* 画像ライブラリ */
.image-library {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.image-item {
    background: #fafafa;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 8px;
    cursor: grab;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.image-item:hover {
    background: #f0e6d6;
    border-color: #8B4513;
    transform: scale(1.05);
}

.image-item:active {
    cursor: grabbing;
}

.image-item-thumb {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 5px;
    border: 1px solid #ddd;
}

.image-item-name {
    font-size: 11px;
    font-weight: 500;
    color: #555;
    text-align: center;
    word-break: break-all;
    line-height: 1.2;
}

/* エディターエリア */
.editor-area {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

/* 見開きタブ */
.spread-tabs {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.tabs-container {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    flex: 1;
    align-items: flex-start;
}

.tabs-controls {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
}

.tab-item {
    padding: 10px 20px;
    background: #f0f0f0;
    border: 3px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 14px;
    font-weight: bold;
    color: #555;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.tab-item:hover {
    background: #e0e0e0;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.tab-item.active {
    background: #fff;
    color: #8B4513;
    border-color: #8B4513;
    border-width: 4px;
    box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.2);
    transform: scale(1.05);
}

.btn-add-spread {
    padding: 10px 20px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.3s;
}

.btn-add-spread:hover {
    background: #45a049;
    transform: translateY(-2px);
}

/* 見開きコンテナ */
.spread-container {
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: flex-start;
}

.page-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

/* ページキャンバス */
.page-canvas {
    position: relative;
    background: white;
    border: 3px solid #ddd;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    cursor: pointer;
    transition: all 0.3s;
    overflow: hidden;
}

/* A5スリム: 1ページ = 110×210mm */
.page-canvas.size-a5slim {
    width: 330px;  /* 110mm × 3 */
    height: 630px; /* 210mm × 3 */
}

/* B7: 1ページ = 91×128mm */
.page-canvas.size-b7 {
    width: 273px;  /* 91mm × 3 */
    height: 384px; /* 128mm × 3 */
}

.page-canvas:hover {
    border-color: #8B4513;
    box-shadow: 0 6px 15px rgba(139, 69, 19, 0.3);
}

.page-canvas.drag-over {
    border-color: #4CAF50;
    background: #f0fff0;
}

.page-canvas.has-image {
    cursor: pointer;
}

/* プレースホルダー */
.page-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #aaa;
    font-size: 14px;
    pointer-events: none;
}

.page-canvas.has-image .page-placeholder {
    display: none;
}

/* ページ内画像 */
.page-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* ページラベル */
.page-label {
    font-size: 14px;
    font-weight: bold;
    color: #8B4513;
}

/* 見開き操作 */
.spread-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
}

/* モーダル */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 15px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.modal-large {
    max-width: 95%;
    max-height: 95vh;
    height: 95vh;
}

.modal-header {
    padding: 20px;
    border-bottom: 2px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 20px;
    color: #8B4513;
}

.modal-close, .modal-close-pdf {
    background: none;
    border: none;
    font-size: 30px;
    cursor: pointer;
    color: #999;
    transition: color 0.3s;
}

.modal-close:hover, .modal-close-pdf:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-pdf-body {
    padding: 0;
    flex: 1;
    min-height: 0;
}

.modal-pdf-body iframe {
    border: none;
    display: block;
}

.modal-footer {
    padding: 20px;
    border-top: 2px solid #f0f0f0;
    display: flex;
    justify-content: center;
    gap: 15px;
}

/* モーダル内画像グリッド */
.modal-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
}

.modal-image-item {
    background: #fafafa;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.modal-image-item:hover {
    background: #f0e6d6;
    border-color: #8B4513;
    transform: scale(1.05);
}

.modal-image-thumb {
    width: 100%;
    height: 120px;
    object-fit: contain;
    border-radius: 5px;
    background: white;
    border: 1px solid #ddd;
}

.modal-image-name {
    font-size: 13px;
    font-weight: 500;
    color: #555;
    text-align: center;
}

/* 通知 */
.notification {
    position: fixed;
    top: 100px;
    right: 30px;
    background: #333;
    color: white;
    padding: 15px 25px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    z-index: 2000;
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.3s;
    pointer-events: none;
    font-size: 14px;
    font-weight: bold;
}

.notification.show {
    opacity: 1;
    transform: translateY(0);
}

.notification.success {
    background: #4CAF50;
}

.notification.error {
    background: #f44336;
}

.notification.info {
    background: #2196F3;
}

/* ローディングオーバーレイ */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 3000;
    justify-content: center;
    align-items: center;
}

.loading-overlay.active {
    display: flex;
}

.loading-content {
    background: white;
    border-radius: 15px;
    padding: 40px 60px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 6px solid #f3f3f3;
    border-top: 6px solid #8B4513;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-size: 18px;
    font-weight: bold;
    color: #8B4513;
}
