:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-input: #252830;
    --border: #2d3140;
    --text: #e4e6ed;
    --text-dim: #8b8fa3;
    --accent: #5b7ff5;
    --accent-hover: #4a6ee0;
    --success: #34d399;
    --error: #f87171;
    --warning: #fbbf24;
    --radius: 8px;
}

html.light {
    --bg: #f0f2f5;
    --bg-card: #ffffff;
    --bg-input: #e4e7ec;
    --border: #d1d5db;
    --text: #111827;
    --text-dim: #6b7280;
    --accent: #3d5de8;
    --accent-hover: #2d4dd0;
    --success: #059669;
    --error: #dc2626;
    --warning: #b45309;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* Layout */
.app {
    display: grid;
    grid-template-columns: 360px 1fr;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
}

header {
    grid-column: 1 / -1;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

header h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.settings-wrap {
    position: relative;
}

.settings-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
    font-size: 18px;
    padding: 4px 8px;
    cursor: pointer;
    line-height: 1;
}

.settings-btn:hover {
    color: var(--text);
    border-color: var(--text-dim);
}

.settings-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    min-width: 180px;
    z-index: 100;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.settings-dropdown.open {
    display: block;
}

.settings-section {
    margin-bottom: 8px;
}

.settings-label {
    display: block;
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.lang-select {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 13px;
    cursor: pointer;
    width: 100%;
}

.settings-link {
    display: block;
    color: var(--text-dim);
    font-size: 12px;
    text-decoration: none;
    padding: 6px 0;
    border-top: 1px solid var(--border);
}

.settings-link:hover {
    color: var(--accent);
}

header h1 span {
    color: var(--accent);
}

header .tagline {
    color: var(--text-dim);
    font-size: 13px;
}

.sidebar {
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.main {
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.card-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: 16px;
}

/* Forms */
.form-group {
    margin-bottom: 12px;
}

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

label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
    margin-bottom: 4px;
}

input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}

input:focus, select:focus {
    border-color: var(--accent);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--bg-input);
    border-color: var(--accent);
}

.btn-danger {
    background: transparent;
    border: 1px solid var(--error);
    color: var(--error);
}

.btn-danger:hover {
    background: var(--error);
    color: white;
}

/* Upload area */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent);
    background: rgba(91, 127, 245, 0.05);
}

.upload-zone .icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.upload-zone p {
    color: var(--text-dim);
    font-size: 13px;
}

.upload-zone .formats {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 4px;
    opacity: 0.7;
}

input[type="file"] {
    display: none;
}

/* Part list */
.part-list {
    list-style: none;
}

.part-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}

.part-item:hover {
    background: rgba(91, 127, 245, 0.08);
}

.part-item.part-highlighted {
    background: rgba(91, 127, 245, 0.15);
    box-shadow: inset 3px 0 0 var(--accent);
}

.part-item:last-child {
    border-bottom: none;
}

.part-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

.part-preview {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.part-preview svg {
    width: 100%;
    height: 100%;
}

.part-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.part-name-input {
    flex: 1;
    min-width: 0;
    padding: 2px 6px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: all 0.15s;
    cursor: text;
}

.part-name-input:hover {
    border-color: var(--border);
    background: var(--bg-input);
}

.part-name-input:focus {
    border-color: var(--accent);
    background: var(--bg-input);
}

.part-info {
    color: var(--text-dim);
    font-size: 11px;
    white-space: nowrap;
}

.part-qty {
    width: 50px;
}

.part-qty input {
    width: 50px;
    padding: 4px 6px;
    font-size: 12px;
    text-align: center;
}

.part-remove {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 2px;
    font-size: 16px;
    line-height: 1;
}

.part-remove:hover {
    color: var(--error);
}

/* Job result */
.job-result {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 24px;
    background: var(--bg-card);
}

.job-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.job-run-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.3px;
}

.job-run-time {
    font-size: 12px;
    color: var(--text-dim);
}

/* Results */
.sheet-preview {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.sheet-preview:last-of-type {
    margin-bottom: 0;
}

.sheet-preview svg {
    width: 100%;
    height: auto;
    max-height: 600px;
}

.download-all-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg-input);
    border-radius: var(--radius);
    margin-bottom: 12px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
}

.stat-value.good { color: var(--success); }
.stat-value.warn { color: var(--warning); }
.stat-value.bad { color: var(--error); }

.stat-label {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

.export-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Alerts */
.alert {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
}

.alert-error {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.3);
    color: var(--error);
}

.alert-success {
    background: rgba(52, 211, 153, 0.1);
    border: 1px solid rgba(52, 211, 153, 0.3);
    color: var(--success);
}

/* Empty state */
/* Hero / Landing */
.hero {
    position: relative;
    padding: 40px 32px;
    max-width: 800px;
    margin: 0 auto;
    animation: fadeIn 0.3s ease;
}

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

.hero-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 20px;
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.hero-close:hover {
    color: var(--text);
    border-color: var(--text-dim);
}

.hero-content h2 {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 12px;
}

.hero-sub {
    color: var(--text-dim);
    font-size: 15px;
    margin-bottom: 32px;
    max-width: 520px;
}

.hero-features {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 32px;
}

