@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

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

:root {
    --primary: #475569;
    /* Slate 600 */
    --primary-hover: #334155;
    /* Slate 700 */
    --accent: #4338ca;
    /* Indigo 700 - for subtle highlights */
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --text: #0f172a;
    --text-muted: #475569;
    --border: #cbd5e1;
    --radius: 8px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --success: #10b981;
    --success-bg: #ecfdf5;
    --success-border: #34d399;
    --error: #ef4444;
}

[x-cloak] {
    display: none !important;
}

.text-left {
    text-align: left;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.container {
    width: 100%;
    max-width: 800px;
    padding: 2rem;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0;
    border: 1px solid var(--border);
    overflow: hidden;
}

.card-content {
    padding: 2.5rem;
}

.tabs {
    display: flex;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    padding: 1rem;
    border: none;
    background: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-muted);
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.tab-btn:hover {
    color: var(--text);
    background: #f1f5f9;
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: #ffffff;
}

/* Sub-tabs / Segmented Control */
.segmented-control {
    display: flex;
    background: #f1f5f9;
    padding: 4px;
    border-radius: calc(var(--radius) + 2px);
    margin-bottom: 2rem;
    border: 1px solid var(--border);
}

.segmented-btn {
    flex: 1;
    padding: 0.625rem;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-muted);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.segmented-btn:hover:not(.active) {
    color: var(--text);
    background: rgba(0, 0, 0, 0.05);
}

.segmented-btn.active {
    background: white;
    color: var(--accent);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

h1 {
    font-size: 2rem;
    font-weight: 800;
    margin-top: 0;
    margin-bottom: 0.5rem;
    text-align: center;
    color: var(--text);
    letter-spacing: -0.025em;
}

p.subtitle {
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 2rem;
    font-size: 0.875rem;
}

.upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg);
}

.upload-area:hover,
.upload-area:focus-within {
    border-color: var(--accent);
    background: #ffffff;
    box-shadow: var(--shadow);
}

.upload-area.drag-over {
    border-color: var(--accent);
    border-style: solid;
    background: #eef2ff;
    transform: scale(1.02);
    box-shadow: 0 0 0 3px rgba(67, 56, 202, 0.15);
}

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

.lookup-section {
    margin-top: 2rem;
    animation: fadeIn 0.4s ease-out;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.input-group {
    position: relative;
    margin-bottom: 1.5rem;
}

input[type="text"] {
    width: 100%;
    padding: 0.75rem 1rem;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s ease;
    box-shadow: var(--shadow);
}

input[type="text"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(67, 56, 202, 0.1);
}

.suggestions-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    margin-top: 2px;
    max-height: 250px;
    overflow-y: auto;
    font-size: 0.95rem;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.suggestions-list::-webkit-scrollbar {
    width: 4px;
}

.suggestions-list::-webkit-scrollbar-track {
    background: transparent;
}

.suggestions-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.suggestion-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text);
    transition: background 0.15s;
    scroll-margin-block: 4px;
}

.suggestion-item:hover,
.suggestion-item.highlighted {
    background: #f1f5f9;
    color: var(--accent);
}

.suggestion-item:not(:last-child) {
    border-bottom: 1px solid #f1f5f9;
}

.definition-box {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    min-height: 100px;
    max-height: 420px;
    overflow-y: auto;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.definition-box::-webkit-scrollbar {
    width: 4px;
}

.definition-box::-webkit-scrollbar-track {
    background: transparent;
}

.definition-box::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.definition-box b {
    color: var(--text);
    font-weight: 700;
}

.definition-box i {
    color: #4f46e5;
    /* Indigo 600 - Academic but distinct */
    font-style: italic;
}

.status {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--card-bg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #cbd5e1;
}

.status-indicator.ready {
    background: #10b981;
}

.status-indicator.busy {
    background: #f59e0b;
}

.status-indicator.error {
    background: var(--error);
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.meta-item {
    position: relative;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    font-size: 0.75rem;
}

.meta-item label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text-muted);
}

.meta-item label small {
    display: block;
    font-weight: 400;
    font-size: 0.65rem;
    margin-top: 0.125rem;
}

.stages-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}

.stage-card {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: all 0.3s ease;
    opacity: 0.5;
}

.stage-card.stage-active {
    opacity: 1;
    border-color: var(--accent);
    box-shadow: var(--shadow);
    background: #ffffff;
}

.stage-card.stage-done {
    opacity: 1;
    background: #f0fdf4;
    border-color: #10b981;
}

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

.stage-name {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text);
}

.stage-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
}

.stage-status {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-align: right;
}

.stage-done .stage-status {
    color: #059669;
}

.stage-active .stage-status {
    color: var(--accent);
}

.progress-container {
    background: #e2e8f0;
    border-radius: 999px;
    height: 6px;
    overflow: hidden;
}

.stage-done .progress-bar {
    background: #10b981;
}

.progress-bar {
    height: 100%;
    background: var(--accent);
    transition: width 0.15s ease-out;
}

.btn-convert {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 2rem;
    transition: background 0.2s;
}

.btn-convert:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-convert:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    background: #94a3b8;
}

.btn-download {
    width: 100%;
    padding: 1rem;
    background: #10b981;
    color: white;
    border: none;
    border-radius: var(--radius);
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
    box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2);
}

.btn-download:hover {
    background: #059669;
    transform: translateY(-1px);
}

.btn-download:active {
    transform: translateY(0);
}

@media (max-width: 640px) {
    .container {
        padding: 1rem;
    }

    .card-content {
        padding: 1.5rem 1.25rem;
    }

    .upload-area {
        padding: 2rem 1rem;
    }

    .status {
        bottom: 0.75rem;
        right: 0.75rem;
        font-size: 0.7rem;
        padding: 0.375rem 0.75rem;
    }
}

@media (max-width: 720px) {
    .convert-section [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
}

/* ===== Modal overlay ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 1rem;
}

.modal-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 1.125rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: var(--card-bg);
    border-radius: var(--radius) var(--radius) 0 0;
    z-index: 1;
}

.modal-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.modal-close-btn {
    background: transparent;
    border: none;
    font-size: 1.375rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    transition: all 0.15s;
}

.modal-close-btn:hover {
    background: #f1f5f9;
    color: var(--text);
}

.modal-body {
    padding: 1.5rem;
    flex: 1;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* ===== Metadata table ===== */
.meta-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.meta-table th,
.meta-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.meta-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: #f8fafc;
    white-space: nowrap;
    width: 38%;
}

.meta-table td {
    color: var(--text);
    word-break: break-word;
}

.meta-table tr:last-child th,
.meta-table tr:last-child td {
    border-bottom: none;
}

/* ===== Form elements ===== */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 0.375rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) / 1.5);
    font-size: 0.875rem;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(67, 56, 202, 0.1);
}

.form-input.invalid {
    border-color: #ef4444;
}

.form-input.invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-error {
    font-size: 0.7rem;
    color: #ef4444;
    margin-top: 0.25rem;
    display: block;
}

/* ===== Button variants ===== */
.btn-secondary {
    padding: 0.5rem 1.125rem;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.btn-secondary:hover {
    background: #f1f5f9;
    color: var(--text);
}

.btn-primary {
    padding: 0.5rem 1.125rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
}

.btn-primary:hover {
    background: #3730a3;
}

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