/* ==========================================================================
   AWACO Console — شیوه‌نامهٔ ظاهری
   --------------------------------------------------------------------------
   طراحی از صفر برای یک کنسول کنترل IoT. تیره‌محور، چون این صفحه ساعت‌ها
   روی مانیتور اتاق کنترل باز می‌ماند و سطح سفید بزرگ خسته‌کننده است.

   ── منطق رنگ (تزئینی نیست، خوانده می‌شود) ──────────────────────────────
     کهربایی  →  خروجی فعال است. «برق دارد می‌رود.»
     خاکستری  →  خروجی خاموش است. حالت عادی.
     آبی‌فیروزه‌ای → رنگ خودِ رابط. هیچ معنای وضعیتی ندارد.
     قرمز     →  خطا: برد قطع است، فرمان نرسیده، احراز اصالت شکست خورده.
     سبز      →  سلامت: برد آنلاین، فرمان تأیید شده.

   نکتهٔ مهم: در نسخهٔ قبل «روشن» قرمز بود که غلط است — قرمز باید فقط
   یعنی «مشکل». اپراتوری که ده رلهٔ روشن می‌بیند نباید ده هشدار قرمز ببیند.
   ========================================================================== */

@font-face {
    font-family: 'YekanNewFace';
    src: url('../fonts/YekanNewFaceD4.ttf') format('truetype');
    font-weight: 100 900;
    font-display: swap;
}

:root {
    /* ---------- سطوح ---------- */
    --bg-0:   #0A0E14;   /* پس‌زمینهٔ صفحه */
    --bg-1:   #111823;   /* کارت */
    --bg-2:   #18212E;   /* ورودی، سطح بالاتر */
    --bg-3:   #212C3B;   /* هاور */
    --line:   #2A3749;
    --line-2: #3A4A5E;

    /* ---------- متن ---------- */
    /* نسبت کنتراست روی کارت (#111823):  t-1 = ۱۶٫۴   t-2 = ۹٫۴   t-3 = ۵٫۹
       t-3 قبلاً #5D6E85 بود با نسبت ۳٫۴ که زیر حد AA برای متن عادی است و
       عملاً دیده نمی‌شد — همان چیزی که در راهنماها و زیرنویس‌ها استفاده می‌شد. */
    --t-1: #F2F6FB;
    --t-2: #AEBECF;
    --t-3: #8496AC;

    /* ---------- برند ---------- */
    --brand:      #35C5E3;
    --brand-2:    #1BA5C4;
    --brand-dim:  rgba(53,197,227,.12);
    --brand-line: rgba(53,197,227,.35);

    /* ---------- وضعیت ---------- */
    --on:        #F5A524;          /* خروجی فعال */
    --on-dim:    rgba(245,165,36,.13);
    --on-line:   rgba(245,165,36,.42);
    --on-glow:   rgba(245,165,36,.22);

    --ok:        #22C55E;
    --ok-dim:    rgba(34,197,94,.13);
    --warn:      #EAB308;
    --warn-dim:  rgba(234,179,8,.13);
    --bad:       #FB7185;   /* روشن‌تر تا روی سطح تیره به AA برسد */
    --bad-dim:   rgba(251,113,133,.14);
    --bad-line:  rgba(251,113,133,.45);

    /* ---------- فاصله ---------- */
    --s1: 4px;  --s2: 8px;  --s3: 12px;
    --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;

    /* ---------- شعاع ---------- */
    --r1: 6px; --r2: 10px; --r3: 14px; --r4: 20px; --rf: 999px;

    /* ---------- سایه ---------- */
    --sh1: 0 1px 2px rgba(0,0,0,.4);
    --sh2: 0 4px 12px rgba(0,0,0,.35);
    --sh3: 0 12px 32px rgba(0,0,0,.45);
    --ring: 0 0 0 3px rgba(53,197,227,.22);

    --ease: cubic-bezier(.4,0,.2,1);

    --sidebar: 246px;
    --topbar: 62px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
    font-family: 'YekanNewFace', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg-0);
    color: var(--t-1);
    font-size: 14px;
    line-height: 1.75;
    direction: rtl;
    -webkit-font-smoothing: antialiased;
}

