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

:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --ai: #7c3aed;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* ── Header ── */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-right { display: flex; align-items: center; gap: 8px; }
.btn-sm { padding: 6px 10px; font-size: 0.75rem; }
.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}

main { padding: 16px; max-width: 600px; margin: 0 auto; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ai { background: var(--ai); color: #fff; width: 100%; margin-top: 8px; }
.btn-large { width: 100%; padding: 14px; font-size: 1rem; }
.btn-icon {
    width: 36px; height: 36px; padding: 0;
    font-size: 1.5rem; line-height: 1; border-radius: 50%;
}

/* ── Inputs ── */
.input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: var(--surface);
    color: var(--text);
    appearance: none;
    -webkit-appearance: none;
}
.input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
select.input { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

/* ── Filters ── */
.filters {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

/* ── Item Grid ── */
.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}
.item-card {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.15s;
}
.item-card:hover { box-shadow: var(--shadow-lg); }
.item-card-photo { aspect-ratio: 1; overflow: hidden; background: #f1f5f9; }
.item-card-photo img { width: 100%; height: 100%; object-fit: cover; }
.no-photo {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); font-size: 0.8rem;
}
.item-card-info { padding: 10px; }
.item-card-info h3 { font-size: 0.9rem; margin-bottom: 2px; }
.item-meta { font-size: 0.8rem; color: var(--text-muted); }
.tag {
    display: inline-block;
    padding: 2px 8px;
    background: #e0e7ff;
    color: #3730a3;
    border-radius: 99px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 4px;
}
.tag-location { background: #dcfce7; color: #166534; }

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state .btn { margin-top: 16px; }

/* ── Flash messages ── */
.flashes { padding: 0 16px; max-width: 600px; margin: 8px auto 0; }
.flash {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin-bottom: 8px;
}
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }

/* ── Form ── */
.form-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}
.form-section h2 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 12px;
}
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 0.8rem; font-weight: 600; margin-bottom: 4px; color: var(--text-muted); }
.form-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
    margin-bottom: 32px;
}

/* ── Photos ── */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
    margin-bottom: 8px;
}
.photo-thumb {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #f1f5f9;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-remove {
    position: absolute;
    top: 4px; right: 4px;
    width: 24px; height: 24px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.photo-actions { display: flex; gap: 8px; }
.photo-actions .btn { flex: 1; }

.ai-status {
    text-align: center;
    font-size: 0.85rem;
    color: var(--ai);
    margin-top: 4px;
    min-height: 1.2em;
}

/* ── Item detail view ── */
.item-detail h1 { font-size: 1.5rem; margin-bottom: 4px; }
.item-description { color: var(--text-muted); margin-bottom: 16px; }
.photo-gallery {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin-bottom: 16px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}
.gallery-img {
    width: 280px;
    height: 280px;
    object-fit: cover;
    border-radius: var(--radius);
    flex-shrink: 0;
    scroll-snap-align: start;
    cursor: pointer;
}
.detail-grid { margin: 16px 0; }
.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.detail-label { color: var(--text-muted); }
.notes-section { margin-top: 16px; }
.notes-section h3 { font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.item-timestamp { margin-top: 20px; font-size: 0.75rem; color: var(--text-muted); }

/* ── Lightbox ── */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,0.95);
    overflow: hidden;
}
.lightbox.active {
    display: flex;
    align-items: center;
    touch-action: none;
    overscroll-behavior: contain;
}
.lightbox-close {
    position: absolute;
    top: 12px; right: 12px;
    z-index: 1001;
    width: 40px; height: 40px;
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.lightbox-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    color: rgba(255,255,255,0.7);
    font-size: 0.85rem;
}
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1001;
    width: 44px;
    height: 64px;
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.lightbox-prev { left: 8px; }
.lightbox-next { right: 8px; }
.lightbox-nav:active { background: rgba(255,255,255,0.3); }
.lightbox-track {
    display: flex;
    width: 100%;
    height: 100%;
    will-change: transform;
    touch-action: none;
}
.lightbox-slide {
    flex: 0 0 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.lightbox-slide img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    -webkit-user-select: none;
    user-select: none;
}

/* ── Auth pages ── */
.auth-page { max-width: 360px; margin: 40px auto; }
.auth-page h1 { font-size: 1.5rem; margin-bottom: 20px; text-align: center; }
.auth-form { background: var(--surface); padding: 20px; border-radius: var(--radius); box-shadow: var(--shadow); }
.auth-form .field { margin-bottom: 14px; }
.auth-alt { text-align: center; margin-top: 16px; font-size: 0.85rem; color: var(--text-muted); }
.auth-alt a { color: var(--primary); text-decoration: none; font-weight: 600; }

/* ── Loading spinner ── */
.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 6px;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
