:root {
  --primary: #0756CC;
  --primary-dark: #054AAD;
  --secondary: #1678ED;
  --light-blue: #EAF2FF;
  --bg: #F6F9FF;
  --text: #14264D;
  --text-secondary: #5A7199;
  --white: #FFFFFF;
  --border: #D6E4F5;
  --success: #22C55E;
  --warning: #F59E0B;
  --danger: #EF4444;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --shadow: 0 2px 12px rgba(7,86,204,0.08);
  --shadow-lg: 0 8px 32px rgba(7,86,204,0.12);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-height: 72px;
  --header-height: 56px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', 'Noto Sans Arabic', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100dvh;
}

html[dir="rtl"] body { font-family: 'Noto Sans Arabic', 'Inter', -apple-system, sans-serif; }

.hidden { display: none !important; }

/* Splash */
#splash-screen {
  position: fixed; inset: 0; z-index: 1000;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
}
#splash-screen:not(.active) { display: none; }
.splash-bg { position: absolute; inset: 0; overflow: hidden; }
.splash-wave { position: absolute; bottom: 0; width: 100%; height: 50%; }
.splash-content { position: relative; z-index: 1; text-align: center; color: white; }
.splash-logo { margin-bottom: 20px; }
.splash-title { font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.splash-subtitle { font-size: 16px; opacity: 0.9; margin-bottom: 32px; }
.splash-tagline { font-size: 14px; opacity: 0.7; letter-spacing: 2px; margin-bottom: 24px; }
.splash-loader {
  width: 32px; height: 32px; border: 3px solid rgba(255,255,255,0.3);
  border-top-color: white; border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Header */
.app-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-height);
  background: var(--white);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo img { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; }
.header-title { font-size: 17px; font-weight: 700; color: var(--text); }
.header-settings {
  width: 40px; height: 40px; border: none; background: var(--light-blue);
  border-radius: 10px; display: flex; align-items: center; justify-content: center; cursor: pointer;
}

/* Page content */
.page-content {
  padding: 16px 16px calc(var(--nav-height) + var(--safe-bottom) + 16px);
  min-height: calc(100dvh - var(--header-height));
}
.screen:not(.active) { display: none; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 16px; font-weight: 600; border: none; border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.2s; font-family: inherit;
}
.btn-primary {
  background: var(--primary); color: white; padding: 14px 24px;
}
.btn-primary:active { background: var(--primary-dark); transform: scale(0.98); }
.btn-outline {
  background: var(--white); color: var(--primary); border: 2px solid var(--primary);
  padding: 12px 24px;
}
.btn-outline:active { background: var(--light-blue); }
.btn-lg { width: 100%; margin-top: 12px; padding: 16px; border-radius: var(--radius); }

/* Home */
.home-container { max-width: 400px; margin: 0 auto; }
.home-card {
  background: var(--white); border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow); margin-bottom: 16px;
}
.scan-card { text-align: center; padding: 32px 24px; }
.scan-icon {
  width: 88px; height: 88px; border-radius: 50%; background: var(--light-blue);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 16px;
}
.scan-title { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.scan-desc { font-size: 14px; color: var(--text-secondary); margin-bottom: 24px; line-height: 1.5; }
.customers-card { cursor: pointer; }
.customers-card:active { background: var(--light-blue); }
.customers-card-inner { display: flex; align-items: center; gap: 14px; flex: 1; }
.customers-card { display: flex; align-items: center; }
.customers-card-icon {
  width: 48px; height: 48px; border-radius: 12px; background: var(--light-blue);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.customers-card-title { font-size: 16px; font-weight: 600; }
.customers-card-desc { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

/* Camera */
.camera-screen { padding: 0 !important; min-height: 100dvh; background: black; }
.camera-container { position: relative; width: 100%; height: 100dvh; overflow: hidden; }
#camera-video { width: 100%; height: 100%; object-fit: cover; }
.camera-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.camera-frame {
  width: 280px; height: 380px; border: 2px solid rgba(255,255,255,0.6);
  border-radius: 12px; position: relative;
}
.camera-frame::before, .camera-frame::after {
  content: ''; position: absolute; width: 24px; height: 24px;
  border-color: white; border-style: solid;
}
.camera-frame::before { top: -1px; left: -1px; border-width: 3px 0 0 3px; border-radius: 8px 0 0 0; }
.camera-frame::after { top: -1px; right: -1px; border-width: 3px 3px 0 0; border-radius: 0 8px 0 0; }
.camera-back-btn {
  position: absolute; top: 16px; left: 16px; z-index: 10;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(0,0,0,0.4); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.camera-back-btn:active { background: rgba(0,0,0,0.6); }
[dir="rtl"] .camera-back-btn { left: auto; right: 16px; }
[dir="rtl"] .camera-back-btn svg { transform: scaleX(-1); }
.camera-controls {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 24px 32px calc(24px + var(--safe-bottom));
  display: flex; align-items: center; justify-content: center; gap: 40px;
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
}
.camera-btn {
  background: none; border: none; color: white; font-size: 16px;
  cursor: pointer; font-family: inherit;
}
.camera-btn.capture {
  width: 72px; height: 72px; border-radius: 50%;
  background: white; position: relative;
}
.capture-ring {
  position: absolute; inset: 4px; border: 3px solid var(--primary);
  border-radius: 50%;
}
.camera-btn.capture:active { transform: scale(0.92); }
.camera-btn.gallery { display: flex; flex-direction: column; align-items: center; gap: 4px; }

/* Processing */
.processing-container {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 60vh; text-align: center; padding: 24px;
}
.processing-icon { position: relative; margin-bottom: 24px; }
.processing-check { position: absolute; bottom: -4px; right: -4px; }
.processing-spinner {
  width: 120px; height: 120px; border: 4px solid var(--light-blue);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 1s linear infinite; margin-bottom: 24px;
}
.processing-title { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.processing-desc { font-size: 14px; color: var(--text-secondary); line-height: 1.5; }

/* Result */
.result-container {
  max-width: 400px; margin: 0 auto; padding: 24px 0; text-align: center;
}
.result-success { position: relative; margin-bottom: 16px; }
.result-icon { margin-bottom: 8px; }
.result-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.result-subtitle { font-size: 14px; color: var(--text-secondary); margin-bottom: 20px; }
.result-fields { text-align: left; margin-bottom: 8px; }
.result-field {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--white); border-radius: var(--radius-sm); padding: 16px;
  margin-bottom: 12px; box-shadow: var(--shadow);
}
.field-icon {
  width: 40px; height: 40px; border-radius: 10px; background: var(--light-blue);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.field-content { flex: 1; min-width: 0; }
.field-content label { font-size: 12px; color: var(--text-secondary); font-weight: 500; display: block; margin-bottom: 4px; }
.field-input-row { display: flex; align-items: center; gap: 8px; }
.field-input-row input {
  flex: 1; border: none; outline: none; font-size: 16px; font-weight: 600;
  color: var(--text); background: transparent; font-family: inherit;
  min-width: 0;
}
.field-input-row input::placeholder { color: var(--text-secondary); font-weight: 400; }
.field-edit {
  width: 32px; height: 32px; border: none; background: var(--light-blue);
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.field-content p { font-size: 16px; font-weight: 600; }

/* Customer list */
.sub-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.sub-header h2 { font-size: 20px; font-weight: 700; }
.back-btn {
  width: 40px; height: 40px; border: none; background: none;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  border-radius: 10px;
}
.back-btn:active { background: var(--light-blue); }
html[dir="rtl"] .back-btn svg { transform: rotate(180deg); }
.search-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--white); border-radius: var(--radius-sm);
  padding: 12px 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.search-bar input {
  flex: 1; border: none; outline: none; font-size: 15px;
  color: var(--text); background: transparent; font-family: inherit;
}
.search-bar input::placeholder { color: var(--text-secondary); }
.customer-list { display: flex; flex-direction: column; gap: 8px; }
.customer-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--white); border-radius: var(--radius-sm); padding: 14px 16px;
  box-shadow: var(--shadow); cursor: pointer;
}
.customer-row:active { background: var(--light-blue); }
.customer-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--light-blue);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.customer-info { flex: 1; min-width: 0; }
.customer-info .name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.customer-info .phone { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.customer-arrow {
  flex-shrink: 0; color: var(--text-secondary);
}
html[dir="rtl"] .customer-arrow svg { transform: rotate(180deg); }
.empty-state {
  text-align: center; padding: 48px 24px; color: var(--text-secondary);
}
.empty-state svg { margin-bottom: 12px; }

/* Settings */
.settings-container { max-width: 400px; margin: 0 auto; }
.settings-preview-card {
  background: var(--white); border-radius: var(--radius); padding: 24px;
  text-align: center; box-shadow: var(--shadow); margin-bottom: 20px;
  border: 1px solid var(--border);
}
.settings-preview-card .settings-logo { margin: 0 auto 12px; }
.settings-preview-card .settings-logo img {
  width: 60px; height: 60px; border-radius: 12px; object-fit: cover;
}
.settings-preview-card h3 { font-size: 18px; font-weight: 700; }
.settings-preview-card p { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.settings-group {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; margin-bottom: 20px;
}
.settings-item {
  display: flex; align-items: center; gap: 12px;
  padding: 16px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.settings-item:last-child { border-bottom: none; }
.settings-item:active { background: var(--light-blue); }
.settings-item-icon {
  width: 40px; height: 40px; border-radius: 10px; background: var(--light-blue);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.settings-item-text { flex: 1; }
.settings-item-text span { font-size: 15px; font-weight: 600; display: block; }
.settings-item-text small { font-size: 13px; color: var(--text-secondary); }
.logout-btn { color: var(--primary); border-color: var(--primary); }

/* Modals */
.modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.4); display: flex;
  align-items: flex-end; justify-content: center;
  animation: fadeIn 0.2s;
}
.modal.hidden { display: none !important; }
.modal-content {
  background: var(--white); border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  padding: 24px; padding-bottom: calc(24px + var(--safe-bottom));
  animation: slideUp 0.3s;
}
.modal-sm .modal-body { padding: 0; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close {
  width: 36px; height: 36px; border: none; background: var(--light-blue);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(100%); } }

/* Store info modal */
.store-info-logo { text-align: center; margin-bottom: 12px; }
.store-info-logo img { width: 80px; height: 80px; border-radius: 16px; object-fit: cover; }
.store-info-name { text-align: center; font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.store-info-sub { text-align: center; font-size: 14px; color: var(--text-secondary); margin-bottom: 20px; }
.form-group { margin-bottom: 16px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; display: block; }
.form-group input {
  width: 100%; padding: 12px 16px; border: 2px solid var(--border);
  border-radius: var(--radius-xs); font-size: 15px; color: var(--text);
  font-family: inherit; outline: none; transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--primary); }
.upload-btn { font-size: 14px !important; padding: 10px 16px !important; }

/* Language options */
.lang-option {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 16px; border: none; background: none;
  font-size: 16px; font-family: inherit; color: var(--text); cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.lang-option:last-child { border-bottom: none; }
.lang-option:active { background: var(--light-blue); }
.lang-check { color: var(--primary); font-weight: 700; font-size: 20px; }

/* About */
.about-body { text-align: center; }
.about-body h3 { font-size: 18px; font-weight: 700; margin: 12px 0 4px; }
.about-body p { font-size: 14px; color: var(--text-secondary); margin-bottom: 4px; }
.about-version { font-weight: 600; color: var(--primary) !important; margin: 8px 0 12px !important; }
.about-desc { line-height: 1.6 !important; padding: 0 8px; }
.help-contact { font-weight: 600; color: var(--text) !important; margin-top: 8px !important; }

/* Toast */
.toast {
  position: fixed; bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  left: 50%; transform: translateX(-50%);
  background: var(--text); color: white; padding: 12px 24px;
  border-radius: var(--radius-sm); font-size: 14px; font-weight: 500;
  z-index: 300; animation: fadeIn 0.3s;
  white-space: nowrap; max-width: 90%;
}

/* Bottom Nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--white);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  z-index: 100;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: none; border: none; color: var(--text-secondary);
  font-size: 11px; font-weight: 500; cursor: pointer; padding: 8px 16px;
  font-family: inherit; transition: color 0.2s;
}
.nav-item.active { color: var(--primary); }
.nav-item.active svg { stroke: var(--primary); }

/* Confetti */
.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti-piece {
  position: absolute; width: 8px; height: 8px; border-radius: 2px;
  animation: confettiFall 1s ease-out forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(60px) rotate(360deg); opacity: 0; }
}

/* Export */
.export-btn {
  width: 40px; height: 40px; border: none; background: var(--light-blue);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.export-btn:active { background: var(--border); }
.export-menu {
  background: var(--white); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  margin-bottom: 12px; overflow: hidden; animation: fadeIn 0.2s;
}
.export-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 14px 16px; border: none; background: none; font-size: 15px;
  font-weight: 500; color: var(--text); cursor: pointer; font-family: inherit;
  border-bottom: 1px solid var(--border);
}
.export-menu button:last-child { border-bottom: none; }
.export-menu button:active { background: var(--light-blue); }

/* RTL */
html[dir="rtl"] .header-left { flex-direction: row-reverse; }
html[dir="rtl"] .sub-header { flex-direction: row-reverse; }
html[dir="rtl"] .settings-item { flex-direction: row-reverse; }
html[dir="rtl"] .customers-card { flex-direction: row-reverse; }
html[dir="rtl"] .customer-row { flex-direction: row-reverse; }
html[dir="rtl"] .result-field { flex-direction: row-reverse; }
html[dir="rtl"] .result-fields { text-align: right; }
html[dir="rtl"] .field-input-row { flex-direction: row-reverse; }
html[dir="rtl"] .search-bar { flex-direction: row-reverse; }
html[dir="rtl"] .settings-item svg:last-child { transform: rotate(180deg); }

/* Desktop / tablet */
@media (min-width: 768px) {
  .page-content { max-width: 480px; margin: 0 auto; }
  .bottom-nav { max-width: 480px; left: 50%; transform: translateX(-50%); border-radius: var(--radius) var(--radius) 0 0; }
  .app-header { max-width: 480px; margin: 0 auto; }
  .modal-content { border-radius: var(--radius); margin-bottom: 10vh; }
  .modal { align-items: center; }
}
