/* ── 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;
    --orange: #f57c00;
    --orange-light: #fff3e0;
    --blue: #1976d2;
    --blue-light: #e3f2fd;
    --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);
    text-align: right;
    line-height: 1.3;
}
.header-right .btn-link {
    color: var(--brand);
}

/* ── Main Content ───────────────────────────────────────────────── */
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="tel"],
.form-group input[type="date"],
.form-group textarea {
    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;
    font-family: inherit;
}
.form-group select:focus,
.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--navy);
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* ── Site Cards ──────────────────────────────────────────────────── */
.site-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.site-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(--gray-300);
    cursor: pointer;
    transition: border-color 0.2s;
}
.site-card:active { opacity: 0.8; }
.site-card.status-not-started { border-left-color: var(--gray-300); }
.site-card.status-in-progress { border-left-color: var(--orange); }
.site-card.status-complete { border-left-color: var(--green); }
.site-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}
.site-info strong {
    font-size: 1rem;
    color: var(--navy);
}
.site-info span {
    font-size: 0.8rem;
    color: var(--gray-700);
}
.status-badge {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 12px;
    white-space: nowrap;
    text-transform: uppercase;
}
.badge-not-started { background: var(--gray-200); color: var(--gray-700); }
.badge-in-progress { background: var(--orange-light); color: var(--orange); }
.badge-complete { background: var(--green-light); color: var(--green); }

/* ── Section Selector ────────────────────────────────────────────── */
.section-toggle-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.section-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: background 0.15s;
    -webkit-user-select: none;
    user-select: none;
}
.section-toggle:active { background: var(--gray-100); }
.section-toggle input[type="checkbox"] {
    width: 22px;
    height: 22px;
    accent-color: var(--navy);
    flex-shrink: 0;
}
.section-toggle .toggle-label {
    flex: 1;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--navy);
}
.section-toggle .toggle-count {
    font-size: 0.8rem;
    color: var(--gray-500);
}
.select-all-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--navy);
    color: var(--brand);
    border-radius: var(--radius);
    cursor: pointer;
    margin-bottom: 8px;
    font-weight: 700;
    -webkit-user-select: none;
    user-select: none;
}
.select-all-row input[type="checkbox"] {
    width: 22px;
    height: 22px;
    accent-color: var(--brand);
}

/* ── Survey Form (Equipment Cards) ───────────────────────────────── */
.survey-section-header {
    background: var(--navy);
    color: var(--brand);
    padding: 14px 16px;
    border-radius: var(--radius);
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.survey-section-header .section-progress {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.6);
    font-weight: 400;
}
.equipment-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 8px;
    overflow: hidden;
}
.equipment-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    cursor: pointer;
    transition: background 0.15s;
    -webkit-user-select: none;
    user-select: none;
}
.equipment-card-header:active { background: var(--gray-50); }
.equipment-card-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--gray-900);
    flex: 1;
}
.equipment-card-summary {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-right: 8px;
}
.equipment-card-chevron {
    transition: transform 0.2s;
    color: var(--gray-500);
    font-size: 0.9rem;
}
.equipment-card.collapsed .equipment-card-chevron {
    transform: rotate(-90deg);
}
.equipment-card.collapsed .equipment-card-body {
    display: none;
}
.equipment-card-body {
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.field-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.field-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-700);
}
.field-group input,
.field-group textarea {
    padding: 10px 12px;
    border: 2px solid var(--gray-300);
    border-radius: 8px;
    font-size: 0.95rem;
    background: #fff;
    font-family: inherit;
}
.field-group input:focus,
.field-group textarea:focus {
    outline: none;
    border-color: var(--navy);
}
.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* ── Wizard Navigation ───────────────────────────────────────────── */
.wizard-nav {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-200);
}
.wizard-nav .btn { flex: 1; }

/* ── Photo Section (per equipment section) ───────────────────────── */
.photo-section {
    margin: 16px 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;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
}
.photo-select-btn:hover {
    border-color: var(--brand-dark);
    color: var(--navy);
}

/* ── Site Review ─────────────────────────────────────────────────── */
.review-section {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 12px;
}
.review-section h3 {
    font-size: 0.95rem;
    color: var(--navy);
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--brand);
}
.review-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 0.9rem;
}
.review-row .label { color: var(--gray-700); }
.review-row .value { font-weight: 600; }

/* ── Generate Screen ─────────────────────────────────────────────── */
.generate-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    text-align: center;
    margin-bottom: 12px;
}
.generate-card h2 {
    color: var(--navy);
    margin-bottom: 8px;
}
.generate-card p {
    color: var(--gray-700);
    font-size: 0.9rem;
    margin-bottom: 16px;
}
.generate-card .btn {
    margin-bottom: 8px;
}

/* ── 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;
}

/* ── 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;
}

/* ── 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%;
}

/* ── Confirm Modal ───────────────────────────────────────────────── */
.confirm-card { padding: 28px 24px; text-align: left; }
.confirm-card h2 {
    font-size: 1.2rem;
    color: var(--red);
    margin-bottom: 12px;
}
.confirm-card p {
    font-size: 0.9rem;
    color: var(--gray-700);
    line-height: 1.5;
    margin-bottom: 20px;
    white-space: pre-line;
}
.confirm-actions {
    display: flex;
    gap: 12px;
}
.confirm-actions .btn { flex: 1; }

/* ── 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;
}

/* ── Settings Screen ─────────────────────────────────────────────── */
.settings-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 12px;
}
.settings-heading {
    font-size: 0.95rem;
    color: var(--navy);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--brand);
}
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-200);
    gap: 12px;
}
.settings-row:last-of-type {
    border-bottom: none;
}
.settings-row label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-700);
    flex-shrink: 0;
}
.settings-row select {
    padding: 8px 10px;
    border: 2px solid var(--gray-300);
    border-radius: 8px;
    font-size: 0.85rem;
    background: #fff;
}
.settings-row select:focus {
    border-color: var(--navy);
    outline: none;
}
.settings-value {
    font-size: 0.85rem;
    color: var(--gray-700);
}
.settings-link {
    font-size: 0.85rem;
    color: var(--navy);
    text-decoration: underline;
    text-align: right;
}
.settings-row-stacked {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 0;
}
.settings-row-stacked label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-700);
}

/* ── 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; }
    .field-row { grid-template-columns: 1fr; }

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