/* ============================================
   Food Spec Extraction - Dark Theme
   Matches DAT Workspace design language
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #222636;
    --bg-input: #2a2e3f;
    --border: #2e3348;
    --text-primary: #f5f6fa;
    --text-secondary: #cdd1e0;
    --text-muted: #a0a4b8;
    --accent: #6c8cff;
    --accent-hover: #8ba4ff;
    --green: #4ade80;
    --yellow: #facc15;
    --red: #f87171;
    --orange: #fb923c;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);

    --header-height: 52px;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* ---------- Header ---------- */
.header {
    background: rgba(15, 17, 23, 0.6);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(108, 140, 255, 0.1);
    padding: 0 20px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header__back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
}

.header__back:hover {
    background: rgba(108, 140, 255, 0.15);
    color: var(--text-primary);
}

.header__back svg {
    width: 20px;
    height: 20px;
}

.header__title {
    font-size: 1.1rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent) 0%, hsla(270, 50%, 65%, 1) 50%, hsla(40, 80%, 60%, 1) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
}

/* ---------- Main ---------- */
.main {
    max-width: 900px;
    margin: 0 auto;
    padding: 32px 20px;
}

/* ---------- Section visibility ---------- */
.upload-section,
.progress-section,
.error-section,
.results-section {
    display: none;
}

.upload-section.is-visible,
.progress-section.is-visible,
.error-section.is-visible,
.results-section.is-visible {
    display: block;
}

/* ---------- Upload Zone ---------- */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 60px 40px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    background: rgba(34, 38, 54, 0.4);
}

.upload-zone:hover {
    border-color: var(--accent);
    background: rgba(108, 140, 255, 0.05);
}

.upload-zone.drag-over {
    border-color: var(--accent);
    background: rgba(108, 140, 255, 0.1);
    border-style: solid;
}

.upload-icon {
    width: 64px;
    height: 64px;
    color: var(--text-muted);
    margin-bottom: 16px;
    opacity: 0.6;
}

