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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f5f5f7;
    color: #1d1d1f;
    line-height: 1.5;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px 16px;
}

a { color: #39aa60; text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.8rem; margin-bottom: 8px; }
h2 { font-size: 1.3rem; margin-bottom: 12px; color: #333; }
.subtitle { color: #666; margin-bottom: 24px; }

/* ─── Navbar ────────────────────────────────────────────────────────────── */
.navbar {
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    text-decoration: none;
}
.logo:hover { text-decoration: none; }

.logo-img {
    height: 40px;
    width: auto;
    display: block;
}

.nav-links { display: flex; align-items: center; gap: 16px; }
.nav-user { color: #666; font-size: 0.9rem; }

/* ─── Flash Messages ────────────────────────────────────────────────────── */
.flash-container { max-width: 1200px; margin: 0 auto; padding: 8px 16px 0; }
.flash {
    padding: 10px 16px;
    border-radius: 8px;
    margin-bottom: 4px;
    font-size: 0.9rem;
}
.flash-success { background: #dff6dd; color: #1e7e34; border: 1px solid #b7e1b5; }
.flash-error { background: #fde7e9; color: #c92a2a; border: 1px solid #f5c6cb; }

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid #d0d0d0;
    background: #fff;
    color: #333;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
    transition: all 0.15s;
}
.btn:hover { background: #f0f0f0; text-decoration: none; }
.btn-primary { background: #39aa60; color: #fff; border-color: #39aa60; }
.btn-primary:hover { background: #2d8c4e; }
.btn-danger { background: #dc3545; color: #fff; border-color: #dc3545; }
.btn-danger:hover { background: #c82333; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-outline { background: transparent; border-color: #aaa; }

/* ─── Home Page ─────────────────────────────────────────────────────────── */
.home-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

/* ─── Detail Page - Field Divider ──────────────────────────────────────── */
.field-divider {
    text-align: center;
    margin: 16px 0 8px;
    border-top: 1px solid #e0e0e0;
    position: relative;
}
.field-divider span {
    background: #fff;
    padding: 0 12px;
    position: relative;
    top: -10px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #39aa60;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ocr-raw-details {
    margin-top: 12px;
    font-size: 0.85rem;
}
.ocr-raw-details summary {
    cursor: pointer;
    color: #39aa60;
    font-weight: 500;
    padding: 4px 0;
}
.ocr-raw-details .ocr-raw {
    margin-top: 8px;
    max-height: 200px;
    overflow-y: auto;
    background: #f8f8f8;
    padding: 12px;
    border-radius: 6px;
    font-size: 0.78rem;
    color: #555;
    white-space: pre-wrap;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    background: #fff;
    border-radius: 10px;
    margin-bottom: 12px;
    align-items: center;
    border: 1px solid #e0e0e0;
}
.filter-bar input,
.filter-bar select {
    padding: 6px 10px;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    font-size: 0.85rem;
    background: #fff;
    min-width: 120px;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.product-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
}
.product-card-link:hover { text-decoration: none; }

.product-card {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #e0e0e0;
    transition: box-shadow 0.2s, transform 0.15s;
    cursor: pointer;
    height: 100%;
}
.product-card:hover { box-shadow: 0 4px 16px rgba(57,170,96,0.15); transform: translateY(-2px); }

.card-image {
    position: relative;
    width: 100%;
    height: 200px;
    overflow: hidden;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.no-image {
    color: #aaa;
    font-size: 0.9rem;
}

.ocr-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}
.ocr-pending { background: #fff3cd; color: #856404; }
.ocr-done { background: #d4edda; color: #155724; }
.ocr-failed { background: #f8d7da; color: #721c24; }

.card-body {
    padding: 12px;
}

.field-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 4px 0;
    border-bottom: 1px solid #f5f5f5;
    font-size: 0.85rem;
}
.field-row:last-child { border-bottom: none; }
.field-label {
    color: #888;
    font-weight: 500;
    white-space: nowrap;
    margin-right: 8px;
}
.field-value {
    text-align: right;
    color: #333;
    word-break: break-word;
}

.editable {
    cursor: pointer;
    border-radius: 4px;
    padding: 2px 6px;
    transition: background 0.15s;
}
.editable:hover { background: #e8f0fe; }

.inline-edit-input {
    width: 140px;
    padding: 2px 6px;
    border: 1px solid #39aa60;
    border-radius: 4px;
    font-size: 0.85rem;
    outline: none;
    text-align: right;
}
.inline-edit-input:focus { box-shadow: 0 0 0 2px rgba(57,170,96,0.2); }

.ocr-text {
    font-size: 0.78rem;
    color: #555;
    max-height: 80px;
    overflow-y: auto;
    text-align: right;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #888;
}
.empty-state p { margin-bottom: 16px; font-size: 1.1rem; }

/* ─── Capture Page ──────────────────────────────────────────────────────── */
.capture-form { max-width: 700px; }

.photo-section, .fields-section {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid #e0e0e0;
}

.photo-instructions {
    color: #666;
    font-size: 0.85rem;
    margin-bottom: 12px;
}
.photo-field {
    padding: 16px;
    background: #fafafa;
    border-radius: 8px;
    border: 1px dashed #d0d0d0;
}
.photo-preview-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}
.photo-preview-row img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #ddd;
}
.photo-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}
.photo-buttons .btn {
    flex: 1;
    text-align: center;
}

.photo-field.required { border-color: #39aa60; background: #f0f7ff; }
.photo-field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9rem; }
.photo-field input[type="file"] { font-size: 0.85rem; width: 100%; }
.hint { color: #999; font-size: 0.75rem; display: block; margin-top: 4px; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.form-group { display: flex; flex-direction: column; }
.form-group label {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 4px;
    color: #555;
}
.form-group input,
.form-group select {
    padding: 8px 12px;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    font-size: 0.9rem;
    background: #fff;
}
.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #39aa60;
    box-shadow: 0 0 0 2px rgba(57,170,96,0.15);
}

.ocr-note { color: #888; font-size: 0.8rem; margin-top: 8px; text-align: center; }

/* ─── Join Page ─────────────────────────────────────────────────────────── */
.join-container {
    max-width: 400px;
    margin: 60px auto;
    text-align: center;
}
.join-container p { margin-bottom: 20px; color: #666; }
.join-form { display: flex; flex-direction: column; gap: 12px; }
.join-form input {
    padding: 10px 14px;
    border: 1px solid #d0d0d0;
    border-radius: 8px;
    font-size: 1rem;
    text-align: center;
}
.join-form input:focus { outline: none; border-color: #39aa60; box-shadow: 0 0 0 2px rgba(57,170,96,0.15); }

/* ─── Admin Page ────────────────────────────────────────────────────────── */
.admin-stats {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    flex: 1;
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    border: 1px solid #e0e0e0;
}
.stat-value { font-size: 2rem; font-weight: 700; color: #39aa60; display: block; }
.stat-label { color: #888; font-size: 0.85rem; }

.admin-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

.admin-section {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid #e0e0e0;
}

.admin-form { margin-top: 8px; }

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.admin-table th {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 2px solid #e0e0e0;
    color: #666;
    font-weight: 600;
}
.admin-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #f0f0f0;
}
.admin-table code { background: #f5f5f5; padding: 2px 6px; border-radius: 4px; font-size: 0.8rem; }

.role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}
.role-admin { background: #e8f0fe; color: #1967d2; }
.role-marketer { background: #fce8e6; color: #c5221f; }
.role-hunter { background: #e6f4ea; color: #137333; }

.muted { color: #bbb; }

/* ─── Detail Page ───────────────────────────────────────────────────────── */
.detail-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}
.detail-header h1 { margin-bottom: 0; }

.detail-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.detail-photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.detail-photo {
    background: #fff;
    border-radius: 10px;
    padding: 12px;
    border: 1px solid #e0e0e0;
}
.detail-photo .photo-label {
    display: block;
    font-weight: 600;
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 8px;
}
.detail-photo img {
    width: 100%;
    max-height: 400px;
    object-fit: contain;
    border-radius: 6px;
    cursor: pointer;
}

.detail-info, .detail-ocr {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid #e0e0e0;
}
.detail-fields {
    margin-top: 8px;
}

.ocr-raw {
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    font-size: 0.78rem;
    color: #555;
}

.detail-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.detail-meta {
    color: #aaa;
    font-size: 0.78rem;
    text-align: center;
}

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .product-grid { grid-template-columns: 1fr; }
    .photo-grid, .form-grid { grid-template-columns: 1fr; }
    .admin-stats { flex-direction: column; }
    .filter-bar { flex-direction: column; }
    .filter-bar input, .filter-bar select { width: 100%; }
}