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

:root {
    --teal: #00695c;
    --teal-dark: #004d40;
    --teal-mid: #00796b;
    --teal-pale: #e0f2f1;
    --teal-faint: #f0faf9;
    --mustard: #e6a817;
    --mustard-dark: #c88c00;
    --mustard-pale: #fff8e1;
    --bg: #f8fafa;
    --surface: #ffffff;
    --border: #e0e8e7;
    --border-mid: #c8d8d6;
    --text: #1a2e2c;
    --text-2: #4a6360;
    --text-3: #8aacaa;
    --error: #c62828;
    --mono: 'DM Mono', 'Google Sans Mono', 'Courier New', monospace;
    --sans: 'Nunito Sans', 'Google Sans', 'Google Sans Text', system-ui, sans-serif;
    --radius: 10px;
}

html,
body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

button,
input,
label {
    font: inherit;
}

button,
label {
    cursor: pointer;
}

.hidden {
    display: none !important;
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 0 32px;
    min-height: 56px;
}

.logo,
.header-right,
.step-trail,
.format-row,
.metrics,
.actions,
.preview-head,
.footer,
.footer-status {
    display: flex;
    align-items: center;
}

.logo {
    gap: 10px;
}

.logo-mark {
    width: 28px;
    height: 28px;
    background: var(--teal);
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--teal-dark);
    letter-spacing: -0.2px;
}

.logo-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--mustard);
    margin-left: 2px;
    display: inline-block;
    vertical-align: middle;
}

.header-right {
    gap: 20px;
}

.step-trail {
    gap: 6px;
}

.step-item {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-3);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.step-item--active {
    color: var(--teal);
    font-weight: 600;
}

.step-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    border: 1.5px solid var(--border-mid);
    flex-shrink: 0;
}

.step-dot--active {
    background: var(--teal);
    border-color: var(--teal);
}

.step-dot--done {
    background: var(--border-mid);
    border-color: var(--border-mid);
}

.step-sep {
    color: var(--border-mid);
    font-size: 11px;
}

.btn-reset {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
    background: none;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 6px 14px;
    transition: all 0.15s;
}

.btn-reset:hover,
.btn-secondary:hover {
    border-color: var(--border-mid);
    color: var(--text);
}

.main {
    flex: 1;
    max-width: 680px;
    width: 100%;
    margin: 0 auto;
    padding: 40px 24px 64px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.sec-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-3);
    margin-bottom: 10px;
}

.format-row {
    gap: 8px;
    flex-wrap: wrap;
}

.format-row input {
    display: none;
}

.fmt-pill {
    font-size: 13px;
    font-weight: 600;
    padding: 7px 18px;
    border-radius: 99px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    transition: all 0.15s;
}

.fmt-pill:hover {
    border-color: var(--border-mid);
    color: var(--text);
}

.format-row input:checked + .fmt-pill {
    background: var(--teal);
    border-color: var(--teal);
    color: #fff;
}

.fmt-desc {
    font-size: 12px;
    color: var(--text-3);
    margin-left: 4px;
}

.dropzone {
    background: var(--surface);
    border: 1.5px dashed var(--border-mid);
    border-radius: var(--radius);
    min-height: 220px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s;
    position: relative;
}

.dropzone:hover,
.dropzone--drag {
    border-color: var(--teal);
    background: var(--teal-faint);
}

.drop-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--teal-pale);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--teal);
    transition: all 0.2s;
}

.dropzone:hover .drop-icon,
.dropzone--drag .drop-icon {
    background: var(--teal);
    color: #fff;
}

.drop-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.drop-hint {
    font-size: 12px;
    color: var(--text-3);
}

.drop-types {
    display: flex;
    gap: 5px;
    margin-top: 2px;
}

.type-chip,
.fmt-badge {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--teal-pale);
    color: var(--teal-mid);
    border: 1px solid #b2dfdb;
}

.processing {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 220px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2.5px solid var(--teal-pale);
    border-top-color: var(--teal);
    animation: spin 0.8s linear infinite;
}

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

.proc-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.proc-steps {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 200px;
}

.proc-step {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-3);
}

.proc-step--active {
    color: var(--teal);
    font-weight: 500;
}

.p-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--border-mid);
    flex-shrink: 0;
}

.p-dot--active {
    background: var(--teal);
}

.p-dot--done {
    background: var(--teal-pale);
    border: 1px solid var(--teal);
}

.results-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.metrics {
    flex-wrap: wrap;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    animation: up 0.3s ease both;
}

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

.metric-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-2);
}

.metric-item strong {
    font-weight: 700;
    color: var(--text);
}

.k-metric-warn {
    color: var(--mustard-dark) !important;
}

.metric-sep {
    color: var(--border-mid);
    font-size: 14px;
}

.reduction-badge {
    background: var(--mustard-pale);
    border: 1px solid #ffe082;
    color: var(--mustard-dark);
    font-size: 12px;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 99px;
    white-space: nowrap;
}

.ocr-badge {
    font-size: 12px;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 99px;
    white-space: nowrap;
}

