/* ===== DESIGN TOKENS ===== */
:root {
    --color-bg: #f8f9fb;
    --color-surface: #ffffff;
    --color-surface-hover: #f3f4f6;
    --color-border: #e2e5ea;
    --color-border-focus: #6366f1;
    --color-text: #1a1d23;
    --color-text-secondary: #6b7280;
    --color-text-muted: #9ca3af;
    --color-primary: #4f46e5;
    --color-primary-hover: #4338ca;
    --color-primary-light: #eef2ff;
    --color-sev1: #ef4444;
    --color-sev1-bg: #fef2f2;
    --color-sev2: #f97316;
    --color-sev2-bg: #fff7ed;
    --color-sev3: #eab308;
    --color-sev3-bg: #fefce8;
    --color-sev4: #3b82f6;
    --color-sev4-bg: #eff6ff;
    --color-success: #10b981;
    --color-success-bg: #ecfdf5;
    --color-warning: #f59e0b;
    --color-warning-bg: #fffbeb;
    --color-danger: #ef4444;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.08);
    --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== HEADER ===== */
.app-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 1480px;
    margin: 0 auto;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--color-primary);
}

.logo h1 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text);
}

.header-actions {
    display: flex;
    gap: 6px;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.87rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-primary);
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
}

.btn-ghost:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}

.btn-danger:hover {
    opacity: 0.9;
}

/* ===== MAIN LAYOUT ===== */
.app-main {
    flex: 1;
    max-width: 1480px;
    margin: 0 auto;
    padding: 24px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    width: 100%;
}

/* ===== FORM PANEL ===== */
.form-panel {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.template-selector {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.template-selector label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.template-selector select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.87rem;
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    transition: border-color var(--transition);
}

.template-selector select:focus {
    border-color: var(--color-border-focus);
    outline: none;
}

/* Step Indicator */
.step-indicator {
    display: flex;
    gap: 2px;
    margin-bottom: 20px;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: 4px;
    border: 1px solid var(--color-border);
}

.step-indicator .step {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 8px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.step-indicator .step:hover {
    color: var(--color-text-secondary);
    background: var(--color-surface-hover);
}

.step-indicator .step.active {
    background: var(--color-primary);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.step-indicator .step.completed {
    color: var(--color-success);
}

.step-num {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.72rem;
    font-weight: 700;
}

/* Wizard Steps */
.wizard-step {
    display: none;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 28px;
    animation: fadeSlideIn 0.3s ease;
}

.wizard-step[data-active="true"] {
    display: block;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

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

.section-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--color-text);
}

.subsection-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--color-text);
}

.section-desc {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    margin-bottom: 16px;
}

/* Form Elements */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 6px;
}

.required {
    color: var(--color-danger);
}

.form-group input[type="text"],
.form-group input[type="date"],
.form-group input[type="datetime-local"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.form-group textarea {
    resize: vertical;
    line-height: 1.6;
}

.form-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

.form-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

.time-separator {
    color: var(--color-text-muted);
    font-weight: 600;
    padding-top: 24px;
}

/* Blame Warning */
.blame-warning {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 8px;
    padding: 10px 14px;
    background: var(--color-warning-bg);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: #92400e;
    animation: fadeSlideIn 0.3s ease;
}

.blame-warning svg {
    flex-shrink: 0;
    margin-top: 1px;
    color: var(--color-warning);
}

/* Step Actions */
.step-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--color-border);
}

