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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #eef1f6;
    min-height: 0;
    height: auto;
    padding: 0;
    color: #333;
    width: 500px;
    max-height: 800px;
    overflow-y: auto;
}

.container {
    background: white;
    overflow: hidden;
}

header {
    background: #26354d;
    color: white;
    padding: 25px 20px;
    text-align: center;
}

header h1 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 1.8em;
    margin-bottom: 8px;
    font-weight: 700;
}

.ui-icon {
    display: block;
    width: 1.25em;
    height: 1.25em;
    flex: 0 0 auto;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.title-icon {
    width: 1.05em;
    height: 1.05em;
}

header p {
    font-size: 0.95em;
    opacity: 0.9;
}

main {
    padding: 25px 20px;
}

/* Upload Section */
.upload-section {
    margin-bottom: 0;
}

.upload-box {
    border: 3px dashed #2563eb;
    border-radius: 15px;
    padding: 40px 15px;
    text-align: center;
    background: #eff6ff;
    cursor: pointer;
    transition: all 0.3s ease;
}

.upload-box:hover {
    border-color: #1d4ed8;
    background: #dbeafe;
    transform: translateY(-2px);
}

.upload-box.dragover {
    border-color: #1d4ed8;
    background: #bfdbfe;
    transform: scale(1.02);
}

.upload-content svg {
    color: #2563eb;
    margin-bottom: 15px;
}

.upload-text {
    font-size: 1em;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.upload-hint {
    color: #666;
    font-size: 0.85em;
    margin-bottom: 15px;
}

.btn-select {
    background: #2563eb;
    color: white;
    border: none;
    padding: 10px 25px;
    border-radius: 25px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-select:hover {
    background: #1d4ed8;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(37, 99, 235, 0.28);
}

/* File Info */
.file-info {
    padding: 15px;
    background: #eff6ff;
    border-radius: 10px;
    border: 2px solid #bfdbfe;
}

.file-details {
    display: flex;
    align-items: center;
    gap: 12px;
}

.file-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    color: #2563eb;
}

.file-text {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
    font-size: 0.9em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-size {
    color: #666;
    font-size: 0.85em;
}

.btn-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #dc3545;
    color: white;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.btn-remove:hover {
    background: #b92332;
}

/* ZIP Archive Contents */
.archive-section {
    margin-top: 20px;
    padding: 14px;
    background: #eff6ff;
    border: 2px solid #bfdbfe;
    border-radius: 12px;
}

.archive-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.archive-header h2 {
    margin: 0 0 4px;
    color: #333;
    font-size: 0.98em;
}

.archive-summary {
    margin: 0;
    color: #666;
    font-size: 0.78em;
    line-height: 1.35;
}

.archive-filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}

.archive-filter {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    color: #5b6475;
    font-size: 0.72em;
    font-weight: 700;
}

.archive-filter-select {
    width: 100%;
    min-width: 0;
    padding: 8px 9px;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    background: #fff;
    color: #333;
    font-family: inherit;
    font-size: 0.65rem;
    line-height: 1.25;
    font-weight: 600;
}

.archive-filter-select option {
    font-size: 0.65rem;
}

.archive-filter-select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.archive-count {
    flex-shrink: 0;
    padding: 5px 9px;
    color: #1d4ed8;
    background: #dbeafe;
    border-radius: 999px;
    font-size: 0.75em;
    font-weight: 700;
}

.archive-search {
    width: 100%;
    margin-bottom: 10px;
    padding: 9px 11px;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    background: white;
    color: #333;
    font: inherit;
    font-size: 0.85em;
}

.archive-search:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

@media (max-width: 420px) {
    .archive-filters {
        grid-template-columns: 1fr;
    }
}

.archive-list {
    display: flex;
    flex-direction: column;
    gap: 7px;
    max-height: 245px;
    overflow-y: auto;
    padding-right: 3px;
}

.archive-item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px;
    border: 1px solid #bfdbfe;
    border-radius: 9px;
    background: white;
    color: #333;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.archive-item:hover:not(:disabled) {
    border-color: #60a5fa;
    background: #eff6ff;
    transform: translateY(-1px);
}

.archive-item.selected {
    border-color: #2563eb;
    background: #eff6ff;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.archive-item:disabled {
    cursor: not-allowed;
    opacity: 0.58;
}

.archive-item-main {
    min-width: 0;
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 3px;
}

.archive-item-name,
.archive-item-path {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.archive-item-name {
    font-size: 0.83em;
    font-weight: 700;
}

.archive-item-path {
    color: #6b7280;
    font-size: 0.7em;
}

.archive-item-meta {
    display: flex;
    flex-shrink: 0;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.archive-type-badge {
    min-width: 31px;
    padding: 3px 6px;
    color: #fff;
    background: #2563eb;
    border-radius: 999px;
    font-size: 0.68em;
    font-weight: 700;
    text-align: center;
}

.archive-item-size {
    color: #6b7280;
    font-size: 0.68em;
    white-space: nowrap;
}

.archive-empty {
    padding: 22px 12px;
    color: #6b7280;
    background: white;
    border: 1px dashed #bfdbfe;
    border-radius: 9px;
    font-size: 0.83em;
    text-align: center;
}

/* Form Section */
.form-section {
    margin-top: 20px;
}

/* Detection Info */
.detection-info {
    margin-bottom: 15px;
    padding: 10px;
    background: #e8f4f8;
    border: 1px solid #4a90e2;
    border-radius: 10px;
    animation: slideDown 0.3s ease;
}

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

.detection-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    font-size: 0.85em;
}

.detection-icon {
    font-size: 1.1em;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    font-size: 0.95em;
}

.form-select {
    width: 100%;
    padding: 12px;
    border: 2px solid #bfdbfe;
    border-radius: 10px;
    font-size: 0.95em;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

.form-select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn-convert,
.btn-print {
    width: auto;
    background: #fff;
    color: #315f8f;
    border: 1px solid rgba(255, 255, 255, 0.7);
    padding: 8px 13px;
    border-radius: 999px;
    font-size: 0.88em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-convert:hover:not(:disabled),
.btn-print:hover:not(:disabled) {
    background: #eef4fa;
}

.btn-convert:disabled,
.btn-print:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-close-preview {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.btn-close-preview:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* HTML Preview Section */
.html-preview-section {
    margin-top: 20px;
    border: 2px solid #3b82f6;
    border-radius: 15px;
    overflow: hidden;
    background: white;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    animation: slideUp 0.4s ease;
}

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

.html-preview-header {
    background: #315f8f;
    color: white;
    padding: 12px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.html-preview-header h4 {
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 0;
    font-size: 1em;
    font-weight: 600;
}

.html-preview-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-download-icon {
    width: 17px;
    height: 17px;
}

.html-preview-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 300px;
    background: #f5f5f5;
    padding: 30px;
}

.loader-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #bfdbfe;
    border-top: 4px solid #2563eb;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

.html-preview-loader p {
    color: #2563eb;
    font-weight: 600;
    font-size: 0.9em;
    margin: 0;
}

.html-preview-wrapper {
    width: 100%;
    height: 400px;
    overflow: auto;
    background: #f5f5f5;
    padding: 8px;
    display: none;
}

.html-preview-wrapper.show {
    display: block;
}

.html-preview {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
    min-height: 400px;
}

.preview-empty-state {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    height: 100%;
    padding: 40px;
    border: 2px solid #dce4f3;
    border-radius: 15px;
    background: #fbfcff;
    color: #526174;
    text-align: center;
}

.preview-empty-illustration {
    width: min(220px, 42%);
    margin-bottom: 18px;
}

.preview-empty-illustration svg {
    display: block;
    width: 100%;
    height: auto;
}

.wireframe-page-outline {
    stroke: #9aadd0;
    stroke-width: 2;
    stroke-dasharray: 5 5;
    fill: #fff;
}

.wireframe-line {
    stroke: #c1cde2;
    stroke-width: 4;
    stroke-linecap: round;
}

.wireframe-block {
    fill: #e8eef9;
    stroke: #b5c4de;
    stroke-width: 2;
}

.wireframe-arrow {
    stroke: #2563eb;
    stroke-width: 4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.preview-empty-state h2 {
    margin: 0 0 8px;
    color: #26354d;
    font-size: 1.2rem;
}

.preview-empty-state p {
    max-width: 420px;
    margin: 0;
    color: #526174;
    font-size: 0.95rem;
    line-height: 1.5;
}

.preview-empty-hint {
    margin-top: 12px;
    color: #8190a6;
    font-size: 0.82rem;
}

/* Button Loader Animation */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.btn-loader svg {
    display: inline-block;
    vertical-align: middle;
    animation: spin 1s linear infinite;
}

/* Inline Result Message */
.result-message-inline {
    margin-top: 12px;
    animation: slideDown 0.3s ease;
}

.success-message-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 15px;
    background: #f0fdf4;
    border: 2px solid #4ade80;
    border-radius: 10px;
    color: #166534;
}

.success-icon-inline {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.success-message-inline p {
    margin: 0;
    font-size: 0.9em;
    font-weight: 500;
    color: #166534;
}

/* Error Section */
.error-section {
    margin-top: 20px;
}

.error-message {
    text-align: center;
    padding: 30px 20px;
    background: #fff5f5;
    border: 2px solid #f87171;
    border-radius: 15px;
}

.error-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin: 0 auto 15px;
    color: #dc2626;
}

.error-message h3 {
    color: #dc2626;
    margin-bottom: 12px;
    font-size: 1.3em;
}

.error-message p {
    color: #666;
    margin-bottom: 20px;
    font-size: 0.9em;
}

.btn-retry {
    background: #dc3545;
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 10px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-retry:hover {
    background: #b92332;
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(248, 113, 113, 0.4);
}

.workspace-page:not(.has-file) .preview-empty-state {
    display: none !important;
}

/* Full-page document workspace */
body.workspace-page {
    width: auto;
    max-height: none;
    min-width: 0;
    padding: 20px;
    overflow-y: auto;
}

.workspace-page .container {
    /* width: min(1440px, 100%); */
    height: calc(100vh - 40px);
    min-height: calc(100vh - 40px);
    margin: 0 auto;
    border: 1px solid #d9dee8;
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(31, 41, 55, 0.08);
    display: flex;
    flex-direction: column;
}

.seo-content {
    width: min(1180px, calc(100% - 32px));
    margin: 20px auto 20px;
    color: #26354d;
}

.seo-content-intro {
    max-width: 760px;
    margin-bottom: 26px;
}

.seo-eyebrow {
    margin-bottom: 8px;
    color: #2563eb;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.seo-content h2 {
    margin-bottom: 12px;
    color: #1e293b;
    font-size: clamp(1.55rem, 3vw, 2.15rem);
    line-height: 1.2;
}

.seo-content p {
    color: #526077;
    line-height: 1.7;
}

.seo-feature-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

.seo-feature-grid article {
    padding: 24px;
    background: #fff;
    border: 1px solid #d9dee8;
    border-radius: 12px;
}

.seo-feature-grid h3 {
    margin-bottom: 9px;
    color: #1e293b;
    font-size: 1rem;
}

.workspace-page header {
    flex: 0 0 auto;
    padding: 24px 30px;
    text-align: left;
}

.workspace-page header h1 {
    justify-content: flex-start;
    font-size: 1.55em;
}

.workspace-page main {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
    gap: 20px;
    padding: 24px;
    align-items: stretch;
}

.workspace-page .workspace-sidebar {
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.workspace-page .upload-section {
    order: 2;
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
}

.workspace-page .upload-box {
    padding: 24px 15px;
}

.workspace-page.has-file .upload-box {
    display: none;
}

.workspace-page .archive-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
}

.workspace-page .form-section {
    order: 1;
    flex: 0 0 auto;
    margin: 0;
    padding: 14px;
    border: 1px solid #d9dee8;
    border-radius: 12px;
    background: #fff;
}

.workspace-page .form-group {
    margin-bottom: 0;
}

.workspace-page .detection-info {
    margin-bottom: 12px;
}

.workspace-page .html-preview-section {
    min-height: 0;
    height: 100%;
    margin: 0;
    flex-direction: column;
}

.workspace-page .preview-empty-state {
    grid-column: 2;
}

.workspace-page .html-preview-header {
    flex: 0 0 auto;
}

.workspace-page .html-preview-wrapper {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    overflow: hidden;
}

.workspace-page .html-preview {
    height: 100%;
    min-height: 0;
}

.workspace-page .error-section {
    order: 3;
    flex: 0 0 auto;
    margin: 0;
}

.workspace-page .archive-section {
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
}

/* Keep the empty/error workspace compact until a document is available. */
.workspace-page:not(.has-file) main {
    display: block;
    overflow-y: auto;
}

.workspace-page:not(.has-file) .container {
    width: min(1180px, calc(100% - 32px));
    height: auto;
    min-height: 0;
}

.workspace-page:not(.has-file) .workspace-sidebar {
    width: min(640px, 100%);
    height: auto;
    margin: 0 auto;
}

.workspace-page:not(.has-file) .upload-section {
    flex: 0 0 auto;
}

@media (max-width: 900px) {
    body.workspace-page {
        padding: 0;
    }

    .workspace-page .container {
        height: auto;
        min-height: 100vh;
        border: 0;
        border-radius: 0;
    }

    .workspace-page:not(.has-file) .container {
        width: min(calc(100% - 36px), 680px);
    }

    .workspace-page main {
        display: block;
        padding: 18px;
    }

    .workspace-page .workspace-sidebar,
    .workspace-page .html-preview-section,
    .workspace-page .preview-empty-state {
        height: auto;
    }

    .workspace-page .upload-section,
    .workspace-page .form-section,
    .workspace-page .html-preview-section,
    .workspace-page .preview-empty-state,
    .workspace-page .error-section {
        margin-bottom: 18px;
    }

    .workspace-page .archive-list {
        max-height: 320px;
        min-height: 0;
    }

    .workspace-page .html-preview-wrapper,
    .workspace-page .html-preview {
        height: 540px;
        min-height: 540px;
    }

    .seo-content {
        width: min(100% - 36px, 680px);
        margin-top: 36px;
    }

    .seo-feature-grid {
        grid-template-columns: 1fr;
    }
}
