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

:root {
    --bg: #1a1a2e;
    --surface: #16213e;
    --surface2: #0f3460;
    --text: #e0e0e0;
    --text-dim: #999;
    --accent: #e94560;
    --accent2: #0ea5e9;
    --green: #4caf50;
    --red: #f44336;
    --orange: #ff9800;
    --grey: #9e9e9e;
    --border: #2a2a4a;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
}

#app {
    display: flex;
    height: 100%;
    overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────── */
#sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
}

#sidebar-header h1 {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
    color: #fff;
}

#boat-info-bar {
    font-size: 0.78rem;
    color: var(--text-dim);
    padding: 0.25rem 0 0.5rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
}

#boat-name-label {
    color: var(--accent2);
    font-weight: 600;
}

#progress-bar-wrap {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin: 0.5rem 0;
}

#progress-bar {
    height: 100%;
    background: var(--accent2);
    width: 0%;
    transition: width 0.3s;
}

#progress-text {
    font-size: 0.8rem;
    color: var(--text-dim);
}

#nav-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.25rem 0;
}

.nav-summary-btn {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--surface2);
    color: var(--accent2);
    border: none;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
    text-align: left;
    cursor: pointer;
}

/* Part headers */
.nav-part-header {
    display: flex;
    align-items: center;
    padding: 0.6rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.nav-part-header:hover {
    background: rgba(255,255,255,0.03);
}

.part-toggle {
    font-size: 0.7rem;
    margin-right: 0.5rem;
    color: var(--text-dim);
    width: 12px;
}

.part-label {
    flex: 1;
    font-weight: 600;
    font-size: 0.9rem;
}

.part-progress {
    font-size: 0.75rem;
    color: var(--text-dim);
    background: var(--border);
    padding: 2px 8px;
    border-radius: 10px;
}

/* Section headers in nav */
.nav-section-header {
    padding: 0.4rem 1rem 0.4rem 2.5rem;
    font-size: 0.82rem;
    color: var(--text-dim);
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.nav-section-header:hover {
    color: var(--text);
}

/* Check items in nav */
.nav-checks {
    padding-left: 1.5rem;
}

.nav-check {
    display: flex;
    align-items: center;
    padding: 0.35rem 1rem 0.35rem 3.5rem;
    cursor: pointer;
    font-size: 0.8rem;
    border-bottom: 1px solid rgba(255,255,255,0.02);
}

.nav-check:hover {
    background: rgba(255,255,255,0.04);
}

.check-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.status-pass    { background: var(--green); }
.status-fail    { background: var(--red); }
.status-not-verified, .status-nv { background: var(--orange); }
.status-na      { background: var(--grey); }
.status-unset   { background: transparent; border: 1px solid var(--text-dim); }

/* ── Exam list view ───────────────────────────────── */
#exam-list-view {
    max-width: 700px;
    margin: 0 auto;
    padding-bottom: 4rem;
}

#exam-list-view h2 {
    margin-bottom: 1rem;
}

#exam-list-empty {
    text-align: center;
    color: var(--text-dim);
    padding: 2rem;
}

.btn-primary {
    padding: 0.7rem 1.4rem;
    background: var(--accent2);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 1.5rem;
}

.btn-secondary {
    padding: 0.7rem 1.4rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
}

.btn-danger {
    background: rgba(244,67,54,0.2) !important;
    color: var(--red) !important;
    border: 1px solid rgba(244,67,54,0.4) !important;
}

.btn-small {
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.btn-open {
    background: rgba(14,165,233,0.2);
    color: var(--accent2);
    border-color: rgba(14,165,233,0.4);
}

.exam-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    transition: background 0.15s;
}

.exam-card:hover {
    background: var(--surface2);
}

.exam-card-main {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    flex: 1;
    overflow: hidden;
}

.exam-card-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: #fff;
}

.exam-card-bin {
    font-size: 0.82rem;
    color: var(--accent2);
    font-weight: 600;
}

.exam-card-date {
    font-size: 0.78rem;
    color: var(--text-dim);
}

.exam-card-meta {
    font-size: 0.78rem;
    color: var(--text-dim);
}

.exam-card-actions {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
    margin-left: 1rem;
}

/* ── Exam form ────────────────────────────────────── */
#exam-form-view {
    max-width: 700px;
    margin: 0 auto;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.form-field label {
    font-size: 0.82rem;
    color: var(--text-dim);
    font-weight: 600;
}

.form-field input,
.form-field select {
    padding: 0.65rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
    font-family: var(--font);
}

.form-field input:focus,
.form-field select:focus {
    outline: none;
    border-color: var(--accent2);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

/* ── Main area ─────────────────────────────────────── */
#main {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    position: relative;
}

#menu-toggle {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 100;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.7rem;
    font-size: 1.2rem;
    cursor: pointer;
}

#sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    position: absolute;
    top: 0.5rem;
    right: -14px;
    z-index: 210;
    background: var(--surface2);
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 14px;
    font-size: 0.65rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.15s;
}

#sidebar-toggle:hover {
    color: var(--text);
}

#sidebar-close {
    display: none;
    position: absolute;
    top: 0.65rem;
    right: 2.2rem;
    z-index: 215;
    background: none;
    color: var(--text-dim);
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    line-height: 1;
}

#sidebar-close:hover {
    color: var(--text);
}

#sidebar.collapsed {
    margin-left: -320px;
    margin-left: -320px;
    min-width: 0;
    width: 0;
    border-right: none;
}

#sidebar.collapsed #sidebar-toggle {
    right: -16px;
    border-radius: 0 14px 14px 0;
}

/* ── Sidebar exam list items ─────────────────────── */
.nav-exam-item {
    padding: 0.6rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    transition: background 0.12s;
}

