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

:root {
    /* Light theme (default) */
    --bg-primary: #fafafa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f3f4f6;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border-color: #e5e5e5;
    --accent-color: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-muted: rgba(37, 99, 235, 0.1);
    --success-color: #10b981;
    --success-muted: rgba(16, 185, 129, 0.1);
    --warning-color: #f59e0b;
    --warning-muted: rgba(245, 158, 11, 0.1);
    --error-color: #ef4444;
    --error-muted: rgba(239, 68, 68, 0.1);
    --purple-color: #8b5cf6;
    --purple-muted: rgba(139, 92, 246, 0.1);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.08);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
}

[data-theme="dark"] {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #252525;
    --text-primary: #f5f5f5;
    --text-secondary: #a3a3a3;
    --text-muted: #737373;
    --border-color: #2e2e2e;
    --accent-color: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-muted: rgba(59, 130, 246, 0.15);
    --success-color: #22c55e;
    --success-muted: rgba(34, 197, 94, 0.15);
    --warning-color: #fbbf24;
    --warning-muted: rgba(251, 191, 36, 0.15);
    --error-color: #f87171;
    --error-muted: rgba(248, 113, 113, 0.15);
    --purple-color: #a78bfa;
    --purple-muted: rgba(167, 139, 250, 0.15);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
}

/* Header */
header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background 0.3s, border-color 0.3s;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 32px;
}

.logo {
    display: flex;
    flex-direction: column;
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.logo h1 a {
    color: inherit;
    text-decoration: none;
}

.logo p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Navigation */
.nav {
    display: flex;
    gap: 4px;
}

.nav-link {
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.15s;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.nav-link.active {
    color: var(--accent-color);
    background: var(--accent-muted);
}

/* Theme Toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.theme-toggle:hover {
    color: var(--text-primary);
    background: var(--border-color);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
}

.theme-toggle .sun-icon {
    display: none;
}

.theme-toggle .moon-icon {
    display: block;
}

[data-theme="dark"] .theme-toggle .sun-icon {
    display: block;
}

[data-theme="dark"] .theme-toggle .moon-icon {
    display: none;
}

/* Main Content */
main {
    padding: 40px 0 60px;
}

/* Page Title */
.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 32px;
}

/* Search */
.search-container {
    position: relative;
    margin-bottom: 32px;
}

.search-input {
    width: 100%;
    padding: 16px 20px 16px 52px;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s, background 0.3s;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-muted);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-icon {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    pointer-events: none;
}

/* Search Results */
.search-results {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.search-results:empty {
    display: none;
}

.search-item {
    display: block;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
    cursor: pointer;
}

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

.search-item:hover {
    background: var(--bg-tertiary);
}

.search-item-code {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--accent-color);
    margin-bottom: 4px;
}

.search-item-description {
    font-size: 0.9375rem;
    color: var(--text-primary);
    line-height: 1.4;
}

.search-item-meta {
    display: flex;
    gap: 16px;
    margin-top: 8px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.search-empty {
    padding: 24px 20px;
    text-align: center;
    color: var(--text-muted);
}

/* Loading indicator */
.htmx-request .search-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='10' stroke='%23404040' stroke-width='3' fill='none'/%3E%3Cpath d='M12 2a10 10 0 0 1 10 10' stroke='%233b82f6' stroke-width='3' fill='none' stroke-linecap='round'%3E%3CanimateTransform attributeName='transform' type='rotate' from='0 12 12' to='360 12 12' dur='1s' repeatCount='indefinite'/%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 20px;
}

/* Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.stat-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.stat-icon svg {
    width: 24px;
    height: 24px;
}

.stat-icon.blue {
    background: var(--accent-muted);
    color: var(--accent-color);
}

.stat-icon.green {
    background: var(--success-muted);
    color: var(--success-color);
}

.stat-icon.yellow {
    background: var(--warning-muted);
    color: var(--warning-color);
}

.stat-icon.red {
    background: var(--error-muted);
    color: var(--error-color);
}

.stat-icon.purple {
    background: var(--purple-muted);
    color: var(--purple-color);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Progress Section */
.progress-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
}

.progress-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.progress-bar-container {
    margin-bottom: 16px;
}

.progress-bar-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.875rem;
}

.progress-bar-label span:first-child {
    color: var(--text-secondary);
}

.progress-bar-label span:last-child {
    color: var(--text-primary);
    font-weight: 500;
}

.progress-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease-out;
}

.progress-bar-fill.blue {
    background: var(--accent-color);
}

.progress-bar-fill.green {
    background: var(--success-color);
}

/* Status List */
.status-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.status-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.status-list {
    list-style: none;
}

.status-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
}

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

.status-item-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.queue { background: var(--text-muted); }
.status-dot.processing { background: var(--warning-color); animation: pulse 2s infinite; }
.status-dot.done { background: var(--accent-color); }
.status-dot.processed { background: var(--success-color); }
.status-dot.error { background: var(--error-color); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status-item-name {
    font-size: 0.875rem;
    color: var(--text-primary);
}

.status-badge {
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    border-radius: var(--radius-sm);
}

.status-badge.queue {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.status-badge.processing {
    background: var(--warning-muted);
    color: var(--warning-color);
}

.status-badge.done {
    background: var(--accent-muted);
    color: var(--accent-color);
}

.status-badge.processed {
    background: var(--success-muted);
    color: var(--success-color);
}

.status-badge.error {
    background: var(--error-muted);
    color: var(--error-color);
}

/* Composition Detail */
.composition-header {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 28px;
    margin-bottom: 24px;
    border: 1px solid var(--border-color);
}

.composition-code {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--accent-color);
    margin-bottom: 8px;
}

.composition-title {
    font-size: 1.375rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
    margin-bottom: 16px;
}

.composition-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.meta-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.meta-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.meta-value {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-primary);
}

.meta-value.highlight {
    color: var(--accent-color);
    font-weight: 600;
}

/* Cost Breakdown */
.cost-breakdown {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid var(--border-color);
}

.cost-item {
    text-align: center;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.cost-value {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.cost-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.cost-percent {
    font-size: 0.6875rem;
    color: var(--text-muted);
}

/* Items Table */
.items-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.items-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.items-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.items-count {
    font-weight: 400;
    color: var(--text-secondary);
    margin-left: 8px;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
}

.items-table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.items-table td {
    padding: 14px 16px;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
}

.items-table tr:last-child td {
    border-bottom: none;
}

.items-table tr:hover {
    background: var(--bg-tertiary);
}

.item-code {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.8125rem;
    color: var(--accent-color);
    white-space: nowrap;
}

.item-description {
    color: var(--text-primary);
    max-width: 400px;
}

.item-type {
    display: inline-block;
    padding: 2px 8px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    border-radius: 4px;
}

.item-type.composicao {
    background: var(--accent-muted);
    color: var(--accent-color);
}

.item-type.insumo {
    background: var(--success-muted);
    color: var(--success-color);
}

.item-numeric {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.8125rem;
    text-align: right;
    white-space: nowrap;
}

/* Back link */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    margin-bottom: 20px;
    transition: color 0.15s;
}

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

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 0 16px;
    }

    .header-left {
        gap: 16px;
    }

    .nav {
        display: none;
    }

    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .composition-header {
        padding: 20px;
    }

    .composition-meta {
        gap: 16px;
    }

    .cost-breakdown {
        grid-template-columns: repeat(2, 1fr);
        padding: 16px;
    }

    .items-table {
        display: block;
        overflow-x: auto;
    }
}
