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

:root {
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;

    /* Colors */
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-text: #0f172a;
    --color-text-secondary: #475569;
    --color-text-muted: #94a3b8;
    --color-border: #e2e8f0;
    --color-border-light: #f1f5f9;

    --color-primary: #2563eb;
    --color-primary-light: #dbeafe;
    --color-primary-dark: #1d4ed8;

    --color-success: #16a34a;
    --color-success-light: #dcfce7;

    --color-danger: #dc2626;
    --color-danger-light: #fee2e2;
    --color-danger-surface: #fef2f2;
    --color-danger-border: #fecaca;
    --color-danger-text: #991b1b;

    --color-amber: #d97706;
    --color-amber-light: #fef3c7;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);

    /* Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App Shell (Sidebar Layout) ──────────────── */
.app-shell { display: grid; grid-template-columns: 240px 1fr; height: 100vh; height: 100dvh; overflow: hidden; }
.app-sidebar { background: #020617; color: #fff; display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; width: 240px; z-index: 60; }
.app-workspace { display: grid; grid-template-rows: 51px 1fr; overflow: hidden; min-width: 0; }

/* ── Chrome (Top Bar) ────────────────────────── */
.app-chrome { background: var(--color-surface); border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; padding: 0 1rem; height: 51px; z-index: 30; }
.topbar-left { display: flex; align-items: center; gap: 0.75rem; }
.topbar-right { display: flex; align-items: center; gap: 0.5rem; }

/* ── Frame ───────────────────────────────────── */
.app-frame { overflow: auto; background: var(--color-bg); -webkit-overflow-scrolling: touch; }
.frame-canvas { padding: 1.5rem; max-width: 860px; }

/* ── Sidebar ─────────────────────────────────── */
.sidebar-top { padding: 1rem 1rem 0.75rem; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar-brand { display: flex; align-items: center; gap: 0.75rem; text-decoration: none; color: #fff; }
.sidebar-brand:hover { text-decoration: none; }
.sidebar-brand-icon { width: 36px; height: 36px; background: var(--color-primary); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1rem; }
.sidebar-brand-text { font-size: 0.9375rem; font-weight: 600; letter-spacing: -0.01em; }
.sidebar-body { flex: 1; overflow-y: auto; padding: 0.5rem 0; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent; }
.sidebar-section { padding: 0 0.5rem; margin-bottom: 0.25rem; }
.sidebar-section-label { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: rgba(255,255,255,0.4); padding: 0.75rem 0.75rem 0.375rem; }
.sidebar-item { display: flex; align-items: center; gap: 0.625rem; padding: 0.5rem 0.75rem; border-radius: var(--radius-md); color: rgba(255,255,255,0.7); text-decoration: none; font-size: 0.8125rem; font-weight: 450; transition: all 150ms ease; cursor: pointer; }
.sidebar-item:hover { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.95); text-decoration: none; }
.sidebar-item.active { background: rgba(37, 99, 235, 0.2); color: #ffffff; font-weight: 500; }
.sidebar-item-icon { width: 1.25rem; height: 1.25rem; display: flex; align-items: center; justify-content: center; font-size: 0.875rem; flex-shrink: 0; opacity: 0.7; }
.sidebar-item.active .sidebar-item-icon { opacity: 1; }
.sidebar-footer { padding: 0.75rem 1rem; border-top: 1px solid rgba(255,255,255,0.08); font-size: 0.6875rem; color: rgba(255,255,255,0.35); }

/* ── Breadcrumb ──────────────────────────────── */
.breadcrumb { display: flex; align-items: center; gap: 0.375rem; font-size: 0.8125rem; color: var(--color-text-muted); list-style: none; }
.breadcrumb a { color: var(--color-text-secondary); text-decoration: none; }
.breadcrumb a:hover { color: var(--color-primary); text-decoration: none; }

/* ── Buttons (ghost, sm) ─────────────────────── */
.btn-ghost { background: transparent; color: var(--color-text-secondary); border-color: transparent; }
.btn-ghost:hover { background: rgba(0,0,0,0.04); color: var(--color-text); text-decoration: none; }
.btn-sm { padding: 0.3125rem 0.75rem; font-size: 0.75rem; }

/* ── Sidebar Collapse (desktop) ───────────────── */
.sidebar-collapse-btn { display: flex; background: none; border: none; font-size: 1rem; color: var(--color-text-secondary); cursor: pointer; padding: 0.375rem; border-radius: var(--radius-md); transition: background 150ms ease; }
.sidebar-collapse-btn:hover { background: rgba(0,0,0,0.04); }
.app-shell.sidebar-collapsed { grid-template-columns: 0px 1fr; }
.app-shell.sidebar-collapsed .app-sidebar { width: 0 !important; overflow: hidden; border: none; }
.sidebar-collapse-btn .fa-angles-left { transition: transform 200ms ease; }
.app-shell.sidebar-collapsed .sidebar-collapse-btn .fa-angles-left { transform: rotate(180deg); }

/* ── Sidebar Toggle & Overlay (hidden on desktop) ── */
.sidebar-toggle { display: none; background: none; border: none; font-size: 1.125rem; color: var(--color-text-secondary); cursor: pointer; padding: 0.375rem; border-radius: var(--radius-md); transition: background 150ms ease; }
.sidebar-toggle:hover { background: rgba(0,0,0,0.04); }
.sidebar-overlay { display: none; }

/* ── Hero ─────────────────────────────────────── */
.hero {
    text-align: center;
    padding: 2rem 0 1.5rem;
}
.hero-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 0.25rem;
}
.hero-subtitle {
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
    font-weight: 400;
}

/* ── Section Titles ──────────────────────────── */
.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.section-title i { color: var(--color-primary); }
.section-title-emergency i { color: var(--color-danger); }

.checklist-section { margin-bottom: 2rem; }

/* ── Phase Grid (Home) ───────────────────────── */
.phase-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.phase-card {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 0.875rem 1rem;
    text-decoration: none;
    color: var(--color-text);
    transition: box-shadow 0.15s, border-color 0.15s;
}
.phase-card:hover {
    text-decoration: none;
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
}
.phase-card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--color-primary-light);
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    flex-shrink: 0;
}
.phase-card-icon-emergency {
    background: var(--color-danger-light);
    color: var(--color-danger);
}
.phase-card-body { flex: 1; min-width: 0; }
.phase-card-title {
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.3;
}
.phase-card-count {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}
.phase-card-arrow {
    color: var(--color-text-muted);
    font-size: 0.75rem;
    flex-shrink: 0;
}
.phase-card-emergency { border-left: 3px solid var(--color-danger); }
.phase-card-emergency:hover { border-color: var(--color-danger); border-left-width: 3px; }

/* ── Phase Detail Header ─────────────────────── */
.phase-header { margin-bottom: 1.25rem; }
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-bottom: 0.75rem;
}
.back-link:hover { color: var(--color-primary); text-decoration: none; }
.phase-header-info { margin-bottom: 1rem; }
.phase-badge {
    display: inline-block;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    margin-bottom: 0.375rem;
}
.phase-badge-normal { background: var(--color-primary-light); color: var(--color-primary-dark); }
.phase-badge-emergency { background: var(--color-danger-light); color: var(--color-danger); }
.phase-title {
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.phase-title i {
    font-size: 1.25rem;
    color: var(--color-primary);
}

/* ── Progress Bar ────────────────────────────── */
.phase-progress { margin-bottom: 0.25rem; }
.progress-text {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    font-weight: 500;
    margin-bottom: 0.375rem;
    display: block;
}
.progress-bar {
    height: 6px;
    background: var(--color-border-light);
    border-radius: 999px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--color-success);
    border-radius: 999px;
    transition: width 0.3s ease;
}