.nav-exam-item:hover {
    background: rgba(255,255,255,0.04);
}

.nav-exam-item-name {
    font-weight: 600;
    font-size: 0.88rem;
    color: #fff;
}

.nav-exam-item-bin {
    font-size: 0.76rem;
    color: var(--accent2);
    font-weight: 600;
    margin-top: 0.1rem;
}

.nav-exam-item-date {
    font-size: 0.73rem;
    color: var(--text-dim);
    margin-top: 0.1rem;
}

#welcome {
    max-width: 600px;
    margin: 3rem auto;
    text-align: center;
}

#welcome h2 {
    margin-bottom: 0.5rem;
}

#welcome p {
    color: var(--text-dim);
    margin: 0.5rem 0;
}

/* ── Check detail ──────────────────────────────────── */
#check-detail {
    max-width: 700px;
    margin: 0 auto;
}

#check-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

#check-id {
    font-size: 0.85rem;
    color: var(--text-dim);
}

.badge {
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 700;
}

.badge-r {
    background: var(--accent);
    color: #fff;
}

.badge-a {
    background: var(--accent2);
    color: #fff;
}

#check-question {
    font-size: 1.15rem;
    line-height: 1.5;
    margin-bottom: 0.75rem;
    color: #fff;
}

#check-meta {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

/* Result buttons */
#result-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

#result-buttons button {
    flex: 1;
    min-width: 80px;
    padding: 0.75rem 0.5rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

#result-buttons button.active {
    border-color: var(--accent2);
    background: rgba(14,165,233,0.15);
}

.btn-pass.active  { border-color: var(--green) !important; background: rgba(76,175,80,0.15) !important; }
.btn-fail.active  { border-color: var(--red) !important; background: rgba(244,67,54,0.15) !important; }
.btn-nv.active    { border-color: var(--orange) !important; background: rgba(255,152,0,0.15) !important; }
.btn-na.active    { border-color: var(--grey) !important; background: rgba(158,158,158,0.15) !important; }

#result-buttons button:active {
    transform: scale(0.97);
}

/* Notes */
#notes-section {
    margin-bottom: 1.5rem;
}

#notes-section label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 0.4rem;
}

#notes {
    width: 100%;
    min-height: 100px;
    padding: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.9rem;
    resize: vertical;
}

#notes:focus {
    outline: none;
    border-color: var(--accent2);
}

/* Nav buttons */
#nav-buttons {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1.5rem;
}

#nav-buttons button {
    padding: 0.7rem 1.2rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
}

#nav-buttons button:disabled {
    opacity: 0.3;
    cursor: default;
}

#position-indicator {
    font-size: 0.85rem;
    color: var(--text-dim);
}

/* ── Procedure / action section ──────────────────── */
#procedure-section {
    margin: 1rem 0 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

#procedure-toggle {
    padding: 0.7rem 1rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--accent2);
    user-select: none;
    background: var(--surface2);
    list-style: none;
}

#procedure-toggle::-webkit-details-marker {
    display: none;
}

#procedure-toggle::before {
    content: '▶ ';
    font-size: 0.7rem;
    display: inline-block;
    transition: transform 0.15s;
}

#procedure-section[open] #procedure-toggle::before {
    content: '▼ ';
}

#check-action {
    padding: 0.75rem 1rem;
    font-size: 0.87rem;
    line-height: 1.6;
    color: var(--text);
    white-space: pre-line;
}

#check-action p {
    margin: 0 0 0.5rem;
}

#check-action p:last-child {
    margin-bottom: 0;
}

/* ── Summary view ──────────────────────────────────── */
#summary-view {
    max-width: 900px;
    margin: 0 auto;
}

#summary-view h2 {
    margin-bottom: 1rem;
}

.summary-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.85rem;
}

.summary-info-grid div {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.summary-info-grid strong {
    color: var(--text-dim);
}

#summary-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

#filter-status {
    padding: 0.5rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
}

#btn-export {
    padding: 0.5rem 1rem;
    background: var(--accent2);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}

.summary-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.85rem;
}

.summary-row:hover {
    background: rgba(255,255,255,0.03);
}

.summary-part {
    color: var(--text-dim);
    font-size: 0.75rem;
    min-width: 30px;
}

.summary-id {
    font-weight: 600;
    min-width: 45px;
}

.summary-question {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.summary-result {
    font-weight: 600;
    text-transform: capitalize;
    min-width: 90px;
    text-align: right;
}

.result-pass    { color: var(--green); }
.result-fail    { color: var(--red); }
.result-not-verified, .result-nv { color: var(--orange); }
.result-na      { color: var(--grey); }
.result-unset   { color: var(--text-dim); }

/* ── Sidebar backdrop (mobile) ─────────────────────── */
#sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 195;
    background: rgba(0,0,0,0.5);
}

/* ── Mobile ────────────────────────────────────────── */
@media (max-width: 767px) {
    #sidebar {
        position: fixed;
        left: -320px;
        top: 0;
        bottom: 0;
        z-index: 200;
        transition: left 0.25s;
    }

    #sidebar.open {
        left: 0;
    }

    #sidebar.collapsed {
        margin-left: 0;
        width: 320px;
        min-width: 320px;
    }

    #sidebar-toggle {
        display: none;
    }

    #sidebar-close {
        display: block;
    }

    #sidebar-backdrop.show {
        display: block;
    }

    #menu-toggle {
        display: block;
    }

    #main {
        padding: 1rem;
        padding-top: 3rem;
    }

    #result-buttons {
        flex-direction: column;
    }

    .summary-question {
        white-space: normal;
        font-size: 0.8rem;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .exam-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .exam-card-actions {
        margin-left: 0;
        align-self: flex-end;
    }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 5px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
