* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4a6cf7;
    --primary-dark: #3a56d4;
    --secondary: #6c757d;
    --success: #28a745;
    --danger: #dc3545;
    --warning: #ffc107;
    --dark: #1a1a2e;
    --text: #212529;
    --text-light: #6c757d;
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --border: #dee2e6;
    --shadow: 0 2px 12px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 16px 80px;
    min-height: 100vh;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 100;
}

header h1 { font-size: 1.5rem; font-weight: 700; color: var(--dark); }

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-btn {
    width: auto;
    padding: 6px 12px;
    font-size: 0.8rem;
    white-space: nowrap;
}

.icon-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; padding: 8px; border-radius: 50%; transition: background 0.2s; line-height: 1; }
.icon-btn:hover { background: rgba(0,0,0,0.05); }

/* ===== Hero Card (Homepage) ===== */
.hero-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-top: 8px;
}

.hero-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.hero-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.hero-card-header .btn {
    width: auto;
    padding: 6px 12px;
    font-size: 0.8rem;
}

#heroAuctionInfo {
    margin-bottom: 20px;
}

.hero-auction-key {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--dark);
    margin-bottom: 4px;
}

.hero-auction-dates {
    font-size: 0.95rem;
    color: var(--text-light);
    margin-bottom: 2px;
}

.hero-auction-lot-range {
    font-size: 0.85rem;
    color: var(--text-light);
}

.hero-cta {
    margin-top: 0;
}

.home-actions {
    margin-top: 16px;
}

/* ===== Form Page Header ===== */
.form-page-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 100;
}

.form-back-btn {
    flex-shrink: 0;
    padding: 6px 12px;
    font-size: 0.85rem;
}

