/* ==========================================================================
   Clopr SmartFab — لوحة التحكم
   واجهة كثيفة تُقرأ بالمسح لا بالقراءة: شريط جانبي ثابت وجداول بيانات.
   ========================================================================== */

:root {
    --navy-950: #0D131E;
    --navy-900: #141B28;
    --navy-800: #1A2231;
    --navy-700: #212B3D;
    --navy-600: #2C3850;

    --teal-700: #0E6E62;
    --teal-600: #12806F;
    --teal-500: #188C7E;
    --teal-400: #22A894;
    --teal-100: #D6F2EC;
    --teal-50: #EEFAF7;

    --slate-700: #384047;
    --slate-500: #5B6673;
    --slate-400: #8A94A3;
    --slate-300: #B9C1CC;
    --slate-200: #DCE2E9;
    --slate-100: #EDF1F5;
    --slate-50: #F6F8FA;

    --amber: #A86B2E;
    --amber-soft: #FBF3E7;
    --danger: #B4453F;
    --danger-soft: #FBEDEC;

    --ink: var(--navy-700);
    --ink-soft: var(--slate-500);
    --line: var(--slate-200);
    --page: #F4F6F8;

    --sidebar-w: 248px;
    --topbar-h: 60px;

    --font-base: 'Tajawal', system-ui, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;

    --shadow-sm: 0 1px 2px rgba(19, 26, 38, .06), 0 2px 8px rgba(19, 26, 38, .05);
    --shadow-md: 0 4px 12px rgba(19, 26, 38, .08), 0 12px 28px rgba(19, 26, 38, .07);
}

/* الحزمة المرفقة هي ثيم Bootswatch Litera الذي يفرض خطًا مذيّلًا على الفقرات */
body, p, li, a, span, small, strong, label, th, td,
button, input, select, textarea, .btn, .form-control, .form-select {
    font-family: var(--font-base);
}

* { box-sizing: border-box; }

body.console {
    margin: 0;
    background: var(--page);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5 {
    font-family: var(--font-base);
    color: var(--navy-700);
    font-weight: 700;
    margin: 0;
    line-height: 1.4;
}

a { color: var(--teal-600); text-decoration: none; }
a:hover { color: var(--teal-500); }

:focus-visible { outline: 2px solid var(--teal-500); outline-offset: 2px; }

code, .mono {
    font-family: var(--font-mono);
    direction: ltr;
    unicode-bidi: embed;
}

code {
    font-size: .86em;
    background: var(--slate-100);
    color: var(--navy-700);
    padding: 1px 5px;
    border-radius: 3px;
}

/* --------------------------------------------------------------------------
   الشريط الجانبي
   -------------------------------------------------------------------------- */
.sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: var(--sidebar-w);
    background: var(--navy-900);
    color: var(--slate-300);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: 1rem 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}

.sidebar-brand img { width: 30px; height: 34px; object-fit: contain; }

.sidebar-brand .brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.sidebar-brand b { color: #fff; font-size: .98rem; font-weight: 700; }
.sidebar-brand b em { font-style: normal; color: var(--teal-400); }
.sidebar-brand small { color: var(--slate-400); font-size: .74rem; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .8rem .6rem; }

.nav-group {
    font-size: .7rem;
    letter-spacing: .06em;
    color: var(--slate-500);
    margin: 1rem .6rem .35rem;
    font-weight: 700;
}

.nav-group:first-child { margin-top: .2rem; }

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem .7rem;
    border-radius: 7px;
    color: var(--slate-300);
    font-size: .93rem;
    font-weight: 500;
    transition: background-color .16s ease, color .16s ease;
}

.sidebar .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; flex-shrink: 0; }
.sidebar .nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }

.sidebar .nav-link.active {
    background: var(--teal-500);
    color: #fff;
    font-weight: 700;
}

.sidebar-foot {
    padding: .8rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, .07);
}