/* گرادیان بسیار ملایم بالای صفحه تا سطح تیره کاملاً تخت نباشد */
body::before {
    content: ''; position: fixed; inset: 0 0 auto 0; height: 380px; z-index: 0;
    background: radial-gradient(900px 380px at 82% -12%, rgba(53,197,227,.10), transparent 70%);
    pointer-events: none;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: #5FD6EF; }

h1,h2,h3,h4 { margin: 0; font-weight: 700; letter-spacing: -.2px; color: var(--t-1); }
h1 { font-size: 21px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

.muted   { color: var(--t-2); }
.dim     { color: var(--t-3); }
.sm      { font-size: 12.5px; }
.xs      { font-size: 11.5px; }
.nowrap  { white-space: nowrap; }
.center  { text-align: center; }
.mono    { font-family: ui-monospace,'SF Mono',Consolas,monospace; direction: ltr; unicode-bidi: embed; letter-spacing: .3px; }
.grow    { flex: 1; }
.row     { display: flex; align-items: center; gap: var(--s3); }
.row-b   { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.stack   { display: flex; flex-direction: column; gap: var(--s2); }

/* ==========================================================================
   پوستهٔ برنامه
   ========================================================================== */

/* ⚠ z-index اینجا یک بافتار انباشتگی می‌سازد. هر چیزی که باید روی کشو
   یا زیر آن بنشیند، باید *داخل* همین عنصر باشد وگرنه اعدادش با ۱ مقایسه
   می‌شود، نه با ۱۰۰ی کشو. پرده به همین دلیل داخل است. */
.shell { display: flex; min-height: 100vh; position: relative; z-index: 1; }

/* ==========================================================================
   ناوبری — نوار کناری و کشوی موبایل
   --------------------------------------------------------------------------
   ⚠ این ماژول عمداً از خصوصیات *فیزیکی* استفاده می‌کند (right / left)
     نه منطقی (inset-inline-start / end).

     دلیلش یک اشتباه واقعی در نسخهٔ قبل بود: نوشته بودم
     `inset-inline-end: 0` با این تصور که «end یعنی راست». اما در RTL
     محور inline از راست به چپ می‌رود، پس:

         inline-start = راست        inline-end = چپ

     یعنی کشو به لبهٔ چپ سنجاق شده بود و translateX(100%) به‌جای اینکه
     بیرونش کند، وسط صفحه می‌آوردش. نتیجه: منویی که نصف صفحه را می‌گرفت
     و بسته نمی‌شد.

     این برنامه فقط فارسی و فقط RTL است (dir روی <html> ثابت است)، پس
     خصوصیت فیزیکی هم درست‌تر است هم خواناتر و هم جای اشتباه نمی‌گذارد.

   ── قرارداد ─────────────────────────────────────────────────────────────
     نوار کناری همیشه سمت راست است.
     بسته  = translateX(100%)  یعنی به راست، بیرون از صفحه
     باز   = translateX(0)
   ========================================================================== */

.side {
    width: var(--sidebar);
    flex: 0 0 var(--sidebar);
    background: var(--bg-1);
    border-left: 1px solid var(--line);   /* لبهٔ رو به محتوا */
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
}

/* ---------------------------- سربرگ کشو ---------------------------- */

.side-brand {
    height: var(--topbar); flex: 0 0 var(--topbar);
    display: flex; align-items: center; gap: 10px;
    padding: 0 var(--s4);
    border-bottom: 1px solid var(--line);
}
.side-brand .mark {
    width: 32px; height: 32px; border-radius: 9px; flex: 0 0 32px;
    background: linear-gradient(140deg, var(--brand), var(--brand-2));
    display: grid; place-items: center;
    color: #04222B; font-weight: 800; font-size: 14px;
    box-shadow: 0 2px 10px rgba(53,197,227,.3);
}
.side-brand .txt { min-width: 0; }
.side-brand .name { font-weight: 700; font-size: 14.5px; line-height: 1.25; }
.side-brand .sub  { font-size: 11px; color: var(--t-3); line-height: 1; }

/* دکمهٔ بستن: روی دسکتاپ اصلاً وجود ندارد.
   در نسخهٔ قبل فقط داخل media query تعریف شده بود و بیرون از آن هیچ
   قاعده‌ای مخفی‌اش نمی‌کرد — به همین دلیل روی دسکتاپ یک ✕ خام دیده می‌شد. */
.side-brand .close { display: none; }

/* ---------------------------- فهرست ---------------------------- */

.side-nav { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: var(--s4) var(--s3); }
.side-nav::-webkit-scrollbar { width: 6px; }
.side-nav::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }

.nav-label {
    font-size: 10.5px; font-weight: 700; letter-spacing: .8px;
    color: var(--t-3); padding: 0 var(--s3); margin: var(--s4) 0 var(--s2);
}
.nav-label:first-child { margin-top: 0; }

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px var(--s3); border-radius: var(--r2);
    color: var(--t-2); font-size: 13.5px; font-weight: 500;
    transition: background .15s var(--ease), color .15s var(--ease);
    position: relative;
}
.nav-item .ico { width: 18px; text-align: center; font-size: 15px; flex: 0 0 18px; opacity: .9; }
.nav-item:hover { background: var(--bg-2); color: var(--t-1); }
.nav-item:focus-visible { outline: none; box-shadow: var(--ring); }

.nav-item.active { background: var(--brand-dim); color: var(--brand); font-weight: 700; }
/* نوار تأکید سمت راستِ آیتم — لبهٔ بیرونی نوار کناری */
.nav-item.active::before {
    content: ''; position: absolute; right: 0; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 18px; border-radius: 3px; background: var(--brand);
}

.nav-item .count {
    margin-right: auto; font-size: 11px; font-weight: 700;
    background: var(--bg-3); color: var(--t-2);
    padding: 1px 7px; border-radius: var(--rf);
}
.nav-item.active .count { background: var(--brand); color: #04222B; }

/* ---------------------------- پاورقی ---------------------------- */

.side-foot { border-top: 1px solid var(--line); padding: var(--s3); }
.user-chip {
    display: flex; align-items: center; gap: 10px;
    padding: var(--s2); border-radius: var(--r2); background: var(--bg-2);
}
.user-chip .av {
    width: 32px; height: 32px; border-radius: 9px; flex: 0 0 32px;
    background: var(--bg-3); color: var(--brand);
    display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.user-chip .txt { min-width: 0; }
.user-chip .nm { font-size: 12.5px; font-weight: 600; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .rl { font-size: 10.5px; color: var(--t-3); line-height: 1.2; }

/* ---------------------------- سه‌خط و پرده ---------------------------- */

/* هر دو روی دسکتاپ کاملاً غایب‌اند. */
.burger { display: none; }
.scrim  { display: none; }

/* ---------------------------- نوار بالا -------------------------------- */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar); flex: 0 0 var(--topbar);
    display: flex; align-items: center; gap: var(--s4);
    padding: 0 var(--s5);
    border-bottom: 1px solid var(--line);
    background: rgba(17,24,35,.72);
    backdrop-filter: blur(14px);
    position: sticky; top: 0; z-index: 40;
}
.topbar h1 { font-size: 17px; }
.topbar .crumb { font-size: 11.5px; color: var(--t-3); line-height: 1; }

/* نبض اتصال زنده */
.live {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 11.5px; color: var(--t-2);
    background: var(--bg-2); border: 1px solid var(--line);
    padding: 5px 11px; border-radius: var(--rf);
}
.live .pulse {
    width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
    box-shadow: 0 0 0 0 rgba(34,197,94,.6); animation: pulse 2.4s infinite;
}
.live.stale .pulse { background: var(--bad); animation: none; }
.live.stale { color: var(--bad); border-color: var(--bad-line); }
@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(34,197,94,.5); }
    70%  { box-shadow: 0 0 0 7px rgba(34,197,94,0); }
    100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

.content { padding: var(--s5); max-width: 1560px; width: 100%; }

/* ==========================================================================
   کارت و پنل
   ========================================================================== */

.card {
    background: var(--bg-1); border: 1px solid var(--line);
    border-radius: var(--r3); box-shadow: var(--sh1);
    margin-bottom: var(--s4); overflow: hidden;
}
.card-head {
    display: flex; align-items: center; gap: var(--s3);
    padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line);
}
.card-head h2 { font-size: 14.5px; }
.card-body { padding: var(--s4); }
.card-foot { padding: var(--s3) var(--s4); border-top: 1px solid var(--line); background: var(--bg-2); }

