/* ============================================
   NanoSpeed Design System
   Dark theme, modern, clean
   ============================================ */

/* --- Tokens --- */
:root {
    --bg:           #08080d;
    --bg-surface:   #0f0f16;
    --bg-card:      #13131d;
    --bg-hover:     #1a1a28;
    --bg-input:     #0c0c14;
    --border:       #1e1e30;
    --border-focus: #7c3aed;
    --text:         #e4e4ef;
    --text-muted:   #6b6b80;
    --text-dim:     #4a4a5e;
    --primary:      #7c3aed;
    --primary-hover:#6d28d9;
    --primary-glow: rgba(124, 58, 237, 0.15);
    --cyan:         #06b6d4;
    --green:        #22c55e;
    --red:          #ef4444;
    --orange:       #f59e0b;
    --radius-sm:    6px;
    --radius-md:    10px;
    --radius-lg:    14px;
    --radius-xl:    18px;
    --shadow:       0 4px 24px rgba(0,0,0,0.4);
    --transition:   0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ============================================
   PIN PAD
   ============================================ */
.pin-body {
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.pin-screen {
    transition: opacity 0.3s ease;
}
.pin-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
    padding: 40px;
}
.pin-logo {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
.pin-logo-icon {
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.pin-logo-icon svg { width: 64px; height: 64px; }
.pin-title {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #7c3aed, #06b6d4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.pin-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
}
.pin-dots {
    display: flex;
    gap: 16px;
    padding: 8px 0;
}
.pin-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--text-muted);
    transition: all 0.15s ease;
}
.pin-dot.filled {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(124, 58, 237, 0.4);
}
.pin-error {
    color: var(--red);
    font-size: 0.85rem;
    min-height: 1.2em;
}
.pin-pad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-width: 280px;
}
.pin-key {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    font-size: 1.6rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.pin-key:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--primary);
}
.pin-key:active:not(:disabled) {
    transform: scale(0.95);
    background: var(--primary);
}
.pin-key-empty {
    visibility: hidden;
    pointer-events: none;
}
.pin-key-delete {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 1rem;
}
.pin-key-delete:hover:not(:disabled) {
    color: var(--text);
    background: transparent;
}

/* Shake animation */
.shake {
    animation: shake 0.5s ease;
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-10px); }
    40%, 80% { transform: translateX(10px); }
}

/* ============================================
   APP HEADER
   ============================================ */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(12px);
}
.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.header-logo svg { width: 32px; height: 32px; }
.header-title {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}
.btn-ghost {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.btn-ghost:hover {
    color: var(--text);
    background: var(--bg-hover);
}

/* ============================================
   APP MAIN
   ============================================ */
.app-main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 24px;
}

/* ============================================
   DASHBOARD GRID
   ============================================ */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}
@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   CARDS
   ============================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}
.card-title svg { color: var(--primary); }

/* ============================================
   FORMS
   ============================================ */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.form-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.form-hint {
    font-weight: 400;
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
}
.form-textarea, .form-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    padding: 12px 14px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    transition: border-color var(--transition);
    width: 100%;
}
.form-textarea:focus, .form-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.form-textarea::placeholder, .form-input::placeholder {
    color: var(--text-dim);
}

/* ============================================
   FORMAT SELECTOR
   ============================================ */
.format-selector {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.format-group-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
}
.format-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
}
.format-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-surface);
    text-align: center;
}
.format-option:hover {
    border-color: var(--text-muted);
    background: var(--bg-hover);
}
.format-option.selected {
    border-color: var(--primary);
    background: var(--primary-glow);
    box-shadow: 0 0 0 2px var(--primary-glow);
}
.format-preview {
    width: 100%;
    max-width: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.format-ratio {
    width: 100%;
    max-height: 50px;
    background: var(--border);
    border-radius: 3px;
    min-height: 12px;
}
.format-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}
.format-dims {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}
.format-name {
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.3;
}

