/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --orange: #FF5C35;
    --orange-light: #FF7A57;
    --orange-dark: #E04420;
    --bg: #F5F3EF;
    --bg2: #EDEAE4;
    --surface: #FFFFFF;
    --surface2: #F9F7F4;
    --text: #1A1410;
    --text2: #6B6158;
    --text3: #9E958A;
    --border: #E2DDD6;
    --shadow: 0 2px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --radius: 16px;
    --radius-sm: 10px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --header-h: calc(60px + var(--safe-top));
    --nav-h: calc(60px + env(safe-area-inset-bottom, 0px));
}

html {
    height: 100%;
    /* Critical for iOS PWA safe area to work */
    min-height: calc(100% + env(safe-area-inset-top));
    background: var(--surface);
}

body {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    font-family: 'DM Sans', -apple-system, sans-serif;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}



/* ===== APP SHELL ===== */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 540px;
    margin: 0 auto;
    position: relative;
}

/* ===== HEADER ===== */
#header {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 540px;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding-top: var(--safe-top);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 60px;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 22px;
    line-height: 1;
}

.logo-text {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.3px;
}

.add-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--orange);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: transform 0.15s, background 0.15s;
    box-shadow: 0 2px 10px rgba(255,92,53,0.4);
}

.add-btn:active { transform: scale(0.92); background: var(--orange-dark); }

/* ===== MAIN ===== */
#main {
    flex: 1;
    overflow: hidden;
    margin-top: var(--header-h);
    margin-bottom: var(--nav-h);
    position: relative;
}

/* ===== PAGES ===== */
.page {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    opacity: 0;
    pointer-events: none;
    transform: translateX(30px);
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.page.active {
    opacity: 1;
    pointer-events: all;
    transform: translateX(0);
}

.page.slide-left {
    transform: translateX(-30px);
}

/* ===== SEARCH ===== */
.search-wrap {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
    padding: 14px 16px 10px;
}

.search-box {
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 0 14px;
    gap: 10px;
    transition: border-color 0.15s;
}

.search-box:focus-within {
    border-color: var(--orange);
}

.search-icon { color: var(--text3); flex-shrink: 0; }

#search-input {
    flex: 1;
    border: none;
    background: transparent;
    height: 46px;
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    outline: none;
}

#search-input::placeholder { color: var(--text3); }

.search-clear {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text3);
    font-size: 14px;
    padding: 4px;
}

/* ===== PRODUCT LIST ===== */
#product-list {
    padding: 4px 0 16px;
}

.product-row {
    display: flex;
    align-items: center;
    padding: 13px 18px;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid var(--border);
}

.product-row:nth-child(even) { background: var(--surface2); }
.product-row:nth-child(odd)  { background: var(--surface); }
.product-row:active { background: var(--bg2); }

.product-main {
    flex: 1;
    min-width: 0;
}

.product-naam {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-meta {
    font-size: 12.5px;
    color: var(--text3);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-chips {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    margin-left: 12px;
}

.chip {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    color: var(--text2);
}

.chip-stand {
    background: #FFF0EC;
    color: var(--orange-dark);
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 11.5px;
}

.chip-arrow {
    color: var(--text3);
}

/* ===== DETAIL PAGE ===== */
#detail-content {
    padding: 20px 18px 32px;
}

.detail-header {
    margin-bottom: 24px;
}

.detail-naam {
    font-family: 'Fraunces', serif;
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
    margin-bottom: 4px;
}

.detail-merk {
    font-size: 15px;
    color: var(--text3);
}

.detail-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 10px;
    text-align: center;
}

.stat-value {
    font-family: 'Fraunces', serif;
    font-size: 24px;
    font-weight: 700;
    color: var(--orange);
    line-height: 1;
}

.stat-unit {
    font-size: 11px;
    color: var(--text3);
    margin-top: 2px;
}

.stat-label {
    font-size: 11.5px;
    color: var(--text2);
    margin-top: 6px;
    font-weight: 500;
}

