/* ===== 最適化されたCSS ===== */

/* ===== Scrollbar ===== */
.custom-scrollbar::-webkit-scrollbar {
    width: 10px;
    height: 8px;
}
.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Dark Mode Scrollbar */
@media (prefers-color-scheme: dark) {
    .custom-scrollbar::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.2);
    }
    .custom-scrollbar::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.3);
    }
}

/* ===== Layout (Sidebar Resizable Grid) ===== */
:root {
    --sidebar-width: 50vw;
    --sidebar-min: 30vw;
    --sidebar-max: 70vw;
    --resize-handle-width: 6px;
}

.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) var(--resize-handle-width) 1fr;
    height: 100vh;
    overflow: hidden;
    background: var(--tw-color-gray-50, #f9fafb);
}

@media (prefers-color-scheme: dark) {
    .app-layout { background: #111827; }
}

#sidebar {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(0,0,0,0.05);
    transition: none;
    will-change: width;
}

.dark #sidebar {
    border-right-color: rgba(255,255,255,0.08);
}

#mainPanel {
    overflow: hidden;
}

.resize-handle {
    cursor: col-resize;
    background: linear-gradient(to right, rgba(0,0,0,0.05), rgba(0,0,0,0.08));
    position: relative;
    transition: background .2s;
}

.dark .resize-handle {
    background: linear-gradient(to right, rgba(255,255,255,0.08), rgba(255,255,255,0.12));
}

.resize-handle:hover,
.resize-handle.resizing {
    background: linear-gradient(to right, #3b82f6, #2563eb);
}

.resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 34px;
    transform: translate(-50%, -50%);
    background: rgba(255,255,255,0.7);
    border-radius: 1px;
    opacity: 0.4;
}

.dark .resize-handle::after {
    background: rgba(255,255,255,0.85);
}

/* ===== Mode Switch ===== */
.mode-switch {
    position: relative;
    background: #e5e7eb;
    border-radius: 9999px;
    padding: 2px;
}

.mode-switch-indicator {
    position: absolute;
    background: white;
    border-radius: 9999px;
    transition: transform 0.3s ease;
    width: calc(50% - 2px);
    height: calc(100% - 4px);
    top: 2px;
    left: 2px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.mode-switch-indicator.batch {
    transform: translateX(100%);
}

@media (prefers-color-scheme: dark) {
    .mode-switch { background: #374151; }
    .mode-switch-indicator { background: #1f2937; }
}

.mode-switch button.active {
    color: #1e3a8a;
}

.dark .mode-switch button.active {
    color: #60a5fa;
}

.mode-switch button:not(.active) {
    opacity: .7;
}

/* ===== Execution Tabs ===== */
.exec-tab-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.exec-tab-list {
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    padding: 0.15rem 0.1rem 0.25rem;
    align-items: center;
    flex: 1;
}

.exec-tab-strip {
    background: transparent;
    border-radius: 0;
    border: none;
}

.exec-tab-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 0.5rem 0.65rem;
    box-shadow: 0 1px 2px rgba(15,23,42,0.06);
}

.dark .exec-tab-card {
    background: #111827;
    border-color: #1f2937;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.exec-tab-list::-webkit-scrollbar {
    height: 6px;
}

.exec-tab-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 9999px;
}

.exec-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: 2rem;
    padding: 0 0.85rem;
    border-radius: 0.5rem;
    border: 1px solid rgba(203,213,225,0.9);
    background: #ffffff;
    color: #374151;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.exec-tab-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    margin-left: 0.2rem;
    border-radius: 9999px;
    color: #9ca3af;
    font-size: 0.8rem;
    line-height: 1;
    transition: color 0.2s ease, background 0.2s ease;
}

.exec-tab-close:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.12);
}

.dark .exec-tab-close {
    color: #6b7280;
}

.dark .exec-tab-close:hover {
    color: #f87171;
    background: rgba(248, 113, 113, 0.15);
}

.exec-tab-dot {
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 9999px;
    background: #9ca3af;
    flex-shrink: 0;
}

.exec-tab-dot.dot-idle {
    background: #9ca3af;
}