.sidebar-foot a {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--slate-400);
    font-size: .85rem;
}

.sidebar-foot a:hover { color: var(--teal-400); }

.sidebar-scrim {
    position: fixed;
    inset: 0;
    background: rgba(13, 19, 30, .5);
    opacity: 0;
    visibility: hidden;
    transition: opacity .25s ease;
    z-index: 1035;
}

.sidebar-scrim.show { opacity: 1; visibility: visible; }

/* --------------------------------------------------------------------------
   الهيكل والشريط العلوي
   -------------------------------------------------------------------------- */
.shell {
    margin-inline-start: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: .9rem;
    padding-inline: 1.3rem;
    position: sticky;
    inset-block-start: 0;
    z-index: 1020;
}

.topbar-title { font-size: 1.06rem; font-weight: 700; }

.topbar-actions {
    margin-inline-start: auto;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: .45rem;
    background: var(--slate-50);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: .25rem .8rem;
    font-size: .87rem;
    color: var(--slate-700);
}

.user-chip i { color: var(--teal-600); font-size: 1rem; }
.user-chip small {
    color: var(--slate-400);
    font-size: .72rem;
    border-inline-start: 1px solid var(--line);
    padding-inline-start: .45rem;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 7px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--slate-700);
    display: inline-grid;
    place-items: center;
    font-size: 1.05rem;
    transition: all .16s ease;
}

.icon-btn:hover { border-color: var(--teal-500); color: var(--teal-600); background: var(--teal-50); }
.sidebar-open { display: none; }

/* مبدّل اللغة */
.lang-switch {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    height: 34px;
    padding-inline: .75rem;
    border-radius: 7px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--slate-700);
    font-size: .84rem;
    font-weight: 700;
    cursor: pointer;
    transition: all .16s ease;
}

.lang-switch i { font-size: 1rem; }

.lang-switch:hover {
    border-color: var(--teal-500);
    color: var(--teal-600);
    background: var(--teal-50);
}

.content { flex: 1; padding: 1.4rem 1.3rem 2.4rem; }

.shell-foot {
    border-top: 1px solid var(--line);
    padding: .9rem 1.3rem;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .5rem;
    font-size: .82rem;
    color: var(--slate-400);
}

/* --------------------------------------------------------------------------
   البطاقات ومؤشرات الأرقام
   -------------------------------------------------------------------------- */
.card-x {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
}

.card-x > header {
    padding: .8rem 1.1rem;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: .7rem;
    flex-wrap: wrap;
}

.card-x > header h2 { font-size: 1rem; margin: 0; }
.card-x > header .spacer { margin-inline-start: auto; }
.card-x > .body { padding: 1.1rem; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(172px, 1fr));
    gap: .9rem;
    margin-bottom: 1.4rem;
}

.stat {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: .95rem 1.1rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: .1rem;
}

.stat .label {
    font-size: .82rem;
    color: var(--slate-500);
    display: flex;
    align-items: center;
    gap: .4rem;
}

.stat .label i { color: var(--teal-600); }

.stat .value {
    font-family: var(--font-mono);
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--navy-700);
    line-height: 1.25;
    font-variant-numeric: tabular-nums;
}

.stat .hint { font-size: .78rem; color: var(--slate-400); }
.stat.warn .value { color: var(--amber); }
.stat.warn .label i { color: var(--amber); }

/* --------------------------------------------------------------------------
   الجداول
   -------------------------------------------------------------------------- */
.table-wrap {
    overflow-x: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
}

table.dt {
    width: 100%;
    border-collapse: collapse;
    font-size: .89rem;
    font-variant-numeric: tabular-nums;
}

table.dt th, table.dt td {
    padding: .6rem .85rem;
    text-align: start;
    border-bottom: 1px solid var(--slate-100);
    vertical-align: middle;
    white-space: nowrap;
}

