/* ══════════════════════════════════════════════════════
   Variables
══════════════════════════════════════════════════════ */
:root {
  --pr:    #0891B2;
  --pr-h:  #0E7490;
  --pr-l:  #E0F7FA;
  --pr-d:  #164E63;
  --ac:    #F472B6;
  --ok:    #16A34A;
  --ok-l:  #DCFCE7;
  --wn:    #D97706;
  --wn-l:  #FEF3C7;
  --er:    #DC2626;
  --er-l:  #FEE2E2;
  --bg:    #F0FBFC;
  --sf:    #FFFFFF;
  --bd:    #CFF3F7;
  --tx:    #0F2A33;
  --mx:    #4B7480;
  --lx:    #94C6CE;
  --sh:    0 1px 3px rgba(8,145,178,.08);
  --sh2:   0 4px 16px rgba(8,145,178,.12);
  --sh3:   0 14px 44px rgba(8,145,178,.16);
  --r:     14px;
  --r2:    10px;
  --r3:    22px;
  --bottom-nav-h: 62px;
}

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

body {
  font-family: 'Cairo', sans-serif;
  background: var(--bg);
  min-height: 100vh;
  direction: rtl;
  color: var(--tx);
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ══════════════════════════════════════════════════════
   Login Page
══════════════════════════════════════════════════════ */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
  background: radial-gradient(ellipse at 30% 0%, var(--pr-l) 0%, var(--bg) 60%);
}
.login-wrap { width: 100%; max-width: 380px; }
.login-card {
  background: var(--sf);
  border-radius: var(--r3);
  border: 1.5px solid var(--bd);
  box-shadow: var(--sh3);
  padding: 36px 28px;
  text-align: center;
}
.login-logo {
  width: 70px; height: 70px; font-size: 34px;
  background: linear-gradient(135deg, var(--pr-d), var(--pr));
  border-radius: 20px; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; margin-bottom: 16px;
  box-shadow: 0 8px 28px rgba(8,145,178,.35);
}
.login-card h1 { font-size: 20px; font-weight: 900; color: var(--pr-d); margin-bottom: 4px; }
.login-sub { font-size: 13px; color: var(--mx); margin-bottom: 22px; }
.login-error {
  background: var(--er-l); color: var(--er); border-right: 3px solid var(--er);
  border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px; text-align: right;
}
.login-form { display: flex; flex-direction: column; gap: 12px; }

/* ══════════════════════════════════════════════════════
   Inputs & Buttons
══════════════════════════════════════════════════════ */
.inp-wrap { position: relative; }
.inp-icon { position: absolute; right: 13px; top: 50%; transform: translateY(-50%); font-size: 17px; pointer-events: none; }
.inp-field {
  width: 100%; padding: 13px 44px 13px 14px;
  border: 2px solid var(--bd); border-radius: var(--r2);
  font-family: 'Cairo', sans-serif; font-size: 14.5px; color: var(--tx); background: var(--sf);
  transition: border-color .2s, box-shadow .2s;
}
.inp-field:focus { outline: none; border-color: var(--pr); box-shadow: 0 0 0 4px rgba(8,145,178,.12); }

.btn-primary {
  padding: 12px 20px; background: linear-gradient(135deg, var(--pr), var(--pr-h));
  color: #fff; border: none; border-radius: var(--r2); cursor: pointer;
  font-weight: 700; font-size: 14px;
  box-shadow: 0 4px 14px rgba(8,145,178,.3); transition: all .2s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 7px 22px rgba(8,145,178,.4); }
.btn-primary:disabled { opacity: .65; cursor: wait; transform: none; }
.btn-block { width: 100%; }

.btn-secondary {
  padding: 11px 18px; background: var(--sf); color: var(--pr-d);
  border: 1.5px solid var(--bd); border-radius: var(--r2); cursor: pointer;
  font-weight: 700; font-size: 13.5px; transition: all .2s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-secondary:hover { background: var(--pr-l); border-color: var(--pr); }

.btn-danger { background: var(--er-l); color: var(--er); border: 1.5px solid #FECACA; }
.btn-danger:hover { background: var(--er); color: #fff; }

.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff;
  border-radius: 50%; animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════════
   App Layout — Topbar (desktop) + Bottom Nav (mobile)
══════════════════════════════════════════════════════ */
.app-body { padding-bottom: calc(var(--bottom-nav-h) + 16px); min-height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px; background: var(--sf); border-bottom: 1.5px solid var(--bd);
  position: sticky; top: 0; z-index: 100; box-shadow: var(--sh);
}
.topbar-brand { display: flex; align-items: center; gap: 9px; }
.topbar-logo { font-size: 22px; }
.topbar-title { font-size: 16px; font-weight: 900; color: var(--pr-d); }
.topbar-nav { display: flex; gap: 6px; }
.topbar-nav a {
  padding: 8px 16px; border-radius: 20px; font-size: 13.5px; font-weight: 700;
  color: var(--mx); transition: all .2s;
}
.topbar-nav a:hover { background: var(--pr-l); color: var(--pr-d); }
.topbar-nav a.active { background: var(--pr); color: #fff; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--mx); font-weight: 600; }
.btn-logout {
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--er-l); transition: all .2s;
}
.btn-logout:hover { background: var(--er); }

.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--sf); border-top: 1.5px solid var(--bd);
  box-shadow: 0 -4px 20px rgba(8,145,178,.1);
  height: var(--bottom-nav-h);
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--mx); font-size: 10.5px; font-weight: 700; transition: color .2s;
}
.bottom-nav a.active { color: var(--pr); }
.bn-icon { font-size: 19px; }

