/* ═══════════════════════════════════════════════════════════════════════════
   components.css — أنماط مكوّنات Tesla الجديدة القابلة لإعادة الاستعمال

   ⚠️ ملفّ ساكن يُربط في App.razor ولا يمرّ ببناء Tailwind — نفس سبب delivery.css:
      app.css مُدخَل لا مخرَج، وإعادة توليد tailwind-output.css المُودَع تُسقط أصنافاً
      انجرفت عن المصدر. والبادئة tsl- حتى لا تصطدم بأصناف tesla- القائمة.

   الرموز من رموز اللوحة (app.css: --primary, --muted, --foreground…) فيتبع الوضع الليليّ
   تلقائياً بلا كتلة خاصّة.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── TeslaSegmented — شريط مقسّم ─── */
.tsl-seg {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border-radius: 999px;
    background: hsl(var(--muted));
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
}
.tsl-seg::-webkit-scrollbar { display: none; }

.tsl-seg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 14px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: hsl(var(--muted-foreground));
    font: inherit;
    font-size: 13.5px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s, color .15s, box-shadow .15s;
    min-height: 0;   /* app.css تفرض 44px على كل button فينتفخ الشريط */
}
.tsl-seg-btn:hover { color: hsl(var(--foreground)); }
.tsl-seg-btn:focus-visible { outline: 2px solid hsl(var(--primary)); outline-offset: 1px; }

.tsl-seg-btn.is-active {
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    font-weight: 600;
    box-shadow: 0 1px 2px hsl(222 47% 10% / .08), 0 1px 1px hsl(222 47% 10% / .04);
}

