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

:root {
    --bg: #f4f6f9;
    --card: #ffffff;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success: #16a34a;
    --success-hover: #15803d;
    --danger: #dc2626;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.04);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); }

/* ===== Layout ===== */
.container {
    max-width: 860px;
    margin: 0 auto;
    padding: 2rem 1.25rem 4rem;
}

header { text-align: center; margin-bottom: 2rem; }
header h1 { font-size: 2rem; font-weight: 700; }
.subtitle { color: var(--text-muted); margin-top: .25rem; }

footer { text-align: center; margin-top: 3rem; color: var(--text-muted); font-size: .85rem; }

/* ===== Cards ===== */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    position: relative;
}

.step-badge {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 3px 10px;
    border-radius: 50px;
    margin-bottom: .75rem;
}

.result-badge { background: var(--success); }

.card h2 { font-size: 1.2rem; margin-bottom: .35rem; }
.help-text { color: var(--text-muted); font-size: .9rem; margin-bottom: 1rem; }
.help-text code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: .85em;
}

/* ===== Inputs ===== */
.input-group {
    display: flex;
    gap: .5rem;
    margin-bottom: .5rem;
}
.input-group input {
    flex: 1;
    padding: .6rem .75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .95rem;
    outline: none;
    transition: border .2s;
}
.input-group input:focus { border-color: var(--primary); }

textarea {
    width: 100%;
    padding: .75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .95rem;
    font-family: inherit;
    resize: vertical;
    outline: none;
    transition: border .2s;
}
textarea:focus { border-color: var(--primary); }

select {
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .9rem;
    background: #fff;
    margin-top: .5rem;
    width: 100%;
}

/* ===== Buttons ===== */
button { cursor: pointer; border: none; font-family: inherit; font-size: .9rem; }

.btn-icon {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.btn-link {
    background: none;
    color: var(--primary);
    text-decoration: underline;
    font-size: .85rem;
    margin-top: .5rem;
}

.btn-sm {
    background: transparent;
    color: var(--danger);
    font-size: 1.2rem;
    line-height: 1;
    padding: 0 4px;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    padding: .7rem 1.6rem;
    border-radius: 8px;
    font-weight: 600;
    transition: background .2s;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: .55rem 1.2rem;
    border-radius: 8px;
    font-weight: 500;
    transition: background .2s;
}
.btn-secondary:hover { background: #e2e8f0; }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
    padding: .65rem 1.4rem;
    border-radius: 8px;
    font-weight: 600;
    transition: all .2s;
}
.btn-outline:hover:not(:disabled) { background: var(--primary); color: #fff; }
.btn-outline:disabled { opacity: .55; cursor: not-allowed; }

.btn-success {
    background: var(--success);
    color: #fff;
    padding: .6rem 1.3rem;
    border-radius: 8px;
    font-weight: 600;
}
.btn-success:hover { background: var(--success-hover); }

/* ===== Upload Area ===== */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s, background .2s;
}
.upload-area:hover, .upload-area.dragover {
    border-color: var(--primary);
    background: #eef2ff;
}
.upload-icon { font-size: 2rem; margin-bottom: .5rem; }

/* ===== Template Info ===== */
.template-info { margin-top: 1rem; }
.file-badge {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    background: #eef2ff;
    color: var(--primary);
    padding: .35rem .75rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: .9rem;
}
.placeholders-list {
    margin-top: .75rem;
    font-size: .9rem;
}
.placeholders-list span {
    display: inline-block;
    background: #fef3c7;
    color: #92400e;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: monospace;
    font-size: .85rem;
    margin: 2px 4px 2px 0;
}

/* ===== Action Bar ===== */
.action-bar {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

/* ===== Progress ===== */
.progress-container {
    margin-bottom: 1.5rem;
    padding: .75rem 1rem;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.progress-steps { display: flex; gap: .5rem; flex-wrap: wrap; }
.progress-step {
    flex: 1;
    text-align: center;
    font-size: .8rem;
    padding: .5rem .25rem;
    border-radius: 6px;
    background: var(--bg);
    color: var(--text-muted);
    transition: all .3s;
    min-width: 120px;
}
.progress-step.active {
    background: #eef2ff;
    color: var(--primary);
    font-weight: 600;
}
.progress-step.done {
    background: #dcfce7;
    color: var(--success);
    font-weight: 600;
}

/* ===== Output ===== */
.output-toolbar {
    display: flex;
    gap: .75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.document-preview {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2rem 2.5rem;
    background: #fff;
    min-height: 200px;
    line-height: 1.7;
    font-size: .95rem;
}
.document-preview h1, .document-preview h2, .document-preview h3 {
    margin: 1rem 0 .5rem;
}
.document-preview p { margin-bottom: .75rem; }
.document-preview table {
    border-collapse: collapse;
    width: 100%;
    margin: .75rem 0;
}
.document-preview th, .document-preview td {
    border: 1px solid var(--border);
    padding: .5rem .75rem;
    text-align: left;
}
.document-preview th { background: #f8fafc; }

/* ===== Edit Panel ===== */
.edit-panel {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}
.edit-panel h3 { font-size: 1rem; margin-bottom: .75rem; }
.edit-panel small { color: var(--text-muted); }
.mapping-row {
    display: flex;
    gap: .5rem;
    align-items: flex-start;
    margin-bottom: .5rem;
}
.mapping-row label {
    min-width: 140px;
    font-weight: 600;
    font-family: monospace;
    font-size: .85rem;
    padding-top: .5rem;
}
.mapping-row textarea {
    flex: 1;
    font-size: .85rem;
    padding: .4rem .5rem;
    min-height: 50px;
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}
.modal {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal h2 { margin-bottom: 1rem; }
.modal-actions {
    display: flex;
    gap: .75rem;
    justify-content: flex-end;
    margin-top: 1rem;
}
.modal .mapping-row { margin-bottom: .75rem; }

/* ===== Spinner ===== */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-loading { display: inline-flex; align-items: center; gap: .4rem; }

/* ===== Status ===== */
.status-msg {
    font-size: .85rem;
    min-height: 1.2em;
    margin-top: .25rem;
}
.status-msg.ok { color: var(--success); }
.status-msg.err { color: var(--danger); }

/* ===== Utilities ===== */
.hidden { display: none !important; }

.model-details {
    margin-top: .75rem;
    font-size: .9rem;
}

.preview-warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
    border-radius: 6px;
    padding: .5rem .75rem;
    font-size: .85rem;
    margin-bottom: 1rem;
}
.model-details summary {
    cursor: pointer;
    color: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
    .container { padding: 1rem .75rem 3rem; }
    header h1 { font-size: 1.5rem; }
    .document-preview { padding: 1rem; }
    .mapping-row { flex-direction: column; }
    .mapping-row label { min-width: unset; }
}
