/* ── Basira QR · style.css ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Noto+Sans+Arabic:wght@400;500;700&display=swap');

/* ── CSS Variables ── */
:root {
  --color-primary: #6366F1;
  --color-primary-dark: #4F46E5;
  --color-primary-light: #818CF8;
  --color-accent: #8B5CF6;
  --color-success: #10B981;
  --color-warning: #F59E0B;
  --color-danger:  #EF4444;
  --color-info:    #3B82F6;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0,0,0,.12);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.2);
  --transition: .2s ease;
}

[data-theme="light"] {
  --bg:      #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-surf: #F1F5F9;
  --text:    #1E293B;
  --text-2:  #64748B;
  --text-3:  #94A3B8;
  --border:  #E2E8F0;
}
[data-theme="dark"] {
  --bg:      #0F172A;
  --bg-card: #1E293B;
  --bg-surf: #334155;
  --text:    #F1F5F9;
  --text-2:  #94A3B8;
  --text-3:  #64748B;
  --border:  #334155;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
body {
  font-family: 'Inter', 'Noto Sans Arabic', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
[dir="rtl"] { font-family: 'Noto Sans Arabic', 'Inter', sans-serif; }

/* ── App Shell ── */
#app { display: flex; flex-direction: column; height: 100dvh; width: 100%; max-width: 480px; margin: 0 auto; position: relative; overflow: hidden; }

/* ── Screens ── */
.screen { display: none; flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.screen.active { display: flex; flex-direction: column; }

/* ── Bottom Nav ── */
.bottom-nav {
  display: flex; align-items: center; background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 4px 0 max(8px, env(safe-area-inset-bottom));
  flex-shrink: 0; z-index: 10;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; cursor: pointer; padding: 8px 4px;
  color: var(--text-3); transition: color var(--transition);
  min-height: 56px; /* phone touch target */
}
.nav-btn .nav-icon { font-size: 24px; line-height: 1; }
.nav-btn .nav-label { font-size: 11px; font-weight: 600; letter-spacing: .3px; }
.nav-btn.active { color: var(--color-primary); }
.nav-btn.active .nav-icon { transform: translateY(-1px); }

/* ── Cards ── */
.card {
  background: var(--bg-card); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; color: var(--text); }

/* ── Setup Screen ── */
#screen-setup {
  justify-content: center; align-items: center; padding: 24px 20px;
  background: linear-gradient(160deg, var(--bg) 0%, var(--bg-surf) 100%);
}
.setup-logo { font-size: 72px; margin-bottom: 16px; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }
.setup-title { font-size: 26px; font-weight: 700; text-align: center; margin-bottom: 6px; color: var(--text); }
.setup-sub { font-size: 14px; color: var(--text-2); text-align: center; margin-bottom: 28px; }
.setup-card { width: 100%; max-width: 380px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; display: block; }
.input-wrap { display: flex; gap: 8px; margin-bottom: 16px; }
.form-input {
  flex: 1; padding: 12px 14px; border-radius: var(--radius-sm);
  border: 2px solid var(--border); background: var(--bg-surf);
  color: var(--text); font-size: 14px; outline: none; transition: border-color var(--transition);
}
.form-input:focus { border-color: var(--color-primary); }
.icon-btn {
  padding: 0 14px; border-radius: var(--radius-sm); border: 2px solid var(--border);
  background: var(--bg-surf); cursor: pointer; font-size: 18px; color: var(--text-2);
}
.btn-primary {
  width: 100%; padding: 14px; border-radius: var(--radius-sm); border: none;
  background: var(--color-primary); color: #fff; font-size: 15px; font-weight: 700;
  cursor: pointer; transition: transform var(--transition), background var(--transition);
}
.btn-primary:hover  { background: var(--color-primary-dark); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.setup-link { display: block; text-align: center; margin-top: 12px; font-size: 13px; color: var(--color-primary); text-decoration: none; }
.privacy-box { margin-top: 16px; padding: 12px; border-radius: var(--radius-sm); background: var(--bg-surf); }
.privacy-title { font-size: 12px; font-weight: 700; color: var(--text-2); margin-bottom: 4px; }
.privacy-text { font-size: 11px; color: var(--text-3); line-height: 1.5; }

/* ── Scanner Screen ── */
#screen-scanner { position: relative; background: #000; overflow: hidden; }
#scanner-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; pointer-events: none; }
.network-banner {
  background: rgba(245,158,11,.9); color: #000; font-size: 12px; font-weight: 600;
  text-align: center; padding: 6px 12px; backdrop-filter: blur(4px);
}
.scanner-top { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; }
.scan-frame {
  width: 240px; height: 240px; position: relative;
  animation: pulse-frame 2s ease-in-out infinite;
}
@keyframes pulse-frame { 0%,100%{opacity:1} 50%{opacity:.7} }
.corner {
  position: absolute; width: 32px; height: 32px; border-color: var(--color-primary);
  border-style: solid; border-width: 0;
}
.corner.tl { top:0;left:0;  border-top-width:4px; border-left-width:4px;  border-top-left-radius:6px; }
.corner.tr { top:0;right:0; border-top-width:4px; border-right-width:4px; border-top-right-radius:6px; }
.corner.bl { bottom:0;left:0;  border-bottom-width:4px; border-left-width:4px;  border-bottom-left-radius:6px; }
.corner.br { bottom:0;right:0; border-bottom-width:4px; border-right-width:4px; border-bottom-right-radius:6px; }
.scan-line {
  position: absolute; left: 4px; right: 4px; height: 3px;
  background: linear-gradient(90deg, transparent, var(--color-primary), transparent);
  border-radius: 2px; animation: scan 2s linear infinite;
}
@keyframes scan { 0%{top:4px;opacity:1} 90%{top:calc(100% - 4px);opacity:1} 100%{top:calc(100% - 4px);opacity:0} }
.scanner-settings-btn {
  position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; pointer-events: all;
  background: rgba(0,0,0,.55); border: none; border-radius: 50%;
  width: 52px; height: 52px; font-size: 24px; cursor: pointer;
  backdrop-filter: blur(4px); color: #fff; display: flex; align-items: center; justify-content: center;
}
[dir="rtl"] .scanner-settings-btn { right: auto; left: 12px; }
.scanner-bottom {
  padding: 20px; background: linear-gradient(to top, rgba(0,0,0,.8), transparent);
  pointer-events: all;
}
.scanner-status { color: #fff; font-size: 16px; font-weight: 700; text-align: center; text-shadow: 0 1px 4px rgba(0,0,0,.8); margin-bottom: 4px; }
.scanner-hint { color: rgba(255,255,255,.8); font-size: 13px; text-align: center; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.history-chip {
  position: absolute; bottom: 0; left: 0; pointer-events: all;
  background: rgba(0,0,0,.6); color: #fff; font-size: 11px; font-weight: 600;
  padding: 4px 10px; border-radius: 0 8px 0 0; backdrop-filter: blur(4px);
}
[dir="rtl"] .history-chip { left: auto; right: 0; border-radius: 8px 0 0 0; }
.camera-error {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; background: var(--bg); padding: 32px; gap: 16px;
}
.camera-error-icon { font-size: 56px; }
.camera-error h3 { font-size: 18px; font-weight: 700; text-align: center; color: var(--text); }
.camera-error p { font-size: 14px; color: var(--text-2); text-align: center; line-height: 1.5; }

/* Processing Overlay */
.processing-overlay {
  position: absolute; inset: 0; background: rgba(15,23,42,.85);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; backdrop-filter: blur(6px); z-index: 20;
}
.spinner {
  width: 52px; height: 52px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.2);
  border-top-color: var(--color-primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.processing-text { color: #fff; font-size: 16px; font-weight: 600; text-align: center; }
.processing-sub  { color: rgba(255,255,255,.6); font-size: 13px; text-align: center; }

/* ── Results Screen ── */
#screen-results { padding: 16px 16px 24px; }
.security-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: 999px; color: #fff;
  font-size: 16px; font-weight: 700; margin-bottom: 14px;
}
.result-title { font-size: 22px; font-weight: 700; margin-bottom: 6px; color: var(--text); }
.result-msg { font-size: 14px; color: var(--text-2); line-height: 1.6; margin-bottom: 4px; }
.result-action { font-size: 13px; color: var(--text-3); font-style: italic; line-height: 1.5; }
.info-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.info-row:last-child { border-bottom: none; }
.info-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.info-value { font-size: 13px; color: var(--text); font-family: monospace; text-align: end; max-width: 60%; word-break: break-all; }
.score-display { text-align: center; padding: 8px 0; }
.score-number { font-size: 40px; font-weight: 800; color: var(--text); line-height: 1; }
.score-label  { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.warning-bar { background: #fff3cd; border-left: 4px solid var(--color-warning); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; color: #856404; margin-bottom: 10px; }
[dir="rtl"] .warning-bar { border-left: none; border-right: 4px solid var(--color-warning); }
.details-toggle { display: flex; justify-content: space-between; align-items: center; cursor: pointer; padding: 4px 0; }
.vendor-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); }
.vendor-row:last-child { border-bottom: none; }
.vendor-name   { font-size: 13px; color: var(--text); flex: 1; }
.vendor-result { font-size: 12px; font-weight: 700; }
.vendor-result.detected { color: var(--color-danger); }
.vendor-result.clean    { color: var(--color-success); }
.action-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.btn-action {
  padding: 15px; border-radius: var(--radius-sm); border: none;
  font-size: 15px; font-weight: 700; cursor: pointer; text-align: center;
  transition: transform var(--transition); color: #fff;
}
.btn-action:active { transform: scale(.98); }
.btn-outline {
  padding: 13px; border-radius: var(--radius-sm); border: 2px solid var(--color-primary);
  background: transparent; color: var(--color-primary); font-size: 14px; font-weight: 700;
  cursor: pointer; transition: background var(--transition);
}
.btn-outline:hover { background: color-mix(in srgb, var(--color-primary) 10%, transparent); }
.btn-permalink {
  width: 100%; padding: 12px; border-radius: var(--radius-sm); border: none;
  background: var(--bg-surf); color: var(--color-primary); font-size: 13px; font-weight: 600;
  cursor: pointer; margin-top: 8px;
}

/* ── History Screen ── */
#screen-history { padding: 16px; }
.screen-header { font-size: 20px; font-weight: 700; color: var(--text); margin-bottom: 16px; padding: 4px 0; }
.history-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-card); border-radius: var(--radius); padding: 14px 16px;
  margin-bottom: 10px; cursor: pointer; box-shadow: var(--shadow);
  transition: transform var(--transition);
}
.history-card:active { transform: scale(.99); }
.history-icon { font-size: 28px; flex-shrink: 0; }
.history-info { flex: 1; min-width: 0; }
.history-domain { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.history-arrow { font-size: 20px; color: var(--text-3); }
[dir="rtl"] .history-arrow { transform: scaleX(-1); }
.empty-state { display: flex; flex-direction: column; align-items: center; padding: 60px 20px; gap: 12px; }
.empty-icon { font-size: 52px; }
.empty-state p { font-size: 14px; color: var(--text-3); text-align: center; }

/* ── Settings Screen ── */
#screen-settings { padding: 16px; }
.settings-section { margin-bottom: 20px; }
.settings-section-title { font-size: 13px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .8px; margin-bottom: 10px; padding: 0 4px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-card); padding: 14px 16px; border-radius: var(--radius-sm);
  margin-bottom: 2px; gap: 12px;
}
.setting-row:first-of-type { border-radius: var(--radius) var(--radius) var(--radius-sm) var(--radius-sm); }
.setting-row:last-of-type  { border-radius: var(--radius-sm) var(--radius-sm) var(--radius) var(--radius); margin-bottom: 0; }
.setting-label { font-size: 14px; font-weight: 600; color: var(--text); }
.setting-sub   { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.setting-value { font-size: 13px; color: var(--text-2); font-family: monospace; }

/* Toggle switch */
.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--border); border-radius: 999px; transition: background var(--transition);
}
.toggle-slider::before {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform var(--transition); box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle-slider { background: var(--color-primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* Mode buttons */
.mode-group, .lang-group { display: flex; gap: 6px; flex-wrap: wrap; }
.mode-btn, .lang-btn {
  padding: 7px 14px; border-radius: 999px; border: 2px solid var(--border);
  background: var(--bg-surf); color: var(--text-2); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all var(--transition);
}
.mode-btn.active, .lang-btn.active { border-color: var(--color-primary); background: var(--color-primary); color: #fff; }

/* Color swatches */
.scheme-swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.scheme-swatch {
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer; border: 3px solid transparent;
  transition: transform var(--transition), border-color var(--transition);
}
.scheme-swatch:hover { transform: scale(1.15); }
.scheme-swatch.active { border-color: var(--text); transform: scale(1.2); }

/* Settings buttons */
.btn-settings {
  padding: 10px 16px; border-radius: var(--radius-sm); border: none;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: background var(--transition);
}
.btn-settings.edit { background: var(--bg-surf); color: var(--color-primary); }
.btn-settings.danger { background: color-mix(in srgb, var(--color-danger) 15%, transparent); color: var(--color-danger); }
.settings-footer { text-align: center; padding: 20px 0 8px; color: var(--text-3); font-size: 12px; }

/* ── Change Key Modal ── */
.modal-sheet {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center; backdrop-filter: blur(4px);
}
.modal-content {
  background: var(--bg-card); border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px max(24px, env(safe-area-inset-bottom)); width: 100%; max-width: 480px;
  animation: slide-up .25s ease;
}
@keyframes slide-up { from { transform: translateY(100%); } }
.modal-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 20px; }
.modal-title { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.modal-sub { font-size: 13px; color: var(--text-2); margin-bottom: 16px; line-height: 1.5; }
.modal-link { display: block; font-size: 13px; color: var(--color-primary); margin-bottom: 16px; text-decoration: none; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn-primary { flex: 1; }
.btn-secondary { flex: 1; padding: 14px; border-radius: var(--radius-sm); border: 2px solid var(--border); background: transparent; color: var(--text-2); font-size: 15px; font-weight: 700; cursor: pointer; }

/* ── Confirm Modal ── */
#modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  backdrop-filter: blur(4px);
}
.modal-box { background: var(--bg-card); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 360px; box-shadow: var(--shadow-lg); animation: pop-in .2s ease; }
@keyframes pop-in { from { transform: scale(.9); opacity: 0; } }
.modal-box .modal-title { margin-bottom: 10px; }
.modal-box .modal-message { font-size: 14px; color: var(--text-2); line-height: 1.5; margin-bottom: 20px; white-space: pre-wrap; }
#modal-buttons { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.modal-btn { padding: 10px 18px; border-radius: var(--radius-sm); border: none; font-size: 14px; font-weight: 700; cursor: pointer; }
.modal-btn.primary   { background: var(--color-primary); color: #fff; }
.modal-btn.danger    { background: var(--color-danger); color: #fff; }
.modal-btn.secondary { background: var(--bg-surf); color: var(--text-2); }

/* ── Toast ── */
#toast-container { position: fixed; bottom: 80px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 999; pointer-events: none; }
.toast {
  padding: 12px 20px; border-radius: 999px; font-size: 14px; font-weight: 600;
  color: #fff; max-width: 340px; text-align: center; box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(10px); transition: all .3s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--color-success); }
.toast-error   { background: var(--color-danger); }
.toast-warning { background: var(--color-warning); }
.toast-info    { background: var(--color-primary); }

/* ── Utilities ── */
.hidden { display: none !important; }
.text-muted { color: var(--text-3); }
.url-text { font-family: monospace; font-size: 13px; word-break: break-all; color: var(--text); line-height: 1.4; }
.divider { height: 1px; background: var(--border); margin: 8px 0; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Desktop layout only ── */
@media (min-width: 520px) {
  #app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); box-shadow: var(--shadow-lg); }
  body { display: flex; justify-content: center; background: var(--bg-surf); }
}
/* ── Phone tweaks ── */
@media (max-width: 519px) {
  .setup-card { padding: 16px; }
  .card { padding: 16px; }
  .btn-primary, .btn-action { padding: 16px; font-size: 16px; }
  .result-title { font-size: 20px; }
  .scan-frame { width: 220px; height: 220px; }
}