.exec-tab-dot.dot-complete {
    background: #2563eb;
}

.exec-tab-dot.dot-running {
    background: #ef4444;
}

.exec-tab.active {
    background: #ffffff;
    border-color: #2563eb;
    color: #111827;
    box-shadow: 0 2px 6px rgba(15,23,42,0.08);
}

.exec-tab.is-queued {
    border-color: rgba(245,158,11,0.7);
}

.exec-tab.is-running {
    border-color: rgba(239,68,68,0.7);
}

.dark .exec-tab {
    background: #0f172a;
    border-color: rgba(55,65,81,0.9);
    color: #e5e7eb;
}

.dark .exec-tab.active {
    background: #0f172a;
    border-color: rgba(59,130,246,0.8);
    color: #f8fafc;
    box-shadow: 0 2px 10px rgba(0,0,0,0.35);
}

.dark .exec-tab.is-queued {
    border-color: rgba(245, 158, 11, 0.5);
}

.dark .exec-tab.is-running {
    border-color: rgba(239, 68, 68, 0.5);
}

.exec-tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.1rem;
    height: 1.1rem;
    padding: 0 0.3rem;
    border-radius: 9999px;
    background: rgba(0, 0, 0, 0.08);
    color: inherit;
    font-size: 0.65rem;
    font-weight: 700;
}

.exec-tab-add-btn {
    border-radius: 0.5rem;
    width: 2rem;
    height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
    color: #1d4ed8;
    background: #ffffff;
    border: 1px dashed #cbd5f5;
    transition: all 0.2s ease;
}

.exec-tab-add-btn:hover {
    background: #eff6ff;
    border-color: #93c5fd;
}

.dark .exec-tab-add-btn {
    color: #bfdbfe;
    background: rgba(15, 23, 42, 0.8);
    border-color: rgba(148, 163, 184, 0.3);
}

.dark .exec-tab-add-btn:hover {
    background: rgba(37, 99, 235, 0.35);
}

/* ===== Drop Zone ===== */
.drop-zone {
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.drop-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.05) 0%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.drop-zone:hover::before {
    opacity: 1;
}

.drop-zone:focus-visible {
    outline: 3px solid #2563eb;
    outline-offset: 2px;
}

.drop-zone.dragover {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, rgba(59, 130, 246, 0.05) 100%);
    border-color: rgb(59, 130, 246);
    transform: scale(1.01);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.25) inset;
}

/* ===== Option Form Rows ===== */
.option-row {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 1rem;
    align-items: start;
}

.option-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #4b5563;
    padding-top: 0.625rem;
    user-select: none;
}

.dark .option-label {
    color: #9ca3af;
}

.option-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    background: white;
    resize: vertical;
    min-height: 36px;
    transition: all 0.2s;
    font-family: inherit;
}

.dark .option-input {
    background: #374151;
    border-color: #4b5563;
    color: #e5e7eb;
}

.option-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.option-input:hover {
    border-color: #9ca3af;
}

.dark .option-input:hover {
    border-color: #6b7280;
}

/* ===== AIO Textarea ===== */
.aio-textarea {
    width: 100%;
    padding: 0.55rem 0.7rem;
    font-size: 0.72rem;
    line-height: 1.5;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    background: #fff;
    resize: vertical;
    min-height: 70px;
    font-family: inherit;
    transition: border-color .18s, box-shadow .18s;
}

.dark .aio-textarea {
    background: #374151;
    border-color: #4b5563;
    color: #e5e7eb;
}

.aio-textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.aio-textarea:hover {
    border-color: #9ca3af;
}

.dark .aio-textarea:hover {
    border-color: #6b7280;
}

/* ===== Status Badge ===== */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

/* ===== Run Button ===== */
.run-btn-running {
    position: relative;
    pointer-events: none;
    opacity: .85;
}

.run-btn-running .run-btn-label { visibility: hidden; }

.run-btn-running::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 22px; height: 22px;
    margin: -11px 0 0 -11px;
    border: 3px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: runspin .75s linear infinite;
}

#startBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

#startBtn:not(:disabled) {
    opacity: 1;
    cursor: pointer;
    pointer-events: auto;
}

