/* ============================================================
   圖片處理工坊 – Custom CSS (supplements Tailwind)
   ============================================================ */

/* ── Custom scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }
.dark ::-webkit-scrollbar-thumb { background: #475569; }
.dark ::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* ── Sidebar transition ────────────────────────────────────── */
#sidebar {
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                width     0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Tool panel fade-in ────────────────────────────────────── */
.tool-panel {
    display: none;
    animation: fadeIn 0.18s ease;
}
.tool-panel.active { display: block; }

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

/* ── Range/slider thumb ────────────────────────────────────── */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e2e8f0;
    outline: none;
    cursor: pointer;
}
.dark input[type="range"] { background: #334155; }

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #2563eb;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover { background: #1d4ed8; transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
    width: 18px; height: 18px;
    border-radius: 50%;
    background: #2563eb;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
    cursor: pointer;
}

/* ── Canvas preview area ───────────────────────────────────── */
.preview-canvas-wrap {
    position: relative;
    overflow: hidden;
    border-radius: 0.5rem;
    min-height: 220px;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dark .preview-canvas-wrap { background: #1e293b; }

.preview-canvas-wrap canvas {
    max-width: 100%;
    cursor: grab;
    transform-origin: center center;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}
.preview-canvas-wrap canvas:active { cursor: grabbing; }

/* ── Checkered transparent background ─────────────────────── */
.preview-bg-transparent {
    background-image:
        linear-gradient(45deg, #ccc 25%, transparent 25%),
        linear-gradient(-45deg, #ccc 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ccc 75%),
        linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.preview-bg-dark  { background-color: #1e293b !important; }
.preview-bg-light { background-color: #f8fafc !important; }

/* ── Preview overlay (empty state) ────────────────────────── */
.preview-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    color: #94a3b8;
}
.preview-overlay i { font-size: 2.5rem; margin-bottom: 0.75rem; }

/* ── Drop-zone ─────────────────────────────────────────────── */
.drop-zone {
    border: 2px dashed #94a3b8;
    border-radius: 0.75rem;
    padding: 1.5rem;
    text-align: center;
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
}
.drop-zone:hover,
.drop-zone.drag-over {
    border-color: #2563eb;
    background: rgba(37,99,235,0.05);
}
.dark .drop-zone {
    border-color: #475569;
    color: #94a3b8;
}
.dark .drop-zone:hover,
.dark .drop-zone.drag-over {
    border-color: #60a5fa;
    background: rgba(96,165,250,0.07);
}

/* ── File list ─────────────────────────────────────────────── */
.file-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.375rem 0.625rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    background: #f1f5f9;
    margin-top: 0.375rem;
}
.dark .file-list-item { background: #1e293b; }

/* ── Toast notifications ───────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    pointer-events: all;
    animation: toastIn 0.25s ease forwards;
    max-width: 320px;
    color: #fff;
}
.toast.success { background: #16a34a; }
.toast.error   { background: #dc2626; }
.toast.info    { background: #2563eb; }
.toast.warning { background: #d97706; }
.toast.out     { animation: toastOut 0.25s ease forwards; }

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

/* ── Progress bar ──────────────────────────────────────────── */
.progress-track {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}
.dark .progress-track { background: #334155; }
.progress-fill {
    height: 100%;
    background: #2563eb;
    border-radius: 4px;
    width: 0%;
    transition: width 0.25s ease;
}

/* ── Pixel grid controls ───────────────────────────────────── */
.pixel-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 0.5rem;
    place-items: center;
}

/* ── Server tool result panel ──────────────────────────────── */
.result-panel {
    border-top: 1px solid #e2e8f0;
    margin-top: 1.25rem;
    padding-top: 1.25rem;
}
.dark .result-panel { border-color: #334155; }

/* ── History table ─────────────────────────────────────────── */
.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}
.history-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    background: #f1f5f9;
    font-weight: 600;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
}
.dark .history-table th { background: #1e293b; color: #94a3b8; border-color: #334155; }

.history-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #f1f5f9;
    color: #374151;
    vertical-align: middle;
}
.dark .history-table td { border-color: #1e293b; color: #cbd5e1; }
.history-table tr:hover td { background: #f8fafc; }
.dark .history-table tr:hover td { background: #1e293b; }

/* ── Tool badges ───────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge-resize    { background:#dbeafe; color:#1e40af; }
.badge-compress  { background:#dcfce7; color:#166534; }
.badge-convert   { background:#fef9c3; color:#854d0e; }
.badge-watermark { background:#fce7f3; color:#9d174d; }

.dark .badge-resize    { background:#1e3a5f; color:#93c5fd; }
.dark .badge-compress  { background:#14532d; color:#86efac; }
.dark .badge-convert   { background:#422006; color:#fde68a; }
.dark .badge-watermark { background:#4a044e; color:#f0abfc; }

/* ── Split direction badges ────────────────────────────────── */
.badge-split-h { background:#dbeafe; color:#1e40af; }
.badge-split-v { background:#dcfce7; color:#166534; }
.dark .badge-split-h { background:#1e3a5f; color:#93c5fd; }
.dark .badge-split-v { background:#14532d; color:#86efac; }

/* ── Sidebar nav items ─────────────────────────────────────── */
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: #cbd5e1;
    transition: background 0.15s, color 0.15s;
    user-select: none;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #f1f5f9; }
.nav-item.active { background: #2563eb; color: #fff; }
.nav-item .nav-icon { width: 1.25rem; text-align: center; flex-shrink: 0; }

/* ── Stats card ────────────────────────────────────────────── */
.stats-card {
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(255,255,255,0.07);
    margin-top: 0.5rem;
}
.stats-card .stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #60a5fa;
}
.stats-card .stat-label {
    font-size: 0.7rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ── Comparison view (original vs result) ─────────────────── */
.compare-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
@media (max-width: 768px) {
    .compare-grid { grid-template-columns: 1fr; }
}

/* ── Loading spinner ───────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Sidebar mobile overlay ────────────────────────────────── */
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 39;
}
#sidebar-overlay.visible { display: block; }

/* ── Image result size info ────────────────────────────────── */
.size-reduction-pos { color: #16a34a; font-weight: 600; }
.size-reduction-neg { color: #dc2626; font-weight: 600; }

/* ── Focus visible ─────────────────────────────────────────── */
*:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}
