*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --teal-50: #E1F5EE;
  --teal-100: #9FE1CB;
  --teal-400: #1D9E75;
  --teal-600: #0F6E56;
  --coral-50: #FAECE7;
  --coral-400: #D85A30;
  --coral-600: #993C1D;
  --amber-50: #FAEEDA;
  --amber-400: #BA7517;
  --green-50: #EAF3DE;
  --green-400: #639922;
  --gray-50: #F1EFE8;
  --gray-100: #D3D1C7;
  --gray-200: #B4B2A9;
  --gray-400: #888780;
  --gray-600: #5F5E5A;
  --gray-900: #2C2C2A;
  --bg: #F7F5F0;
  --surface: #FFFFFF;
  --border: rgba(44,44,42,0.12);
  --border-strong: rgba(44,44,42,0.25);
  --text-primary: #2C2C2A;
  --text-secondary: #5F5E5A;
  --text-muted: #888780;
  --sidebar-w: 220px;
  --radius: 10px;
  --radius-lg: 14px;
}

body {
  font-family: 'Noto Sans Arabic', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  direction: rtl;
}

.hidden { display: none !important; }

html.has-session #loginScreen { display: none !important; }
html.has-session #appShell.hidden { display: flex !important; }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--gray-900);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 100;
}
.main {
  margin-right: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.content { padding: 24px; flex: 1; }

.logo { padding: 20px 20px 16px; border-bottom: 0.5px solid rgba(255,255,255,0.08); flex-shrink: 0; }
.logo-mark { font-size: 22px; font-weight: 700; color: var(--teal-100); }
.logo-sub { font-size: 11px; color: rgba(255,255,255,0.35); margin-top: 2px; }

.nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-section-label {
  font-size: 10px;
  color: rgba(255,255,255,0.3);
  padding: 12px 20px 4px;
  letter-spacing: 0.5px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  transition: all 0.15s;
  border-right: 3px solid transparent;
  font-size: 13.5px;
  text-decoration: none;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,0.05); }
.nav-item.active {
  color: #fff;
  background: rgba(29,158,117,0.2);
  border-right-color: var(--teal-400);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 0.5px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.sidebar-logout {
  width: 100%;
  margin-top: 12px;
  justify-content: center;
  font-size: 12px;
  padding: 8px;
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.15);
  color: #fff;
}
.sidebar-logout:hover {
  background: rgba(216,90,48,0.25);
  border-color: var(--coral-400);
  color: #fff;
}
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--teal-600);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: #fff;
}
.user-name { font-size: 13px; color: #fff; }
.user-role { font-size: 11px; color: rgba(255,255,255,0.4); }

.shift-badge {
  display: flex; align-items: center; gap: 8px;
  background: var(--teal-50);
  border: 0.5px solid var(--teal-100);
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 13px;
  color: var(--teal-600);
  font-weight: 500;
}
.shift-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--teal-400);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }
.page-title { font-size: 15px; font-weight: 600; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar-user {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.topbar-logout {
  white-space: nowrap;
}

/* Cards & tables */
.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.card-title { font-size: 14px; font-weight: 600; }

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: right;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 0.5px solid var(--border);
  white-space: nowrap;
}
.tbl td {
  padding: 8px 10px;
  border-bottom: 0.5px solid var(--border);
  vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: var(--gray-50); }
.tbl tr.row-active td { background: var(--teal-50); }
.tbl tr.row-done td { opacity: 0.85; }

.num { direction: ltr; display: inline-block; font-variant-numeric: tabular-nums; }

/* Forms */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  border: 0.5px solid var(--border-strong);
  background: none;
  color: var(--text-primary);
}
.btn:hover { background: var(--gray-50); }
.btn-primary {
  background: var(--teal-400);
  color: #fff;
  border-color: var(--teal-400);
}
.btn-primary:hover { background: var(--teal-600); border-color: var(--teal-600); }
.btn-danger { background: var(--coral-400); color: #fff; border-color: var(--coral-400); }
.btn-sm { font-size: 12px; padding: 5px 10px; }

.form-input, .form-select, .cell-input {
  padding: 7px 10px;
  border: 0.5px solid var(--border-strong);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text-primary);
  outline: none;
  width: 100%;
}
.form-input:focus, .form-select:focus, .cell-input:focus {
  border-color: var(--teal-400);
  box-shadow: 0 0 0 2px rgba(29,158,117,0.15);
}
.cell-input { min-width: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }

.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: var(--green-50); color: var(--green-400); }
.badge-warning { background: var(--amber-50); color: var(--amber-400); }
.badge-danger { background: var(--coral-50); color: var(--coral-600); }
.badge-info { background: var(--teal-50); color: var(--teal-600); }
.badge-gray { background: var(--gray-50); color: var(--gray-600); }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 400px;
  max-width: 100%;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo-mark { font-size: 36px; font-weight: 700; color: var(--teal-400); }