#startBtn:not(:disabled):hover {
    transform: scale(1.01);
}

#startBtn:not(:disabled):active {
    transform: scale(0.99);
}

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

/* ===== Bookmark UI ===== */
.bookmark-item {
    transition: all 0.2s ease;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    animation: bookmarkSlideIn 0.3s ease-out;
}

.bookmark-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #8b5cf6, #a855f7);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.bookmark-item:hover::before {
    opacity: 1;
}

.bookmark-item:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.dark .bookmark-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.bookmark-delete-btn {
    transition: all 0.2s ease;
    opacity: 0.7;
}

.bookmark-delete-btn:hover {
    opacity: 1;
    transform: scale(1.05);
}

#sharedPresetsList {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.05) 0%, rgba(168, 85, 247, 0.02) 100%);
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: 12px;
    padding: 12px;
}

.dark #sharedPresetsList {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1) 0%, rgba(168, 85, 247, 0.05) 100%);
    border-color: rgba(139, 92, 246, 0.3);
}

#sharedSaveBtn {
    background: linear-gradient(135deg, #8b5cf6, #a855f7);
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

#sharedSaveBtn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

#sharedSaveBtn:hover::before {
    left: 100%;
}

#sharedSaveBtn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

#sharedToggleBtn {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(168, 85, 247, 0.1));
    border: 1px solid rgba(139, 92, 246, 0.3);
    transition: all 0.2s ease;
}

#sharedToggleBtn:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(168, 85, 247, 0.2));
    border-color: rgba(139, 92, 246, 0.5);
    transform: translateY(-1px);
}

.dark #sharedToggleBtn {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(168, 85, 247, 0.2));
    border-color: rgba(139, 92, 246, 0.4);
}

.dark #sharedToggleBtn:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.3), rgba(168, 85, 247, 0.3));
    border-color: rgba(139, 92, 246, 0.6);
}

.bookmark-item.options-preset {
    border-left: 4px solid #f59e0b;
}

.bookmark-item.options-preset::before {
    background: linear-gradient(90deg, #f59e0b, #f97316);
}

.bookmark-item.regular-preset {
    border-left: 4px solid #8b5cf6;
}

.bookmark-item.regular-preset::before {
    background: linear-gradient(90deg, #8b5cf6, #a855f7);
}

.bookmark-item h4 {
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 4px;
}

.dark .bookmark-item h4 {
    color: #f9fafb;
}

.bookmark-item .bookmark-meta {
    font-size: 0.75rem;
    color: #6b7280;
    margin-bottom: 2px;
}

.dark .bookmark-item .bookmark-meta {
    color: #9ca3af;
}

.bookmark-item .bookmark-preview {
    font-size: 0.7rem;
    color: #9ca3af;
    line-height: 1.4;
    max-height: 2.8em;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.dark .bookmark-item .bookmark-preview {
    color: #6b7280;
}

.bookmark-item .bookmark-date {
    font-size: 0.65rem;
    color: #9ca3af;
    margin-top: 4px;
}

.dark .bookmark-item .bookmark-date {
    color: #6b7280;
}

.bookmark-item:hover h4 {
    color: #8b5cf6;
}

.dark .bookmark-item:hover h4 {
    color: #a855f7;
}

.bookmark-empty {
    text-align: center;
    padding: 2rem;
    color: #9ca3af;
    font-size: 0.875rem;
}

.bookmark-empty svg {
    width: 3rem;
    height: 3rem;
    margin: 0 auto 1rem;
    opacity: 0.5;
}

.dark .bookmark-empty {
    color: #6b7280;
}

.bookmark-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    color: #6b7280;
    font-size: 0.875rem;
}

.bookmark-loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top-color: #8b5cf6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 0.5rem;
}

/* ===== Batch Result Cards ===== */
.batch-result-card {
    border-radius: 0.875rem;
    border-color: rgba(96, 165, 250, 0.45) !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    box-shadow: 0 12px 24px -16px rgba(37, 99, 235, 0.35);
}

.batch-result-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 28px -14px rgba(37, 99, 235, 0.45);
}