/* ── Checklist Card ──────────────────────────── */
.checklist-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-bottom: 1rem;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.checklist-card-emergency { border-left: 3px solid var(--color-danger); }
.checklist-card-header {
    padding: 0.75rem 1rem;
    background: var(--color-border-light);
    border-bottom: 1px solid var(--color-border);
}
.checklist-card-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.checklist-card-body { padding: 0.25rem 0; }

/* ── Checklist Item ──────────────────────────── */
.checklist-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--color-border-light);
    transition: background 0.1s;
    user-select: none;
}
.checklist-item:last-child { border-bottom: none; }
.checklist-item:hover { background: #f8fafc; }
.checklist-item.is-checked {
    background: var(--color-success-light);
}
.checklist-item.is-checked .checklist-challenge,
.checklist-item.is-checked .checklist-response {
    color: var(--color-text-muted);
}

.checklist-checkbox {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.checklist-check-icon {
    width: 22px;
    height: 22px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
    color: transparent;
    font-size: 0.6875rem;
}
.checklist-item.is-checked .checklist-check-icon {
    background: var(--color-success);
    border-color: var(--color-success);
    color: #fff;
}

.checklist-challenge {
    font-weight: 600;
    font-size: 0.875rem;
    white-space: nowrap;
    flex-shrink: 0;
}
.checklist-dots {
    flex: 1;
    border-bottom: 2px dotted var(--color-border);
    min-width: 1rem;
    align-self: flex-end;
    margin-bottom: 0.2em;
}
.checklist-response {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    text-align: right;
    flex-shrink: 0;
    max-width: 50%;
}

.checklist-note {
    padding: 0.25rem 1rem 0.625rem 3.125rem;
    font-size: 0.75rem;
    color: var(--color-amber);
    display: flex;
    align-items: flex-start;
    gap: 0.375rem;
    border-bottom: 1px solid var(--color-border-light);
}
.checklist-note i { margin-top: 0.1em; flex-shrink: 0; }

/* ── Phase Actions ───────────────────────────── */
.phase-actions {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* ── Buttons ─────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    font-family: var(--font-family);
}
.btn:hover { text-decoration: none; }
.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-primary-dark); color: #fff; }
.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text-secondary);
    border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-border-light); }