.login-logo-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.login-title { font-size: 17px; font-weight: 600; margin-bottom: 20px; }
.login-field { margin-bottom: 14px; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1.5px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.sub-tabs { margin-bottom: 16px; }
.panel-desc {
  padding: 0 16px 12px;
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}
.tab {
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1.5px;
  background: none;
  border-top: none; border-left: none; border-right: none;
  font-family: inherit;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--teal-600); border-bottom-color: var(--teal-400); }

/* KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}
.kpi-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.kpi-value { font-size: 28px; font-weight: 700; line-height: 1; }

/* Staff screen */
.staff-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.staff-hint {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
}
.staff-hint kbd {
  background: var(--gray-50);
  border: 0.5px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 11px;
}
.staff-section { margin-bottom: 16px; }
.staff-table-wrap { overflow-x: auto; }
.staff-section .card-header { padding: 14px 16px; }
.staff-saved-footer {
  padding: 12px 16px;
  border-top: 0.5px solid var(--border);
  text-align: center;
}
.staff-show-more {
  width: 100%;
  justify-content: center;
  color: var(--teal-600);
  border-color: var(--teal-100);
  background: var(--teal-50);
}
.staff-show-more:hover { background: var(--teal-100); }
.staff-active-section { border: 1.5px solid var(--teal-100); }
.staff-saved-section { margin-top: 0; }
.staff-table { table-layout: auto; width: 100%; }
.staff-table td { padding: 10px 8px; vertical-align: middle; }
.staff-table tr.row-active td,
.staff-table tr.row-done td { background: var(--teal-50); opacity: 1; }
.staff-table tr.row-active:hover td,
.staff-table tr.row-done:hover td { background: var(--teal-50); }
.staff-table tr.row-active .cell-input,
.staff-table tr.row-active .form-select,
.staff-table tr.row-active .outcome-picker-trigger {
  background: var(--surface);
}
.staff-table .cell-display {
  background: var(--surface);
  border: 0.5px solid var(--border-strong);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  min-height: 34px;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  width: 100%;
  line-height: 1.4;
}
.staff-table .cell-display.num { direction: ltr; justify-content: flex-start; }
.staff-table .cell-display .badge { flex-shrink: 0; }
.staff-table .col-num { width: 90px; white-space: nowrap; text-align: right; vertical-align: middle; }
.visitor-id-cell { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 2px; line-height: 1.3; }
.staff-table th.col-num { text-align: right; }
.visitor-id-num { font-size: 13px; }
.visitor-id-time { font-size: 11px; color: var(--text-muted); font-weight: 400; }
.staff-table .col-name { width: 14%; min-width: 120px; }
.staff-table .col-phone { width: 12%; min-width: 110px; }
.staff-table .col-outcome { width: 20%; min-width: 170px; position: relative; }
.staff-table-wrap:has(.outcome-picker.is-open) { overflow: visible; }

.outcome-picker { position: relative; width: 100%; outline: none; }
.outcome-picker-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border: 0.5px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary);
  cursor: pointer;
  text-align: right;
  box-sizing: border-box;
}
.outcome-picker-label { flex: 1; line-height: 1.4; }
.outcome-picker-label.placeholder { color: var(--text-muted); }
.outcome-picker-arrow { color: var(--text-muted); font-size: 11px; flex-shrink: 0; }
.outcome-picker:focus-within .outcome-picker-trigger {
  border-color: var(--teal-400);
  box-shadow: 0 0 0 2px rgba(29,158,117,0.15);
}
.outcome-picker-list {
  display: none;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: var(--surface);
  border: 0.5px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  max-height: min(360px, 70vh);
  overflow-y: auto;
}
.outcome-picker-option {
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.45;
  white-space: normal;
}
.outcome-picker-option:hover,
.outcome-picker-option.is-active { background: var(--teal-50); }
.outcome-picker-option.selected { font-weight: 600; color: var(--teal-600); }

.products-import-desc {
  padding: 0 16px 12px;
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}
.products-import-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  padding: 0 16px 12px;
}
.products-import-row .form-group { flex: 1; min-width: 180px; margin: 0; }
.products-import-hint {
  padding: 0 16px 16px;
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.staff-table .col-unavailable { width: 16%; min-width: 180px; }

.item-picker {
  position: relative;
  width: 100%;
  min-height: 34px;
  padding: 4px 6px;
  border: 0.5px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  box-sizing: border-box;
}
.staff-table tr.row-active .item-picker { background: var(--surface); }
.item-picker:focus-within {
  border-color: var(--teal-400);
  box-shadow: 0 0 0 2px rgba(29,158,117,0.15);
}
.item-picker-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
}
.item-picker-tags:empty { margin-bottom: 0; }
.item-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--teal-50);
  color: var(--teal-600);
  font-size: 11px;
  line-height: 1.3;
}
.item-tag-new {
  background: var(--amber-50);
  color: var(--amber-400);
}
.item-tag-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}
.item-tag-remove {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
  opacity: 0.7;
}
.item-tag-remove:hover { opacity: 1; }
.item-tag-readonly {
  display: inline-block;
  padding: 2px 7px;
  margin: 1px 2px;
  border-radius: 6px;
  background: var(--teal-50);
  color: var(--teal-600);
  font-size: 11px;
}
.item-tag-readonly.item-tag-new {
  background: var(--amber-50);
  color: var(--amber-400);
}
.item-picker-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: 13px;
  font-family: inherit;
  padding: 2px 4px;
  box-sizing: border-box;
}
.item-picker-list {
  display: none;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: var(--surface);
  border: 0.5px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  max-height: min(240px, 50vh);
  overflow-y: auto;
}
.item-picker-option {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
}
.item-picker-option:hover,
.item-picker-option.is-active { background: var(--teal-50); }
.item-picker-option-new {
  color: var(--amber-400);
  font-weight: 500;
  border-top: 0.5px solid var(--border);
}
.item-picker-option-hint {
  color: var(--coral-600);
  font-size: 12px;
  cursor: default;
  pointer-events: none;
}
.item-picker-sku {
  font-size: 11px;
  color: var(--text-muted);
  margin-right: 6px;
}
.staff-table-wrap:has(.item-picker.is-open) { overflow: visible; }