.hero-feature {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.hero-icon {
    font-size: 20px;
    margin-bottom: 4px;
}

.hero-feature strong {
    font-size: 13px;
}

.hero-feature span {
    font-size: 12px;
    color: var(--text-dim);
}

.hero-cta {
    text-align: center;
    color: var(--accent);
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 32px;
    padding: 12px;
    background: rgba(91, 127, 245, 0.08);
    border-radius: var(--radius);
}

.hero-arrow {
    font-size: 18px;
}

.hero-pricing {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.hero-price-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.hero-price-featured {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.hero-price-name {
    font-size: 12px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.hero-price-amount {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.hero-price-amount span {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-dim);
}

.hero-price-card ul {
    list-style: none;
    font-size: 12px;
    color: var(--text-dim);
}

.hero-price-card ul li {
    padding: 2px 0;
}

.hero-price-card ul li::before {
    content: "\2713 ";
    color: var(--success);
}

.hero-price-badge {
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.hero-price-old {
    font-size: 16px;
    color: var(--text-dim);
    text-decoration: line-through;
    font-weight: 400;
    margin-right: 4px;
}

.hero-compare {
    text-align: center;
    font-size: 12px;
    color: var(--text-dim);
}

.hero-compare a {
    color: var(--text-dim);
    text-decoration: underline;
}

.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-dim);
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 16px;
    color: var(--text);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 13px;
}

/* Loading */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}

.nest-btn-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.nest-btn-loading .spinner {
    border-top-color: #fff;
    border-color: rgba(255,255,255,0.3);
    border-top-color: #fff;
}

#nest-btn:disabled {
    opacity: 0.7;
    cursor: wait;
}

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

/* Progress */
.nest-progress {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
}

.progress-content {
    text-align: center;
}

.progress-content h3 {
    margin-top: 20px;
    font-size: 18px;
}

.progress-content p {
    color: var(--text-dim);
    font-size: 13px;
    margin-top: 8px;
}

.spinner-large {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}

/* Paywall */
.sheet-svg-wrap {
    position: relative;
    overflow: hidden;
    border-radius: 4px;
}

/* SVG part highlight */
.nested-part {
    transition: opacity 0.2s;
}

.nested-part.highlight path {
    stroke-width: 2 !important;
    filter: drop-shadow(0 0 4px currentColor);
    animation: pulse-highlight 0.6s ease-in-out 3;
}

.nested-part.highlight text {
    font-size: 120%;
}

/* Dim non-highlighted parts when any part is highlighted */
.sheet-svg-wrap:has(.nested-part.highlight) .nested-part:not(.highlight) {
    opacity: 0.2;
}

@keyframes pulse-highlight {
    0%, 100% { filter: drop-shadow(0 0 3px currentColor); }
    50% { filter: drop-shadow(0 0 8px currentColor); }
}

.sheet-locked .sheet-svg-wrap {
    user-select: none;
    pointer-events: none;
}

.sheet-blur-overlay {
    position: absolute;
    inset: 0;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    background: rgba(15, 17, 23, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

html.light .sheet-blur-overlay {
    background: rgba(240, 242, 245, 0.6);
}

.sheet-blur-overlay::after {
    content: "\1F512  Upgrade to view";
    color: var(--text-dim);
    font-size: 14px;
    font-weight: 600;
    background: var(--bg-card);
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.locked-badge {
    background: rgba(251, 191, 36, 0.15);
    color: var(--warning);
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.paywall-cta {
    background: linear-gradient(135deg, rgba(91, 127, 245, 0.08), rgba(155, 89, 182, 0.08));
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 40px 24px;
    text-align: center;
    margin-top: 8px;
}

.paywall-content {
    max-width: 480px;
    margin: 0 auto;
}

.paywall-icon {
    font-size: 36px;
    margin-bottom: 12px;
}

.paywall-content h3 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
}

.paywall-content p {
    color: var(--text-dim);
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 20px;
}

.btn-upgrade {
    font-size: 16px;
    padding: 14px 32px;
    margin: 0 auto;
    display: block;
    background: linear-gradient(135deg, var(--accent), #9b59b6);
    border: none;
    transition: transform 0.15s, box-shadow 0.15s;
}

.btn-upgrade:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(91, 127, 245, 0.3);
    background: linear-gradient(135deg, var(--accent-hover), #8e44ad);
}

.paywall-fine {
    font-size: 12px !important;
    color: var(--text-dim) !important;
    opacity: 0.7;
    margin-top: 12px;
    margin-bottom: 0 !important;
}

/* Part Gallery */
.part-preview {
    cursor: pointer;
}

.gallery-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

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

.gallery-modal {
    display: flex;
    align-items: center;
    gap: 16px;
    max-width: 90vw;
    max-height: 90vh;
}

.gallery-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    min-width: 300px;
    max-width: 70vw;
}

.gallery-svg {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    max-height: 65vh;
}

.gallery-svg svg {
    max-width: 100%;
    max-height: 60vh;
    width: auto;
    height: auto;
}

.gallery-label {
    font-size: 16px;
    font-weight: 600;
    margin-top: 12px;
    color: var(--text);
}

.gallery-counter {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 4px;
}

.gallery-arrow {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 36px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
    line-height: 1;
}

.gallery-arrow:hover {
    background: var(--bg-input);
    border-color: var(--accent);
}

.gallery-close {
    position: fixed;
    top: 16px;
    right: 16px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 101;
    transition: all 0.15s;
}

.gallery-close:hover {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

/* Responsive */
@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
    }
    .main {
        order: 1;
    }
    .sidebar {
        order: 2;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .hero {
        padding: 24px 16px;
    }
    .hero-pricing {
        grid-template-columns: 1fr;
    }
    .hero-features {
        grid-template-columns: 1fr;
    }
}