/* ── Card (generic) ──────────────────────────── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
}
.card-title { font-size: 1.125rem; font-weight: 600; }
.card-body { padding: 1.25rem; }

/* ── Responsive: Tablet ──────────────────────── */
@media (max-width: 768px) {
    .app-shell { grid-template-columns: 1fr; }
    .app-sidebar {
        position: fixed; top: 0; left: 0; bottom: 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 200;
    }
    .app-shell.sidebar-open .app-sidebar { transform: translateX(0); }
    .sidebar-overlay {
        display: block; position: fixed; inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 190;
        opacity: 0; pointer-events: none;
        transition: opacity 300ms ease;
    }
    .app-shell.sidebar-open .sidebar-overlay { opacity: 1; pointer-events: auto; }
    .sidebar-toggle { display: flex; }
    .sidebar-collapse-btn { display: none !important; }
    .app-shell.sidebar-collapsed { grid-template-columns: 1fr; }
    .app-shell.sidebar-collapsed .app-sidebar { width: 280px !important; }
    .frame-canvas { padding: 1rem; }
}

/* ── Responsive: Mobile ─────────────────────── */
@media (max-width: 640px) {
    .frame-canvas { padding: 0.75rem; }
    .hero { padding: 1.25rem 0 1rem; }
    .hero-title { font-size: 1.375rem; }

    .checklist-item {
        flex-wrap: wrap;
        gap: 0.25rem;
    }
    .checklist-challenge {
        white-space: normal;
        flex: 1;
        min-width: 0;
    }
    .checklist-dots { display: none; }
    .checklist-response {
        width: 100%;
        text-align: left;
        padding-left: 2.125rem;
        max-width: 100%;
        font-size: 0.8125rem;
        color: var(--color-primary);
    }

    .phase-title { font-size: 1.25rem; }
    .phase-actions { flex-direction: column; }
    .breadcrumb { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 50vw; }
}