.form-page-auction-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.form-auction-key {
    font-weight: 700;
    font-size: 1rem;
    color: var(--dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.form-auction-dates {
    font-size: 0.8rem;
    color: var(--text-light);
}

/* ===== Auction Selector Modal ===== */
.auction-selector-item {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.auction-selector-item:hover {
    border-color: var(--primary);
    background: #f8f9ff;
}

.auction-selector-item.selected {
    border-color: var(--primary);
    background: #eef1ff;
}

.auction-selector-item .sel-info {
    flex: 1;
    min-width: 0;
}

.auction-selector-item .sel-key {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--dark);
}

.auction-selector-item .sel-dates {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 2px;
}

.auction-selector-item .sel-lot-range {
    font-size: 0.8rem;
    color: var(--text-light);
}

.auction-selector-item .sel-check {
    font-size: 1.2rem;
    color: var(--primary);
    font-weight: bold;
    margin-left: 12px;
    flex-shrink: 0;
}

/* ===== General Form Styles ===== */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9rem; color: var(--text); }
.form-group small { display: block; color: var(--text-light); font-size: 0.8rem; margin-top: 4px; }

input[type="number"], input[type="text"], input[type="password"], textarea, select {
    width: 100%; padding: 12px 16px; border: 2px solid var(--border); border-radius: var(--radius-sm);
    font-size: 1rem; font-family: inherit; transition: border-color 0.2s; background: var(--card-bg); color: var(--text);
}
input[type="number"]:focus, input[type="text"]:focus, input[type="password"]:focus, textarea:focus, select:focus {
    outline: none; border-color: var(--primary);
}
textarea { resize: vertical; min-height: 80px; }

.checkbox-group { margin-bottom: 20px; }
.checkbox-label { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; padding: 8px 0; }
.checkbox-label input[type="checkbox"] { display: none; }
.checkbox-custom {
    width: 24px; height: 24px; border: 2px solid var(--border); border-radius: 4px;
    display: flex; align-items: center; justify-content: center; transition: all 0.2s; flex-shrink: 0;
}
.checkbox-label input:checked + .checkbox-custom { background: var(--primary); border-color: var(--primary); }
.checkbox-label input:checked + .checkbox-custom::after { content: '✓'; color: white; font-size: 16px; font-weight: bold; }
.checkbox-text { font-weight: 600; font-size: 1rem; color: var(--danger); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 12px 24px; border: none; border-radius: var(--radius-sm);
    font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.2s; width: 100%; font-family: inherit;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 8px 16px; font-size: 0.85rem; width: auto; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover:not(:disabled) { background: #5a6268; }
.btn-submit {
    background: linear-gradient(135deg, var(--primary), #6c63ff); color: white;
    padding: 16px; font-size: 1.1rem; border-radius: var(--radius); margin-top: 8px;
}
.btn-submit:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 15px rgba(74,108,247,0.4); }
.btn-success { background: var(--success); color: white; margin-top: 12px; }
.btn-success:hover:not(:disabled) { background: #218838; }

.camera-controls { display: flex; gap: 10px; margin-bottom: 12px; }
.camera-controls .btn { flex: 1; padding: 10px 16px; font-size: 0.9rem; }

.photo-gallery { display: flex; flex-wrap: wrap; gap: 8px; min-height: 60px; }
.photo-gallery .photo-item {
    position: relative; width: calc(33.33% - 6px); aspect-ratio: 1;
    border-radius: var(--radius-sm); overflow: hidden; border: 2px solid var(--border);
}
.photo-gallery .photo-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-gallery .photo-item .delete-photo {
    position: absolute; top: 4px; right: 4px; width: 24px; height: 24px;
    background: rgba(220,53,69,0.9); color: white; border: none; border-radius: 50%;
    font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center; line-height: 1;
    z-index: 2;
}
.photo-gallery .photo-item .photo-include-label {
    position: absolute; left: 0; right: 0; bottom: 0;
    display: flex; align-items: center; gap: 4px;
    background: rgba(255,255,255,0.92); padding: 4px 6px;
    font-size: 0.68rem; line-height: 1.1; cursor: pointer; z-index: 2;
}
.photo-gallery .photo-item .photo-include-label input { flex-shrink: 0; margin: 0; }
.photo-gallery .photo-item.photo-excluded { border-color: var(--danger); }
.photo-gallery .photo-item.photo-excluded img { opacity: 0.35; filter: grayscale(0.7); }
.photo-gallery .photo-item.photo-excluded .photo-include-label { background: rgba(255,235,235,0.95); color: var(--danger); }

.loading { text-align: center; padding: 40px 0; }
.loading p { margin-top: 12px; color: var(--text-light); }
.spinner {
    width: 40px; height: 40px; border: 4px solid var(--border); border-top-color: var(--primary);
    border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-container { background: var(--card-bg); border-radius: var(--radius); padding: 20px; margin-top: 20px; box-shadow: var(--shadow); }
.result-container h3 { margin-bottom: 12px; color: var(--dark); }
.result-content { white-space: pre-wrap; font-size: 0.95rem; line-height: 1.7; color: var(--text); }

/* View-lot image gallery */
.view-lot-images { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.view-lot-images .view-lot-img { position: relative; width: calc(33.33% - 6px); aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 2px solid var(--border); }
.view-lot-images .view-lot-img img { width: 100%; height: 100%; object-fit: cover; }
.view-lot-images .view-lot-img.excluded { border-color: var(--danger); }
.view-lot-images .view-lot-img.excluded img { opacity: 0.4; filter: grayscale(0.8); }
.view-lot-images .view-lot-img .excluded-tag { position: absolute; left: 4px; right: 4px; bottom: 4px; background: rgba(220,53,69,0.9); color: white; font-size: 0.6rem; text-align: center; padding: 2px 4px; border-radius: 4px; }

.saved-lots-section { margin-top: 32px; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-header h2 { font-size: 1.2rem; color: var(--dark); }
.filter-bar { margin-bottom: 12px; }
.filter-bar select { padding: 8px 12px; font-size: 0.9rem; border-radius: var(--radius-sm); border: 2px solid var(--border); width: 100%; background: var(--card-bg); }
.empty-state { text-align: center; color: var(--text-light); padding: 24px; font-style: italic; }

.saved-lot-item {
    background: var(--card-bg); border-radius: var(--radius-sm); padding: 12px 16px;
    margin-bottom: 8px; box-shadow: var(--shadow); display: flex; align-items: center; justify-content: space-between; cursor: pointer; transition: transform 0.2s;
}
.saved-lot-item:hover { transform: translateX(4px); }
.saved-lot-item .lot-info { flex: 1; min-width: 0; }
.saved-lot-item .lot-number { font-weight: 700; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-lot-item .lot-auction { font-size: 0.8rem; color: var(--primary); font-weight: 500; }
.saved-lot-item .lot-meta { font-size: 0.8rem; color: var(--text-light); margin-top: 2px; }
.saved-lot-item .lot-badge { font-size: 0.75rem; padding: 2px 8px; border-radius: 12px; background: var(--warning); color: #856404; font-weight: 600; margin-left: 8px; flex-shrink: 0; }
.saved-lot-item .synced-badge { font-size: 0.7rem; padding: 1px 6px; border-radius: 10px; background: var(--success); color: #fff; font-weight: 500; }
.saved-lot-item .delete-lot { background: none; border: none; color: var(--danger); font-size: 1.2rem; cursor: pointer; padding: 4px 8px; flex-shrink: 0; }

.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.modal.hidden { display: none !important; }
.modal-content { background: var(--card-bg); border-radius: var(--radius); width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,0.2); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card-bg); z-index: 1; }
.modal-header h2 { font-size: 1.2rem; }
.modal-body { padding: 20px; }

#cameraModal { padding: 0; }
#cameraModal.modal { align-items: flex-end; background: rgba(0,0,0,0.85); }
.camera-modal-content { background: #000; width: 100%; max-width: 480px; height: 100vh; max-height: 100vh; display: flex; flex-direction: column; border-radius: 0; box-shadow: none; }
.camera-modal-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: #1a1a2e; color: white; z-index: 2; }
.camera-modal-header .icon-btn { color: white; font-size: 1.3rem; }
.camera-title { font-weight: 600; font-size: 1rem; }
.camera-count { font-size: 0.85rem; color: #aaa; }
.camera-viewfinder { flex: 1; position: relative; overflow: hidden; background: #000; display: flex; align-items: center; justify-content: center; }
.camera-viewfinder video { width: 100%; height: 100%; object-fit: contain; }
.camera-overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.camera-frame { width: 85%; height: 75%; border: 2px solid rgba(255,255,255,0.4); border-radius: 8px; box-shadow: 0 0 0 9999px rgba(0,0,0,0.3); }
.camera-modal-footer { padding: 16px; background: #1a1a2e; display: flex; flex-direction: column; align-items: center; }
.camera-thumbnails { display: flex; gap: 8px; margin-bottom: 12px; min-height: 50px; width: 100%; overflow-x: auto; padding: 4px 0; justify-content: center; flex-wrap: wrap; }
.camera-thumbnails .cam-thumb { width: 84px; border-radius: 6px; overflow: hidden; border: 2px solid #444; flex-shrink: 0; position: relative; background: #111; }
.camera-thumbnails .cam-thumb img { width: 100%; height: 64px; object-fit: cover; display: block; }
.camera-thumbnails .cam-thumb.cam-thumb-excluded { border-color: #dc3545; }
.camera-thumbnails .cam-thumb.cam-thumb-excluded img { opacity: 0.35; filter: grayscale(0.7); }
.camera-thumbnails .cam-thumb .cam-thumb-del { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; background: rgba(220,53,69,0.9); color: white; border: none; border-radius: 50%; font-size: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; line-height: 1; padding: 0; z-index: 2; }
.camera-thumbnails .cam-thumb .cam-thumb-include { display: flex; align-items: center; gap: 3px; padding: 3px 4px; font-size: 0.6rem; line-height: 1.1; color: #ddd; cursor: pointer; background: #222; }
.camera-thumbnails .cam-thumb .cam-thumb-include input { flex-shrink: 0; margin: 0; }
.camera-thumbnails .cam-thumb.cam-thumb-excluded .cam-thumb-include { color: #ff9a9a; background: #3a1216; }
.camera-actions { display: flex; justify-content: center; width: 100%; }

/* Settings modal extras */
.prompt-actions { margin-top: 8px; }
.settings-note { margin-top: 8px; font-size: 0.8rem; color: var(--danger); font-weight: 500; }

/* Admin model list editor */
.models-admin { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }
.models-admin-header { margin-bottom: 6px; }
.models-admin-title { font-weight: 600; font-size: 0.85rem; color: var(--dark); }
#modelsAdminList { margin-bottom: 8px; }
.model-admin-row { display: flex; gap: 6px; margin-bottom: 6px; }
.model-admin-row input { flex: 1; min-width: 0; padding: 6px 8px; font-size: 0.8rem; border-radius: var(--radius-sm); border: 2px solid var(--border); }
.model-remove-btn { width: 30px; height: 30px; flex-shrink: 0; background: rgba(220,53,69,0.9); color: white; border: none; border-radius: 50%; font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center; line-height: 1; align-self: center; }
.models-admin small { display: block; margin-top: 6px; }
.btn-capture-btn { width: 72px; height: 72px; border-radius: 50%; border: 4px solid white; background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; transition: transform 0.15s; }
.btn-capture-btn:active { transform: scale(0.92); }
.capture-circle { width: 56px; height: 56px; border-radius: 50%; background: white; display: block; }

#cameraModal.modal.hidden { display: none; }

/* Hidden utility */
.hidden { display: none !important; }

/* ===== Login Screen ===== */
body.auth-locked > #app > header,
body.auth-locked > #app > #homePage,
body.auth-locked > #app > #auctionFormPage {
    display: none !important;
}

.login-screen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    padding: 16px;
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: #fff;
    border-radius: 16px;
    padding: 28px 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}

.login-title {
    margin: 0 0 4px;
    font-size: 24px;
    text-align: center;
    color: #1a1a2e;
}

.login-subtitle {
    margin: 0 0 20px;
    text-align: center;
    color: #666;
    font-size: 14px;
}

.login-form .form-group {
    margin-bottom: 14px;
}

.login-form label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #333;
}

.login-form input {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #d0d0d8;
    border-radius: 10px;
    font-size: 15px;
    box-sizing: border-box;
}

.login-form input:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
}

.btn-block {
    width: 100%;
    margin-top: 4px;
}

.login-toggle {
    margin-top: 16px;
    text-align: center;
    font-size: 13px;
}

.login-toggle a {
    color: #4f46e5;
    text-decoration: none;
}

.login-toggle a:hover {
    text-decoration: underline;
}

.auth-message {
    margin-top: 14px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    text-align: center;
}

.auth-message.auth-error {
    background: #fdecea;
    color: #c0392b;
}

.auth-message.auth-success {
    background: #e8f6ef;
    color: #1e7e4f;
}

/* ===== Users modal ===== */
.users-list {
    margin-bottom: 8px;
}

.users-divider {
    border: none;
    border-top: 1px solid #e5e5ec;
    margin: 18px 0;
}

.user-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid #ececf2;
    border-radius: 10px;
    margin-bottom: 8px;
}

.user-name {
    font-weight: 600;
    color: #1a1a2e;
}

.user-role {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 3px 8px;
    border-radius: 999px;
    font-weight: 700;
}

.role-admin { background: #eef0ff; color: #4f46e5; }
.role-user { background: #eef2f5; color: #5b6b7b; }

.user-created {
    font-size: 12px;
    color: #888;
}
