/* ========================================
   リセット & 基本設定
======================================== */
* {
   margin: 0;
   padding: 0;
   box-sizing: border-box;
}

body {
   font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
   background-color: #f9fafb;
   color: #111827;
   line-height: 1.6;
}

/* ========================================
   アプリケーションコンテナ
======================================== */
.app-container {
   min-height: 100vh;
   display: flex;
   flex-direction: column;
}

/* ========================================
   ヘッダー
======================================== */
.app-header {
   background: rgba(102, 126, 234, 0.05);
   color: #667eea;
   padding: 0.5rem 1.5rem;
   text-align: left;
   border-bottom: 1px solid rgba(102, 126, 234, 0.1);
}

.app-header h1 {
   font-size: 0.85rem;
   font-weight: 600;
   margin: 0;
   opacity: 0.6;
   letter-spacing: 0.05em;
}

/* ========================================
   メインコンテンツ
======================================== */
.app-main {
   flex: 1;
   display: grid;
   grid-template-columns: 280px 1fr;
   gap: 1rem;
   padding: 1rem;
   max-width: 1800px;
   margin: 0 auto;
   width: 100%;
}

/* ========================================
   統合パネル（左側）
======================================== */
.unified-panel {
   width: 280px;
   height: calc(100vh - 60px);
   overflow-y: auto;
   background-color: white;
   border: 1px solid #e5e7eb;
   border-radius: 8px;
}

.panel-section {
   padding: 0.75rem;
   border-bottom: 1px solid #f3f4f6;
}

.panel-section:last-child {
   border-bottom: none;
}

.section-header {
   display: flex;
   align-items: center;
   justify-content: space-between;
   margin-bottom: 0.5rem;
}

.section-header h2 {
   font-size: 0.8rem;
   font-weight: 700;
   color: #374151;
   text-transform: uppercase;
   letter-spacing: 0.05em;
}

.panel-divider {
   border: none;
   border-top: 1px solid #e5e7eb;
   margin: 0;
}

/* ========================================
   モード切替
======================================== */
.mode-toggle {
   display: flex;
   gap: 0.3rem;
}

.mode-btn {
   flex: 1;
   padding: 0.35rem;
   border: 1.5px solid #e5e7eb;
   border-radius: 5px;
   background: white;
   color: #6b7280;
   font-size: 0.8rem;
   font-weight: 600;
   cursor: pointer;
   transition: all 0.15s;
   text-align: center;
}

.mode-btn:hover {
   border-color: #667eea;
   color: #667eea;
}

.mode-btn.active {
   border-color: #667eea;
   background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
   color: white;
}

/* ========================================
   画像書込モード：アップロード
======================================== */
.annotate-upload {
   display: flex;
   flex-direction: column;
   align-items: center;
   justify-content: center;
   gap: 0.5rem;
   padding: 1.5rem;
   border: 2px dashed #d1d5db;
   border-radius: 6px;
   cursor: pointer;
   color: #9ca3af;
   font-size: 0.8rem;
   transition: all 0.15s;
}

.annotate-upload:hover {
   border-color: #667eea;
   color: #667eea;
}

.annotate-upload.dragover {
   border-color: #667eea;
   background: #f0f4ff;
   color: #667eea;
}

.annotate-upload.has-image {
   padding: 0.5rem;
   border-style: solid;
   border-color: #667eea;
}

.annotate-upload.has-image img {
   width: 100%;
   border-radius: 4px;
}

/* ========================================
   デバイス管理
======================================== */
.device-count-controls {
   display: flex;
   align-items: center;
   gap: 0.5rem;
}

.device-count-label {
   font-size: 0.85rem;
   font-weight: 600;
   color: #374151;
   min-width: 16px;
   text-align: center;
}

.icon-btn {
   display: flex;
   align-items: center;
   justify-content: center;
   width: 28px;
   height: 28px;
   border: 1px solid #d1d5db;
   border-radius: 6px;
   background: white;
   cursor: pointer;
   color: #374151;
   transition: all 0.15s;
}

.icon-btn:hover {
   border-color: #667eea;
   color: #667eea;
}

/* デバイス行（コンパクト） */
#device-settings-container {
   display: flex;
   flex-direction: column;
   gap: 0.4rem;
}

.device-row {
   display: flex;
   align-items: center;
   gap: 0.4rem;
   padding: 0.35rem 0.5rem;
   background: #f9fafb;
   border: 1px solid #e5e7eb;
   border-radius: 6px;
}

.device-row .device-index {
   font-size: 0.7rem;
   font-weight: 600;
   color: #9ca3af;
   min-width: 14px;
}