.detail-stand-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--orange);
    color: white;
    padding: 10px 18px;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 20px;
}

.detail-info {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.detail-info-row {
    display: flex;
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.detail-info-row:last-child { border-bottom: none; }

.detail-info-label {
    font-size: 13px;
    color: var(--text3);
    min-width: 90px;
    flex-shrink: 0;
}

.detail-info-value {
    font-size: 13.5px;
    color: var(--text);
    font-weight: 500;
}

.detail-tips {
    background: #FFF8F5;
    border: 1px solid #FFD8CC;
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 14px;
}

.detail-tips-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--orange);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.detail-tips p {
    font-size: 14px;
    color: var(--text2);
    line-height: 1.5;
}

.detail-actions {
    display: flex;
    gap: 10px;
    margin-top: 24px;
}

.btn-edit {
    flex: 1;
    background: var(--orange);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 15px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, transform 0.1s;
}

.btn-edit:active { background: var(--orange-dark); transform: scale(0.98); }

.btn-back {
    background: var(--surface);
    color: var(--text);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 15px 20px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

.btn-back:active { background: var(--bg2); }

/* ===== FORM PAGE ===== */
.form-scroll {
    padding: 20px 18px 40px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 8px;
}

.req { color: var(--orange); }

.autocomplete-wrap {
    position: relative;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group textarea {
    width: 100%;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 13px 15px;
    font-size: 16px;
    font-family: inherit;
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
    -webkit-appearance: none;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--orange);
}

.form-group textarea {
    resize: none;
    line-height: 1.5;
}

.autocomplete-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1.5px solid var(--orange);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 50;
    list-style: none;
    max-height: 200px;
    overflow-y: auto;
    display: none;
}

.autocomplete-list.show { display: block; }

.autocomplete-list li {
    padding: 12px 15px;
    font-size: 15px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    transition: background 0.1s;
}

.autocomplete-list li:last-child { border-bottom: none; }
.autocomplete-list li:active,
.autocomplete-list li.highlighted { background: var(--bg2); }

/* ===== STAND GRID ===== */
.stand-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.stand-btn {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: all 0.15s;
    font-family: inherit;
}

.stand-icon { font-size: 20px; }
.stand-label { font-size: 11.5px; font-weight: 500; color: var(--text2); text-align: center; }

.stand-btn.selected {
    border-color: var(--orange);
    background: #FFF0EC;
}

.stand-btn.selected .stand-label { color: var(--orange-dark); }

/* ===== FORM ROW ===== */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-group.half { margin-bottom: 0; }

.input-unit {
    position: relative;
}

.input-unit input {
    padding-right: 44px;
}

.unit {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    color: var(--text3);
    pointer-events: none;
}

/* ===== FORM ACTIONS ===== */
.form-actions {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-save {
    width: 100%;
    background: var(--orange);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 16px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, transform 0.1s;
    box-shadow: 0 4px 16px rgba(255,92,53,0.35);
}

.btn-save:active { background: var(--orange-dark); transform: scale(0.98); }

.btn-delete {
    width: 100%;
    background: transparent;
    color: #E53935;
    border: 1.5px solid #FFCDD2;
    border-radius: var(--radius);
    padding: 14px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

.btn-delete:active { background: #FFEBEE; }

/* ===== BOTTOM NAV ===== */
#bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 540px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    /* Two declarations: fallback first, then env() override */
    padding-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

#bottom-nav-safe { display: none; }

.nav-btn-row {
    display: flex;
    width: 100%;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 60px;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    color: var(--text3);
    font-size: 11px;
    font-weight: 500;
    transition: color 0.15s;
}

/* ===== PULL TO REFRESH ===== */
.ptr-indicator {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 56px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 5;
}

.ptr-indicator.visible { opacity: 1; }

.ptr-spinner {
    width: 24px;
    height: 24px;
    border: 2.5px solid var(--border);
    border-top-color: var(--orange);
    border-radius: 50%;
    transition: transform 0.1s;
}

.ptr-spinner.spinning {
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.nav-btn.active { color: var(--orange); }
.nav-btn svg { transition: transform 0.15s; }
.nav-btn:active svg { transform: scale(0.9); }

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 60px 30px;
    color: var(--text3);
}

.empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-state p { font-size: 15px; line-height: 1.6; }

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: calc(var(--nav-h) + 16px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: white;
    padding: 12px 22px;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 500;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    white-space: nowrap;
    box-shadow: var(--shadow-lg);
    max-width: calc(100vw - 40px);
    text-align: center;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===== SECTION HEADER (alphabet) ===== */
.section-header {
    padding: 8px 18px 4px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 5;
}

/* ===== LOADING ===== */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text3);
    font-size: 14px;
}

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

/* ===== DESKTOP ===== */
@media (min-width: 541px) {
    #app { box-shadow: 0 0 60px rgba(0,0,0,0.08); }
    #header, #bottom-nav { left: 50%; }
}

/* ===== MULTI-STEP FORM ===== */
.stap-form-block {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.stap-form-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.stap-form-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--orange);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stap-remove-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #E53935;
    padding: 4px;
    display: flex;
    align-items: center;
    border-radius: 6px;
    transition: background 0.1s;
}

.stap-remove-btn:active { background: #FFEBEE; }

.btn-add-stap {
    width: 100%;
    background: var(--surface);
    border: 1.5px dashed var(--orange);
    border-radius: var(--radius);
    padding: 13px;
    font-size: 14px;
    font-weight: 500;
    color: var(--orange);
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
    transition: background 0.15s;
}

.btn-add-stap:active { background: #FFF0EC; }

/* ===== DETAIL: MULTI STEP TIMELINE ===== */
.detail-stappen-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.detail-stappen {
    margin-bottom: 14px;
}

.detail-stap {
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.stap-timeline {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    padding-top: 2px;
}

.stap-num {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--orange);
    color: white;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stap-line {
    width: 2px;
    flex: 1;
    min-height: 20px;
    background: var(--border);
    margin: 4px 0;
}

.stap-card {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 8px;
}

.stap-stand {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.stap-details {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text2);
}

.stap-sep { color: var(--text3); }

.detail-totaal {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #FFF0EC;
    border: 1px solid #FFD8CC;
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-size: 14px;
    color: var(--text2);
    margin-bottom: 16px;
}

.detail-totaal strong {
    color: var(--orange-dark);
    font-size: 15px;
}

/* ===== LIST: MULTI-STEP BADGE ===== */
.chip-steps {
    background: var(--orange);
    color: white;
    padding: 2px 7px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

/* ===== AANDACHT FEATURE ===== */
.aandacht-toggle {
    width: 100%;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-family: inherit;
    font-size: 15px;
    color: var(--text2);
    transition: all 0.15s;
    text-align: left;
}

.aandacht-toggle.active {
    border-color: #F59E0B;
    background: #FFFBEB;
    color: #92400E;
}

.aandacht-icon { font-size: 20px; flex-shrink: 0; }

.aandacht-label { flex: 1; font-size: 14px; font-weight: 500; }

.aandacht-check {
    flex-shrink: 0;
    position: relative;
    width: 22px;
    height: 22px;
}

.check-off, .check-on {
    position: absolute;
    top: 0; left: 0;
    transition: opacity 0.15s;
}

.check-off { color: var(--border); opacity: 1; }
.check-on  { color: #F59E0B; opacity: 0; }

.aandacht-toggle.active .check-off { opacity: 0; }
.aandacht-toggle.active .check-on  { opacity: 1; }

/* List row highlight */
.row-aandacht { background: #FFFDF5 !important; }

/* Aandacht chip in list */
.chip-aandacht {
    font-size: 15px;
    line-height: 1;
}

/* Detail page banner */
.detail-aandacht {
    background: #FFFBEB;
    border: 1px solid #FCD34D;
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-size: 14px;
    color: #92400E;
    margin-bottom: 14px;
    line-height: 1.5;
}