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

:root {
    --brand: #A5F921;
    --brand-dark: #8AD41A;
    --brand-light: #E8FDCC;
    --navy: #1B2A4A;
    --navy-light: #2A3D5E;
    --green: #388e3c;
    --green-light: #e8f5e9;
    --red: #d32f2f;
    --red-light: #ffebee;
    --gray-50: #fafafa;
    --gray-100: #f5f5f5;
    --gray-200: #eee;
    --gray-300: #ddd;
    --gray-500: #999;
    --gray-700: #555;
    --gray-900: #222;
    --radius: 10px;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--gray-900);
    background: var(--gray-100);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    text-decoration: none;
}
.btn:active { opacity: 0.8; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--navy); color: var(--brand); }
.btn-primary:hover:not(:disabled) { background: var(--navy-light); }
.btn-secondary { background: var(--gray-200); color: var(--gray-900); }
.btn-secondary:hover { background: var(--gray-300); }
.btn-danger { background: var(--red-light); color: var(--red); border: 1px solid var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-large { width: 100%; padding: 16px; font-size: 1.1rem; }
.btn-link {
    background: none;
    border: none;
    color: var(--navy);
    cursor: pointer;
    font-size: 0.85rem;
    text-decoration: underline;
    padding: 4px;
}

/* ── Welcome Screen ──────────────────────────────────────────────── */
#screen-welcome {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: var(--navy);
}
.welcome-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 40px 32px;
    text-align: center;
    max-width: 400px;
    width: 100%;
}
.app-logo {
    display: block;
    width: 160px;
    height: auto;
    margin: 0 auto 16px;
}
.welcome-card h1 {
    font-size: 1.5rem;
    margin-bottom: 4px;
    color: var(--navy);
}
.welcome-card .subtitle {
    font-size: 0.9rem;
    color: var(--gray-700);
    margin-bottom: 24px;
}
.welcome-card > p {
    color: var(--gray-700);
    margin-bottom: 24px;
}
.welcome-card .form-group {
    text-align: left;
    margin-bottom: 20px;
}
.welcome-hint {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-top: 12px !important;
}

/* ── Header ──────────────────────────────────────────────────────── */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--navy);
    border-bottom: 2px solid var(--brand);
    position: sticky;
    top: 0;
    z-index: 10;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.header-logo {
    height: 24px;
    width: auto;
}
.header-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--brand);
}
.header-divider {
    width: 1px;
    height: 20px;
    background: rgba(255,255,255,0.2);
}
.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: rgba(255,255,255,0.7);
}
.header-right .btn-link {
    color: var(--brand);
}

/* ── Main Form ───────────────────────────────────────────────────── */
main {
    padding: 16px;
    padding-bottom: 80px;
    max-width: 600px;
    margin: 0 auto;
}
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 6px;
    color: var(--gray-700);
}
.form-group select,
.form-group input[type="text"],
.form-group input[type="date"] {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 1rem;
    background: #fff;
    transition: border-color 0.15s;
    -webkit-appearance: none;
}
.form-group select:focus,
.form-group input:focus {
    outline: none;
    border-color: var(--navy);
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* ── Defaults Indicator ──────────────────────────────────────────── */
.defaults-indicator {
    background: var(--brand-light);
    color: var(--navy);
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 16px;
    text-align: center;
    border-left: 4px solid var(--brand);
}

/* ── Checklist Sections ──────────────────────────────────────────── */
.checklist-section {
    margin-bottom: 8px;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 14px 16px;
    background: var(--navy);
    color: var(--brand);
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 700;
    text-align: left;
    gap: 8px;
}
.section-title { flex: 1; }
.section-count {
    font-weight: 400;
    font-size: 0.8rem;
    opacity: 0.7;
    color: #fff;
}
.section-chevron {
    transition: transform 0.2s;
    font-size: 0.9rem;
    color: var(--brand);
}
.checklist-section.collapsed .section-chevron {
    transform: rotate(-90deg);
}
.checklist-section.collapsed .section-body {
    display: none;
}

.section-body {
    padding: 0;
}

/* ── Checklist Item ──────────────────────────────────────────────── */
.checklist-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-200);
}
.checklist-item:last-child {
    border-bottom: none;
}

.item-task {
    font-size: 0.88rem;
    line-height: 1.4;
    margin-bottom: 10px;
    color: var(--gray-900);
}

.item-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

/* Radio button group (Yes/No/N/A) */
.radio-group {
    display: flex;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid var(--gray-300);
    flex-shrink: 0;
}
.radio-btn {
    padding: 8px 14px;
    border: none;
    background: #fff;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
    transition: all 0.15s;
    border-right: 1px solid var(--gray-300);
}
.radio-btn:last-child {
    border-right: none;
}
.radio-btn.selected {
    background: var(--navy);
    color: var(--brand);
}
.radio-btn:active { opacity: 0.8; }