.dark .batch-result-card {
    background: #1f2937;
    border-color: rgba(96, 165, 250, 0.55) !important;
    box-shadow: 0 10px 24px -14px rgba(37, 99, 235, 0.45);
}

.dark .batch-result-card:hover {
    box-shadow: 0 14px 32px -12px rgba(37, 99, 235, 0.5);
}

.batch-result-card.failure {
    border-color: rgba(248, 113, 113, 0.55) !important;
    box-shadow: 0 12px 24px -16px rgba(248, 113, 113, 0.35);
}

.batch-result-card.failure:hover {
    box-shadow: 0 16px 30px -14px rgba(248, 113, 113, 0.45);
}

.dark .batch-result-card.failure {
    border-color: rgba(248, 113, 113, 0.55) !important;
    box-shadow: 0 12px 26px -14px rgba(248, 113, 113, 0.4);
}

.dark .batch-result-card.failure:hover {
    box-shadow: 0 16px 32px -12px rgba(248, 113, 113, 0.5);
}

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

@keyframes bookmarkSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.bookmark-item.removing {
    animation: bookmarkSlideOut 0.3s ease-in forwards;
}

@keyframes bookmarkSlideOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }
}

/* ===== Hotkeys Overlay ===== */
.hotkeys-overlay {
    position: fixed;
    inset: 0;
    backdrop-filter: blur(4px);
    background: rgba(0,0,0,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 80;
}

.hotkeys-dialog {
    background: #ffffff;
    color: #1f2937;
    width: 520px;
    max-width: 90vw;
    padding: 1.75rem 2rem;
    border-radius: 14px;
    box-shadow: 0 12px 40px -8px rgba(0,0,0,0.25);
    animation: fadeIn .25s ease;
    font-size: 0.9rem;
}

.dark .hotkeys-dialog {
    background: #1f2937;
    color: #e5e7eb;
}

.hotkeys-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.hotkeys-list {
    list-style: none;
    padding: 0;
    margin: 0 0 1.25rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .6rem 1.2rem;
}

.hotkeys-list li {
    line-height: 1.35;
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
}

.hotkeys-list kbd {
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    padding: 2px 6px 3px;
    border-radius: 5px;
    font-size: 11px;
    font-weight: 600;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    box-shadow: 0 1px 0 rgba(0,0,0,0.1);
}

.dark .hotkeys-list kbd {
    background: #374151;
    border-color: #4b5563;
    box-shadow: 0 1px 0 rgba(255,255,255,0.05);
}

.hotkeys-close {
    background: #2563eb;
    color: #fff;
    font-size: .75rem;
    letter-spacing: .05em;
    padding: .55rem 1.1rem;
    border-radius: 9999px;
    font-weight: 600;
    transition: background .18s, transform .18s;
}

.hotkeys-close:hover { background:#1d4ed8; }
.hotkeys-close:active { transform: translateY(1px); }

@keyframes fadeIn {
    from { opacity:0; transform: translateY(6px); }
    to { opacity:1; transform: translateY(0); }
}

/* ===== Result Modal ===== */
#resultModal { backdrop-filter: blur(2px); }
#resultModal .modal-backdrop {
    background: rgba(0,0,0,0.35);
}
#resultModal .modal-panel {
    animation: modalIn .18s ease;
}
@keyframes modalIn {
    from { opacity:0; transform: translateY(6px) scale(.98); }
    to { opacity:1; transform: translateY(0) scale(1); }
}

/* ===== Utilities ===== */
.hidden { display: none !important; }

/* ===== Responsive ===== */
@media (min-width: 1600px) {
    .option-row {
        grid-template-columns: 160px 1fr;
    }
}

@media (max-width: 1400px) {
    :root {
        --sidebar-max: 60vw;
    }
}

@media (min-width: 1200px) {
    #outputContent { font-size: 0.94rem; line-height: 1.55; }
    .compact-input { font-size: 0.8rem; }
    .result-card p { font-size: 0.72rem; }
}

/* ===== Focus States ===== */
:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* ===== Resizing State ===== */
.resize-handle.resizing + #mainPanel,
#sidebar.resizing {
    transition: none;
}
