/* ============================================
   Runbook Builder — Red-Amber Dark Theme
   ============================================ */

:root {
    --primary: #EF4444;
    --primary-hover: #DC2626;
    --primary-glow: rgba(239, 68, 68, 0.25);
    --accent: #F59E0B;
    --accent-glow: rgba(245, 158, 11, 0.2);
    --success: #10B981;
    --info: #3B82F6;
    --bg: #0F172A;
    --bg-card: rgba(15, 23, 42, 0.85);
    --bg-elevated: rgba(30, 41, 59, 0.9);
    --bg-hover: rgba(239, 68, 68, 0.06);
    --border: rgba(239, 68, 68, 0.12);
    --border-hover: rgba(239, 68, 68, 0.25);
    --text: #E2E8F0;
    --text-muted: #94A3B8;
    --text-dim: #475569;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --glass: blur(20px);
    --mono: 'JetBrains Mono', 'Fira Code', monospace;
    --sans: 'Inter', system-ui, -apple-system, sans-serif;
    --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    background-image:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(239, 68, 68, 0.08), transparent),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(245, 158, 11, 0.05), transparent);
}

/* --- Header --- */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
    background: rgba(15, 23, 42, 0.85);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    max-width: 900px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.logo-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    color: var(--primary);
    display: flex;
}

.logo-text {
    font-size: 1.1rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: block;
}

.header-actions {
    display: flex;
    gap: 0.35rem;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--sans);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    line-height: 1;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    box-shadow: 0 0 20px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 30px var(--primary-glow);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

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

.btn-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
}

.btn-dashed {
    width: 100%;
    padding: 0.75rem;
    background: transparent;
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-family: var(--sans);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-dashed:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--bg-hover);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.3rem;
    border-radius: var(--radius-xs);
    transition: all var(--transition);
    display: flex;
}

.btn-icon:hover {
    color: var(--primary);
    background: var(--bg-hover);
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    line-height: 1;
    transition: color var(--transition);
}

.btn-close:hover {
    color: var(--text);
}

/* --- Inputs --- */
.input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    font-family: var(--sans);
    font-size: 0.82rem;
    transition: all var(--transition);
    outline: none;
}

.input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394A3B8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.6rem center;
    padding-right: 2rem;
}

/* --- Main --- */
.main {
    max-width: 900px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* --- Runbook Header --- */
.runbook-header-section {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.runbook-meta {
    flex: 1;
}

.runbook-title-input {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text);
    font-family: var(--sans);
    font-size: 1.5rem;
    font-weight: 700;
    outline: none;
    transition: border-color var(--transition);
    padding: 0.2rem 0;
}

.runbook-title-input:focus {
    border-bottom-color: var(--primary);
}

.meta-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.severity-select {
    width: auto;
    max-width: 180px;
    font-size: 0.78rem;
}

.step-count,
.total-time {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.mode-toggle {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.mode-btn {
    padding: 0.4rem 0.8rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--sans);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

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

.mode-btn:hover:not(.active) {
    color: var(--text);
    background: var(--bg-hover);
}

/* --- Steps --- */
.steps-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.step-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.85rem 1rem;
    backdrop-filter: var(--glass);
    animation: fadeIn 300ms ease-out;
    position: relative;
}

.step-card.completed {
    opacity: 0.6;
}

.step-card.completed .step-title {
    text-decoration: line-through;
}

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

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

.step-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.step-number {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--primary-glow);
    color: var(--primary);
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.step-card.completed .step-number {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    border-color: rgba(16, 185, 129, 0.3);
}

.step-type-badge {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.12rem 0.4rem;
    border-radius: 4px;
}

.type-command {
    background: rgba(59, 130, 246, 0.15);
    color: var(--info);
}

.type-check {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.type-decision {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent);
}

.type-escalation {
    background: rgba(239, 68, 68, 0.15);
    color: var(--primary);
}

.step-title-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: var(--sans);
    font-size: 0.88rem;
    font-weight: 500;
    outline: none;
    min-width: 0;
}

.step-title {
    font-size: 0.88rem;
    font-weight: 500;
    flex: 1;
}

.step-actions {
    display: flex;
    gap: 0.2rem;
    margin-left: auto;
}

.step-body {
    margin-top: 0.35rem;
    padding-left: 2.2rem;
}

.step-description {
    width: 100%;
    padding: 0.4rem 0.6rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-muted);
    font-family: var(--sans);
    font-size: 0.78rem;
    outline: none;
    resize: none;
    transition: all var(--transition);
}

.step-description:focus {
    border-color: var(--primary);
    color: var(--text);
}

.command-block {
    margin-top: 0.35rem;
    background: rgba(0, 0, 0, 0.35);
    border-radius: var(--radius-xs);
    padding: 0.5rem 0.75rem;
    font-family: var(--mono);
    font-size: 0.78rem;
    color: var(--success);
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    position: relative;
}

.command-text {
    flex: 1;
    white-space: pre-wrap;
    word-break: break-all;
}

.command-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--success);
    font-family: var(--mono);
    font-size: 0.78rem;
    outline: none;
    resize: none;
    min-height: 1.6em;
}

.btn-copy-cmd {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 0.2rem;
    transition: color var(--transition);
    flex-shrink: 0;
}

.btn-copy-cmd:hover {
    color: var(--text);
}

.step-footer {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.4rem;
    padding-left: 2.2rem;
}

.timer-badge {
    font-size: 0.7rem;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.step-type-select {
    width: auto;
    max-width: 130px;
    font-size: 0.72rem;
}

.step-timer-input {
    width: 60px;
    padding: 0.25rem 0.4rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--accent);
    font-family: var(--mono);
    font-size: 0.72rem;
    text-align: center;
    outline: none;
}

/* --- Execute mode checkbox --- */
.step-checkbox {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
}

.step-checkbox:hover {
    border-color: var(--success);
}

.step-checkbox.checked {
    background: var(--success);
    border-color: var(--success);
}

.step-checkbox.checked::after {
    content: '✓';
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
}

/* Execute timer */
.execute-timer {
    font-family: var(--mono);
    font-size: 0.82rem;
    color: var(--accent);
    background: rgba(245, 158, 11, 0.1);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    backdrop-filter: blur(4px);
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    overflow: auto;
    box-shadow: var(--shadow);
}

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

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

.modal-body {
    padding: 1.25rem;
}

.template-grid {
    display: grid;
    gap: 0.5rem;
}

.template-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: all var(--transition);
}

.template-card:hover {
    border-color: var(--primary);
    background: var(--bg-hover);
    transform: translateY(-1px);
}

.template-name {
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
}

.template-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.export-textarea {
    width: 100%;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.78rem;
    resize: vertical;
    outline: none;
}

.export-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.mono {
    font-family: var(--mono);
}

/* --- Toast --- */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 1rem;
    font-size: 0.82rem;
    color: var(--text);
    box-shadow: var(--shadow);
    animation: toastIn 300ms ease-out;
}

.toast.success {
    border-left: 3px solid var(--success);
}

.toast.error {
    border-left: 3px solid var(--primary);
}

.toast.info {
    border-left: 3px solid var(--info);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

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

/* --- Responsive --- */
@media (max-width: 640px) {
    .main {
        padding: 1rem;
    }

    .runbook-header-section {
        flex-direction: column;
    }

    .header-inner {
        flex-direction: column;
        align-items: stretch;
    }

    .header-actions {
        justify-content: flex-end;
    }
}