.page-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--s4); margin-bottom: var(--s5); flex-wrap: wrap;
}
.page-head .actions { display: flex; gap: var(--s2); flex-wrap: wrap; }

/* ==========================================================================
   نوار آمار
   ========================================================================== */

.metrics {
    display: grid; gap: var(--s3); margin-bottom: var(--s5);
    grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
}
.metric {
    background: var(--bg-1); border: 1px solid var(--line);
    border-radius: var(--r3); padding: var(--s4);
    display: flex; align-items: center; gap: var(--s3);
    position: relative; overflow: hidden;
}
.metric .ic {
    width: 40px; height: 40px; border-radius: var(--r2); flex: 0 0 40px;
    display: grid; place-items: center; font-size: 18px;
    background: var(--bg-2); color: var(--t-2);
}
.metric .v { font-size: 25px; font-weight: 800; line-height: 1.15; letter-spacing: -.5px; }
.metric .l { font-size: 11.5px; color: var(--t-3); line-height: 1.2; }
.metric.is-on  .ic { background: var(--on-dim);  color: var(--on); }
.metric.is-on  .v  { color: var(--on); }
.metric.is-ok  .ic { background: var(--ok-dim);  color: var(--ok); }
.metric.is-bad .ic { background: var(--bad-dim); color: var(--bad); }
.metric.is-bad .v  { color: var(--bad); }

/* ==========================================================================
   کاشی رله — عنصر اصلی این نرم‌افزار
   ========================================================================== */

.tiles {
    display: grid; gap: var(--s3);
    grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
}

.tile {
    background: var(--bg-1); border: 1px solid var(--line);
    border-radius: var(--r3); padding: var(--s4);
    display: flex; align-items: center; gap: var(--s3);
    transition: border-color .2s var(--ease), background .2s var(--ease), transform .12s var(--ease);
    position: relative;
}
.tile:hover { border-color: var(--line-2); }

/* حالت فعال: قاب کهربایی + هالهٔ ملایم. عمداً پررنگ نیست تا صفحهٔ پر از
   رلهٔ روشن، چشم را نزند. */
.tile.on {
    border-color: var(--on-line);
    background: linear-gradient(180deg, var(--on-dim), transparent 60%), var(--bg-1);
    box-shadow: 0 0 24px -8px var(--on-glow);
}