.ocr-badge--applied {
    background: var(--mustard-pale);
    color: var(--mustard-dark);
    border: 1px solid #ffe082;
}

.ocr-badge--skip {
    background: var(--teal-pale);
    color: var(--teal-mid);
    border: 1px solid #b2dfdb;
}

.preview-head {
    justify-content: space-between;
    gap: 12px;
}

.preview-head .sec-label {
    margin-bottom: 0;
}

.preview-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    animation: up 0.3s ease both;
}

.preview-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--teal-faint);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--teal-dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 6px;
    transition: all 0.15s;
}

.btn-icon:hover {
    background: var(--border);
    color: var(--text);
}

.preview-filename {
    font-size: 13px;
    font-weight: 600;
    color: var(--teal-dark);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fmt-badge {
    text-transform: uppercase;
    white-space: nowrap;
}

.code-block {
    background: #1a2e2c;
    max-height: 360px;
    min-height: 220px;
    overflow: auto;
    padding: 18px 20px;
    scrollbar-width: thin;
    scrollbar-color: #2a4a47 transparent;
}

.code-block pre,
.code-block code {
    font-family: var(--mono);
    font-size: 11.5px;
    line-height: 1.65;
    color: #7db8b3;
    white-space: pre-wrap;
    word-break: break-word;
}

.code-block::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.code-block::-webkit-scrollbar-track {
    background: transparent;
}

.code-block::-webkit-scrollbar-thumb {
    background: #2a4a47;
    border-radius: 4px;
}

.rendered-content {
    font-family: var(--sans);
    color: #d8efed;
}

.rendered-content h1,
.rendered-content h2,
.rendered-content h3,
.rendered-content h4 {
    color: #f0faf9;
    margin: 0 0 12px;
}

.rendered-content p,
.rendered-content li {
    color: #b8d6d2;
    margin-bottom: 10px;
}

.rendered-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 12px;
}

.rendered-content th,
.rendered-content td {
    border: 1px solid #2a4a47;
    padding: 8px 10px;
    text-align: left;
}

.view-toggle {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    padding: 2px;
    gap: 2px;
}

.view-btn {
    background: transparent;
    border: 0;
    color: var(--text-3);
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 5px 10px;
    text-transform: uppercase;
}

.view-btn.active {
    background: var(--teal);
    color: #fff;
}

.actions {
    gap: 8px;
}

.btn-primary,
.btn-secondary {
    border-radius: 8px;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    flex: 1;
    background: var(--teal);
    color: #fff;
    border: none;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
}

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

.btn-secondary {
    background: var(--surface);
    color: var(--text-2);
    border: 1px solid var(--border);
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.btn-secondary--done {
    color: var(--teal);
    border-color: #b2dfdb;
}

.footer {
    border-top: 1px solid var(--border);
    padding: 12px 32px;
    justify-content: space-between;
    background: var(--surface);
    margin-top: auto;
}

.footer-note,
.footer-status {
    font-size: 11px;
    color: var(--text-3);
}

.footer-status {
    gap: 6px;
}

.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--teal);
}

.error-toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1000;
    background: #fff5f5;
    color: var(--error);
    border: 1px solid #ffcdd2;
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(26, 46, 44, 0.12);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: min(360px, calc(100vw - 32px));
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(26, 46, 44, 0.6);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    animation: fade 0.2s ease;
}

@keyframes fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    animation: slideUp 0.3s ease;
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--teal-faint);
    border-radius: var(--radius) var(--radius) 0 0;
}

.modal-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--teal-dark);
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.modal-title span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.modal-body {
    flex: 1;
    overflow: auto;
    padding: 24px;
    background: #1a2e2c;
    border-radius: 0 0 var(--radius) var(--radius);
}

.modal-body pre {
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.65;
    color: #7db8b3;
    white-space: pre-wrap;
    word-break: break-word;
}

#close-error {
    background: transparent;
    border: 0;
    color: var(--error);
    font-size: 18px;
    line-height: 1;
}

.shutdown-state {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
    text-align: center;
}

.shutdown-state h1 {
    color: var(--teal-dark);
    font-size: 24px;
}

.shutdown-state p {
    color: var(--text-3);
}

@media (max-width: 720px) {
    .header,
    .footer {
        padding-left: 20px;
        padding-right: 20px;
    }

    .header {
        align-items: flex-start;
        flex-direction: column;
        padding-top: 14px;
        padding-bottom: 14px;
    }

    .header-right {
        width: 100%;
        justify-content: space-between;
        gap: 12px;
    }

    .step-trail {
        overflow-x: auto;
        max-width: 100%;
        padding-bottom: 2px;
    }

    .main {
        padding: 28px 16px 44px;
    }

    .fmt-desc {
        flex-basis: 100%;
        margin-left: 0;
    }

    .metrics,
    .actions,
    .footer {
        align-items: stretch;
        flex-direction: column;
    }

    .modal-overlay {
        padding: 16px;
    }

    .metric-sep {
        display: none;
    }

    .btn-primary {
        width: 100%;
    }
}