table.dt thead th {
    background: var(--slate-50);
    color: var(--slate-700);
    font-weight: 700;
    font-size: .8rem;
    border-bottom: 1px solid var(--line);
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
}

table.dt tbody tr:hover { background: var(--teal-50); }
table.dt tbody tr:last-child td { border-bottom: 0; }
table.dt td.wrap { white-space: normal; min-width: 240px; }
table.dt td.num { text-align: end; font-family: var(--font-mono); font-size: .84rem; }
table.dt td.mono, table.dt th.mono { font-family: var(--font-mono); font-size: .84rem; }

.muted { color: var(--slate-400); }

/* --------------------------------------------------------------------------
   رسم الوحدات البارامتري
   -------------------------------------------------------------------------- */
.unit-fig {
    display: block;
    overflow: visible;
}

.unit-fig .fig-body, .kitchen-elev .fig-body    { fill: #F2EDE4; stroke: var(--navy-700); stroke-width: 1.4; }
.unit-fig .fig-panel, .kitchen-elev .fig-panel   { fill: #FFFFFF; stroke: var(--slate-500); stroke-width: .9; }
.unit-fig .fig-glass, .kitchen-elev .fig-glass   { fill: #DCEEF3; stroke: var(--slate-500); stroke-width: .9; opacity: .9; }
.unit-fig .fig-basin, .kitchen-elev .fig-basin   { fill: #E4EAEF; stroke: var(--slate-500); stroke-width: .9; }
.unit-fig .fig-appliance, .kitchen-elev .fig-appliance { fill: #E7E9EC; stroke: var(--slate-500); stroke-width: .9; }
.unit-fig .fig-plinth, .kitchen-elev .fig-plinth  { fill: var(--slate-400); stroke: none; }
.unit-fig .fig-line, .kitchen-elev .fig-line    { fill: none; stroke: var(--slate-400); stroke-width: .9; }
.unit-fig .fig-handle, .kitchen-elev .fig-handle  { stroke: var(--navy-700); stroke-width: 1.6; stroke-linecap: round; }
.unit-fig .fig-dim, .kitchen-elev .fig-dim     { stroke: var(--teal-600); stroke-width: .8; }

.unit-fig .fig-code, .kitchen-elev .fig-code {
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 700;
    fill: var(--navy-700);
}

.unit-fig .fig-dimtext, .kitchen-elev .fig-dimtext,
.unit-fig .fig-depth {
    font-family: var(--font-mono);
    font-size: 8px;
    fill: var(--teal-700);
}

.unit-fig .fig-depth { fill: var(--slate-400); }

.fig-cell {
    display: grid;
    place-items: center;
    min-width: 120px;
    padding: .3rem 0;
}

/* --------------------------------------------------------------------------
   الشارات
   -------------------------------------------------------------------------- */
.chip {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    font-size: .75rem;
    font-weight: 700;
    padding: .12rem .55rem;
    border-radius: 999px;
    border: 1px solid transparent;
    white-space: nowrap;
}

.chip-teal   { background: var(--teal-50);   color: var(--teal-700); border-color: var(--teal-100); }
.chip-slate  { background: var(--slate-100); color: var(--slate-700); border-color: var(--slate-200); }
.chip-amber  { background: var(--amber-soft); color: var(--amber);   border-color: #EBD9BF; }
.chip-danger { background: var(--danger-soft); color: var(--danger); border-color: #F0CFCD; }
.chip-navy   { background: #E7EAEF; color: var(--navy-700); border-color: #D3D9E2; }

/* شريط المجموعة بألوان الكتالوج المطبوع */
.band {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .1rem .6rem;
    border-radius: 4px;
    font-size: .76rem;
    font-weight: 700;
    color: #12181C;
}

.band-base  { background: #6F9FB5; }
.band-wall  { background: #7FB394; }
.band-tall  { background: #D98A73; }
.band-other { background: #B9A96B; }

/* --------------------------------------------------------------------------
   الأدوات والنماذج
   -------------------------------------------------------------------------- */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
    align-items: center;
    margin-bottom: 1rem;
}

.toolbar form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.field {
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: .45rem .8rem;
    font-size: .9rem;
    background: #fff;
    color: var(--ink);
    min-width: 160px;
}

.field:focus { outline: none; border-color: var(--teal-500); box-shadow: 0 0 0 3px rgba(24, 140, 126, .13); }

.btn-x {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    border: 1px solid transparent;
    border-radius: 7px;
    padding: .45rem 1rem;
    font-size: .9rem;
    font-weight: 700;
    background: var(--teal-500);
    color: #fff;
    cursor: pointer;
    transition: all .16s ease;
}

.btn-x:hover { background: var(--teal-600); color: #fff; }

.btn-ghost { background: #fff; color: var(--slate-700); border-color: var(--line); }
.btn-ghost:hover { background: var(--slate-50); color: var(--navy-700); border-color: var(--slate-300); }

.pager {
    display: flex;
    gap: .35rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 1rem;
    font-size: .87rem;
}

.pager a, .pager span {
    padding: .3rem .7rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--slate-700);
}

.pager .cur { background: var(--teal-500); border-color: var(--teal-500); color: #fff; font-weight: 700; }
.pager .gap { border: 0; background: none; }

.empty {
    padding: 2.6rem 1rem;
    text-align: center;
    color: var(--slate-400);
}

.empty i { font-size: 2rem; display: block; margin-bottom: .5rem; color: var(--slate-300); }

/* تنبيه */
.note-box {
    border: 1px solid var(--line);
    border-inline-start: 3px solid var(--amber);
    background: var(--amber-soft);
    border-radius: 8px;
    padding: .9rem 1.1rem;
    font-size: .89rem;
    color: var(--slate-700);
    margin-bottom: 1.2rem;
}

.note-box b { color: var(--navy-700); }

/* قائمة تعريف */
.deflist { display: grid; grid-template-columns: auto 1fr; gap: .45rem 1rem; font-size: .9rem; }
.deflist dt { color: var(--slate-500); }
.deflist dd { margin: 0; color: var(--navy-700); font-weight: 500; }

/* --------------------------------------------------------------------------
   شاشة الدخول
   -------------------------------------------------------------------------- */
body.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    background: linear-gradient(160deg, var(--navy-900), var(--navy-700) 60%, #1D3A3C);
    padding: 1.5rem;
}

.login-card {
    width: min(400px, 100%);
    background: #fff;
    border-radius: 14px;
    padding: 2rem 1.9rem;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .32);
}

.login-card .brand {
    display: flex;
    align-items: center;
    gap: .7rem;
    margin-bottom: 1.5rem;
}

.login-card .brand img { width: 38px; height: 43px; object-fit: contain; }
.login-card .brand b { font-size: 1.1rem; color: var(--navy-700); display: block; }
.login-card .brand b em { font-style: normal; color: var(--teal-500); }
.login-card .brand small { color: var(--slate-400); font-size: .8rem; }

.login-card label { font-size: .87rem; font-weight: 700; color: var(--navy-700); display: block; margin-bottom: .3rem; }
.login-card .field { width: 100%; margin-bottom: .9rem; }
.login-card .btn-x { width: 100%; justify-content: center; padding-block: .6rem; }

.login-error {
    background: var(--danger-soft);
    border: 1px solid #F0CFCD;
    color: var(--danger);
    border-radius: 7px;
    padding: .6rem .9rem;
    font-size: .87rem;
    margin-bottom: 1rem;
}

/* --------------------------------------------------------------------------
   الاستجابة
   -------------------------------------------------------------------------- */
@media (max-width: 991.98px) {
    /* الانزلاق عبر inset-inline-start لا عبر translateX: خاصية منطقية تعرف
       الاتجاه بنفسها، فلا نحتاج قاعدة RTL منفصلة. القاعدة السابقة
       (html[dir="rtl"] .sidebar) كانت أعلى أولوية من (.sidebar.open) فتغلبها،
       وكان الشريط لا ينفتح في العربية أصلًا.
       Slide with inset-inline-start rather than translateX: a logical property
       knows the direction itself, so no separate RTL rule is needed. The old
       RTL rule outranked .sidebar.open, so the drawer never opened in Arabic. */
    .sidebar {
        inset-inline-start: calc(var(--sidebar-w) * -1);
        transition: inset-inline-start .25s ease;
    }

    .sidebar.open { inset-inline-start: 0; }

    .shell { margin-inline-start: 0; }
    .sidebar-open { display: inline-grid; }
    .user-chip span { display: none; }
}

@media (max-width: 575.98px) {
    .content { padding: 1rem .8rem 2rem; }
    .topbar { padding-inline: .8rem; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* --------------------------------------------------------------------------
   واجهة المطبخ والمجسّم
   -------------------------------------------------------------------------- */
.kitchen-elev { display: block; max-width: none; }

.kitchen-elev .elev-body  { fill: #F2EDE4; stroke: var(--navy-700); stroke-width: 1.2; }
.kitchen-elev .elev-floor { stroke: var(--slate-400); stroke-width: 2; }
.kitchen-elev .elev-code  { font-family: var(--font-mono); font-size: 8px; font-weight: 700; fill: var(--navy-700); }
.kitchen-elev .elev-w     { font-family: var(--font-mono); font-size: 7px; fill: var(--slate-400); }

.stage-3d {
    width: 100%;
    height: 460px;
    background: linear-gradient(180deg, #FAFBFC, #EEF1F4);
    border-block: 1px solid var(--line);
    cursor: grab;
    touch-action: none;
}

.stage-3d:active { cursor: grabbing; }
.stage-3d canvas { display: block; }

/* --------------------------------------------------------------------------
   الهاتف: أهداف لمس أكبر ومساحة أوضح
   -------------------------------------------------------------------------- */
@media (max-width: 767.98px) {
    /* الأصابع تحتاج مساحة أكبر من مؤشّر الفأرة */
    .sidebar .nav-link { padding-block: .7rem; font-size: .97rem; }
    .icon-btn { width: 40px; height: 40px; }
    .lang-switch { height: 40px; }
    .btn-x { padding-block: .55rem; }

    .toolbar { gap: .5rem; }
    .toolbar form { width: 100%; }
    .toolbar .field { flex: 1 1 100%; min-width: 0; }
    .toolbar .btn-x { flex: 1 1 auto; justify-content: center; }

    /* الجداول تُمرَّر أفقيًا، فنوضّح ذلك بحافة متدرّجة */
    .table-wrap {
        -webkit-overflow-scrolling: touch;
        background:
            linear-gradient(to right, #fff 30%, rgba(255,255,255,0)) left / 24px 100% no-repeat,
            linear-gradient(to left,  #fff 30%, rgba(255,255,255,0)) right / 24px 100% no-repeat,
            linear-gradient(to right, rgba(19,26,38,.10), rgba(19,26,38,0)) left / 10px 100% no-repeat,
            linear-gradient(to left,  rgba(19,26,38,.10), rgba(19,26,38,0)) right / 10px 100% no-repeat;
        background-attachment: local, local, scroll, scroll;
    }

    table.dt th, table.dt td { padding: .55rem .7rem; }

    .stage-3d { height: 340px; }

    .shell-foot { justify-content: center; text-align: center; }
}

@media (max-width: 400px) {
    .stat-grid { grid-template-columns: 1fr; }
    .topbar-title { font-size: .96rem; }
}

/* المؤشّر يتكفّل بالسحب على اللمس، فنمنع تمرير الصفحة داخل اللوحة فقط */
.stage-3d canvas { touch-action: none; }