.tile .ic {
    width: 46px; height: 46px; flex: 0 0 46px; border-radius: var(--r2);
    display: grid; place-items: center; font-size: 21px;
    background: var(--bg-2); color: var(--t-2);
    transition: .2s var(--ease);
}
.tile.on .ic { background: var(--on-dim); color: var(--on); box-shadow: 0 0 0 1px var(--on-line) inset; }

.tile .body { min-width: 0; flex: 1; }
.tile .nm {
    font-size: 14px; font-weight: 600; line-height: 1.35;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile .meta {
    font-size: 11.5px; color: var(--t-3); line-height: 1.4;
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.tile .meta .sep { opacity: .4; }
.tile .st { font-size: 11.5px; font-weight: 700; color: var(--t-3); }
.tile.on .st { color: var(--on); }

/* برد قطع است: کاشی کم‌رنگ می‌شود ولی خوانا می‌ماند */
.tile.offline { opacity: .55; }
.tile.offline .ic { background: var(--bad-dim); color: var(--bad); }

/* فرمان رفته ولی برد تأیید نکرده */
.tile.pending::after {
    content: ''; position: absolute; right: 0; top: 0; bottom: 0;
    width: 3px; border-radius: 3px 0 0 3px; background: var(--warn);
    animation: breathe 1.4s ease-in-out infinite;
}
@keyframes breathe { 0%,100% { opacity: .35; } 50% { opacity: 1; } }

/* ---------------------------- کلید ------------------------------------- */

.sw {
    --w: 52px; --h: 30px;
    width: var(--w); height: var(--h); flex: 0 0 var(--w);
    border-radius: var(--rf); border: 1px solid var(--line-2);
    background: var(--bg-2); cursor: pointer; padding: 0;
    position: relative; transition: .22s var(--ease);
}
.sw::after {
    content: ''; position: absolute; top: 50%; transform: translateY(-50%);
    /* در RTL «خاموش» باید سمت راست باشد (شروع خط) و با روشن شدن به چپ
       برود. با inset-inline-end دقیقاً برعکس می‌شد. */
    right: 3px;
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--t-2); transition: .22s var(--ease);
}
.sw[aria-checked="true"] {
    background: var(--on); border-color: var(--on);
    box-shadow: 0 0 16px -4px var(--on-glow);
}
.sw[aria-checked="true"]::after {
    right: calc(var(--w) - 25px);
    background: #1A1206;
}
.sw:focus-visible { outline: none; box-shadow: var(--ring); }
.sw:disabled { opacity: .4; cursor: not-allowed; }
.sw.busy { opacity: .6; pointer-events: none; }

/* ==========================================================================
   بخش گروه
   ========================================================================== */

.group {
    margin-bottom: var(--s5);
    border: 1px solid var(--line); border-radius: var(--r3);
    background: var(--bg-1); overflow: hidden;
}
.group-head {
    display: flex; align-items: center; gap: var(--s3);
    padding: var(--s3) var(--s4);
    border-bottom: 1px solid var(--line);
    background: var(--bg-2);
}
.group-head .dot { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 9px; }
.group-head .ttl { font-weight: 700; font-size: 14px; }
.group-head .cnt { font-size: 11.5px; color: var(--t-3); }
.group-head .acts { margin-inline-start: auto; display: flex; gap: var(--s2); align-items: center; }
.group-body { padding: var(--s4); }
.group.collapsed .group-body { display: none; }

.caret {
    width: 26px; height: 26px; border-radius: var(--r1); border: none;
    background: transparent; color: var(--t-3); cursor: pointer;
    display: grid; place-items: center; font-size: 12px; transition: .15s var(--ease);
}
.caret:hover { background: var(--bg-3); color: var(--t-1); }
.group.collapsed .caret { transform: rotate(-90deg); }

/* ==========================================================================
   دکمه
   ========================================================================== */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    font-family: inherit; font-size: 13px; font-weight: 600;
    padding: 8px 15px; min-height: 36px;
    border-radius: var(--r2); border: 1px solid var(--line-2);
    background: var(--bg-2); color: var(--t-1);
    cursor: pointer; white-space: nowrap;
    transition: .15s var(--ease);
}
.btn:hover { background: var(--bg-3); border-color: #3A4A5E; color: var(--t-1); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }

.btn-primary {
    background: var(--brand); border-color: var(--brand); color: #04222B;
    box-shadow: 0 2px 10px -2px rgba(53,197,227,.4);
}
.btn-primary:hover { background: #4FD3EE; border-color: #4FD3EE; color: #04222B; }

.btn-on   { background: var(--on-dim);  border-color: var(--on-line);  color: var(--on); }
.btn-on:hover { background: rgba(245,165,36,.2); color: var(--on); }
.btn-off  { background: var(--bg-2); border-color: var(--line-2); color: var(--t-2); }
.btn-bad  { background: var(--bad-dim); border-color: var(--bad-line); color: var(--bad); }
.btn-bad:hover { background: rgba(251,113,133,.22); color: var(--bad); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--t-2); }
.btn-ghost:hover { background: var(--bg-2); color: var(--t-1); }

.btn-sm { padding: 5px 11px; min-height: 30px; font-size: 12px; }
.btn-lg { padding: 11px 22px; min-height: 44px; font-size: 14.5px; }
.btn-block { width: 100%; }
.btn-icon { width: 34px; padding: 0; flex: 0 0 34px; }

/* ==========================================================================
   فرم
   ========================================================================== */

.form-grid { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(240px,1fr)); }
.form-grid .full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--t-2); }
.field .hint { font-size: 11.5px; color: var(--t-3); line-height: 1.65; }
.field .err  { font-size: 11.5px; color: var(--bad); }

.input, .select, .textarea {
    font-family: inherit; font-size: 13.5px; color: var(--t-1);
    background: var(--bg-2); border: 1px solid var(--line-2);
    border-radius: var(--r2); padding: 9px 12px; min-height: 38px;
    transition: .15s var(--ease); width: 100%;
}
.textarea { min-height: 84px; resize: vertical; line-height: 1.8; }
.input:focus, .select:focus, .textarea:focus {
    outline: none; border-color: var(--brand); box-shadow: var(--ring); background: var(--bg-1);
}
.input::placeholder { color: var(--t-3); }
.input[readonly] { background: var(--bg-1); color: var(--t-2); }
.input.bad, .select.bad { border-color: var(--bad); }

.select {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--t-3) 50%),
                      linear-gradient(135deg, var(--t-3) 50%, transparent 50%);
    background-position: left 14px center, left 9px center;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-left: 30px;
}

/* ---------------------------- کنترل قطعه‌ای ---------------------------- */
/* برای انتخاب‌های کوتاه و مهم (نوع رله، مود) — بهتر از select چون همهٔ
   گزینه‌ها هم‌زمان دیده می‌شوند و یک کلیک کمتر دارد. */

.seg { display: flex; gap: 4px; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: var(--r2); padding: 4px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
    flex: 1; text-align: center; cursor: pointer; user-select: none;
    padding: 7px 10px; border-radius: 7px; font-size: 12.5px; font-weight: 600;
    color: var(--t-2); transition: .15s var(--ease); line-height: 1.4;
}
.seg label .sub { display: block; font-size: 10.5px; font-weight: 500; color: var(--t-3); }
.seg label:hover { background: var(--bg-3); color: var(--t-1); }
.seg input:checked + label { background: var(--brand); color: #04222B; }
.seg input:checked + label .sub { color: rgba(4,34,43,.7); }
.seg input:focus-visible + label { box-shadow: var(--ring); }

/* ---------------------------- سوییچ فرم -------------------------------- */

.toggle-row {
    display: flex; align-items: center; gap: var(--s3);
    padding: var(--s3); border: 1px solid var(--line);
    border-radius: var(--r2); background: var(--bg-2); cursor: pointer;
}
.toggle-row:hover { border-color: var(--line-2); }
.toggle-row .tx { flex: 1; min-width: 0; }
.toggle-row .tx b { display: block; font-size: 13px; font-weight: 600; }
.toggle-row .tx span { font-size: 11.5px; color: var(--t-3); line-height: 1.55; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.mini-sw {
    --w: 40px; width: var(--w); height: 23px; flex: 0 0 var(--w);
    border-radius: var(--rf); background: var(--bg-3); border: 1px solid var(--line-2);
    position: relative; transition: .2s var(--ease);
}
.mini-sw::after {
    content: ''; position: absolute; top: 50%; transform: translateY(-50%);
    right: 3px; width: 15px; height: 15px; border-radius: 50%;
    background: var(--t-2); transition: .2s var(--ease);
}
.toggle-row input:checked ~ .mini-sw { background: var(--brand); border-color: var(--brand); }
.toggle-row input:checked ~ .mini-sw::after { right: calc(var(--w) - 19px); background: #04222B; }

/* ---------------------------- بخش شرطی --------------------------------- */
/* فیلدهایی که فقط برای یک نوع رله معنا دارند. */

.when { display: none; }
.when.show { display: block; animation: slide .22s var(--ease); }
@keyframes slide { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: none; } }

.fieldset {
    border: 1px solid var(--line); border-radius: var(--r3);
    padding: var(--s4); background: var(--bg-2);
}
.fieldset > .lg {
    display: flex; align-items: center; gap: 8px;
    font-size: 12.5px; font-weight: 700; color: var(--t-2);
    margin-bottom: var(--s3);
}

/* ==========================================================================
   نشان و برچسب
   ========================================================================== */

.tag {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11px; font-weight: 700; padding: 3px 9px;
    border-radius: var(--r1); background: var(--bg-3); color: var(--t-2);
    border: 1px solid transparent; line-height: 1.7;
}
.tag-on      { background: var(--on-dim);   color: var(--on);   border-color: var(--on-line); }
.tag-off     { background: var(--bg-3);     color: var(--t-2); }
.tag-ok      { background: var(--ok-dim);   color: var(--ok); }
.tag-bad     { background: var(--bad-dim);  color: var(--bad); }
.tag-warn    { background: var(--warn-dim); color: var(--warn); }
.tag-brand   { background: var(--brand-dim);color: var(--brand); }

.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }

/* گزینهٔ انتخابی چندتایی (گروه‌های کاربر، اهداف سناریو) */
.pick {
    display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
    padding: 7px 13px; border-radius: var(--r2);
    border: 1px solid var(--line-2); background: var(--bg-2);
    font-size: 12.5px; color: var(--t-2); transition: .15s var(--ease); user-select: none;
}
.pick input { position: absolute; opacity: 0; pointer-events: none; }
.pick:hover { border-color: #3A4A5E; color: var(--t-1); }
.pick:has(input:checked) { background: var(--brand-dim); border-color: var(--brand-line); color: var(--brand); }

/* ==========================================================================
   جدول
   ========================================================================== */

.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
    text-align: right; font-weight: 700; font-size: 11.5px; color: var(--t-3);
    padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line);
    background: var(--bg-2); white-space: nowrap;
}
table.tbl td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tbody tr { transition: background .12s var(--ease); }
table.tbl tbody tr:hover { background: var(--bg-2); }
table.tbl .acts { display: flex; gap: 6px; justify-content: flex-start; }

