:root {
    --primary: #007AFF;
    --bg: #F2F2F7;
    --card: #FFFFFF;
    --text: #1C1C1E;
    --text-secondary: #8E8E93;
    --destructive: #FF3B30;
    --success: #34C759;
    --radius: 14px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Arabic', sans-serif; }
body { background: var(--bg); color: var(--text); min-height: 100vh; overflow-x: hidden; }

#splash { position: fixed; inset: 0; background: var(--card); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 9999; transition: opacity 0.5s; }
#splash.hide { opacity: 0; pointer-events: none; }
.loader { width: 40px; height: 40px; border: 4px solid var(--bg); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.view { display: none; flex-direction: column; min-height: 100vh; }
.view.active { display: flex; animation: fadeUp 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }

/* Auth View */
.auth-view { justify-content: center; align-items: center; padding: 30px; background: var(--bg); text-align: center; }
.auth-icon { width: 80px; height: 80px; background: var(--card); border-radius: 20px; display: flex; align-items: center; justify-content: center; font-size: 40px; margin-bottom: 20px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.auth-title { font-size: 26px; font-weight: 700; margin-bottom: 8px; }
.auth-subtitle { font-size: 15px; color: var(--text-secondary); margin-bottom: 30px; }
.auth-group { background: var(--card); border-radius: var(--radius); overflow: hidden; width: 100%; max-width: 350px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.auth-input { width: 100%; padding: 14px 16px; border: none; background: transparent; font-size: 16px; outline: none; border-bottom: 1px solid #E5E5EA; }
.auth-input:last-child { border-bottom: none; }
.auth-btn { width: 100%; max-width: 350px; padding: 16px; border-radius: 12px; border: none; font-size: 17px; font-weight: 600; cursor: pointer; transition: 0.2s; margin-bottom: 10px; }
.auth-btn:active { opacity: 0.7; }
.auth-btn-primary { background: var(--primary); color: white; }
.auth-btn-text { background: transparent; color: var(--primary); }
.auth-error { color: var(--destructive); font-size: 14px; margin-bottom: 15px; display: none; }

/* Welcome View */
.welcome-view { justify-content: center; align-items: center; padding: 30px; background: var(--card); text-align: center; }
.welcome-icon { width: 80px; height: 80px; background: var(--bg); border-radius: 20px; display: flex; align-items: center; justify-content: center; font-size: 40px; margin-bottom: 20px; }
.welcome-title { font-size: 26px; font-weight: 700; margin-bottom: 10px; }
.welcome-subtitle { font-size: 16px; color: var(--text-secondary); margin-bottom: 40px; max-width: 300px; }
.upload-zone { background: var(--bg); border: 2px dashed var(--text-secondary); border-radius: var(--radius); padding: 40px 20px; width: 100%; max-width: 320px; cursor: pointer; transition: 0.3s; }
.upload-zone:active { transform: scale(0.97); border-color: var(--primary); }
input[type="file"] { display: none; }

/* Search View */
.search-header { background: var(--card); padding: 10px 20px; padding-top: calc(var(--safe-top) + 10px); border-bottom: 1px solid #E5E5EA; position: sticky; top: 0; z-index: 10; }
.header-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; margin-top: 10px; }
.header-title { font-size: 34px; font-weight: 800; letter-spacing: -0.5px; }
.btn-icon { width: 36px; height: 36px; border-radius: 50%; background: var(--bg); border: none; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 18px; }
.btn-icon:active { transform: scale(0.9); }
.tabs-container { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.tab-btn { flex: 1; padding: 8px; border: none; background: transparent; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--text-secondary); cursor: pointer; transition: 0.3s; }
.tab-btn.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.search-field-wrap { display: flex; gap: 10px; align-items: center; }
.search-input { flex: 1; padding: 12px 16px; border-radius: 12px; border: none; background: var(--bg); font-size: 16px; outline: none; }
.search-input:focus { box-shadow: 0 0 0 2px var(--primary); }
.camera-fab { width: 48px; height: 48px; border-radius: 14px; background: var(--primary); color: white; border: none; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 22px; }

.results-list { flex: 1; padding: 20px; padding-bottom: calc(var(--safe-bottom) + 20px); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.empty-state { text-align: center; padding-top: 60px; color: var(--text-secondary); }
.record-card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); cursor: pointer; transition: 0.2s; }
.record-card:active { transform: scale(0.98); }
.card-top-row { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; }
.card-title { font-size: 17px; font-weight: 600; flex: 1; }
.pin-btn { background: none; border: none; font-size: 20px; cursor: pointer; }
.card-sub { font-size: 14px; color: var(--text-secondary); }
.card-alert { font-size: 12px; font-weight: 600; color: var(--destructive); margin-top: 8px; background: #FFF2F2; padding: 6px 10px; border-radius: 6px; display: inline-block; }

/* Settings View */
.settings-header { background: var(--card); padding: 10px 20px; padding-top: calc(var(--safe-top) + 10px); border-bottom: 1px solid #E5E5EA; display: flex; align-items: center; gap: 15px; }
.settings-content { padding: 30px 20px; }
.info-group { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 20px; }
.info-row { padding: 15px 20px; border-bottom: 1px solid #E5E5EA; }
.info-row:last-child { border-bottom: none; }
.info-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.info-value { font-size: 16px; font-weight: 500; word-break: break-all; }
.btn-ios { width: 100%; padding: 16px; border-radius: var(--radius); border: none; font-size: 17px; font-weight: 600; cursor: pointer; margin-bottom: 10px; }
.btn-ios:active { opacity: 0.7; }
.btn-primary { background: var(--primary); color: white; }
.btn-danger { background: var(--destructive); color: white; }

/* Modals & Sheets */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); z-index: 50; display: none; justify-content: center; align-items: flex-end; }
.modal-overlay.active { display: flex; }
.bottom-sheet { background: var(--card); width: 100%; max-height: 85vh; border-radius: 20px 20px 0 0; padding: 20px; padding-bottom: calc(var(--safe-bottom) + 20px); overflow-y: auto; animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 36px; height: 5px; background: #C7C7CC; border-radius: 5px; margin: 0 auto 20px; }
.sheet-title { font-size: 22px; font-weight: 700; margin-bottom: 20px; text-align: center; }
.detail-item { background: var(--bg); padding: 14px; border-radius: 10px; margin-bottom: 8px; }
.detail-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; margin-bottom: 2px; }
.detail-value { font-size: 16px; font-weight: 600; color: var(--text); }
.follow-sheet-btn { width: 100%; padding: 16px; border-radius: 12px; border: none; font-size: 17px; font-weight: 700; cursor: pointer; margin-top: 15px; }

/* Camera */
.camera-screen { position: fixed; inset: 0; background: black; z-index: 100; display: none; flex-direction: column; color: white; }
.camera-screen.active { display: flex; }
.cam-header { padding: 10px 20px; padding-top: calc(var(--safe-top) + 10px); display: flex; justify-content: space-between; align-items: center; z-index: 10; background: rgba(0,0,0,0.5); }
.cam-title { font-size: 18px; font-weight: 600; }
.cam-close { background: rgba(255,255,255,0.2); width: 36px; height: 36px; border-radius: 50%; border: none; color: white; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.cam-body { flex: 1; position: relative; overflow: hidden; }
#reader { width: 100% !important; border: none !important; }
#reader video { object-fit: cover !important; }
.cam-overlay { position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 30%, transparent 70%, rgba(0,0,0,0.8) 100%); pointer-events: none; z-index: 5; }
.cam-viewfinder { width: 280px; height: 160px; border: 2px solid rgba(255,255,255,0.5); border-radius: 12px; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 6; box-shadow: 0 0 0 9999px rgba(0,0,0,0.5); }
.cam-instruction { position: absolute; bottom: 100px; text-align: center; font-size: 14px; opacity: 0.8; z-index: 6; width: 100%; padding: 0 40px; padding-bottom: var(--safe-bottom); }

.toast { position: fixed; top: calc(var(--safe-top) + 20px); left: 50%; transform: translateX(-50%) translateY(-20px); background: var(--text); color: white; padding: 14px 24px; border-radius: 14px; font-size: 15px; font-weight: 500; z-index: 200; box-shadow: 0 10px 30px rgba(0,0,0,0.2); opacity: 0; transition: 0.3s; pointer-events: none; text-align: center; max-width: 90%; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }