/* ==========================================================================
   MostaERP Design System — tokens, base, typography, forms, tables, navbar
   ========================================================================== */

:root {
    /* ==================================================================
       ERP Theme tokens — the ONLY place raw brand colors are defined.
       Settings → Branding overrides these five via a small inline
       <style> block (see layouts.partials.theme-vars); every hover/soft
       variant below is derived from them with color-mix(), never
       hardcoded, so changing one color updates the whole system.
       ================================================================== */
    --erp-primary: #4f46e5;
    --erp-navbar-bg: #1e1b4b;
    --erp-body-bg: #f4f6fb;
    --erp-surface: #ffffff;
    --erp-text: #1e2433;
    --erp-text-muted: #6b7280;
    --erp-border: #e5e8f0;
    --erp-success: #16a34a;
    --erp-warning: #d97706;
    --erp-danger: #dc2626;
    --erp-info: #0284c7;
    --erp-radius: 9px;

    /* Derived automatically — never store these separately. */
    --erp-primary-hover: color-mix(in srgb, var(--erp-primary) 85%, black);
    --erp-primary-soft: color-mix(in srgb, var(--erp-primary) 12%, white);
    --erp-primary-active: color-mix(in srgb, var(--erp-primary) 92%, black);
    --erp-success-soft: color-mix(in srgb, var(--erp-success) 12%, white);
    --erp-warning-soft: color-mix(in srgb, var(--erp-warning) 12%, white);
    --erp-danger-soft: color-mix(in srgb, var(--erp-danger) 12%, white);
    --erp-info-soft: color-mix(in srgb, var(--erp-info) 12%, white);

    /* ---- Back-compat aliases: the rest of this stylesheet was written
       against --mosta-*; keep them pointed at the tokens above so there
       is a single source of truth instead of two parallel palettes. ---- */
    --mosta-primary: var(--erp-primary);
    --mosta-primary-dark: var(--erp-primary-hover);
    --mosta-primary-light: var(--erp-primary-soft);
    --mosta-purple: #7c3aed;
    --mosta-navy: var(--erp-navbar-bg);
    --mosta-navy-light: color-mix(in srgb, var(--erp-navbar-bg) 85%, white);

    --mosta-success: var(--erp-success);
    --mosta-success-light: var(--erp-success-soft);
    --mosta-danger: var(--erp-danger);
    --mosta-danger-light: var(--erp-danger-soft);
    --mosta-warning: var(--erp-warning);
    --mosta-warning-light: var(--erp-warning-soft);
    --mosta-info: var(--erp-info);
    --mosta-info-light: var(--erp-info-soft);

    --mosta-bg: var(--erp-body-bg);
    --mosta-surface: var(--erp-surface);
    --mosta-border: var(--erp-border);
    --mosta-border-strong: #d7dbe7;

    --mosta-text: var(--erp-text);
    --mosta-text-muted: var(--erp-text-muted);
    --mosta-text-subtle: #9aa1b1;

    /* Geometry */
    --mosta-radius-sm: 7px;
    --mosta-radius: var(--erp-radius);
    --mosta-radius-lg: 12px;
    --mosta-navbar-h: 56px;
    --mosta-subbar-h: 44px;
    --mosta-control-h: 38px;
    --mosta-control-h-sm: 32px;

    /* Spacing scale: 4 / 8 / 12 / 16 / 24 / 32 */
    --space-1: .25rem;
    --space-2: .5rem;
    --space-3: .75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;

    /* Elevation */
    --mosta-shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --mosta-shadow: 0 2px 10px rgba(16, 24, 40, .06);
    --mosta-shadow-lg: 0 16px 40px rgba(16, 24, 40, .14);

    --mosta-font: "Inter", "Noto Sans Arabic", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html, body {
    height: 100%;
    background: var(--mosta-bg);
}

body {
    display: flex;
    flex-direction: column;
    font-family: var(--mosta-font);
    font-size: .875rem;
    line-height: 1.45;
    color: var(--mosta-text);
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; }

h1, h2, h3, h4, h5, h6 { color: var(--mosta-text); font-weight: 600; }

.text-muted { color: var(--mosta-text-muted) !important; }
.text-subtle { color: var(--mosta-text-subtle) !important; }

/* ---------- Typography scale ---------- */
.page-title { font-size: 1.3rem; font-weight: 600; color: var(--mosta-text); letter-spacing: -.01em; }
.section-title { font-size: .9375rem; font-weight: 600; color: var(--mosta-text); }
.form-label { font-size: .8125rem; font-weight: 500; color: var(--mosta-text); margin-bottom: .3rem; }
.form-label .required-mark { color: var(--mosta-danger); margin-left: .15rem; }
.form-help { font-size: .74rem; color: var(--mosta-text-muted); margin-top: .25rem; }
.meta-text { font-size: .75rem; color: var(--mosta-text-subtle); }
small, .small { font-size: .78rem; }

/* ---------- Buttons ---------- */
.btn {
    font-size: .8125rem;
    font-weight: 500;
    border-radius: var(--mosta-radius-sm);
    padding: .45rem .9rem;
    min-height: var(--mosta-control-h);
    line-height: 1.3;
    box-shadow: none !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
}
.btn-sm { padding: .3rem .7rem; font-size: .8rem; min-height: var(--mosta-control-h-sm); }
.btn-lg { padding: .55rem 1.1rem; font-size: .9rem; min-height: 44px; }

.btn-primary { background: var(--mosta-primary); border-color: var(--mosta-primary); font-weight: 600; }
.btn-primary:hover, .btn-primary:active { background: var(--mosta-primary-dark) !important; border-color: var(--mosta-primary-dark) !important; }

.btn-outline-secondary { color: var(--mosta-text); border-color: var(--mosta-border-strong); background: #fff; }
.btn-outline-secondary:hover { background: var(--mosta-bg); color: var(--mosta-text); border-color: var(--mosta-border-strong); }

.btn-outline-danger { --bs-btn-color: var(--mosta-danger); --bs-btn-border-color: #f3d3d3; }
.btn-outline-danger:hover { background: var(--mosta-danger); border-color: var(--mosta-danger); }

.btn-link { font-weight: 600; }

/* ---------- Forms ---------- */
.form-control, .form-select {
    font-size: .8125rem;
    border-color: var(--mosta-border-strong);
    border-radius: var(--mosta-radius-sm);
    padding: .5rem .75rem;
    min-height: var(--mosta-control-h);
    color: var(--mosta-text);
}
.form-control-sm, .form-select-sm { padding: .4rem .6rem; font-size: .8rem; min-height: var(--mosta-control-h-sm); }
.form-control:focus, .form-select:focus {
    border-color: var(--mosta-primary);
    box-shadow: 0 0 0 .16rem rgba(79, 70, 229, .14);
}
.form-control::placeholder { color: var(--mosta-text-subtle); }
textarea.form-control { min-height: 5.5rem; }

.form-control.is-invalid, .form-select.is-invalid { border-color: var(--mosta-danger); background-image: none; }
.form-control.is-invalid:focus, .form-select.is-invalid:focus { box-shadow: 0 0 0 .16rem rgba(220, 38, 38, .14); }
.invalid-feedback { font-size: .74rem; color: var(--mosta-danger); }

.form-check-input { border-color: var(--mosta-border-strong); }
.form-check-input:checked { background-color: var(--mosta-primary); border-color: var(--mosta-primary); }
.form-check-input:focus { box-shadow: 0 0 0 .16rem rgba(79, 70, 229, .14); }

.form-switch .form-check-input { height: 1.35rem; width: 2.4rem; }

.input-group-text { background: #fbfbfd; border-color: var(--mosta-border-strong); color: var(--mosta-text-subtle); min-height: var(--mosta-control-h); }

.form-field-group { margin-bottom: var(--space-4); }

/* ---------- Cards / panels ---------- */
.mosta-card {
    border: 1px solid var(--mosta-border);
    border-radius: var(--mosta-radius);
    background: var(--mosta-surface);
    box-shadow: var(--mosta-shadow-sm);
}

.mosta-content { flex: 1; padding: var(--space-6) var(--space-6) var(--space-8); }

/* ---------- Tables ---------- */
.table-dense {
    --bs-table-bg: transparent;
    margin-bottom: 0;
}
.table-dense > :not(caption) > * > * { padding: .5rem .75rem; vertical-align: middle; border-bottom-color: var(--mosta-border); }
.table-dense thead th {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--mosta-text-muted);
    background: #fafbfd;
    border-bottom: 1px solid var(--mosta-border);
    white-space: nowrap;
}
.table-dense tbody tr { transition: background-color .1s ease; }
.table-dense tbody tr:hover { background-color: #fafbff; }
.table-dense tbody tr:last-child td { border-bottom: none; }
.table-row-link { cursor: pointer; }

/* ---------- Badges / status / priority ---------- */
.badge-status {
    font-weight: 600;
    font-size: .7rem;
    padding: .32em .6em;
    border-radius: 999px;
    letter-spacing: .01em;
}
.text-bg-primary.badge-status { background: var(--mosta-primary-light) !important; color: var(--mosta-primary-dark) !important; }
.text-bg-secondary.badge-status { background: #eef0f4 !important; color: #4b5061 !important; }
.text-bg-success.badge-status { background: var(--mosta-success-light) !important; color: var(--mosta-success) !important; }
.text-bg-danger.badge-status { background: var(--mosta-danger-light) !important; color: var(--mosta-danger) !important; }
.text-bg-warning.badge-status { background: var(--mosta-warning-light) !important; color: var(--mosta-warning) !important; }
.text-bg-info.badge-status { background: var(--mosta-info-light) !important; color: var(--mosta-info) !important; }

.priority-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.priority-low { background: #9ca3af; }
.priority-medium { background: #2563eb; }
.priority-high { background: #d97706; }
.priority-urgent { background: #dc2626; }

.color-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    font-size: .7rem;
    font-weight: 600;
    padding: .2rem .55rem;
    border-radius: 999px;
    background: #eef0f4;
    color: #4b5061;
    line-height: 1.4;
}
.chip .chip-remove { cursor: pointer; opacity: .6; }
.chip .chip-remove:hover { opacity: 1; }

/* ---------- Avatars ---------- */
.avatar-sm { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }
.avatar-xs { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; }
.avatar-md { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
.avatar-lg { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; }

.avatar-stack { display: flex; }
.avatar-stack img { margin-left: -7px; border: 2px solid #fff; }
.avatar-stack img:first-child { margin-left: 0; }

/* ---------- Dropdowns / Modals / Toasts ---------- */
.dropdown-menu {
    border: 1px solid var(--mosta-border);
    border-radius: var(--mosta-radius);
    box-shadow: var(--mosta-shadow-lg);
    padding: .35rem;
    font-size: .8125rem;
}
.dropdown-item { border-radius: var(--mosta-radius-sm); padding: .4rem .6rem; }
.dropdown-item:hover, .dropdown-item:focus { background: var(--mosta-bg); }
.dropdown-item.text-danger:hover { background: var(--mosta-danger-light); }

.modal-content { border: none; border-radius: var(--mosta-radius-lg); box-shadow: var(--mosta-shadow-lg); }
.modal-header { border-bottom: 1px solid var(--mosta-border); padding: 1rem 1.15rem; }
.modal-body { padding: 1.15rem; }
.modal-footer { border-top: 1px solid var(--mosta-border); padding: .85rem 1.15rem; }
.modal-title { font-size: .95rem; font-weight: 700; }

.toast { border: none; border-radius: var(--mosta-radius); box-shadow: var(--mosta-shadow-lg); }

.alert { border: 1px solid transparent; border-radius: var(--mosta-radius); font-size: .82rem; }
.alert-success { background: var(--mosta-success-light); color: #0e6b32; border-color: #cdf0da; }
.alert-danger { background: var(--mosta-danger-light); color: #a01515; border-color: #f6d3d3; }
.alert-warning { background: var(--mosta-warning-light); color: #92600a; border-color: #f7e5bd; }

/* ---------- Empty states ---------- */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--mosta-text-subtle); }
.empty-state i { font-size: 2.2rem; opacity: .45; }
.empty-state h5 { color: var(--mosta-text-muted); font-weight: 600; font-size: .92rem; }

/* ---------- Pagination ---------- */
.pagination { --bs-pagination-font-size: .78rem; }
.page-link { color: var(--mosta-text); border-color: var(--mosta-border); }
.page-item.active .page-link { background: var(--mosta-primary); border-color: var(--mosta-primary); }
.page-link:hover { background: var(--mosta-bg); color: var(--mosta-primary-dark); }

/* ---------- Top Navbar ---------- */
.mosta-navbar {
    height: var(--mosta-navbar-h);
    min-height: var(--mosta-navbar-h);
    max-height: var(--mosta-navbar-h);
    flex: none;
    background: linear-gradient(180deg, var(--mosta-navy) 0%, color-mix(in srgb, var(--mosta-navy) 85%, black) 100%);
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    padding: 0 .65rem;
    position: sticky;
    top: 0;
    z-index: 1030;
    gap: .35rem;
    box-shadow: 0 1px 0 rgba(0, 0, 0, .12);
    box-sizing: border-box;
}

.mosta-navbar .brand {
    font-weight: 600;
    color: #fff;
    font-size: .85rem;
    padding: 0 .3rem;
    display: flex;
    align-items: center;
    gap: .45rem;
    letter-spacing: -.01em;
}
.mosta-navbar .brand .brand-mark {
    width: 22px;
    height: 22px;
    border-radius: .4rem;
    background: linear-gradient(135deg, #22d3ee 0%, #6366f1 55%, #a855f7 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .68rem;
    font-weight: 700;
    color: #fff;
    flex: none;
}
.mosta-navbar .brand .brand-logo-img { height: 24px; max-height: 24px; width: auto; flex: none; object-fit: contain; }
.mosta-navbar .brand span.accent { color: #a5b4fc; }

.mosta-navbar .nav-link {
    position: relative;
    color: rgba(255, 255, 255, .65);
    font-size: .78rem;
    font-weight: 500;
    padding: .32rem .65rem;
    border-radius: var(--mosta-radius-sm);
    white-space: nowrap;
    transition: background-color .12s ease, color .12s ease;
}
.mosta-navbar .nav-link:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.mosta-navbar .nav-link.active {
    color: #fff;
    background: rgba(255, 255, 255, .1);
    font-weight: 600;
}
.mosta-navbar .nav-link.active::after {
    content: "";
    position: absolute;
    left: .65rem;
    right: .65rem;
    bottom: -1px;
    height: 2px;
    border-radius: 2px;
    background: #fff;
}

.mosta-navbar .icon-btn {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--mosta-radius-sm);
    color: rgba(255, 255, 255, .78);
    border: none;
    background: transparent;
}
.mosta-navbar .icon-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.mosta-navbar .icon-btn i { font-size: 1.05rem; }

.mosta-navbar .avatar-sm { border: 1.5px solid rgba(255, 255, 255, .35); }

/* ---------- Apps launcher ---------- */
.apps-launcher-menu { width: 336px; padding: .85rem; }
.apps-launcher-menu .app-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .4rem;
    padding: .75rem .25rem;
    border-radius: var(--mosta-radius);
    color: var(--mosta-text);
    text-align: center;
}
.apps-launcher-menu .app-tile:hover { background: var(--mosta-bg); }
.apps-launcher-menu .app-tile .app-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--mosta-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: #fff;
}
.apps-launcher-menu .app-tile small { font-size: .68rem; color: var(--mosta-text-muted); font-weight: 500; }
.apps-launcher-menu .app-tile.disabled { opacity: .38; pointer-events: none; }

/* ---------- Sub navigation / control panel ---------- */
.mosta-subbar {
    background: #fff;
    border-bottom: 1px solid var(--mosta-border);
    padding: 0 var(--space-6);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: .5rem;
    height: var(--mosta-subbar-h);
    min-height: var(--mosta-subbar-h);
    max-height: var(--mosta-subbar-h);
    overflow-x: auto;
    overflow-y: hidden;
    box-sizing: border-box;
}
.mosta-subbar > * { flex: none; }
.mosta-subbar > *:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.mosta-subbar .breadcrumb { white-space: nowrap; }

@media (max-width: 768px) {
    .mosta-subbar { flex-wrap: wrap; height: auto; min-height: var(--mosta-subbar-h); padding: .4rem var(--space-4); overflow: visible; }
}
.mosta-subbar .breadcrumb { margin: 0; font-size: .74rem; --bs-breadcrumb-divider-color: var(--mosta-text-subtle); }
.mosta-subbar .breadcrumb-item { color: var(--mosta-text-subtle); }
.mosta-subbar .breadcrumb-item + .breadcrumb-item { padding-left: .4rem; }
.mosta-subbar .breadcrumb-item + .breadcrumb-item::before { color: var(--mosta-text-subtle); padding-right: .4rem; }
.mosta-subbar .breadcrumb-item.active { color: var(--mosta-text-muted); }
.mosta-subbar .breadcrumb-item a { color: var(--mosta-text-muted); font-weight: 500; }
.mosta-subbar .breadcrumb-item a:hover { color: var(--mosta-primary-dark); }

/* ---------- Auth ---------- */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: var(--mosta-bg);
    position: relative;
    overflow: hidden;
}
.auth-wrapper::before,
.auth-wrapper::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(79, 70, 229, .1), rgba(56, 189, 248, .1));
    z-index: 0;
}
.auth-wrapper::before { width: 520px; height: 520px; top: -180px; right: -160px; }
.auth-wrapper::after { width: 420px; height: 420px; bottom: -160px; left: -140px; }

.auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: var(--mosta-radius-lg);
    padding: 2.5rem 2rem;
    box-shadow: var(--mosta-shadow-lg);
    position: relative;
    z-index: 1;
}

.auth-logo-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto .75rem;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #22d3ee 0%, #4f46e5 55%, #7c3aed 100%);
    color: #fff;
    font-weight: 800;
    font-size: 1.6rem;
}
.auth-brand { font-weight: 800; font-size: 1.4rem; color: var(--mosta-text); }
.auth-brand span { color: var(--mosta-primary); }
.auth-logo-img { max-height: 56px; max-width: 220px; margin: 0 auto .75rem; display: block; }

.auth-input-group .input-group-text { background: #fff; border-right: none; color: var(--mosta-text-subtle); }
.auth-input-group .form-control { border-left: none; }
.auth-input-group .form-control:focus { box-shadow: none; border-color: var(--mosta-border-strong); }
.auth-input-group .btn-toggle-password { border-color: var(--mosta-border-strong); background: #fff; color: var(--mosta-text-subtle); }

/* ---------- Toasts ---------- */
.mosta-toast-container {
    position: fixed;
    top: calc(var(--mosta-navbar-h) + 12px);
    right: 16px;
    z-index: 1080;
    width: 320px;
    max-width: calc(100vw - 24px);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.mosta-toast-container .toast {
    width: 100%;
    box-shadow: var(--mosta-shadow-lg);
    border-radius: var(--mosta-radius);
    font-size: .8125rem;
}
.mosta-toast-container .toast .toast-body {
    padding: .55rem .75rem;
    display: flex;
    align-items: center;
    gap: .4rem;
}
.mosta-toast-container .toast .btn-close {
    opacity: .65;
    font-size: .65rem;
    padding: .55rem;
}
.mosta-toast-container .toast .btn-close:hover { opacity: 1; }

/* ---------- Misc ---------- */
.field-inline-edit { cursor: pointer; border-bottom: 1px dashed transparent; }
.field-inline-edit:hover { border-bottom-color: var(--mosta-border-strong); }

@media (max-width: 768px) {
    .mosta-navbar .nav-link span.label { display: none; }
    .mosta-content { padding: .75rem; }
}
