/* ===== AliOileApp — Mobile-first design system ===== */

:root {
    --brand: #0e7490;
    --brand-dark: #155e75;
    --brand-soft: #e0f2f5;
    --bg: #f2f4f7;
    --surface: #ffffff;
    --ink: #1a2430;
    --muted: #6b7684;
    --border: #e3e8ee;
    --radius: 0.9rem;
    --radius-sm: 0.6rem;
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.12);
    --nav-h: 60px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--ink);
}

/* ---------- إطار عام ---------- */

.app-main {
    padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 76px);
    max-width: 1100px;
    margin-inline: auto;
}

@media (min-width: 768px) {
    .app-main {
        padding-bottom: 3rem;
    }
}

.card {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: var(--surface);
}

.form-control,
.form-select {
    border-radius: var(--radius-sm);
    border-color: var(--border);
    min-height: 44px;
    font-size: 1rem;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 0.2rem rgba(14, 116, 144, 0.12);
}

.form-check-input {
    width: 1.25em;
    height: 1.25em;
    cursor: pointer;
}

.form-check-input:checked {
    background-color: var(--brand);
    border-color: var(--brand);
}

.btn {
    border-radius: var(--radius-sm);
    min-height: 44px;
    font-weight: 600;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-dark);
    --bs-btn-hover-border-color: var(--brand-dark);
    --bs-btn-active-bg: var(--brand-dark);
    --bs-btn-active-border-color: var(--brand-dark);
}

.btn-outline-primary {
    --bs-btn-color: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand);
    --bs-btn-hover-border-color: var(--brand);
    --bs-btn-active-bg: var(--brand);
    --bs-btn-active-border-color: var(--brand);
}

.bg-brand {
    background: var(--brand) !important;
}

.text-brand {
    color: var(--brand) !important;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.page-head h1,
.page-head h3 {
    font-weight: 700;
    margin: 0;
}

/* ---------- الشريط العلوي (موبايل) ---------- */

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: var(--brand);
    color: #fff;
    padding: calc(0.6rem + env(safe-area-inset-top, 0px)) 1rem 0.6rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
}

.app-topbar .brand {
    font-weight: 700;
    font-size: 1.15rem;
    color: #fff;
    text-decoration: none;
}

.app-topbar .lang-btn {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 999px;
    padding: 0.3rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

/* ---------- التنقل السفلي (موبايل) ---------- */

.bottom-nav {
    position: fixed;
    bottom: 0;
    inset-inline: 0;
    z-index: 1040;
    height: calc(var(--nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    box-shadow: 0 -2px 12px rgba(16, 24, 40, 0.08);
}

.bottom-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.72rem;
    font-weight: 600;
    border: none;
    background: none;
    min-height: var(--nav-h);
    transition: color 0.15s ease;
}

.bottom-nav .nav-item svg {
    width: 22px;
    height: 22px;
}

.bottom-nav .nav-item.active {
    color: var(--brand);
}

.bottom-nav .nav-item:active {
    transform: scale(0.95);
}

/* ---------- شريط إجراءات أسفل الشاشة (موبايل) ---------- */

.m-actionbar {
    position: fixed;
    bottom: calc(var(--nav-h) + var(--safe-bottom));
    inset-inline: 0;
    z-index: 1035;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    padding: 0.6rem 1rem;
    display: flex;
    gap: 0.6rem;
}

.m-actionbar .btn {
    flex: 1;
}

.m-actionbar .btn-icon {
    flex: 0 0 52px;
    font-size: 1.4rem;
    font-weight: 700;
    padding: 0;
}

/* ---------- بطاقة العمل (موبايل) ---------- */

.job-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 0.9rem;
    animation: fadeUp 0.25s ease both;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.job-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.7rem;
}

.job-num {
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: 700;
    border-radius: 999px;
    padding: 0.15rem 0.8rem;
    font-size: 0.9rem;
}

.job-del {
    border: none;
    background: none;
    color: #c0392b;
    font-size: 1.35rem;
    line-height: 1;
    padding: 0.2rem 0.5rem;
    min-height: 40px;
    min-width: 40px;
}

.job-card label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 0.2rem;
    display: block;
}

.job-well {
    font-weight: 700;
    font-size: 1.05rem;
    margin-bottom: 0.15rem;
}

.job-meta {
    color: var(--muted);
    font-size: 0.85rem;
}

.job-icon-btn {
    border: none;
    background: none;
    color: var(--muted);
    padding: 0.35rem;
    min-width: 40px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: color 0.15s ease, background 0.15s ease;
}

.job-icon-btn:hover {
    color: var(--brand);
    background: var(--brand-soft);
}

.job-icon-btn.danger:hover {
    color: #b42318;
    background: #fee4e2;
}

.chip-static {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0.15rem 0.75rem;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand-dark);
    font-size: 0.8rem;
    font-weight: 600;
}

.svc-check {
    color: var(--brand);
    font-weight: 700;
    font-size: 1.1rem;
}

/* ---------- رقائق الخدمات ---------- */

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.4rem;
}

.chip {
    position: relative;
    cursor: pointer;
    margin: 0;
}

.chip input {
    position: absolute;
    opacity: 0;
    inset: 0;
    cursor: pointer;
}