/* ===== TIMELINE ENTRIES ===== */
.timeline-entries {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.timeline-entry {
    display: grid;
    grid-template-columns: 160px 1fr 140px 32px;
    gap: 10px;
    align-items: start;
    padding: 14px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    animation: fadeSlideIn 0.25s ease;
}

.timeline-entry input {
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color var(--transition);
}

.timeline-entry input:focus {
    outline: none;
    border-color: var(--color-border-focus);
}

.timeline-entry .btn-remove {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.timeline-entry .btn-remove:hover {
    color: var(--color-danger);
    background: #fef2f2;
}

/* ===== ACTION ITEMS ===== */
.action-items {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.action-item {
    padding: 16px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    animation: fadeSlideIn 0.25s ease;
}

.action-item .action-top {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.action-item .action-top input {
    flex: 1;
}

.action-item .action-top .btn-remove {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    flex-shrink: 0;
}

.action-item .action-top .btn-remove:hover {
    color: var(--color-danger);
    background: #fef2f2;
}

.action-item .action-bottom {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}

.action-item input,
.action-item select {
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color var(--transition);
}

.action-item input:focus,
.action-item select:focus {
    outline: none;
    border-color: var(--color-border-focus);
}

/* ===== 5-WHY ===== */
.five-why-section {
    margin: 20px 0;
    padding: 20px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.five-why-entry {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.five-why-entry:last-child {
    margin-bottom: 0;
}

.five-why-entry label {
    width: 60px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-primary);
    flex-shrink: 0;
}

.five-why-entry input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.87rem;
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color var(--transition);
}

.five-why-entry input:focus {
    outline: none;
    border-color: var(--color-border-focus);
}

/* ===== EXPORT ACTIONS ===== */
.export-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.btn-export {
    padding: 16px 24px;
    font-size: 0.95rem;
    justify-content: center;
}

.btn-export svg {
    width: 20px;
    height: 20px;
}

@keyframes downloadPulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(0.96);
    }

    100% {
        transform: scale(1);
    }
}

.btn-export.downloading {
    animation: downloadPulse 0.4s ease;
    pointer-events: none;
}

/* ===== PREVIEW PANEL ===== */
.preview-panel {
    position: sticky;
    top: 80px;
    align-self: start;
    max-height: calc(100vh - 104px);
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
}

.preview-header h2 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.preview-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.7;
    color: var(--color-text);
    white-space: pre-wrap;
    word-break: break-word;
}

.preview-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 60px 20px;
    text-align: center;
    color: var(--color-text-muted);
    font-family: var(--font-sans);
    font-size: 0.9rem;
}

/* Severity Badge in preview */
.sev-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    font-family: var(--font-sans);
    letter-spacing: 0.5px;
}

.sev-badge.sev1 {
    background: var(--color-sev1-bg);
    color: var(--color-sev1);
}

.sev-badge.sev2 {
    background: var(--color-sev2-bg);
    color: var(--color-sev2);
}

.sev-badge.sev3 {
    background: var(--color-sev3-bg);
    color: var(--color-sev3);
}

.sev-badge.sev4 {
    background: var(--color-sev4-bg);
    color: var(--color-sev4);
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 520px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalSlide 0.25s ease;
}

@keyframes modalSlide {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.97);
    }

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.draft-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all var(--transition);
}

.draft-item:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-primary);
}

.draft-item .draft-info {
    flex: 1;
}

.draft-item .draft-title {
    font-weight: 600;
    font-size: 0.9rem;
}

.draft-item .draft-date {
    font-size: 0.78rem;
    color: var(--color-text-muted);
}

.draft-item .draft-actions {
    display: flex;
    gap: 4px;
}

.empty-state {
    text-align: center;
    color: var(--color-text-muted);
    padding: 32px 0;
    font-size: 0.9rem;
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background: var(--color-text);
    color: #fff;
    border-radius: var(--radius-md);
    font-size: 0.87rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 300;
    animation: toastIn 0.3s ease;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 960px) {
    .app-main {
        grid-template-columns: 1fr;
        padding: 16px;
    }

    .preview-panel {
        position: static;
        max-height: 50vh;
    }

    .step-indicator .step span:not(.step-num) {
        display: none;
    }

    .timeline-entry {
        grid-template-columns: 1fr 1fr;
    }

    .action-item .action-bottom {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .header-inner {
        padding: 0 12px;
    }

    .logo h1 {
        font-size: 0.95rem;
    }

    .wizard-step {
        padding: 18px;
    }

    .form-row {
        flex-direction: column;
    }

    .time-separator {
        padding-top: 0;
    }

    .timeline-entry {
        grid-template-columns: 1fr;
    }
}

/* ===== PRINT ===== */
@media print {

    .app-header,
    .form-panel,
    .toast,
    .modal-overlay {
        display: none !important;
    }

    .app-main {
        grid-template-columns: 1fr;
        padding: 0;
    }

    .preview-panel {
        position: static;
        max-height: none;
        border: none;
        box-shadow: none;
    }

    .preview-header {
        display: none;
    }

    .preview-content {
        font-size: 11pt;
        padding: 0;
    }
}