.empty { padding: var(--s7) var(--s4); text-align: center; color: var(--t-3); }
.empty .big { font-size: 34px; display: block; margin-bottom: var(--s3); opacity: .5; }
.empty .ttl { font-size: 14px; font-weight: 600; color: var(--t-2); display: block; margin-bottom: 4px; }

/* ==========================================================================
   فیلتر، صفحه‌بندی، پیام
   ========================================================================== */

.filters {
    display: grid; gap: var(--s3); padding: var(--s4);
    border-bottom: 1px solid var(--line);
    grid-template-columns: repeat(auto-fit, minmax(150px,1fr));
    align-items: end;
}
.filters .btn { min-height: 38px; }

.pager { display: flex; gap: 5px; list-style: none; padding: var(--s3) var(--s4); margin: 0; flex-wrap: wrap; justify-content: center; }
.pager li a, .pager li span {
    display: grid; place-items: center; min-width: 33px; height: 33px; padding: 0 9px;
    border-radius: var(--r1); border: 1px solid var(--line);
    font-size: 12.5px; color: var(--t-2); background: var(--bg-2);
}
.pager li a:hover { background: var(--bg-3); color: var(--t-1); }
.pager li.active span { background: var(--brand); border-color: var(--brand); color: #04222B; font-weight: 700; }
.pager li.disabled span { opacity: .35; }

.note {
    display: flex; gap: var(--s3); align-items: flex-start;
    padding: var(--s3) var(--s4); border-radius: var(--r2);
    border: 1px solid var(--line); background: var(--bg-2);
    font-size: 12.5px; line-height: 1.75; margin-bottom: var(--s4);
}
.note .ic { flex: 0 0 auto; font-size: 15px; line-height: 1.5; }
.note-ok   { border-color: rgba(34,197,94,.35);  background: var(--ok-dim); }
.note-bad  { border-color: var(--bad-line);      background: var(--bad-dim); }
.note-warn { border-color: rgba(234,179,8,.35);  background: var(--warn-dim); }
.note-info { border-color: var(--brand-line);    background: var(--brand-dim); }

/* ---------------------------- توست ------------------------------------- */

.toasts { position: fixed; bottom: var(--s5); inset-inline-start: var(--s5); z-index: 200; display: flex; flex-direction: column; gap: var(--s2); }
.toast {
    display: flex; align-items: center; gap: 10px;
    background: var(--bg-2); border: 1px solid var(--line-2);
    border-radius: var(--r2); padding: 11px 15px; box-shadow: var(--sh3);
    font-size: 13px; min-width: 250px; max-width: 400px;
    animation: rise .25s var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.toast.ok  { border-inline-start: 3px solid var(--ok); }
.toast.bad { border-inline-start: 3px solid var(--bad); }
.toast.out { opacity: 0; transform: translateY(8px); transition: .25s var(--ease); }

/* ---------------------------- گفتگوی تأیید ----------------------------- */

.modal-bg {
    position: fixed; inset: 0; z-index: 300; display: none;
    background: rgba(5,8,12,.72); backdrop-filter: blur(3px);
    align-items: center; justify-content: center; padding: var(--s4);
}
.modal-bg.show { display: flex; animation: fade .18s var(--ease); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
    background: var(--bg-1); border: 1px solid var(--line-2);
    border-radius: var(--r3); box-shadow: var(--sh3);
    width: 100%; max-width: 400px; padding: var(--s5);
    animation: pop .22s var(--ease);
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h3 { margin-bottom: var(--s2); }
.modal p { color: var(--t-2); font-size: 13px; margin: 0 0 var(--s5); line-height: 1.8; }
.modal .acts { display: flex; gap: var(--s2); justify-content: flex-start; }

/* ==========================================================================
   ورود
   ========================================================================== */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--s4); position: relative; z-index: 1; }
.login-card {
    width: 100%; max-width: 380px; background: var(--bg-1);
    border: 1px solid var(--line); border-radius: var(--r4);
    padding: var(--s6); box-shadow: var(--sh3);
}
.login-card .mark {
    width: 52px; height: 52px; border-radius: var(--r3); margin: 0 auto var(--s4);
    background: linear-gradient(140deg, var(--brand), var(--brand-2));
    display: grid; place-items: center; color: #04222B; font-weight: 800; font-size: 20px;
    box-shadow: 0 6px 20px -4px rgba(53,197,227,.5);
}

/* ==========================================================================
   پیش‌نمایش زنده (فرم رله)
   ========================================================================== */

.preview {
    position: sticky; top: calc(var(--topbar) + var(--s4));
}
.preview .lb { font-size: 11px; font-weight: 700; color: var(--t-3); letter-spacing: .6px; margin-bottom: var(--s2); }

/* راهنمای جامپر */
.jumpers { display: flex; gap: var(--s2); }
.jmp {
    flex: 1; text-align: center; padding: var(--s2); border-radius: var(--r1);
    border: 1px solid var(--line-2); background: var(--bg-1); font-size: 11.5px;
}
.jmp b { display: block; font-size: 13px; font-family: ui-monospace, monospace; }
.jmp.closed { border-color: var(--brand-line); background: var(--brand-dim); color: var(--brand); }
.jmp.open   { color: var(--t-3); }

/* ==========================================================================
   واکنش‌گرا
   ========================================================================== */

/* ==========================================================================
   موبایل و تبلت
   --------------------------------------------------------------------------
   دو تصمیم:
     ۱. نوار کناری روی صفحهٔ کوچک به آیکن جمع نمی‌شود. آیکن تک‌رنگِ بدون
        متن قابل تشخیص نیست و کاربر باید حدس بزند. به‌جایش کاملاً بیرون
        می‌رود و با سه‌خط، با *متن کامل*، کشویی باز می‌شود.
     ۲. جهت‌ها فیزیکی‌اند (right/left)، نه منطقی. توضیح کامل بالای
        ماژول ناوبری.
   ========================================================================== */

@media (max-width: 900px) {

    /* ---------- پرده ---------- */
    /* position:fixed است، پس با اینکه داخل .shell نشسته، کل دیدگاه را
       می‌پوشاند. تفاوتش با قبل فقط در بافتار انباشتگی است: حالا با کشو
       مقایسه می‌شود (۹۰ < ۱۰۰) نه با کل پوسته. */
    .scrim {
        display: block;
        position: fixed; inset: 0; z-index: 90;
        background: rgba(4,7,11,.66);
        opacity: 0; pointer-events: none;
        transition: opacity .24s var(--ease);
    }

    /* ---------- کشو ---------- */
    /* راست: چون نوار کناری در حالت دسکتاپ هم سمت راست است.
       بسته = ۱۰۰٪ به راست، یعنی کاملاً بیرون از صفحه. */
    .side {
        position: fixed;
        right: 0; left: auto; top: 0;
        z-index: 100;
        width: min(84vw, 300px);
        flex: none;
        height: 100vh; height: 100dvh;
        transform: translateX(100%);
        border-left: 1px solid var(--line);
        will-change: transform;

        /* visibility جدا از transform لازم است: عنصری که فقط با transform
           بیرون رفته، هنوز با Tab قابل فوکوس است و صفحه‌خوان می‌خواندش.
           تأخیرِ ۰٫۲۶ ثانیه‌ای، انیمیشن بسته‌شدن را حفظ می‌کند. */
        visibility: hidden;
        transition: transform .26s var(--ease), visibility 0s linear .26s;
    }

    body.nav-open .side {
        transform: translateX(0);
        visibility: visible;
        box-shadow: -18px 0 40px rgba(0,0,0,.5);
        transition: transform .26s var(--ease), visibility 0s;
    }

    body.nav-open .scrim { opacity: 1; pointer-events: auto; }

    /* قفل اسکرول پس‌زمینه هنگام باز بودن کشو */
    body.nav-open { overflow: hidden; }

    /* آیتم‌ها بزرگ‌تر: هدف لمس‌اند، نه اشاره‌گر. حداقل ۴۴ پیکسل. */
    .nav-item { padding: 12px var(--s3); font-size: 14.5px; min-height: 44px; }
    .nav-item .ico { font-size: 17px; }
    .nav-label { font-size: 11px; margin: var(--s5) 0 var(--s2); }

    /* دکمهٔ بستن — فقط اینجا ظاهر می‌شود */
    .side-brand .close {
        display: grid; place-items: center;
        margin-right: auto;
        width: 36px; height: 36px; border-radius: var(--r2);
        border: 1px solid var(--line-2); background: var(--bg-2);
        color: var(--t-1); font-size: 15px; cursor: pointer;
        font-family: inherit; line-height: 1;
    }
    .side-brand .close:active { background: var(--bg-3); }

    /* ---------- نوار بالا ---------- */
    /* سه‌خط.
       قبلاً display:grid بود؛ با سه فرزند، گرید سه *ردیف* می‌ساخت و
       margin هر خط هم رویش سوار می‌شد — به همین دلیل خط‌ها از هم باز
       بودند. flex ستونی با gap دقیقاً همان چیزی است که لازم است. */
    .burger {
        display: flex; flex-direction: column;
        align-items: center; justify-content: center; gap: 4px;
        width: 40px; height: 40px; flex: 0 0 40px;
        border-radius: var(--r2); border: 1px solid var(--line-2);
        background: var(--bg-2); color: var(--t-1);
        cursor: pointer; padding: 0;
    }
    .burger:active { background: var(--bg-3); }
    .burger span {
        display: block; width: 18px; height: 2px; border-radius: 2px;
        background: currentColor; margin: 0;
    }

    .topbar {
        height: auto; flex-basis: auto; min-height: 58px;
        padding: var(--s2) var(--s4);
        gap: var(--s3); flex-wrap: wrap;
    }
    .topbar h1 { font-size: 16px; line-height: 1.3; }
    .topbar .crumb { font-size: 11px; }

    /* عنوان نباید کنار دکمه‌ها له شود */
    .topbar > div:first-of-type { min-width: 0; flex: 1; }
    .topbar h1, .topbar .crumb {
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }

    /* عملیات صفحه به خط دوم می‌روند و افقی اسکرول می‌شوند تا هرگز
       روی هم نیفتند */
    .topbar .bar-actions {
        order: 3; width: 100%;
        display: flex; gap: var(--s2);
        overflow-x: auto; padding-bottom: 2px;
        scrollbar-width: none;
    }
    .topbar .bar-actions::-webkit-scrollbar { display: none; }
    .topbar .bar-actions .btn { flex: 0 0 auto; }

    .live { font-size: 11px; padding: 4px 9px; }
    .live .txt { display: none; }   /* فقط نقطهٔ نبض می‌ماند */
}

@media (max-width: 720px) {
    .content { padding: var(--s4); }
    .tiles { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .metrics { grid-template-columns: repeat(2, 1fr); }
    .seg { flex-direction: column; }
    .preview { position: static; }

    /* ستون پیش‌نمایش فرم رله زیر فرم می‌آید */
    #relay-form > div { grid-template-columns: 1fr !important; }

    .page-head { gap: var(--s3); }
    .group-head { flex-wrap: wrap; }
    .group-head .acts { margin-inline-start: 0; width: 100%; }
    .group-head .acts .btn { flex: 1; }

    .filters { grid-template-columns: 1fr 1fr; }
    .modal { max-width: none; }
    .toasts { inset-inline: var(--s4); bottom: var(--s4); }
    .toast { min-width: 0; max-width: none; }

    /* جدول‌های عریض روی موبایل اسکرول افقی می‌گیرند */
    table.tbl { min-width: 560px; }
}

@media (max-width: 420px) {
    .metrics { grid-template-columns: 1fr 1fr; }
    .filters { grid-template-columns: 1fr; }
    .btn { padding: 8px 12px; }
}

@media print {
    .side, .topbar, .btn, .filters, .toasts { display: none !important; }
    body { background: #fff; color: #000; }
    .card, .tile { border-color: #ccc; background: #fff; }
}

/* ==========================================================================
   سازگاری — کلاس‌هایی که لاراول یا ویوهای منتقل‌شده تولید می‌کنند
   ========================================================================== */

/* صفحه‌بندی لاراول کلاس pagination می‌سازد، نه pager */
.pagination { display: flex; gap: 5px; list-style: none; padding: var(--s3) var(--s4); margin: 0; flex-wrap: wrap; justify-content: center; }
.pagination li a, .pagination li span {
    display: grid; place-items: center; min-width: 33px; height: 33px; padding: 0 9px;
    border-radius: var(--r1); border: 1px solid var(--line);
    font-size: 12.5px; color: var(--t-2); background: var(--bg-2);
}
.pagination li a:hover { background: var(--bg-3); color: var(--t-1); }
.pagination li.active span { background: var(--brand); border-color: var(--brand); color: #04222B; font-weight: 700; }
.pagination li.disabled span { opacity: .35; }
.pagination svg { width: 14px; height: 14px; }

.form-actions { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s5); }

/* جعبهٔ رشتهٔ جفت‌سازی */
.pairing-box {
    font-family: ui-monospace, monospace; direction: ltr; text-align: left;
    background: var(--bg-2); border: 1px dashed var(--brand-line);
    border-radius: var(--r2); padding: var(--s4); font-size: 13px;
    word-break: break-all; color: var(--brand); line-height: 1.9;
}

/* شبکهٔ خلاصه (صفحهٔ برد) */
.kv { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fit, minmax(190px,1fr)); }
.kv .k { font-size: 11.5px; color: var(--t-3); }
.kv .v { font-size: 13.5px; font-weight: 600; }