/* ============================================
   UPLOAD ZONE
   ============================================ */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 20px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    min-height: 100px;
}
.upload-zone:hover, .upload-zone-active {
    border-color: var(--primary);
    background: var(--primary-glow);
}
.upload-zone-has-files {
    padding: 12px;
    min-height: auto;
}
.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
}
.upload-placeholder svg { color: var(--text-dim); }
.upload-placeholder p { font-size: 0.9rem; }
.upload-previews {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
    margin-top: 10px;
}
.upload-preview-item {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-surface);
    border: 1px solid var(--border);
}
.upload-thumb {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}
.upload-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0,0,0,0.7);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    opacity: 0;
    transition: opacity var(--transition);
}
.upload-preview-item:hover .upload-remove { opacity: 1; }
.upload-name {
    font-size: 0.6rem;
    color: var(--text-muted);
    padding: 2px 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.upload-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    font-size: 0.55rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 1px 5px;
    border-radius: 3px;
    letter-spacing: 0.04em;
}
.badge-url { background: var(--cyan); color: #000; }
.badge-upload { background: var(--primary); color: #fff; }

/* URL input */
.url-input-group {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.url-input-group .form-input {
    flex: 1;
    padding: 8px 12px;
    font-size: 0.85rem;
}
.btn-sm {
    padding: 8px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-hover);
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn-sm:hover:not(:disabled) { border-color: var(--primary); }
.btn-sm:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================
   MULTIPLIER
   ============================================ */
.multiplier-row {
    display: flex;
    gap: 8px;
}
.multiplier-btn {
    flex: 1;
    padding: 10px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}
.multiplier-btn:hover {
    border-color: var(--text-muted);
    color: var(--text);
}
.multiplier-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
    box-shadow: 0 0 16px rgba(124, 58, 237, 0.3);
}

/* ============================================
   JOB SUMMARY
   ============================================ */
.job-summary {
    background: var(--primary-glow);
    border: 1px solid rgba(124, 58, 237, 0.2);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    text-align: center;
}
.job-summary-count {
    font-size: 0.95rem;
    color: var(--text);
}
.job-summary-number {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
    margin-right: 4px;
}
.job-summary-detail {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    box-shadow: 0 0 20px rgba(124, 58, 237, 0.3);
}
.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.btn-full { width: 100%; }
.btn-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}
.btn-icon:hover { border-color: var(--text-muted); color: var(--text); }
.btn-icon-danger:hover { border-color: var(--red); color: var(--red); }

/* ============================================
   QUEUE
   ============================================ */
.queue-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.queue-title {
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.queue-title svg { color: var(--cyan); }
.queue-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.status-active {
    background: var(--green);
    animation: pulse 1.5s infinite;
}
.status-idle { background: var(--text-dim); }
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.batch-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ============================================
   BATCH CARD
   ============================================ */
.batch-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: border-color var(--transition);
}
.batch-card.batch-processing {
    border-color: rgba(124, 58, 237, 0.4);
}
.batch-card.batch-completed {
    border-color: rgba(34, 197, 94, 0.3);
}
.batch-card.batch-failed {
    border-color: rgba(239, 68, 68, 0.3);
}
.batch-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.batch-info {
    display: flex;
    align-items: center;
    gap: 8px;
}
.batch-id {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.batch-status-badge {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 99px;
    letter-spacing: 0.04em;
}
.badge-pending { background: rgba(107, 107, 128, 0.2); color: var(--text-muted); }
.badge-processing { background: rgba(124, 58, 237, 0.2); color: var(--primary); }
.badge-completed { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.badge-failed { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.batch-actions {
    display: flex;
    gap: 4px;
}
.batch-prompt {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
}
.batch-meta {
    display: flex;
    gap: 12px;
    font-size: 0.75rem;
    color: var(--text-dim);
}

/* ============================================
   PROGRESS BAR
   ============================================ */
.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--bg-input);
    border-radius: 2px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.5s ease;
}
.progress-pending { background: var(--text-dim); }
.progress-processing {
    background: linear-gradient(90deg, var(--primary), var(--cyan));
    animation: shimmer 2s infinite;
}
.progress-completed { background: var(--green); }
.progress-failed { background: var(--red); }
@keyframes shimmer {
    0% { opacity: 0.8; }
    50% { opacity: 1; }
    100% { opacity: 0.8; }
}
.batch-progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted);
}
.text-red { color: var(--red); }
.text-muted { color: var(--text-muted); }

/* ============================================
   JOB THUMBNAILS
   ============================================ */
.batch-jobs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 6px;
    margin-top: 4px;
}
.job-thumb-item {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--bg-surface);
}
.job-thumb-img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}
.job-thumb-loading, .job-thumb-failed, .job-thumb-pending {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.job-thumb-loading { color: var(--primary); }
.job-thumb-failed { color: var(--red); background: rgba(239,68,68,0.05); }
.job-thumb-pending { background: var(--bg-input); }
.job-thumb-label {
    font-size: 0.55rem;
    color: var(--text-dim);
    padding: 2px 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.batch-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 4px 0;
    transition: color var(--transition);
}
.batch-toggle:hover { color: var(--text-muted); }
.batch-toggle svg { transition: transform var(--transition); }

/* ============================================
   QUEUE EMPTY
   ============================================ */
.queue-empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-dim);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.queue-empty svg { color: var(--text-dim); opacity: 0.5; }
.queue-empty p:first-of-type { font-size: 0.95rem; color: var(--text-muted); }

/* ============================================
   SPINNER
   ============================================ */
.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}
.spinner-sm {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================
   TOAST
   ============================================ */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow);
    max-width: 360px;
}
.toast-success { background: var(--green); color: #000; }
.toast-error { background: var(--red); color: #fff; }
.toast-info { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); }
.toast-enter { animation: slideIn 0.3s ease; }
.toast-leave { animation: slideOut 0.3s ease; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } }
@keyframes slideOut { to { transform: translateX(100%); opacity: 0; } }

/* ============================================
   LIGHTBOX
   ============================================ */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    cursor: zoom-out;
}
.lightbox-img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: var(--radius-md);
    cursor: default;
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.6);
}
.lightbox-close {
    position: absolute;
    top: 16px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}
.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.25);
}
.lightbox-label {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.6);
}
.job-thumb-clickable {
    cursor: zoom-in;
    transition: opacity var(--transition);
}
.job-thumb-clickable:hover {
    opacity: 0.8;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 640px) {
    .app-main { padding: 16px; }
    .card { padding: 16px; gap: 14px; }
    .format-options { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
    .pin-key { width: 68px; height: 68px; font-size: 1.4rem; }
    .pin-pad-grid { gap: 10px; }
}