.device-row select {
   flex: 1;
   padding: 0.25rem 0.4rem;
   border: 1px solid #d1d5db;
   border-radius: 4px;
   font-size: 0.75rem;
   background: white;
   cursor: pointer;
   min-width: 0;
}

.device-row .upload-btn {
   display: flex;
   align-items: center;
   justify-content: center;
   width: 30px;
   height: 30px;
   border: 1px dashed #d1d5db;
   border-radius: 4px;
   background: white;
   cursor: pointer;
   color: #9ca3af;
   transition: all 0.15s;
   flex-shrink: 0;
}

.device-row .upload-btn:hover {
   border-color: #667eea;
   color: #667eea;
}

.device-row .upload-btn.has-image {
   border-style: solid;
   border-color: #667eea;
   padding: 1px;
   overflow: hidden;
}

.device-row .upload-btn.has-image img {
   width: 100%;
   height: 100%;
   object-fit: cover;
   border-radius: 3px;
}

.device-row .remove-btn {
   display: flex;
   align-items: center;
   justify-content: center;
   width: 20px;
   height: 20px;
   border: none;
   border-radius: 50%;
   background: transparent;
   cursor: pointer;
   color: #9ca3af;
   font-size: 0.7rem;
   flex-shrink: 0;
   transition: all 0.15s;
}

.device-row .remove-btn:hover {
   color: #ef4444;
   background: #fef2f2;
}

/* ========================================
   レイアウト設定（折りたたみ）
======================================== */
.section-toggle {
   display: flex;
   align-items: center;
   gap: 0.5rem;
   width: 100%;
   padding: 0.4rem 0;
   border: none;
   background: none;
   cursor: pointer;
   font-size: 0.8rem;
   font-weight: 600;
   color: #6b7280;
   transition: color 0.15s;
}

.section-toggle:hover {
   color: #667eea;
}

.toggle-chevron {
   margin-left: auto;
   transition: transform 0.2s;
   transform: rotate(-90deg);
}

.toggle-chevron.open {
   transform: rotate(0deg);
}

.section-content.collapsed {
   display: none;
}

.section-content {
   padding-top: 0.5rem;
}

.setting-group {
   margin-bottom: 0.75rem;
}

.setting-group:last-child {
   margin-bottom: 0;
}

.setting-group > label {
   display: block;
   font-size: 0.75rem;
   font-weight: 600;
   color: #6b7280;
   margin-bottom: 0.35rem;
}

.preset-grid {
   display: grid;
   grid-template-columns: repeat(4, 1fr);
   gap: 0.3rem;
}

/* 固定サイズモード */
.size-mode-toggle {
   display: flex;
   gap: 0.4rem;
   margin-bottom: 0.5rem;
}

.size-mode-toggle .toggle-item {
   flex: 1;
   display: flex;
   align-items: center;
   justify-content: center;
   padding: 0.2rem;
   border: 1.5px solid #e5e7eb;
   border-radius: 5px;
   cursor: pointer;
   font-size: 0.8rem;
   transition: all 0.15s;
}

.size-mode-toggle .toggle-item:has(input:checked) {
   border-color: #667eea;
   background-color: #f0f4ff;
}

.size-mode-toggle input[type="radio"] {
   margin-right: 0.4rem;
   width: 14px;
   height: 14px;
}

.size-presets select {
   width: 100%;
   padding: 0.35rem;
   border: 1px solid #d1d5db;
   border-radius: 5px;
   font-size: 0.8rem;
   background: white;
   cursor: pointer;
}

/* マージン設定 */
.margin-control {
   display: flex;
   align-items: center;
   gap: 0.4rem;
   margin-bottom: 0.3rem;
}

.margin-control .margin-label {
   font-size: 0.7rem;
   color: #6b7280;
   min-width: 28px;
}

.margin-control input[type="range"] {
   flex: 1;
}

.margin-control .value-display {
   font-size: 0.7rem;
   color: #9ca3af;
   min-width: 36px;
   text-align: right;
}

/* 背景設定 */
.background-controls {
   display: flex;
   gap: 0.4rem;
}

.bg-option {
   flex: 1;
   display: flex;
   align-items: center;
   gap: 0.35rem;
   padding: 0.25rem 0.4rem;
   border: 1.5px solid #e5e7eb;
   border-radius: 5px;
   cursor: pointer;
   font-size: 0.8rem;
   transition: all 0.15s;
}

.bg-option:has(input:checked) {
   border-color: #667eea;
   background-color: #f0f4ff;
}

