/* ============================================================
   Real Nutrition — Sales Excellence
   Mobile-first CSS
   Primary: green (#16a34a), Alert: red (#dc2626)
   Arabic font: Cairo | English font: Nunito Sans
   RTL default, LTR on [dir="ltr"]
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700&family=Nunito+Sans:wght@400;500;600;700&display=swap');

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Cairo', 'Nunito Sans', sans-serif;
    background-color: #f8fafc;
    color: #1e293b;
    min-height: 100vh;
    direction: rtl;
}

[dir="ltr"] body,
body[dir="ltr"] {
    font-family: 'Nunito Sans', 'Cairo', sans-serif;
    direction: ltr;
}

/* ── CSS Variables ────────────────────────────────────────── */
:root {
    --clr-primary:      #16a34a;
    --clr-primary-dk:   #15803d;
    --clr-primary-lt:   #dcfce7;
    --clr-danger:       #dc2626;
    --clr-danger-lt:    #fee2e2;
    --clr-warning:      #d97706;
    --clr-warning-lt:   #fef3c7;
    --clr-info:         #2563eb;
    --clr-info-lt:      #dbeafe;
    --clr-gray-50:      #f8fafc;
    --clr-gray-100:     #f1f5f9;
    --clr-gray-200:     #e2e8f0;
    --clr-gray-400:     #94a3b8;
    --clr-gray-600:     #475569;
    --clr-gray-800:     #1e293b;
    --clr-white:        #ffffff;
    --radius:           0.5rem;
    --radius-lg:        0.75rem;
    --shadow-sm:        0 1px 2px rgba(0,0,0,.06);
    --shadow:           0 2px 8px rgba(0,0,0,.1);
    --transition:       0.2s ease;
    --nav-height:       3.5rem;
}

/* ── Typography ───────────────────────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 600; }
p  { line-height: 1.6; }

/* ── Layout ───────────────────────────────────────────────── */
.app-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    padding: 1rem;
    padding-top: calc(var(--nav-height) + 1rem);
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

/* ── Navigation ───────────────────────────────────────────── */
.navbar {
    position: fixed;
    top: 0;
    inset-inline: 0;
    height: var(--nav-height);
    background: var(--clr-primary);
    color: var(--clr-white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 1000;
    box-shadow: var(--shadow);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--clr-white);
    font-weight: 700;
    font-size: 1rem;
}

.navbar-brand .logo-circle {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--clr-white);
    color: var(--clr-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: background var(--transition), opacity var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary   { background: var(--clr-primary); color: var(--clr-white); }
.btn-primary:hover:not(:disabled) { background: var(--clr-primary-dk); }

.btn-danger    { background: var(--clr-danger); color: var(--clr-white); }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--clr-primary);
    color: var(--clr-primary);
}
.btn-outline:hover:not(:disabled) { background: var(--clr-primary-lt); }

.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.8rem; }
.btn-block { width: 100%; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
    background: var(--clr-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--clr-gray-200);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.card-header {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--clr-gray-200);
    color: var(--clr-gray-800);
}

/* ── Dashboard Widgets ────────────────────────────────────── */
.widgets-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.widget {
    background: var(--clr-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--clr-gray-200);
    padding: 1rem;
    cursor: pointer;
    transition: box-shadow var(--transition);
    text-decoration: none;
    color: inherit;
    display: block;
}

.widget:hover { box-shadow: var(--shadow); }

.widget-label {
    font-size: 0.72rem;
    color: var(--clr-gray-600);
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.widget-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--clr-gray-800);
    line-height: 1;
    margin-bottom: 0.25rem;
}

.widget-delta {
    font-size: 0.75rem;
    font-weight: 600;
}

.widget-delta.up   { color: var(--clr-primary); }
.widget-delta.down { color: var(--clr-danger); }
.widget-delta.same { color: var(--clr-gray-400); }

.widget--alert { border-color: var(--clr-danger-lt); }
.widget--alert .widget-value { color: var(--clr-danger); }

/* ── Forms ────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1rem;
}

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--clr-gray-800);
    margin-bottom: 0.3rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="tel"],
select,
textarea {
    width: 100%;
    padding: 0.6rem 0.875rem;
    border: 1.5px solid var(--clr-gray-200);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--clr-gray-800);
    background: var(--clr-white);
    transition: border-color var(--transition);
    appearance: none;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 3px rgba(22,163,74,.15);
}

textarea { resize: vertical; min-height: 5rem; }

.form-error {
    font-size: 0.78rem;
    color: var(--clr-danger);
    margin-top: 0.25rem;
}

/* ── Alerts ───────────────────────────────────────────────── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    font-weight: 500;
}

.alert-success { background: var(--clr-primary-lt); color: #14532d; }
.alert-danger  { background: var(--clr-danger-lt);  color: #7f1d1d; }
.alert-warning { background: var(--clr-warning-lt); color: #78350f; }
.alert-info    { background: var(--clr-info-lt);    color: #1e3a8a; }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--clr-gray-200);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead th {
    background: var(--clr-gray-50);
    padding: 0.6rem 0.875rem;
    text-align: start;
    font-weight: 600;
    color: var(--clr-gray-600);
    border-bottom: 1px solid var(--clr-gray-200);
    white-space: nowrap;
}

tbody td {
    padding: 0.6rem 0.875rem;
    border-bottom: 1px solid var(--clr-gray-100);
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--clr-gray-50); }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-success  { background: var(--clr-primary-lt); color: #14532d; }
.badge-danger   { background: var(--clr-danger-lt);  color: #7f1d1d; }
.badge-warning  { background: var(--clr-warning-lt); color: #78350f; }
.badge-info     { background: var(--clr-info-lt);    color: #1e3a8a; }
.badge-gray     { background: var(--clr-gray-100);   color: var(--clr-gray-600); }

/* ── Route / Assignment List ──────────────────────────────── */
.route-list { list-style: none; }