/* Item dropdowns */
.item-issue,
.item-attention {
    padding: 8px 10px;
    border: 2px solid var(--gray-300);
    border-radius: 8px;
    font-size: 0.8rem;
    background: #fff;
    color: var(--gray-700);
    max-width: 140px;
    flex-shrink: 0;
}
.item-issue:focus,
.item-attention:focus {
    border-color: var(--navy);
    outline: none;
}

/* Item notes */
.item-notes {
    flex: 1;
    min-width: 120px;
    padding: 8px 10px;
    border: 2px solid var(--gray-300);
    border-radius: 8px;
    font-size: 0.85rem;
    background: #fff;
}
.item-notes:focus {
    border-color: var(--navy);
    outline: none;
}
.item-notes::placeholder {
    color: var(--gray-500);
}

/* ── Photo Section ───────────────────────────────────────────────── */
.photo-section {
    margin: 20px 0;
}
.photo-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.photo-header label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--gray-700);
}
#photo-count {
    font-size: 0.85rem;
    color: var(--gray-500);
    font-weight: 500;
}
.photo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}
.photo-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: var(--gray-200);
}
.photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.photo-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.photo-number {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
}
.photo-select-btn {
    width: 100%;
    border: 2px dashed var(--gray-300);
    background: #fff;
    color: var(--gray-700);
    padding: 16px;
    cursor: pointer;
    text-align: center;
    margin-bottom: 8px;
}
.photo-select-btn:hover {
    border-color: var(--brand-dark);
    color: var(--navy);
}

/* ── Action Bar ──────────────────────────────────────────────────── */
.action-bar {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}
.action-bar .btn {
    flex: 1;
}

/* ── Bottom Navigation ───────────────────────────────────────────── */
#bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--navy);
    border-top: 2px solid var(--brand);
    z-index: 50;
    padding: 4px 0;
    padding-bottom: env(safe-area-inset-bottom, 4px);
}
.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    border: none;
    background: none;
    cursor: pointer;
    color: rgba(255,255,255,0.5);
    font-size: 0.7rem;
    font-weight: 600;
    transition: color 0.15s;
}
.nav-btn.active {
    color: var(--brand);
}
.nav-icon {
    font-size: 1.3rem;
    line-height: 1;
    margin-bottom: 2px;
}

/* ── History Screen ──────────────────────────────────────────────── */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.history-empty {
    text-align: center;
    color: var(--gray-500);
    padding: 40px 16px;
}
.history-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border-left: 4px solid var(--brand);
}
.history-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.history-info strong {
    font-size: 1.1rem;
    color: var(--navy);
}
.history-info span {
    font-size: 0.8rem;
    color: var(--gray-700);
}
.history-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.history-actions .btn {
    padding: 8px 12px;
    font-size: 0.8rem;
}

/* ── Overlays ────────────────────────────────────────────────────── */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(27,42,74,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 24px;
}
.overlay-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 4px 24px rgba(0,0,0,0.2);
    padding: 40px 32px;
    text-align: center;
    max-width: 400px;
    width: 100%;
}
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--gray-200);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
#progress-text {
    color: var(--gray-700);
    font-size: 0.95rem;
}

/* ── Success ─────────────────────────────────────────────────────── */
.success-card { padding: 32px 24px; }
.success-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--brand-light);
    color: var(--navy);
    font-size: 1.8rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}
.success-card h2 {
    margin-bottom: 8px;
    color: var(--navy);
}
.success-card p {
    color: var(--gray-700);
    font-size: 0.9rem;
    margin-bottom: 12px;
}
.success-card .btn {
    margin-top: 8px;
    width: 100%;
}

/* ── Error Toast ─────────────────────────────────────────────────── */
.error-toast {
    position: fixed;
    bottom: 70px;
    left: 16px;
    right: 16px;
    max-width: 500px;
    margin: 0 auto;
    background: var(--red-light);
    color: var(--red);
    border: 1px solid var(--red);
    border-radius: var(--radius);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    z-index: 200;
    font-size: 0.9rem;
    box-shadow: var(--shadow);
}
.error-toast .btn-link {
    color: var(--red);
    flex-shrink: 0;
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .photo-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
    .form-row { grid-template-columns: 1fr; }
    main { padding: 12px; padding-bottom: 80px; }
    .overlay-card { padding: 28px 20px; }

    .item-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .radio-group {
        width: 100%;
    }
    .radio-btn {
        flex: 1;
        text-align: center;
    }
    .item-issue,
    .item-attention {
        max-width: 100%;
    }
    .item-notes {
        min-width: 100%;
    }

    .history-card {
        flex-direction: column;
        align-items: stretch;
    }
    .history-actions {
        justify-content: stretch;
    }
    .history-actions .btn {
        flex: 1;
    }
}