.bg-option input[type="radio"] {
   margin: 0;
   width: 14px;
   height: 14px;
}

.bg-option input[type="color"] {
   width: 28px;
   height: 22px;
   border: 1px solid #d1d5db;
   border-radius: 3px;
   cursor: pointer;
   padding: 1px;
   margin-left: auto;
}

.bg-option input[type="color"]:disabled {
   opacity: 0.4;
   cursor: not-allowed;
}

/* ========================================
   編集ツールグリッド
======================================== */
.edit-tools-grid {
   display: grid;
   grid-template-columns: repeat(4, 1fr);
   gap: 0.25rem;
}

.tool-btn {
   display: flex;
   align-items: center;
   justify-content: center;
   padding: 0.5rem;
   border: 1.5px solid transparent;
   border-radius: 6px;
   background: white;
   cursor: pointer;
   color: #6b7280;
   transition: all 0.15s;
}

.tool-btn:hover {
   background: #f3f4f6;
   color: #374151;
}

.tool-btn.active {
   background: #f0f4ff;
   border-color: #667eea;
   color: #667eea;
}

/* ========================================
   ユーティリティボタン
======================================== */
.utility-grid {
   display: grid;
   grid-template-columns: repeat(4, 1fr);
   gap: 0.25rem;
}

.util-btn {
   display: flex;
   align-items: center;
   justify-content: center;
   padding: 0.4rem;
   border: 1px solid #e5e7eb;
   border-radius: 5px;
   background: white;
   cursor: pointer;
   color: #6b7280;
   transition: all 0.15s;
}

.util-btn:hover {
   border-color: #667eea;
   color: #667eea;
}

/* ========================================
   プロパティパネル
======================================== */
.property-group {
   margin-bottom: 0.75rem;
}

.property-group:last-child {
   margin-bottom: 0;
}

.property-group > label {
   display: block;
   font-size: 0.75rem;
   font-weight: 600;
   color: #6b7280;
   margin-bottom: 0.35rem;
}

/* 色プリセット */
.color-preset-grid {
   display: grid;
   grid-template-columns: repeat(12, 1fr);
   gap: 2px;
   margin-bottom: 0.4rem;
}

.color-preset {
   width: 100%;
   aspect-ratio: 1;
   border: 2px solid transparent;
   border-radius: 3px;
   cursor: pointer;
   transition: all 0.15s;
   padding: 0;
}

.color-preset:hover {
   transform: scale(1.15);
}

.color-preset.active {
   border-color: #667eea;
   box-shadow: 0 0 0 1px rgba(102, 126, 234, 0.3);
}

.color-custom {
   display: flex;
   gap: 0.4rem;
   align-items: center;
}

.color-custom input[type="color"] {
   flex-shrink: 0;
   width: 20px;
   height: 20px;
   border: 1px solid #d1d5db;
   border-radius: 3px;
   cursor: pointer;
   padding: 1px;
}

.color-custom input[type="text"] {
   flex: 1;
   min-width: 0;
   padding: 0.3rem 0.4rem;
   border: 1px solid #d1d5db;
   border-radius: 4px;
   font-size: 0.7rem;
   font-family: 'Courier New', monospace;
   text-transform: uppercase;
}