.tsl-seg-count {
    min-width: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: hsl(var(--background));
    color: hsl(var(--muted-foreground));
    font-size: 11px;
    line-height: 18px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.tsl-seg-btn.is-active .tsl-seg-count {
    background: hsl(var(--primary) / .12);
    color: hsl(var(--primary));
}

/* أزرار متساوية العرض تملأ الشريط */
.tsl-seg--stretch { display: flex; width: 100%; }
.tsl-seg--stretch .tsl-seg-btn { flex: 1 1 0; padding-inline: 6px; }

/* ═══════════════════════════════════════════════════════════════════════════
   TeslaSheet و TeslaPicker

   الألوان من متغيّرات --tsl-* بقيمٍ احتياطية من رموز اللوحة: خارج أيّ شاشة تلبس
   اللوحة، وشاشةٌ لها لوحتها (مثل .ctb) تعرّف المتغيّرات فيلبسان ألوانها بلا نسخة ثانية.
   ═══════════════════════════════════════════════════════════════════════════ */

.tsl-sheet, .tsl-pick {
    text-align: start;
    --_surface: var(--tsl-surface, hsl(var(--card)));
    --_tonal: var(--tsl-tonal, hsl(var(--muted)));
    --_tonal-2: var(--tsl-tonal-2, hsl(var(--accent)));
    --_line: var(--tsl-line, hsl(var(--border)));
    --_line-2: var(--tsl-line-2, hsl(var(--input)));
    --_ink: var(--tsl-ink, hsl(var(--foreground)));
    --_ink-2: var(--tsl-ink-2, hsl(var(--foreground) / .8));
    --_ink-3: var(--tsl-ink-3, hsl(var(--muted-foreground)));
    --_brand: var(--tsl-brand, hsl(var(--primary)));
    --_brand-tint: var(--tsl-brand-tint, hsl(var(--primary) / .1));
    --_brand-line: var(--tsl-brand-line, hsl(var(--primary) / .35));
    --_mono: var(--tsl-mono, ui-monospace, Consolas, monospace);
    --_warn: var(--tsl-warn, hsl(var(--warning)));
    --_warn-tint: var(--tsl-warn-tint, hsl(var(--warning) / .12));
}

/* ─── TeslaSheet ─── */
.tsl-scrim {
    position: fixed; inset: 0;
    z-index: 90;
    background: rgba(18, 26, 47, .35);
    backdrop-filter: blur(2px);
    animation: tsl-fade .2s ease-out;
}
.tsl-sheet {
    position: fixed;
    z-index: 95;
    left: 50%; top: 50%;
    width: min(520px, calc(100vw - 32px));
    max-height: min(86vh, 720px);
    display: grid;
    grid-template-rows: auto auto 1fr;
    border-radius: var(--tsl-r-xl, 22px);
    background: var(--_surface);
    color: var(--_ink);
    box-shadow: var(--tsl-sh-3, 0 -4px 24px rgba(18, 26, 47, .08), 0 8px 40px -10px rgba(18, 26, 47, .35));
    direction: rtl;
    transform: translate(-50%, -50%);
    animation: tsl-pop .18s ease-out;
}
.tsl-sheet-handle { display: none; }
.tsl-sheet-h { display: flex; align-items: center; gap: 10px; padding: 18px 20px 8px; }
.tsl-sheet-h h3 { margin: 0; font-size: 16px; font-weight: 600; }
.tsl-sheet-sub { font-size: 12.5px; color: var(--_ink-3); }
.tsl-sheet-x {
    margin-inline-start: auto;
    width: 36px; height: 36px; min-height: 0;
    display: inline-grid; place-items: center;
    flex: none;
    border: 0; border-radius: 50%;
    background: var(--_tonal);
    color: var(--_ink-2);
    cursor: pointer;
}
.tsl-sheet-x:hover { background: var(--_tonal-2); }
.tsl-sheet-x svg { width: 17px; height: 17px; }
.tsl-sheet-b { display: grid; gap: 10px; align-content: start; padding: 8px 20px 20px; }
.tsl-sheet-b.is-scroll { overflow: auto; }

/* رفضُ ما في النافذة يُكتب فيها تحت محتواها. النصّ بلون الحبر، واللون الدلاليّ في الأيقونة والتظليل */
.tsl-sheet-err {
    display: flex; align-items: flex-start; gap: 8px;
    padding: 10px 12px;
    border-radius: var(--tsl-r-s, 9px);
    background: var(--_warn-tint);
    color: var(--_ink);
    font-size: 14px; font-weight: 600; line-height: 1.55;
}
.tsl-sheet-err svg { width: 17px; height: 17px; flex: none; margin-top: 2px; color: var(--_warn); }

@keyframes tsl-fade { from { opacity: 0; } }
@keyframes tsl-pop { from { opacity: 0; transform: translate(-50%, -50%) scale(.96); } }
@keyframes tsl-rise { from { transform: translateY(100%); } }

@media (max-width: 640px) {
    .tsl-sheet {
        left: 0; right: 0; top: auto;
        /* فوق الكيبورد: --tsl-kb يضبطه tslSheet.trackKeyboard من visualViewport */
        bottom: var(--tsl-kb, 0px);
        width: 100%;
        max-height: min(88vh, calc(var(--tsl-vvh, 100vh) - 16px));
        transition: bottom .15s ease-out;
        border-radius: var(--tsl-r-xl, 22px) var(--tsl-r-xl, 22px) 0 0;
        padding-bottom: env(safe-area-inset-bottom);
        transform: none;
        animation: tsl-rise .22s ease-out;
    }
    .tsl-sheet-handle { display: block; width: 40px; height: 4px; margin: 10px auto 0; border-radius: 2px; background: var(--_line-2); }
    .tsl-sheet-h { padding-top: 10px; }
}

/* ─── TeslaPicker ─── */
.tsl-pick { position: relative; min-width: 0; }
.tsl-pick-trig {
    position: relative;
    display: flex; align-items: center; gap: 8px;
    width: 100%; height: 46px; min-height: 0;
    padding-inline: 14px 10px;
    border: 0; border-radius: var(--tsl-r-s, 9px);
    background: var(--_surface);
    box-shadow: inset 0 0 0 1px var(--_line-2);
    color: var(--_ink);
    font: inherit;
    text-align: start;
    cursor: pointer;
    transition: box-shadow .15s;
}
.tsl-pick-trig.is-sm { height: 40px; font-size: 13.5px; }
.tsl-pick-trig:hover { box-shadow: inset 0 0 0 1px var(--_ink-3); }
.tsl-pick-trig:focus-visible, .tsl-pick-trig.is-open { outline: 0; box-shadow: inset 0 0 0 2px var(--_brand); }
.tsl-pick-trig:disabled { opacity: .5; cursor: not-allowed; }
.tsl-pick-lbl { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 500; }
.tsl-pick-lbl.is-ph { color: var(--_ink-3); font-weight: 400; }
.tsl-pick-sub { flex: none; font-size: 12px; color: var(--_ink-3); font-family: var(--_mono); }
.tsl-pick-chev { width: 16px; height: 16px; flex: none; color: var(--_ink-3); transition: transform .15s; }
.tsl-pick-trig.is-open .tsl-pick-chev { transform: rotate(180deg); }
.tsl-pick-clr { width: 22px; height: 22px; display: grid; place-items: center; flex: none; border-radius: 50%; color: var(--_ink-3); }
.tsl-pick-clr:hover { background: var(--_tonal-2); color: var(--_ink); }
.tsl-pick-clr svg { width: 12px; height: 12px; }
.tsl-pick-trig .tsl-pick-av { width: 24px; height: 24px; font-size: 11px; background: var(--_brand-tint); color: var(--_brand); }
.tsl-pick .is-mono { font-family: var(--_mono); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; text-align: start; }

.tsl-pick-pop {
    position: absolute;
    top: calc(100% + 6px);
    inset-inline-start: 0;
    z-index: 120;
    width: max(100%, 280px);
    max-width: calc(100vw - 24px);
    max-height: 320px;
    overflow: auto;
    overscroll-behavior: contain;
    border-radius: var(--tsl-r-m, 12px);
    background: var(--_surface);
    border: 1px solid var(--_line);
    box-shadow: var(--tsl-sh-2, 0 2px 6px rgba(18, 26, 47, .06), 0 12px 32px -14px rgba(18, 26, 47, .22));
    animation: tsl-fade .12s ease-out;
}
.tsl-pick-pop[data-up="true"] { top: auto; bottom: calc(100% + 6px); }
.tsl-pick-search { position: sticky; top: 0; z-index: 1; padding: 8px; background: var(--_surface); border-bottom: 1px solid var(--_line); }
.tsl-pick-search > svg { position: absolute; inset-inline-start: 18px; top: 19px; width: 15px; height: 15px; color: var(--_ink-3); pointer-events: none; z-index: 1; }
.tsl-pick-search input {
    width: 100%; height: 38px; min-height: 0;
    border: 0; border-radius: var(--tsl-r-s, 9px);
    padding-inline: 34px 12px;
    background: var(--_tonal);
    color: var(--_ink);
    font: inherit;
}
.tsl-pick-search input:focus { outline: 0; box-shadow: 0 0 0 2px var(--_brand-line); }
.tsl-pick-row {
    display: flex; align-items: center; gap: 10px;
    width: 100%; min-height: 0;
    padding: 10px 14px;
    border: 0; border-bottom: 1px solid var(--_line);
    background: none;
    color: inherit;
    font: inherit;
    text-align: start;
    cursor: pointer;
}
.tsl-pick-row:last-child { border-bottom: 0; }
.tsl-pick-row:hover, .tsl-pick-row.is-act { background: var(--_tonal); }
.tsl-pick-row.is-sel { background: var(--_brand-tint); }
.tsl-pick-row.is-sel .tsl-pick-l { color: var(--_brand); }
.tsl-pick-t { flex: 1; min-width: 0; display: grid; gap: 1px; }
.tsl-pick-l { font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tsl-pick-s { font-size: 11.5px; color: var(--_ink-3); font-family: var(--_mono); direction: ltr; text-align: start; unicode-bidi: isolate; }
.tsl-pick-c { flex: none; font-size: 11.5px; color: var(--_ink-3); font-family: var(--_mono); }
.tsl-pick-ck { width: 18px; height: 18px; flex: none; color: var(--_brand); opacity: 0; }
.tsl-pick-row.is-sel .tsl-pick-ck { opacity: 1; }
.tsl-pick-av { width: 30px; height: 30px; display: grid; place-items: center; flex: none; border-radius: 50%; background: var(--_tonal-2); color: var(--_ink-2); font-size: 12.5px; font-weight: 600; }
.tsl-pick-row.is-sel .tsl-pick-av { background: var(--_brand); color: #fff; }
.tsl-pick-empty { padding: 16px 14px; color: var(--_ink-3); font-size: 13px; text-align: center; }

/* app.css تفرض 16px على كل input لمنع تكبير iOS — تبقى على اللمس وتُرفع على الماوس */
@media (hover: hover) and (pointer: fine) {
    .tsl-pick-search input { font-size: 14px !important; }
}
@media (prefers-reduced-motion: reduce) {
    .tsl-scrim, .tsl-sheet, .tsl-pick-pop { animation: none; }
}