.route-item {
    background: var(--clr-white);
    border: 1px solid var(--clr-gray-200);
    border-radius: var(--radius-lg);
    padding: 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.route-item--visited { border-color: var(--clr-primary-lt); background: #f0fdf4; }
.route-item--pending { border-color: var(--clr-gray-200); }

.route-item-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--clr-gray-800);
}

.route-item-meta {
    font-size: 0.78rem;
    color: var(--clr-gray-600);
    margin-top: 0.2rem;
}

/* ── GPS Status ───────────────────────────────────────────── */
.gps-status {
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: 500;
    margin-top: 0.5rem;
}

.gps-status--success  { background: var(--clr-primary-lt); color: #14532d; }
.gps-status--error    { background: var(--clr-danger-lt);  color: #7f1d1d; }
.gps-status--loading  { background: var(--clr-info-lt);    color: #1e3a8a; }
.gps-status--demo     { background: var(--clr-warning-lt); color: #78350f; }

/* ── Photo Upload Preview ─────────────────────────────────── */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.photo-thumb {
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--clr-gray-200);
    width: 100%;
}

/* ── Pagination ───────────────────────────────────────────── */
.pagination {
    display: flex;
    gap: 0.25rem;
    justify-content: center;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    text-decoration: none;
    color: var(--clr-gray-800);
    border: 1px solid var(--clr-gray-200);
    background: var(--clr-white);
}

.pagination .active span,
.pagination a:hover {
    background: var(--clr-primary);
    color: var(--clr-white);
    border-color: var(--clr-primary);
}

/* ── Language Toggle ──────────────────────────────────────── */
.lang-toggle {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: rgba(255,255,255,.15);
    border-radius: var(--radius);
    padding: 0.2rem 0.5rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--clr-white);
    cursor: pointer;
    border: none;
    font-family: inherit;
}

.lang-toggle:hover { background: rgba(255,255,255,.25); }

/* ── Notification Badge ───────────────────────────────────── */
.nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.1rem;
    height: 1.1rem;
    border-radius: 999px;
    background: var(--clr-danger);
    color: var(--clr-white);
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0 0.25rem;
    margin-inline-start: 0.2rem;
}

/* ── Utilities ────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-start  { text-align: start; }
.text-end    { text-align: end; }
.text-muted  { color: var(--clr-gray-400); }
.text-danger { color: var(--clr-danger); }
.text-success{ color: var(--clr-primary); }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.d-flex  { display: flex; }
.gap-2   { gap: 0.5rem; }
.gap-3   { gap: 1rem; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full  { width: 100%; }
.hidden  { display: none !important; }

/* ── Rep Status Board ─────────────────────────────────────── */
.rep-board {
    background: var(--clr-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--clr-gray-200);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.rep-board__header {
    padding: .65rem 1rem;
    border-bottom: 1px solid var(--clr-gray-100);
    font-size: .8rem;
    font-weight: 600;
    color: var(--clr-gray-600);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.rep-board__table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
    font-size: .82rem;
}

.rep-board__table th {
    padding: .45rem 1rem;
    text-align: start;
    font-size: .68rem;
    font-weight: 600;
    color: var(--clr-gray-400);
    border-bottom: 1px solid var(--clr-gray-100);
    background: var(--clr-gray-50);
    white-space: nowrap;
}

.rep-board__table td {
    padding: .6rem 1rem;
    border-bottom: 1px solid var(--clr-gray-100);
    color: var(--clr-gray-800);
    vertical-align: middle;
}

.rep-board__table tr:last-child td { border-bottom: none; }
.rep-board__table tr:hover td      { background: var(--clr-gray-50); }

.rep-progress-track {
    height: 5px;
    background: var(--clr-gray-100);
    border-radius: 3px;
    width: 64px;
    overflow: hidden;
    flex-shrink: 0;
}

.rep-progress-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--clr-primary);
    transition: width .4s ease;
}

.rep-status {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .15rem .55rem;
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 600;
    white-space: nowrap;
}