.upload-title {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.upload-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ---------- Progress ---------- */
.progress-card {
    background: rgba(34, 38, 54, 0.92);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    text-align: center;
}

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

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

.progress-filename {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.progress-status {
    font-size: 0.95rem;
    color: var(--accent);
}

.progress-detail {
    font-size: 0.85rem;
    color: var(--text-muted);
    max-width: 400px;
}

/* ---------- Error ---------- */
.error-card {
    background: rgba(34, 38, 54, 0.92);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(248, 113, 113, 0.3);
    border-radius: 12px;
    padding: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    text-align: center;
}

.error-icon {
    width: 48px;
    height: 48px;
    color: var(--red);
}

.error-message {
    font-size: 0.95rem;
    color: var(--red);
    max-width: 400px;
}

/* ---------- Buttons ---------- */
.btn {
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    transition: background 0.2s, opacity 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn--primary {
    background: rgba(108, 140, 255, 0.15);
    color: var(--text-secondary);
    border: 1px solid rgba(108, 140, 255, 0.2);
}

.btn--primary:hover {
    background: rgba(108, 140, 255, 0.25);
    color: var(--text-primary);
}

/* ---------- Results: Summary Card ---------- */
.summary-card {
    background: rgba(34, 38, 54, 0.92);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
}

.summary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.summary-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.summary-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

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

/* ---------- Badge ---------- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    width: fit-content;
}

.badge.confidence-high {
    background: rgba(74, 222, 128, 0.15);
    color: var(--green);
    border: 1px solid rgba(74, 222, 128, 0.25);
}

.badge.confidence-medium {
    background: rgba(250, 204, 21, 0.15);
    color: var(--yellow);
    border: 1px solid rgba(250, 204, 21, 0.25);
}

.badge.confidence-low {
    background: rgba(248, 113, 113, 0.15);
    color: var(--red);
    border: 1px solid rgba(248, 113, 113, 0.25);
}

/* ---------- Results: Fields Table ---------- */
.fields-card {
    background: rgba(34, 38, 54, 0.92);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.fields-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
}

.table-container {
    overflow-x: auto;
}

.fields-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.fields-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 10px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.fields-table th:last-child {
    width: 160px;
}

.fields-table td {
    padding: 10px 16px;
    border-bottom: 1px solid rgba(46, 51, 72, 0.5);
    color: var(--text-primary);
    vertical-align: top;
}

.field-name {
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    width: 200px;
}

.field-value {
    color: var(--text-primary);
    word-break: break-word;
}

.field-row:hover td {
    background: rgba(108, 140, 255, 0.04);
}

/* ---------- Confidence Bar ---------- */
.field-confidence {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.confidence-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
    min-width: 60px;
}

.confidence-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.confidence-fill.confidence-high {
    background: var(--green);
}

.confidence-fill.confidence-medium {
    background: var(--yellow);
}

.confidence-fill.confidence-low {
    background: var(--red);
}

.confidence-pct {
    font-size: 0.8rem;
    color: var(--text-muted);
    min-width: 32px;
    text-align: right;
}

/* ---------- Evidence ---------- */
.evidence-row td {
    padding: 0 16px 10px;
    border-bottom: 1px solid var(--border);
}

.evidence-toggle {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 0;
    font-family: inherit;
}

.evidence-toggle:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.evidence-content {
    display: none;
    margin-top: 6px;
    padding: 10px 14px;
    background: rgba(42, 46, 63, 0.6);
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    line-height: 1.5;
    border-left: 3px solid var(--border);
}

.evidence-content.is-visible {
    display: block;
}

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

/* ---------- Pipeline / How it works ---------- */
.pipeline-details {
    margin-top: 20px;
}

.pipeline-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 20px;
    background: rgba(34, 38, 54, 0.6);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    list-style: none;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
    user-select: none;
}

.pipeline-summary::-webkit-details-marker {
    display: none;
}

.pipeline-summary:hover {
    background: rgba(108, 140, 255, 0.08);
    border-color: rgba(108, 140, 255, 0.25);
    color: var(--text-primary);
}

.pipeline-summary__icon {
    width: 18px;
    height: 18px;
    color: var(--accent);
    flex-shrink: 0;
}

.pipeline-summary__chevron {
    width: 16px;
    height: 16px;
    margin-left: auto;
    transition: transform 0.25s ease;
    flex-shrink: 0;
}

.pipeline-details[open] > .pipeline-summary .pipeline-summary__chevron {
    transform: rotate(180deg);
}

.pipeline-details[open] > .pipeline-summary {
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom-color: transparent;
}

.pipeline-content {
    background: rgba(34, 38, 54, 0.92);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    padding: 24px;
    animation: fadeIn 0.2s ease;
}

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

.pipeline-intro {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 20px;
}

.pipeline-intro strong {
    color: var(--accent);
    font-weight: 600;
}

/* Flow diagram */
.pipeline-flow {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 28px;
    padding: 16px;
    background: rgba(15, 17, 23, 0.5);
    border-radius: var(--radius);
    border: 1px solid rgba(108, 140, 255, 0.1);
}

.pipeline-flow__step {
    padding: 6px 14px;
    background: rgba(108, 140, 255, 0.12);
    border: 1px solid rgba(108, 140, 255, 0.2);
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
}

.pipeline-flow__arrow {
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Steps */
.pipeline-steps {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 24px;
}

.pipeline-step {
    display: flex;
    gap: 16px;
    padding: 14px 16px;
    border-radius: var(--radius);
    transition: background 0.15s;
}

.pipeline-step:hover {
    background: rgba(108, 140, 255, 0.04);
}

.pipeline-step__number {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(108, 140, 255, 0.15);
    border: 1px solid rgba(108, 140, 255, 0.25);
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent);
    flex-shrink: 0;
    margin-top: 1px;
}

.pipeline-step__body {
    flex: 1;
    min-width: 0;
}

.pipeline-step__title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.pipeline-step__body p {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.55;
}

/* Categories */
.pipeline-categories__title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 12px;
}

.pipeline-categories__grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pipeline-tag {
    padding: 4px 12px;
    background: rgba(250, 204, 21, 0.08);
    border: 1px solid rgba(250, 204, 21, 0.15);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--yellow);
}

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

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
    .main {
        padding: 20px 12px;
    }

    .upload-zone {
        padding: 40px 20px;
    }

    .summary-grid {
        grid-template-columns: 1fr 1fr;
    }

    .field-name {
        width: auto;
    }

    .fields-table th:last-child {
        width: 120px;
    }
}