.staff-table .col-other-desc { width: 12%; min-width: 110px; }
.staff-table .col-notes { width: auto; min-width: 100px; }
.staff-table .col-save { width: 70px; white-space: nowrap; }
.staff-table .cell-input,
.staff-table .form-select { max-width: 100%; box-sizing: border-box; }
.staff-table .muted-cell { color: var(--text-muted); }

.new-visitor-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--teal-50);
  border: 1.5px dashed var(--teal-100);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  cursor: pointer;
  transition: all 0.15s;
}
.new-visitor-bar:hover, .new-visitor-bar:focus {
  background: #d4f0e6;
  outline: none;
}
.new-visitor-bar .plus {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--teal-400);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  font-weight: 300;
  flex-shrink: 0;
}
.new-visitor-label { font-weight: 600; color: var(--teal-600); }
.new-visitor-sub { font-size: 12px; color: var(--text-muted); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(44,44,42,0.5);
  display: none; align-items: center; justify-content: center;
  z-index: 200;
  padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 440px;
  max-width: 100%;
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.modal-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--gray-900);
  color: #fff;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  transition: transform 0.3s;
  z-index: 999;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

.empty-state { text-align: center; padding: 40px; color: var(--text-muted); font-size: 13px; }

.inline-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
  padding: 16px;
  background: var(--gray-50);
  border-radius: var(--radius);
}
.inline-form .form-group { flex: 1; min-width: 140px; }

.req { color: var(--coral-400); font-weight: 600; }

.field-hint {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 6px 0 0;
  opacity: 0.85;
  transition: color 0.15s, opacity 0.15s;
}
.field-hint-warn { color: var(--amber-400); font-weight: 500; }
.field-hint.is-active { opacity: 1; color: var(--amber-400); }
.field-hint.field-hint-error { color: var(--coral-600); font-weight: 600; }

.email-confirm-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.35);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-secondary);
}
.email-confirm-check input { margin-top: 3px; flex-shrink: 0; accent-color: var(--green-500); }
.user-form-full { grid-column: 1 / -1; }
.badge-sm { font-size: 0.72rem; padding: 2px 8px; margin-top: 4px; display: inline-block; }
.badge-success { background: rgba(34, 197, 94, 0.15); color: var(--green-600); }

.verify-email-panel {
  margin-top: 14px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  text-align: center;
}
.verify-email-panel.hidden { display: none; }
.verify-email-title { font-weight: 700; color: var(--coral-600); margin-bottom: 6px; }
.verify-email-text { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.verify-email-note { font-size: 12px; color: var(--text-muted); margin-top: 8px; line-height: 1.5; }
.settings-form .form-group { margin-bottom: 14px; }
.form-input.input-invalid {
  border-color: var(--coral-400);
  box-shadow: 0 0 0 2px rgba(216, 90, 48, 0.12);
}

.user-form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px 16px;
  padding: 16px;
}
.user-form-grid .user-form-actions { align-self: end; }
.modal-form-grid { padding: 0; margin-bottom: 16px; }

.users-table-wrap { overflow-x: auto; }
.users-table { table-layout: fixed; width: 100%; }
.users-table th,
.users-table td { vertical-align: middle; padding: 10px 12px; }
.users-table .user-email { font-size: 13px; color: var(--teal-600); word-break: break-all; }
.users-table .user-phone { font-size: 13px; }
.users-table .col-actions { width: 140px; white-space: nowrap; text-align: center; }
.users-table .col-actions .btn { margin: 0 2px; }

.sidebar-footer .sidebar-logout { width: 100%; margin-top: 6px; }
.sidebar-footer .sidebar-logout:first-of-type { margin-top: 10px; background: var(--surface); color: var(--text-secondary); border: 0.5px solid var(--border); }
.modal-wide { max-width: 640px; width: 100%; }

@media (max-width: 900px) {
  .user-form-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .user-form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-right: 0; }
  .form-row { grid-template-columns: 1fr; }
}
