:root {
    --bg: #f2f7fa;
    --surface: #ffffff;
    --text: #18354f;
    --blue: #1264d8;
    --muted: #71879a;
    --border: #d8e6ee;
    --running: #16a368;
    --running-soft: #e9f8f1;
    --stopped: #dc3545;
    --stopped-soft: #fff1f2;
    --stopped-border: #efb2b8;
    --closed: #7f8c98;
    --closed-soft: #f1f4f6;
    --cyan: #22b1c9;
    --purple: #972780;
    --orange: #e6631a;
    --shadow: 0 8px 28px rgba(38, 78, 104, .065);
    --card-gap: clamp(7px, .65vh, 12px);
    /* يتم ضبط ارتفاع الكارت من JavaScript على أساس Baseline = 6 أطباء.
       يظل الارتفاع ثابتًا مهما كان العدد الفعلي، وقد تستوعب الشاشة 7/8 إذا كان
       هناك ارتفاع إضافي حقيقي بنفس مقاس الكارت، من غير Stretch أو Shrink حسب العدد. */
    --doctor-card-height: 108px;
    --doctor-image-width: calc(var(--doctor-card-height) * .92);
}

* { box-sizing: border-box; }

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
}

body {
    direction: rtl;
    font-family: Cairo, "Segoe UI", Tahoma, Arial, sans-serif;
    color: var(--text);
    cursor: none;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.display-shell {
    width: 100vw;
    height: 100vh;
    min-width: 320px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: clamp(8px, .9vh, 16px);
    padding: clamp(12px, 1.6vh, 28px) clamp(14px, 2.2vw, 40px) clamp(8px, 1vh, 18px);
    background:
        radial-gradient(circle at 10% 4%, rgba(34,177,201,.08), transparent 26%),
        radial-gradient(circle at 92% 3%, rgba(151,39,128,.045), transparent 23%),
        var(--bg);
}

.display-header {
    min-height: clamp(82px, 9.2vh, 138px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: clamp(14px, 2vw, 34px);
    padding: 0 clamp(4px, .8vw, 14px);
}

.header-main {
    display: flex;
    align-items: center;
    gap: clamp(12px, 1.45vw, 24px);
    min-width: 0;
}

.title-wrap { min-width: 0; }

.brand-mark {
    width: clamp(48px, 5.1vh, 76px);
    height: clamp(48px, 5.1vh, 76px);
    position: relative;
    flex: 0 0 auto;
}

.brand-dot {
    position: absolute;
    width: 52%;
    height: 52%;
    border-radius: 50%;
    border: clamp(5px, .52vh, 8px) solid currentColor;
    background: transparent;
}

.brand-dot-orange { color: var(--orange); right: 0; top: 0; }
.brand-dot-purple { color: var(--purple); left: 0; top: 0; }
.brand-dot-cyan { color: var(--cyan); left: 24%; bottom: 0; }

.display-header h1 {
    margin: 0;
    font-size: clamp(34px, 4.25vh, 64px);
    line-height: 1.05;
    font-weight: 900;
    letter-spacing: -.8px;
    white-space: nowrap;
}

.display-header p {
    margin: clamp(3px, .5vh, 8px) 0 0;
    font-size: clamp(16px, 2.05vh, 28px);
    color: var(--muted);
    font-weight: 600;
    white-space: nowrap;
}

.header-side {
    direction: ltr;
    display: flex;
    align-items: stretch;
    gap: clamp(8px, 1vw, 16px);
    flex: 0 0 auto;
}

.live-count,
.clock-box {
    min-width: clamp(112px, 10.5vw, 176px);
    border: 1px solid var(--border);
    background: rgba(255,255,255,.92);
    border-radius: clamp(16px, 1.5vh, 24px);
    padding: clamp(8px, 1vh, 14px) clamp(12px, 1.2vw, 20px);
    box-shadow: 0 7px 22px rgba(35,72,98,.045);
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.live-count strong {
    font-size: clamp(30px, 3.6vh, 52px);
    line-height: 1;
    color: var(--blue);
    font-weight: 900;
}

.live-count span,
.clock-box span {
    margin-top: 4px;
    font-size: clamp(13px, 1.48vh, 20px);
    color: var(--muted);
    font-weight: 700;
}

.clock-box strong {
    font-size: clamp(24px, 2.85vh, 40px);
    line-height: 1.05;
    color: var(--text);
    font-weight: 900;
}

.display-body {
    min-height: 0;
    position: relative;
    overflow: hidden;
}

.card-height-probe {
    position: absolute;
    width: 1px;
    height: var(--doctor-card-height);
    visibility: hidden;
    pointer-events: none;
}

.connection-banner {
    position: absolute;
    z-index: 20;
    top: 0;
    left: 50%;
    transform: translate(-50%, -8%);
    max-width: 88%;
    padding: 8px 18px;
    border-radius: 0 0 14px 14px;
    background: #fff3db;
    color: #8b5b0a;
    border: 1px solid #f2d69c;
    font-size: clamp(13px, 1.4vh, 19px);
    font-weight: 800;
    box-shadow: 0 8px 24px rgba(86,61,18,.07);
}

.doctors-list {
    width: 100%;
    height: 100%;
    display: grid;
    grid-auto-flow: row;
    grid-auto-rows: var(--doctor-card-height);
    gap: var(--card-gap);
    align-content: start;
}

.doctor-card {
    direction: ltr;
    min-height: 0;
    overflow: hidden;
    display: grid;
    grid-template-columns: clamp(118px, 24%, 190px) minmax(0, 1fr) var(--doctor-image-width);
    align-items: stretch;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: clamp(18px, 1.7vh, 28px);
    box-shadow: var(--shadow);
    position: relative;
    opacity: 1;
    transform: none;
    transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.doctor-card::before {
    content: "";
    position: absolute;
    left: 0;
    top: 16%;
    bottom: 16%;
    width: clamp(5px, .45vw, 8px);
    border-radius: 0 7px 7px 0;
    background: var(--running);
}

/* الطبيب الشغال: الكارت أبيض كما طلب المستخدم. */
.doctor-card.doctor-running {
    background: #fff;
}

/* Stop_Reservation: الكارت كله يتلوّن بالأحمر الفاتح، وليس البادج فقط. */
.doctor-card.doctor-stopped {
    background: linear-gradient(90deg, #fff6f6 0%, var(--stopped-soft) 100%);
    border-color: var(--stopped-border);
    box-shadow: 0 8px 28px rgba(220,53,69,.075);
}

.doctor-card.doctor-stopped::before { background: var(--stopped); }

.doctor-card.doctor-closed {
    background: var(--closed-soft);
    border-color: #d8dfe4;
}

.doctor-card.doctor-closed::before { background: var(--closed); }

.doctor-service-box {
    direction: rtl;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 7px clamp(8px, 1vw, 15px);
    border-right: 1px solid rgba(216,230,238,.9);
    background: rgba(249,252,253,.48);
}

.doctor-stopped .doctor-service-box {
    background: rgba(255,232,234,.46);
    border-right-color: rgba(239,178,184,.85);
}

.doctor-status-text {
    max-width: 100%;
    min-height: clamp(24px, calc(var(--doctor-card-height) * .24), 34px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px clamp(8px, .8vw, 13px);
    border-radius: 999px;
    background: var(--running-soft);
    color: var(--running);
    font-size: clamp(12px, calc(var(--doctor-card-height) * .115), 19px);
    font-weight: 900;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doctor-stopped .doctor-status-text {
    background: #ffe1e4;
    color: var(--stopped);
}

.doctor-closed .doctor-status-text {
    background: #e5eaee;
    color: var(--closed);
}

.current-label {
    margin-top: clamp(4px, calc(var(--doctor-card-height) * .045), 8px);
    color: var(--muted);
    font-size: clamp(11px, calc(var(--doctor-card-height) * .09), 16px);
    line-height: 1.25;
    font-weight: 750;
}

.doctor-current-number {
    margin-top: 1px;
    font-size: clamp(30px, calc(var(--doctor-card-height) * .34), 58px);
    line-height: .95;
    font-weight: 950;
    color: var(--running);
    letter-spacing: -2px;
}

.doctor-stopped .doctor-current-number { color: var(--stopped); }
.doctor-closed .doctor-current-number { color: var(--closed); }

.doctor-info-box {
    direction: rtl;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: 7px clamp(12px, 1.5vw, 24px);
}

.doctor-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: clamp(18px, calc(var(--doctor-card-height) * .19), 34px);
    line-height: 1.2;
    font-weight: 900;
    color: var(--blue);
}

.doctor-stopped .doctor-name { color: #b4232f; }
.doctor-closed .doctor-name { color: #64727f; }

.doctor-clinic {
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: clamp(12px, calc(var(--doctor-card-height) * .115), 21px);
    line-height: 1.3;
    color: var(--muted);
    font-weight: 750;
}

.doctor-location {
    margin-top: 0;
    font-size: clamp(10px, calc(var(--doctor-card-height) * .075), 15px);
    line-height: 1.25;
    color: #8ea0ae;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doctor-numbers {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1px;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid #e7eef3;
}

.doctor-stopped .doctor-numbers { border-top-color: #f1c6ca; }

.metric {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.metric span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #607990;
    font-size: clamp(11px, calc(var(--doctor-card-height) * .105), 18px);
    line-height: 1.3;
    font-weight: 750;
}

.metric strong {
    color: #ef222f;
    font-size: clamp(14px, calc(var(--doctor-card-height) * .13), 24px);
    line-height: 1.1;
    font-weight: 900;
}

.doctor-image-box {
    direction: rtl;
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 0;
}

.doctor-photo,
.doctor-photo-fallback {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    border-radius: 0 clamp(18px, 1.7vh, 28px) clamp(18px, 1.7vh, 28px) 0;
    border: 0;
    border-left: 1px solid #e9f0f4;
    background: #edf2f5;
    object-fit: contain;
    object-position: center bottom;
}

.doctor-stopped .doctor-photo,
.doctor-stopped .doctor-photo-fallback {
    border-left-color: #f3c8cc;
    background: #fff0f1;
}

.doctor-photo-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #8fa5b5;
}

.doctor-photo-fallback svg {
    width: 76%;
    height: 76%;
    fill: none;
    stroke: currentColor;
    stroke-width: 5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.empty-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--muted);
}

.empty-icon {
    width: clamp(76px, 8vh, 112px);
    height: clamp(76px, 8vh, 112px);
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #fff;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    font-size: clamp(52px, 6vh, 72px);
    color: var(--cyan);
    font-weight: 300;
}

.empty-state h2 {
    margin: 20px 0 6px;
    color: var(--text);
    font-size: clamp(25px, 3vh, 40px);
}

.empty-state p {
    margin: 0;
    font-size: clamp(16px, 1.8vh, 24px);
}

.display-footer {
    min-height: clamp(28px, 3.3vh, 48px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 6px;
    color: var(--muted);
    font-size: clamp(11px, 1.2vh, 17px);
}

.update-status {
    display: flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
}

.connection-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #b8c3cc;
    box-shadow: 0 0 0 3px rgba(184,195,204,.16);
}

.connection-dot.online { background: var(--running); box-shadow: 0 0 0 3px rgba(34,160,107,.13); }
.connection-dot.offline { background: var(--stopped); box-shadow: 0 0 0 3px rgba(220,53,69,.12); }

.separator { color: #b6c2cb; }
.footer-brand { font-weight: 800; color: #6f8799; }

.is-hidden { display: none !important; }

/* الشاشات العرضية: نحتفظ بارتفاع كارت مريح ولا نحشر النص لمجرد زيادة العدد. */
@media (orientation: landscape) {
    :root { --doctor-image-width: calc(var(--doctor-card-height) * .95); }
    .display-header { min-height: clamp(76px, 11vh, 112px); }
    .doctor-card { grid-template-columns: clamp(150px, 18%, 230px) minmax(0, 1fr) var(--doctor-image-width); }
    .doctor-name { font-size: clamp(18px, calc(var(--doctor-card-height) * .18), 32px); }
    .doctor-clinic { font-size: clamp(12px, calc(var(--doctor-card-height) * .11), 20px); }
    .doctor-current-number { font-size: clamp(32px, calc(var(--doctor-card-height) * .34), 58px); }
    .doctor-info-box { padding-block: 7px; }
    .doctor-image-box { padding: 0; }
}

@media (max-width: 720px) {
    .display-shell { padding-inline: 10px; }
    .header-side .clock-box { display: none; }
    .doctor-card { grid-template-columns: clamp(108px, 25%, 150px) minmax(0, 1fr) var(--doctor-image-width); }
    .doctor-service-box { padding-inline: 7px; }
    .doctor-info-box { padding: 6px 10px; gap: 1px; }
    .doctor-name { font-size: clamp(17px, calc(var(--doctor-card-height) * .19), 28px); }
    .doctor-clinic { font-size: clamp(11px, calc(var(--doctor-card-height) * .11), 18px); }
    .metric span { font-size: clamp(10px, calc(var(--doctor-card-height) * .10), 16px); }
    .metric strong { font-size: clamp(14px, calc(var(--doctor-card-height) * .13), 21px); }
    .doctor-location { display: none !important; }
    .doctor-image-box { padding: 0; }
    .footer-brand { display: none; }
}


/* عندما يكون ارتفاع الكارت قريبًا من مقاس الستة في شاشة قصيرة،
   نخفي Location فقط ونحافظ على الاسم/العيادة/الأرقام كاملة بدون قص. */
@media (max-height: 950px) {
    .doctor-location { display: none !important; }
    .doctor-info-box { justify-content: center; }
    .doctor-numbers { margin-top: 3px; padding-top: 3px; }
}

@media (prefers-reduced-motion: reduce) {
    .doctor-card { transition: none; }
}