.chip span {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 0.35rem 0.9rem;
    border-radius: 999px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
    transition: all 0.15s ease;
    user-select: none;
}

.chip input:checked + span {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

.chip input:focus-visible + span {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

.logo-thumb {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--brand-soft);
    color: var(--brand-dark);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.logo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
}

.logo-thumb-lg {
    width: 64px;
    height: 64px;
    border-radius: 14px;
    border: 1px solid var(--border);
}

/* ---------- جدول الشيت (سطح المكتب) ---------- */

.sheet-scroll {
    overflow-x: auto;
    background: #fff;
    border-radius: var(--radius);
}

.sheet-table {
    border-collapse: separate;
    border-spacing: 0;
    width: max-content;
    min-width: 100%;
}

.sheet-table th,
.sheet-table td {
    vertical-align: middle;
    white-space: nowrap;
    padding: 0.4rem 0.55rem;
    border-color: var(--border) !important;
}

.sheet-table .row-label {
    position: sticky;
    inset-inline-start: 0;
    background: #f0f4f6;
    z-index: 2;
    min-width: 130px;
    font-weight: 700;
    color: var(--brand-dark);
}

.sheet-table .job-col {
    min-width: 170px;
}

.sheet-table input[type="number"] {
    width: 60px;
}

.sheet-table .form-control,
.sheet-table .form-select {
    min-height: 38px;
    font-size: 0.9rem;
}

/* ---------- قوائم البيانات (Lookups) ---------- */

.lookup-item {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.8rem 1rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.7rem;
    margin-bottom: 0.7rem;
}

.lookup-item .name {
    font-weight: 600;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lookup-item.inactive .name {
    color: var(--muted);
    text-decoration: line-through;
}

.lookup-item .order-badge {
    background: var(--brand-soft);
    color: var(--brand-dark);
    border-radius: 8px;
    font-weight: 700;
    min-width: 34px;
    text-align: center;
    padding: 0.1rem 0.4rem;
}

.lookup-actions {
    display: flex;
    gap: 0.35rem;
}

.lookup-actions .btn,
.lookup-actions button {
    min-height: 38px;
    padding: 0.25rem 0.7rem;
    font-size: 0.8rem;
    white-space: nowrap;
}

/* ---------- Offcanvas سفلي ---------- */

.offcanvas.offcanvas-bottom {
    border-start-start-radius: 1.25rem;
    border-start-end-radius: 1.25rem;
    height: auto;
    max-height: 92vh;
    padding-bottom: var(--safe-bottom);
}

.offcanvas-bottom .offcanvas-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* نماذج كبيرة — الـ sheet يغطي الشاشة بالكامل (حتى مع فتح لوحة المفاتيح) */
.offcanvas.offcanvas-bottom.offcanvas-full {
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border-start-start-radius: 0;
    border-start-end-radius: 0;
    padding-top: env(safe-area-inset-top, 0px);
}

.offcanvas-bottom .sheet-handle {
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: #d0d7de;
    margin: 0.5rem auto 0;
}

.offcanvas-bottom .list-group-item {
    min-height: 52px;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-weight: 600;
    border-color: var(--border);
}

.offcanvas-bottom .list-group-item svg {
    width: 20px;
    height: 20px;
    color: var(--brand);
}

/* ---------- FAB ---------- */

.fab {
    position: fixed;
    bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
    inset-inline-end: 16px;
    z-index: 1036;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--brand);
    color: #fff;
    font-size: 1.7rem;
    line-height: 1;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.fab:active {
    transform: scale(0.92);
}

/* ---------- Toast ---------- */

.app-toasts {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    inset-inline: 0;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
    padding-inline: 1rem;
}

.app-toasts .toast {
    pointer-events: auto;
    border: none;
    border-radius: 999px;
    box-shadow: var(--shadow-lg);
    font-weight: 600;
    max-width: 420px;
    width: auto;
}

.app-toasts .toast .toast-body {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.1rem;
}

.toast-success {
    background: #136f3f;
    color: #fff;
}

.toast-error {
    background: #b42318;
    color: #fff;
}

/* ---------- التقارير ---------- */

.chart-box {
    position: relative;
    height: 260px;
}

.chart-box canvas {
    max-height: 100%;
}

.report-stat {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--brand-soft);
    color: var(--brand-dark);
    border-radius: 999px;
    padding: 0.4rem 1.1rem;
    font-weight: 700;
}

/* ---------- متفرقات ---------- */

.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--muted);
}

.empty-state svg {
    width: 56px;
    height: 56px;
    opacity: 0.4;
    margin-bottom: 0.8rem;
}

.seg-toggle {
    display: flex;
    background: var(--bg);
    border-radius: 999px;
    padding: 4px;
    gap: 4px;
}

.seg-toggle a {
    flex: 1;
    text-align: center;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    font-weight: 600;
    text-decoration: none;
    color: var(--muted);
    transition: all 0.15s ease;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.seg-toggle a.on {
    background: var(--surface);
    color: var(--brand);
    box-shadow: var(--shadow);
}

input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* تسجيل الدخول */
.login-wrap {
    min-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    width: 100%;
    max-width: 400px;
}

.login-logo {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0 auto 1rem;
}