.rep-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.rep-status--not_started { background: var(--clr-danger-lt);  color: var(--clr-danger); }
.rep-status--active      { background: var(--clr-primary-lt); color: var(--clr-primary-dk); }
.rep-status--complete    { background: #dbeafe;               color: #1d4ed8; }
.rep-status--unassigned  { background: var(--clr-gray-100);   color: var(--clr-gray-400); }

.rep-flag-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.3rem;
    height: 1.3rem;
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 700;
    background: var(--clr-danger-lt);
    color: var(--clr-danger);
}

.rep-flag-count--none {
    background: transparent;
    color: var(--clr-gray-400);
    font-weight: 400;
}

/* ── Mobile Nav Hamburger ─────────────────────────────────── */
.nav-hamburger {
    display: flex;
    background: rgba(255,255,255,.15);
    border: none;
    color: #fff;
    width: 2.2rem;
    height: 2.2rem;
    border-radius: var(--radius);
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex-shrink: 0;
    padding: 0;
}
.nav-hamburger span {
    display: block;
    width: 18px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
}
.mobile-menu {
    display: none;
    position: fixed;
    top: var(--nav-height);
    inset-inline: 0;
    background: var(--clr-primary);
    z-index: 998;
    padding: .75rem 1rem 1.25rem;
    box-shadow: 0 8px 20px rgba(0,0,0,.25);
    flex-direction: column;
    gap: .3rem;
    max-height: calc(100vh - var(--nav-height));
    overflow-y: auto;
}
.mobile-menu.is-open { display: flex; }
.mobile-menu__link {
    display: block;
    padding: .7rem .85rem;
    color: rgba(255,255,255,.92);
    text-decoration: none;
    font-size: .88rem;
    font-weight: 500;
    background: rgba(255,255,255,.08);
    border-radius: var(--radius);
    border: none;
    width: 100%;
    text-align: start;
    cursor: pointer;
    font-family: inherit;
    box-sizing: border-box;
}
.mobile-menu__link:hover { background: rgba(255,255,255,.18); }
.mobile-menu__link--danger { color: #fca5a5; }
.mobile-menu__sep {
    height: 1px;
    background: rgba(255,255,255,.15);
    margin: .35rem 0;
}
.mobile-menu__label {
    font-size: .65rem;
    color: rgba(255,255,255,.45);
    padding: .4rem .25rem .1rem;
    text-transform: uppercase;
    letter-spacing: .06em;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 639px) {
    .navbar-actions { display: none; }
}

@media (min-width: 640px) {
    .nav-hamburger { display: none; }
    .main-content { padding: 1.5rem; padding-top: calc(var(--nav-height) + 1.5rem); }
    .widgets-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ── Bilingual name input widget ──────────────────────────── */
.bn-wrap {
    border: 1.5px solid var(--clr-gray-200);
    border-radius: var(--radius);
    background: var(--clr-gray-50);
    overflow: hidden;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.bn-wrap:focus-within {
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 3px rgba(var(--clr-primary-rgb,59,130,246),.12);
    background: #fff;
}
.bn-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    direction: ltr;
}
.bn-cell {
    padding: .4rem .65rem .5rem;
}
.bn-cell:first-child {
    border-right: 1.5px solid var(--clr-gray-200);
}
.bn-lang {
    display: flex; align-items: center; gap: .3rem;
    font-size: .65rem; font-weight: 700; letter-spacing: .06em;
    text-transform: uppercase; margin-bottom: .2rem;
}
.bn-lang-en { color: #1d4ed8; }
.bn-lang-ar { color: #92400e; }
.bn-lang-opt {
    font-size: .62rem; font-weight: 400;
    text-transform: none; letter-spacing: 0;
    color: var(--clr-gray-400);
}
.bn-input {
    display: block; width: 100%;
    border: none !important; outline: none !important;
    background: transparent !important; box-shadow: none !important;
    padding: .1rem .1rem !important;
    font-size: .875rem; color: var(--clr-gray-700);
    font-family: inherit;
}
.bn-footer {
    border-top: 1px solid var(--clr-gray-100);
    padding: .3rem .65rem;
    display: flex; align-items: center; gap: .5rem;
    min-height: 1.9rem;
    transition: background .2s;
}
.bn-bar {
    height: 3px; border-radius: 2px; flex-shrink: 0;
    transition: width .25s, background .25s;
}
.bn-msg {
    font-size: .72rem; font-weight: 600;
    transition: color .2s;
    flex: 1;
}
/* states */
.bn-wrap.bn-state-empty  .bn-footer { background: transparent; }
.bn-wrap.bn-state-empty  .bn-bar    { width: 28px; background: var(--clr-gray-200); }
.bn-wrap.bn-state-empty  .bn-msg    { color: var(--clr-gray-400); font-weight: 400; }
.bn-wrap.bn-state-partial .bn-footer { background: #fefce8; }
.bn-wrap.bn-state-partial .bn-bar   { width: 48px; background: #f59e0b; }
.bn-wrap.bn-state-partial .bn-msg   { color: #92400e; }
.bn-wrap.bn-state-full   .bn-footer { background: #f0fdf4; }
.bn-wrap.bn-state-full   .bn-bar    { width: 80px; background: #10b981; }
.bn-wrap.bn-state-full   .bn-msg    { color: #065f46; }