.color-custom input[type="text"]:focus {
   outline: none;
   border-color: #667eea;
   box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

/* スライダー */
input[type="range"] {
   width: 100%;
   height: 5px;
   border-radius: 3px;
   background: #e5e7eb;
   outline: none;
   -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
   -webkit-appearance: none;
   width: 14px;
   height: 14px;
   border-radius: 50%;
   background: #667eea;
   cursor: pointer;
   box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input[type="range"]::-moz-range-thumb {
   width: 14px;
   height: 14px;
   border-radius: 50%;
   background: #667eea;
   cursor: pointer;
   border: none;
   box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.property-group .value-display {
   font-size: 0.7rem;
   color: #9ca3af;
}

/* チェックボックスラベル */
.checkbox-label {
   display: flex !important;
   align-items: center;
   gap: 0.4rem;
   cursor: pointer;
   padding: 0.35rem 0.5rem;
   border: 1.5px solid #e5e7eb;
   border-radius: 5px;
   transition: all 0.15s;
   margin-bottom: 0 !important;
}

.checkbox-label:has(input:checked) {
   border-color: #667eea;
   background-color: #f0f4ff;
}

.checkbox-label input[type="checkbox"] {
   margin: 0;
   cursor: pointer;
   width: 14px;
   height: 14px;
}

.checkbox-label span {
   font-size: 0.8rem;
   font-weight: 500;
   color: #374151;
}

/* フォント・セレクト */
#tool-font-family,
#tool-start-cap,
#tool-end-cap {
   width: 100%;
   padding: 0.35rem;
   border: 1px solid #d1d5db;
   border-radius: 5px;
   font-size: 0.8rem;
   background: white;
   cursor: pointer;
}

/* ウェイトセレクタ */
.weight-selector {
   display: flex;
   gap: 0.3rem;
}

.weight-btn {
   flex: 1;
   padding: 0.3rem;
   font-size: 0.75rem;
   border: 1px solid #d1d5db;
   border-radius: 4px;
   background: white;
   cursor: pointer;
   transition: all 0.15s;
}

.weight-btn.active {
   background: #667eea;
   color: white;
   border-color: #667eea;
}

/* 整列グリッド */
.alignment-grid {
   display: grid;
   grid-template-columns: repeat(3, 1fr);
   gap: 0.3rem;
   margin-bottom: 0.5rem;
}

.distribute-grid {
   grid-template-columns: repeat(2, 1fr);
}

.align-btn,
.distribute-btn {
   display: flex;
   align-items: center;
   justify-content: center;
   padding: 0.4rem;
   border: 1px solid #d1d5db;
   border-radius: 4px;
   background: white;
   cursor: pointer;
   transition: all 0.15s;
}

.align-btn:hover,
.distribute-btn:hover {
   border-color: #667eea;
   color: #667eea;
}

/* ヒントテキスト */
.hint-text {
   font-size: 0.7rem;
   color: #6b7280;
   margin-top: 0.4rem;
}

/* ========================================
   プロジェクト管理
======================================== */
.project-actions {
   display: grid;
   grid-template-columns: 1fr 1fr;
   gap: 0.4rem;
}

/* ========================================
   ボタン共通
======================================== */
.btn {
   padding: 0.35rem 0.5rem;
   border: 1.5px solid #e5e7eb;
   border-radius: 5px;
   background: white;
   color: #374151;
   font-size: 0.8rem;
   font-weight: 600;
   cursor: pointer;
   transition: all 0.15s;
   text-align: center;
   white-space: nowrap;
}

.btn:hover {
   border-color: #667eea;
   color: #667eea;
}

.btn.active {
   border-color: #667eea;
   background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
   color: white;
}

.btn.small {
   padding: 0.25rem 0.35rem;
   font-size: 0.75rem;
}

.btn-outline {
   display: flex;
   align-items: center;
   justify-content: center;
   gap: 0.35rem;
}

/* ========================================
   Canvas エリア（右側）
======================================== */
.canvas-area {
   background: white;
   border-radius: 8px;
   padding: 1rem;
   box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
   display: flex;
   flex-direction: column;
   align-items: center;
   max-width: 100%;
   max-height: calc(100vh - 60px);
   box-sizing: border-box;
   overflow: hidden;
}

.canvas-wrapper {
   position: relative;
   flex: 1;
   width: 100%;
   max-width: 100%;
   display: flex;
   align-items: center;
   justify-content: center;
   overflow: auto;
   background:
      linear-gradient(45deg, #f3f4f6 25%, transparent 25%),
      linear-gradient(-45deg, #f3f4f6 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, #f3f4f6 75%),
      linear-gradient(-45deg, transparent 75%, #f3f4f6 75%);
   background-size: 20px 20px;
   background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
   border-radius: 6px;
}

#stage-container {
   max-width: 100%;
   overflow: visible;
   border: 2px solid #cfd3d9;
   border-radius: 4px;
}

.canvas-info {
   margin-top: 0.75rem;
   font-size: 0.8rem;
   color: #6b7280;
}

.canvas-size-label {
   margin-right: 0.35rem;
}

.canvas-size-value {
   font-weight: 600;
   color: #374151;
}

/* ダウンロード */
.download-controls {
   display: flex;
   align-items: center;
   gap: 0.75rem;
   margin-top: 0.75rem;
}

.download-controls select {
   padding: 0.4rem 0.6rem;
   border: 1px solid #d1d5db;
   border-radius: 5px;
   font-size: 0.8rem;
   background: white;
   cursor: pointer;
}

.download-button {
   display: flex;
   align-items: center;
   gap: 0.5rem;
   background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
   color: white;
   border: none;
   border-radius: 6px;
   padding: 0.6rem 1.25rem;
   font-size: 0.85rem;
   font-weight: 600;
   cursor: pointer;
   transition: transform 0.15s, box-shadow 0.15s;
   box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
}

.download-button:hover {
   transform: translateY(-1px);
   box-shadow: 0 4px 10px rgba(102, 126, 234, 0.4);
}

.download-button:active {
   transform: translateY(0);
}

/* ========================================
   カスタムカーソル（Transformer用）
======================================== */
.rotate-cursor {
   cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8'/%3E%3Cpath d='M3 3v5h5'/%3E%3C/svg%3E") 12 12, crosshair;
}

/* ========================================
   ユーティリティ
======================================== */
.hidden {
   display: none;
}

/* ========================================
   レスポンシブ
======================================== */
/* ========================================
   ライセンスモーダル
======================================== */
.license-overlay {
   display: none;
   position: fixed;
   inset: 0;
   background: rgba(0, 0, 0, 0.5);
   z-index: 10000;
   align-items: center;
   justify-content: center;
}

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

.license-modal {
   background: #fff;
   border-radius: 12px;
   padding: 2rem;
   max-width: 420px;
   width: 90%;
   position: relative;
   box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.license-modal h2 {
   font-size: 1.25rem;
   margin-bottom: 0.5rem;
   color: #111827;
}

.license-modal-close {
   position: absolute;
   top: 0.75rem;
   right: 0.75rem;
   background: none;
   border: none;
   font-size: 1.5rem;
   color: #9ca3af;
   cursor: pointer;
   line-height: 1;
}

.license-modal-close:hover {
   color: #374151;
}

.license-modal-desc {
   color: #6b7280;
   font-size: 0.9rem;
   margin-bottom: 1.25rem;
}

.license-features {
   display: flex;
   flex-direction: column;
   gap: 0.5rem;
   margin-bottom: 1.5rem;
}

.license-feature-item {
   display: flex;
   align-items: center;
   gap: 0.5rem;
   font-size: 0.9rem;
   color: #374151;
}

.license-purchase-btn {
   display: block;
   text-align: center;
   background: linear-gradient(135deg, #667eea, #764ba2);
   color: #fff;
   text-decoration: none;
   padding: 0.75rem;
   border-radius: 8px;
   font-weight: 600;
   font-size: 0.95rem;
   transition: transform 0.15s, box-shadow 0.15s;
   box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.license-purchase-btn:hover {
   transform: translateY(-1px);
   box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.license-activate {
   margin-top: 1.25rem;
   padding-top: 1.25rem;
   border-top: 1px solid #e5e7eb;
}

.license-activate > p {
   font-size: 0.8rem;
   color: #6b7280;
   margin-bottom: 0.5rem;
}

.license-key-form {
   display: flex;
   gap: 0.5rem;
}

.license-key-form input {
   flex: 1;
   padding: 0.4rem 0.6rem;
   border: 1px solid #d1d5db;
   border-radius: 5px;
   font-size: 0.85rem;
}

.license-key-form .btn {
   white-space: nowrap;
}

.license-activate-msg {
   font-size: 0.8rem;
   margin-top: 0.4rem;
   min-height: 1.2em;
}

.license-activate-msg.success {
   color: #10b981;
}

.license-activate-msg.error {
   color: #ef4444;
}

.license-status {
   margin-top: 0.75rem;
   font-size: 0.8rem;
   color: #10b981;
   text-align: center;
}

/* ========================================
   画像読み込みローディング
======================================== */
.loading-indicator {
   position: absolute;
   top: 50%;
   left: 50%;
   transform: translate(-50%, -50%);
   display: flex;
   align-items: center;
   gap: 0.5rem;
   background: rgba(255, 255, 255, 0.9);
   padding: 0.5rem 1rem;
   border-radius: 8px;
   font-size: 0.85rem;
   color: #6b7280;
   box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
   z-index: 100;
   pointer-events: none;
}

.loading-spinner {
   width: 16px;
   height: 16px;
   border: 2px solid #e5e7eb;
   border-top-color: #667eea;
   border-radius: 50%;
   animation: spin 0.6s linear infinite;
}

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

/* Pro badge in header */
.license-badge {
   display: inline-flex;
   align-items: center;
   gap: 0.3rem;
   font-size: 0.7rem;
   font-weight: 600;
   padding: 0.15rem 0.5rem;
   border-radius: 10px;
   margin-left: 0.5rem;
   cursor: pointer;
   vertical-align: middle;
}

.license-badge.free {
   background: #f3f4f6;
   color: #6b7280;
   border: 1px solid #d1d5db;
}

.license-badge.pro {
   background: linear-gradient(135deg, #667eea, #764ba2);
   color: #fff;
}

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

   .unified-panel {
      width: 100%;
      height: auto;
   }
}