@media (max-width: 760px) {
  .topbar-nav { display: none; }
  .bottom-nav { display: flex; }
}

.page-wrap { max-width: 960px; margin: 0 auto; padding: 20px 18px 8px; }

/* ══════════════════════════════════════════════════════
   Scan Page
══════════════════════════════════════════════════════ */
.scan-card {
  background: var(--sf); border-radius: var(--r3); border: 1.5px solid var(--bd);
  box-shadow: var(--sh3); padding: 26px 22px; text-align: center; margin-bottom: 18px;
}
.scan-icon { font-size: 54px; margin-bottom: 10px; }
.scan-card h2 { font-size: 18px; font-weight: 900; color: var(--pr-d); margin-bottom: 5px; }
.scan-card p { font-size: 13px; color: var(--mx); margin-bottom: 18px; }

.manual-row { display: flex; gap: 8px; margin-top: 14px; }
.manual-row .inp-field { direction: ltr; text-align: center; letter-spacing: .04em; }

#scanner-wrap {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(5,15,20,.93); display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 16px;
}
.scanner-box {
  width: 100%; max-width: 420px; background: #111; border-radius: 18px;
  overflow: hidden; border: 2px solid var(--pr); box-shadow: 0 0 60px rgba(8,145,178,.4);
}
.scanner-bar {
  display: flex; align-items: center; justify-content: space-between; padding: 11px 16px;
  background: linear-gradient(90deg, var(--pr-d), var(--pr)); color: #fff;
}
.scanner-bar span { font-size: 14px; font-weight: 700; }
.btn-stop-cam {
  background: rgba(255,255,255,.2); border: none; color: #fff; padding: 5px 14px;
  border-radius: 7px; cursor: pointer; font-family: 'Cairo', sans-serif; font-size: 13px; font-weight: 700;
}
.btn-stop-cam:hover { background: rgba(255,255,255,.35); }
.scanner-tip { text-align: center; padding: 8px 12px; font-size: 12px; color: rgba(255,255,255,.65); background: rgba(0,0,0,.6); }

.scanner-controls {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: rgba(0,0,0,.75);
}
.btn-torch {
  background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.3); color: #fff;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-family: 'Cairo', sans-serif;
  font-size: 12.5px; font-weight: 700; white-space: nowrap; flex-shrink: 0;
}
.btn-torch.on { background: var(--wn); border-color: var(--wn); }
.zoom-row { display: flex; align-items: center; gap: 8px; flex: 1; color: #fff; font-size: 14px; }
.zoom-row input[type="range"] { flex: 1; accent-color: var(--pr); }

/* Recent scans list */
.recent-list { display: flex; flex-direction: column; gap: 8px; }
.recent-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--sf); border: 1px solid var(--bd); border-radius: var(--r2); padding: 11px 14px;
}
.recent-item .ri-name { font-size: 13.5px; font-weight: 700; color: var(--tx); }
.recent-item .ri-meta { font-size: 11.5px; color: var(--mx); margin-top: 2px; }
.recent-item .ri-qty { font-size: 15px; font-weight: 900; color: var(--ok); white-space: nowrap; }

/* ══════════════════════════════════════════════════════
   Modal
══════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,42,51,.55); z-index: 500;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal-box {
  width: 100%; max-width: 400px; background: var(--sf); border-radius: 20px 20px 0 0;
  padding: 16px 16px 18px; box-shadow: 0 -10px 40px rgba(0,0,0,.2);
  animation: modalUp .25s ease;
  max-height: 88vh; overflow-y: auto;
}
@keyframes modalUp { from { transform: translateY(30px); opacity:0 } to { transform: none; opacity:1 } }
@media (min-width: 560px) {
  .modal-overlay { align-items: center; }
  .modal-box { border-radius: 20px; }
}
.modal-hd { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-hd h3 { font-size: 15px; font-weight: 900; color: var(--pr-d); }
.modal-close { font-size: 20px; color: var(--mx); cursor: pointer; padding: 4px; line-height: 1; }

.item-preview {
  background: var(--pr-l); border-radius: var(--r2); padding: 10px 14px; margin-bottom: 12px;
}
.item-preview .ip-name { font-size: 14.5px; font-weight: 800; color: var(--pr-d); margin-bottom: 3px; }
.item-preview .ip-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--mx); margin-top: 2px; }
.item-preview .ip-row b { color: var(--tx); font-weight: 700; }

.qty-control {
  display: grid; grid-template-columns: 42px 1fr 42px; align-items: stretch;
  gap: 8px; margin-bottom: 12px;
}
.qty-btn {
  width: 100%; height: 42px; min-width: 0; border-radius: 10px; border: 1.5px solid var(--bd);
  background: var(--sf); font-size: 18px; font-weight: 900; color: var(--pr); cursor: pointer;
  display: flex; align-items: center; justify-content: center; -webkit-appearance: none;
}
.qty-btn:hover { background: var(--pr-l); }
.qty-input {
  width: 100%; min-width: 0; text-align: center; font-size: 19px; font-weight: 900; padding: 8px;
  border: 2px solid var(--bd); border-radius: var(--r2); color: var(--tx);
}
.qty-input:focus { outline: none; border-color: var(--pr); }

@media (max-width: 400px) {
  .modal-box { padding: 14px 12px 16px; max-width: 100%; }
  .qty-control { grid-template-columns: 38px 1fr 38px; gap: 6px; }
  .qty-btn { height: 38px; font-size: 16px; }
  .qty-input { font-size: 17px; padding: 6px; }
}

.modal-msg { font-size: 13px; text-align: center; padding: 8px; border-radius: 8px; margin-bottom: 10px; display:none; }
.modal-msg.show { display: block; }
.modal-msg.error { background: var(--er-l); color: var(--er); }
.modal-msg.ok { background: var(--ok-l); color: var(--ok); }

/* ══════════════════════════════════════════════════════
   Toast
══════════════════════════════════════════════════════ */
#toast {
  position: fixed; bottom: calc(var(--bottom-nav-h) + 18px); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--tx); color: #fff; padding: 12px 22px; border-radius: 30px;
  font-size: 13.5px; font-weight: 700; box-shadow: var(--sh3); z-index: 2000;
  opacity: 0; pointer-events: none; transition: all .3s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.ok { background: var(--ok); }
#toast.error { background: var(--er); }

/* ══════════════════════════════════════════════════════
   Dashboard
══════════════════════════════════════════════════════ */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.stat-card {
  background: var(--sf); border: 1.5px solid var(--bd); border-radius: var(--r2);
  padding: 14px 12px; text-align: center;
}
.stat-card .sv { font-size: 20px; font-weight: 900; color: var(--pr-d); }
.stat-card .sl { font-size: 11px; color: var(--mx); margin-top: 3px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .inp-wrap { flex: 1; min-width: 180px; }

.table-wrap {
  background: var(--sf); border: 1.5px solid var(--bd); border-radius: var(--r); overflow: hidden;
  box-shadow: var(--sh);
}
table.stock-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stock-table thead th {
  background: var(--pr-l); color: var(--pr-d); font-weight: 800; font-size: 12px;
  padding: 11px 10px; text-align: right; white-space: nowrap;
}
.stock-table tbody td { padding: 10px; border-top: 1px solid var(--bd); vertical-align: middle; }
.stock-table tbody tr:hover { background: var(--bg); }
.stock-table .qty-edit {
  width: 80px; padding: 6px 8px; border: 1.5px solid var(--bd); border-radius: 7px;
  text-align: center; font-weight: 700; font-family: inherit;
}
.stock-table .qty-edit:focus { outline: none; border-color: var(--pr); }
.stock-table .td-actions { display: flex; gap: 6px; white-space: nowrap; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--bd);
  background: var(--sf); cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px;
}
.icon-btn.save { color: var(--ok); border-color: #BBF7D0; }
.icon-btn.save:hover { background: var(--ok-l); }
.icon-btn.del { color: var(--er); border-color: #FECACA; }
.icon-btn.del:hover { background: var(--er-l); }

.empty-row td { text-align: center; padding: 40px 10px; color: var(--mx); font-size: 13px; }

@media (max-width: 640px) {
  .stats-row { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .stat-card { padding: 10px 6px; }
  .stat-card .sv { font-size: 16px; }
  .stat-card .sl { font-size: 9.5px; }
  .table-wrap { overflow-x: auto; }
  table.stock-table { min-width: 640px; }
}
