/* ============================
   Scorpius Dental Clinic - Custom Theme
   ============================ */

:root {
    --primary: #0d9488;
    --primary-dark: #0f766e;
    --primary-light: #14b8a6;
    --primary-bg: #f0fdfa;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --info: #06b6d4;
    --body-bg: #f1f5f9;
    --card-shadow: 0 1px 15px rgba(0,0,0,0.06);
    --card-radius: 14px;
    /* Monthly finance chart. The green/red pair is stepped apart in lightness so the
       columns stay distinct for colour-blind readers; dashboard.js reads these too. */
    --chart-income: #16a34a;
    --chart-income-hover: #22c55e;
    --chart-expenses: #b91c1c;
    --chart-expenses-hover: #dc2626;
}

/* ---- Global ---- */
body {
    font-family: 'Cairo', sans-serif;
    background: var(--body-bg);
    direction: rtl;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main { flex: 1; }

/* The patient screen is dense with white cards and charts, so it sits on a slightly
   deeper ground than the rest of the app to keep those panels reading as panels. */
body.page-patient {
    background: #e2e8f0;
}

a { text-decoration: none; }

/* ---- Navbar ---- */
.clinic-navbar {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
    box-shadow: 0 4px 20px rgba(13,148,136,0.3);
    padding: 0.6rem 1.2rem;
}
.clinic-navbar .navbar-brand {
    font-size: 1.2rem;
    letter-spacing: -0.3px;
}
.navbar-logo {
    height: 40px;
    width: auto;
    border-radius: 8px;
}
.clinic-navbar .nav-link {
    color: rgba(255,255,255,0.85) !important;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transition: all 0.2s;
}
.clinic-navbar .nav-link:hover,
.clinic-navbar .nav-link.active {
    color: #fff !important;
    background: rgba(255,255,255,0.15);
}

/* ---- Navbar quick access: patient search + today's appointments ---- */
.nav-search {
    position: relative;
    width: 250px;
    margin: 0 .5rem;
}
.nav-search .form-control {
    padding-inline-start: 2rem;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,0.18);
    color: #fff;
}
.nav-search .form-control::placeholder { color: rgba(255,255,255,0.75); }
.nav-search .form-control:focus {
    background: #fff;
    color: #0f172a;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.35);
}
.nav-search-icon {
    position: absolute;
    inset-inline-start: .65rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: .8rem;
    color: rgba(255,255,255,0.8);
    pointer-events: none;
}
.nav-search:focus-within .nav-search-icon { color: #64748b; }
.nav-search-results {
    position: absolute;
    top: calc(100% + 4px);
    inset-inline-start: 0;
    width: 100%;
    min-width: 260px;
    max-height: 340px;
    overflow-y: auto;
}
.nav-today-menu {
    min-width: 280px;
    max-height: 380px;
    overflow-y: auto;
}
.nav-today-head {
    padding: .5rem 1rem;
    font-size: .8rem;
    font-weight: 700;
    color: #64748b;
    border-bottom: 1px solid #e2e8f0;
}
.nav-today-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .5rem 1rem;
}
.nav-today-time {
    font-size: .8rem;
    font-weight: 700;
    color: var(--primary);
    min-width: 4.5rem;
}
.nav-today-item.is-done { opacity: .6; }

/* The bar also carries the user, role, clinic and subscription badges, so on a
   laptop-width screen the links must not wrap onto two lines and the search gives
   up width first. */
.clinic-navbar .nav-link { white-space: nowrap; }
@media (min-width: 992px) and (max-width: 1399.98px) {
    .nav-search { width: 190px; }
    .clinic-navbar .nav-link { padding: 0.5rem 0.6rem; }
}
/* Below 1300px the full labels no longer fit beside the badges (at 1024 the bar ran
   170px past the screen), so the links show their icon alone; each keeps its name
   as a tooltip. Under 992px they are back in full in the collapsed menu. */
@media (min-width: 992px) and (max-width: 1299.98px) {
    .clinic-navbar .nav-text { display: none; }
    .clinic-navbar .nav-link .fas { margin-inline-end: 0 !important; font-size: 1.05rem; }
}

/* In the collapsed phone menu the search takes the full row. */
@media (max-width: 991.98px) {
    .nav-search { width: 100%; margin: .5rem 0; }
}

/* The stock link's picture, sized to sit on the line like the font icons beside it.
   Where those links drop to their icon alone, so does this one. */
.nav-stock-icon { width: 22px; height: 22px; vertical-align: -5px; }
@media (min-width: 992px) and (max-width: 1299.98px) {
    .clinic-navbar .nav-stock-icon { margin-inline-end: 0 !important; }
}

/* ---- "COMPLETED" stamp (patient page, treatment finished) ----
   Fixed over the whole viewport and tilted like a rubber stamp. Translucent and
   pointer-transparent, so everything underneath stays readable and usable. Sits under
   the navbar dropdowns and Bootstrap modals (z-index 1050+). */
.treatment-stamp {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 1020;
    overflow: hidden;
}
.treatment-stamp-inner {
    transform: rotate(-24deg);
    border: .09em solid currentColor;
    border-radius: .12em;
    padding: .05em .35em .1em;
    color: rgba(220, 38, 38, .32);
    font-size: clamp(3.2rem, 15vw, 12rem);
    font-weight: 800;
    line-height: 1;
    text-align: center;
    direction: ltr;
    /* An inner rule, as on a real stamp. */
    box-shadow: inset 0 0 0 .03em rgba(255, 255, 255, .6), inset 0 0 0 .06em currentColor;
    animation: stamp-in .35s cubic-bezier(.2, 1.4, .4, 1) both;
}
.treatment-stamp-word { letter-spacing: .06em; }
.treatment-stamp-date {
    font-size: .22em;
    font-weight: 700;
    letter-spacing: .1em;
    margin-top: .1em;
}
@keyframes stamp-in {
    from { transform: rotate(-24deg) scale(1.6); opacity: 0; }
    to   { transform: rotate(-24deg) scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .treatment-stamp-inner { animation: none; }
}
@media print {
    .treatment-stamp { position: absolute; }
}

/* ---- Dropped-out patients (dashboard patients table) ----
   Last visit over three months ago with nothing booked: the whole row reads red. */
#patientsTable tbody tr.patient-dropped > td {
    background-color: #fef2f2;
    color: #b91c1c;
}
#patientsTable tbody tr.patient-dropped:hover > td { background-color: #fee2e2; }
#patientsTable tbody tr.patient-dropped .text-muted { color: #dc2626 !important; opacity: .8; }

/* ---- Device logos (users page login column) ---- */
.device-chip { font-size: .85rem; }
.device-logo {
    display: inline-flex;
    align-items: flex-end;
    gap: 1px;
    font-size: 1.05rem;
    cursor: default;
}
/* The small phone / tablet / laptop shape beside the Apple logo. */
.device-logo .device-shape {
    font-size: .6rem;
    color: #64748b;
}

/* ---- Cards ---- */
.clinic-card {
    border: none;
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    overflow: hidden;
}
.clinic-card:hover {
    box-shadow: 0 4px 25px rgba(0,0,0,0.1);
}
.clinic-card .card-header {
    background: #fff;
    border-bottom: 2px solid var(--primary-bg);
    font-weight: 700;
    padding: 1rem 1.25rem;
    color: var(--primary-dark);
}

/* ---- Summary Cards ---- */
.summary-card {
    display: flex;
    align-items: center;
    padding: 1.5rem;
    border-radius: var(--card-radius);
    background: #fff;
    box-shadow: var(--card-shadow);
    border-right: 5px solid;
    transition: transform 0.2s;
}
.summary-card:hover {
    transform: translateY(-3px);
}
.card-expenses { border-right-color: var(--danger); }
.card-collected { border-right-color: var(--success); }
.card-balance { border-right-color: var(--info); }

.card-expenses .summary-icon { color: var(--danger); background: #fef2f2; }
.card-collected .summary-icon { color: var(--success); background: #f0fdf4; }
.card-balance .summary-icon { color: var(--info); background: #ecfeff; }

.summary-icon {
    width: 60px;
    height: 60px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-left: 1rem;
    flex-shrink: 0;
}
.summary-info { flex: 1; }
.summary-value {
    font-size: 1.6rem;
    font-weight: 800;
    margin: 0;
    color: #1e293b;
}
.summary-label {
    font-size: 0.85rem;
    color: #64748b;
    margin: 0;
}

/* ---- Monthly finance chart (dashboard, doctor only) ---- */
/* White, so the logo's own white ground blends into the button. */
.btn-finance-chart {
    --bs-btn-bg: #fff;
    --bs-btn-hover-bg: #fff;
    --bs-btn-active-bg: #fff;
    --bs-btn-border-color: #cbd5e1;
    --bs-btn-hover-border-color: var(--primary);
    --bs-btn-active-border-color: var(--primary);
    --bs-btn-focus-shadow-rgb: 13, 148, 136;
    flex-shrink: 0;
    width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(15,23,42,0.08);
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
/* Outranks the small-screen .btn padding rule, which would squeeze the logo. */
button.btn.btn-finance-chart { padding: 0 !important; }
.btn-finance-chart img {
    width: 28px;
    height: 28px;
    display: block;
}
@media (max-width: 768px) {
    .btn-finance-chart img { width: 24px; height: 24px; }
}
.btn-finance-chart:hover,
.btn-finance-chart:focus-visible {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(13,148,136,0.25);
}

.finance-chart-modal .modal-body { padding: 1.25rem 1.5rem 1.5rem; }

.finance-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.finance-year {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem;
    background: var(--primary-bg);
    border-radius: 999px;
}
.finance-year-btn {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--primary-dark);
    transition: background 0.2s, box-shadow 0.2s;
}
.finance-year-btn:hover:not(:disabled),
.finance-year-btn:focus-visible {
    background: #fff;
    box-shadow: 0 2px 8px rgba(13,148,136,0.18);
    outline: none;
}
.finance-year-btn:disabled { opacity: 0.35; cursor: default; }
.finance-view-toggle .btn {
    --bs-btn-active-bg: var(--primary);
    --bs-btn-active-border-color: var(--primary);
    --bs-btn-active-color: #fff;
}
.finance-year-label {
    min-width: 4.5rem;
    text-align: center;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--primary-dark);
}

.finance-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
.finance-stat {
    padding: 0.85rem 1rem;
    background: #f8fafc;
    border: 1px solid #eef2f6;
    border-radius: 12px;
}
.finance-stat-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #64748b;
}
.finance-stat-value {
    margin-top: 0.15rem;
    font-size: 1.4rem;
    font-weight: 800;
    color: #1e293b;
    direction: ltr;
    text-align: right;
}
.finance-net-icon { color: #94a3b8; }
.finance-net-icon.is-up { color: var(--chart-income); }
.finance-net-icon.is-down { color: var(--chart-expenses); }

/* Series keys: a swatch in the legend and stat tiles, a short line in the tooltip. */
.finance-key {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}
.finance-key-income { background: var(--chart-income); }
.finance-key-expenses { background: var(--chart-expenses); }

/* Left to right like the chart below it, so income sits on the same side as its columns. */
.finance-legend {
    direction: ltr;
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: #475569;
}
.finance-legend > span { display: inline-flex; align-items: center; gap: 0.4rem; }

/* Fixed height includes the month labels, so the chart never scrolls inside itself. */
.finance-chart-wrap { position: relative; height: 380px; }
.finance-chart-wrap canvas { transition: opacity 0.25s; }
.finance-chart-wrap.is-loading canvas { opacity: 0.35; }
.finance-chart-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    text-align: center;
    font-weight: 600;
    color: #64748b;
    pointer-events: none;
}
.finance-chart-loading { font-size: 1.6rem; color: var(--primary); }
.finance-chart-wrap.is-loading .finance-chart-loading,
.finance-chart-wrap.has-message:not(.is-loading) .finance-chart-message { display: flex; }

.finance-tooltip {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 5;
    min-width: 200px;
    padding: 0.6rem 0.8rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(15,23,42,0.14);
    font-size: 0.85rem;
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.15s, transform 0.15s;
}
.finance-tooltip.show { opacity: 1; transform: translateY(0); }
.ft-title { margin-bottom: 0.3rem; font-weight: 700; color: #0f172a; }
.ft-row { display: flex; align-items: center; gap: 0.5rem; line-height: 1.9; }
.ft-key { width: 14px; height: 3px; border-radius: 2px; flex-shrink: 0; }
.ft-label { flex: 1; color: #64748b; }
.ft-value {
    font-weight: 800;
    color: #0f172a;
    direction: ltr;
    unicode-bidi: isolate;
    font-variant-numeric: tabular-nums;
}
.ft-net { margin-top: 0.3rem; padding-top: 0.3rem; border-top: 1px solid #eef2f6; }

.finance-table td,
.finance-table th { white-space: nowrap; }
.finance-num {
    display: inline-block;
    direction: ltr;
    font-variant-numeric: tabular-nums;
}
.finance-table tr.is-quiet > td { color: #94a3b8; }

@media (max-width: 576px) {
    .finance-chart-modal .modal-body { padding: 1rem; }
    .finance-stats { grid-template-columns: 1fr; gap: 0.5rem; }
    .finance-stat {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.5rem;
        padding: 0.6rem 0.85rem;
    }
    .finance-stat-value { margin-top: 0; font-size: 1.1rem; }
    .finance-chart-wrap { height: 300px; }
    .finance-tooltip { min-width: 170px; font-size: 0.8rem; }
}

/* ---- Amounts ---- */
.amount-red { color: var(--danger) !important; font-weight: 700; }
.amount-green { color: var(--success) !important; font-weight: 700; }

/* ---- Buttons ---- */
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}
.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}
.btn-outline-primary:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.btn-info {
    background: var(--info);
    border-color: var(--info);
}

/* ---- Patient Image ---- */
.patient-image-wrapper {
    position: relative;
    display: inline-block;
}
.patient-image {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid var(--primary-bg);
    box-shadow: 0 4px 15px rgba(13,148,136,0.2);
}
.image-upload-btn {
    position: absolute;
    bottom: 5px;
    left: 5px;
    width: 36px;
    height: 36px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: background 0.2s;
}
.image-upload-btn:hover {
    background: var(--primary-dark);
}

/* ---- Modal ---- */
.clinic-modal-header {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff;
    border: none;
}

/* ---- Account gear: the navbar cog and its two popups ----
   Rendered on every page for a signed-in user, and the only screens a secretary on a
   phone reaches without a table in front of them - so they are sized for a thumb
   rather than inheriting the app's dense desktop form styling. */
.account-gear-btn {
    min-width: 38px;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
/* The caret doubles the button's width for no information; the cog already reads
   as a menu. */
.account-gear-btn.dropdown-toggle::after { display: none; }

.account-gear-menu {
    border: none;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(15,23,42,0.18);
    padding: 0.4rem;
    min-width: 15rem;
}
.account-gear-menu .dropdown-item {
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.account-gear-menu .dropdown-item:active {
    background: var(--primary);
    color: #fff;
}
.account-gear-menu .dropdown-item:active i { color: #fff !important; }

.account-modal .modal-content {
    border: none;
    border-radius: var(--card-radius);
    overflow: hidden;
}
.account-modal .modal-body { padding: 1.25rem; }
.account-field { margin-bottom: 1rem; }

/* Bootstrap rounds only the outer corners of an input group, and in RTL it is the
   toggle that owns the left pair - stated here so the reveal button cannot end up
   square against a rounded field. */
.account-password .form-control { border-inline-end: 0; }
.account-password .btn {
    border-color: var(--bs-border-color, #dee2e6);
    color: #64748b;
    background: #fff;
}
.account-password .btn:hover,
.account-password .btn:focus {
    background: var(--primary-bg);
    color: var(--primary-dark);
}

.suggestion-welcome {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    background: var(--primary-bg);
    border: 1px solid rgba(13,148,136,0.25);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
    color: var(--primary-dark);
    font-weight: 600;
    line-height: 1.6;
}
.suggestion-welcome i { color: var(--primary); margin-top: 0.25rem; }

#suggestionText { min-height: 8rem; resize: vertical; }

/* ---- Account gear popups on a phone ----
   The app-wide mobile block below shrinks every .form-control to 0.8rem and every
   .btn to 0.3rem of padding, which is right for a data table and wrong for these two
   forms: under 16px iOS zooms the page on focus, and the buttons fall well under a
   thumb's target. These selectors are more specific, so they win it back. */
@media (max-width: 576px) {
    /* Only while modal-fullscreen-sm-down is in force: above this the dialog is a
       centred card again and must keep its own height. */
    .account-modal .modal-dialog { margin: 0; }
    .account-modal .modal-content { border-radius: 0; height: 100%; }
}

@media (max-width: 768px) {
    /* Pinned, so the actions stay put while the keyboard is open and only the fields
       between them scroll. */
    .account-modal .modal-header {
        position: sticky;
        top: 0;
        z-index: 2;
        padding: 0.9rem 1rem;
    }
    .account-modal .modal-title { font-size: 1.05rem !important; }
    .account-modal .btn-close {
        padding: 0.75rem;
        margin: -0.5rem;
        opacity: 0.9;
    }

    .account-modal .modal-body {
        padding: 1.15rem 1rem;
        -webkit-overflow-scrolling: touch;
    }
    .account-field { margin-bottom: 1.15rem; }

    .account-modal .form-label {
        font-size: 0.95rem !important;
        font-weight: 700;
        margin-bottom: 0.4rem;
    }
    .account-modal .form-text { font-size: 0.85rem; }

    /* 16px exactly: the threshold under which mobile Safari zooms into the field and
       leaves the rest of the form off-screen. */
    .account-modal .form-control,
    .account-modal textarea.form-control {
        font-size: 16px !important;
        padding: 0.75rem 0.85rem !important;
        min-height: 3rem;
        border-radius: 10px;
    }
    .account-password .btn {
        font-size: 1rem !important;
        padding: 0.5rem 0.9rem !important;
        min-width: 3rem;
    }

    #suggestionText { min-height: 10rem; }

    /* Full-width stacked actions, primary on top where the thumb rests. */
    .account-modal .modal-footer {
        position: sticky;
        bottom: 0;
        z-index: 2;
        background: #fff;
        display: flex;
        flex-direction: column;
        gap: 0.6rem;
        padding: 0.9rem 1rem calc(0.9rem + env(safe-area-inset-bottom));
        border-top: 1px solid #e2e8f0;
    }
    .account-modal .modal-footer > .btn {
        width: 100%;
        margin: 0;
        font-size: 1rem !important;
        padding: 0.8rem 1rem !important;
        border-radius: 10px;
        font-weight: 700;
    }

    /* The phone gear sits beside the hamburger, outside the collapse. */
    .account-gear-btn {
        min-width: 42px;
        min-height: 42px;
        font-size: 1rem !important;
        padding: 0.4rem !important;
    }
    .account-gear-menu {
        min-width: 14rem;
        margin-top: 0.5rem;
    }
    .account-gear-menu .dropdown-item {
        padding: 0.8rem 0.75rem;
        font-size: 0.95rem;
    }
}

/* ---- Card tables (.rwd-table) ----
   The admin screens are six-column tables, which on a phone shrink to 12px text and
   icon buttons a thumb cannot hit. Below 768px each row becomes its own card: the
   first cell is the card's title and every other cell prints its column header beside
   the value, so nothing has to be read out of a header row that scrolled away.

   Done in CSS off a data-label attribute rather than by rendering a second markup
   tree, so the desktop table stays the single source of the row. */
.rwd-card-actions .btn { margin: 0; }

/* Shown only once the row is a card; the desktop table stays icon-only with tooltips. */
.rwd-btn-label { display: none; }

/* "إضافة مستخدم" otherwise breaks across two lines next to the clinic filter. */
.admin-toolbar .btn { white-space: nowrap; }

/* Free-text cells keep a readable column on a desktop table; the phone card relaxes
   this below, which an inline min-width could not do. */
.rwd-table td.rwd-block {
    white-space: pre-wrap;
    min-width: 18rem;
}

@media (max-width: 768px) {
    .rwd-table thead { display: none; }

    .rwd-table,
    .rwd-table tbody,
    .rwd-table td {
        display: block;
        width: 100%;
    }

    /* A flex column rather than a plain block, so .rwd-title can be hoisted to the top
       of the card with order even when its column sits mid-table (the inbox leads with
       the date, but the clinic is what names the card). */
    .rwd-table tr {
        display: flex;
        flex-direction: column;
        width: 100%;
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        box-shadow: 0 1px 6px rgba(15,23,42,0.05);
        padding: 0.85rem 1rem;
        margin-bottom: 0.85rem;
    }
    /* DataTables stripes and hover would repaint the card. */
    .rwd-table tbody tr:hover,
    .rwd-table tbody tr.odd,
    .rwd-table tbody tr.even { background: #fff; }

    .rwd-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        text-align: start;
        border: none !important;
        padding: 0.4rem 0 !important;
        font-size: 0.9rem !important;
        line-height: 1.5;
    }
    .rwd-table td::before {
        content: attr(data-label);
        font-weight: 700;
        color: #64748b;
        font-size: 0.8rem;
        flex: 0 0 auto;
    }

    /* The row's identity - clinic or user name - reads as the card's heading. */
    .rwd-table td.rwd-title {
        display: block;
        order: -1;
        font-size: 1.02rem !important;
        font-weight: 800;
        color: var(--primary-dark);
        padding: 0 0 0.5rem !important;
        margin-bottom: 0.4rem;
        border-bottom: 1px solid #f1f5f9 !important;
    }
    .rwd-table td.rwd-title::before { content: none; }

    /* Free text (a suggestion) needs the width, so it drops under its label. */
    .rwd-table td.rwd-block {
        display: block;
        white-space: pre-wrap;
        min-width: 0;
        overflow-wrap: anywhere;
    }
    .rwd-table td.rwd-block::before {
        display: block;
        margin-bottom: 0.25rem;
    }

    /* Actions become a full-width row of thumb-sized buttons. */
    .rwd-table td.rwd-card-actions {
        display: flex;
        order: 99;
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: stretch;
        padding-top: 0.75rem !important;
        margin-top: 0.4rem;
        border-top: 1px solid #f1f5f9 !important;
    }
    .rwd-table td.rwd-card-actions::before { content: none; }
    /* Two per row: with a word beside each icon, four across a 390px card would leave
       every one of them too narrow to read or hit. */
    .rwd-table td.rwd-card-actions .btn {
        flex: 1 1 45%;
        min-width: 6.5rem;
        min-height: 2.75rem;
        font-size: 0.9rem !important;
        margin: 0 !important;
    }
    /* A tooltip has nowhere to appear on a touch screen, so the title attribute these
       buttons carry is invisible - the label has to be on the button itself. */
    .rwd-card-actions .rwd-btn-label {
        display: inline;
        margin-inline-start: 0.4rem;
    }

    /* The empty-state row is one centred message, not a labelled field. */
    .rwd-table td[colspan] { display: block; text-align: center; }
    .rwd-table td[colspan]::before { content: none; }

    /* ---- The admin card headers and DataTables controls ----
       A header built as a flex row of a filter, a switch and a button overflows a
       phone; stacked full-width, each one is its own tap target. */
    .admin-toolbar {
        flex-direction: column;
        align-items: stretch !important;
    }
    .admin-toolbar > * { width: 100%; }
    .admin-toolbar .form-select,
    .admin-toolbar .btn { min-height: 2.75rem; }
    .admin-toolbar .btn { font-size: 0.95rem !important; }

    /* DataTables 2.x renamed its wrappers (dt-search / dt-info / dt-paging); the
       older dataTables_* names are kept for anything still emitting them. */
    .dt-search, .dataTables_filter { width: 100%; text-align: start !important; }
    .dt-search input, .dataTables_filter input {
        width: 100% !important;
        font-size: 16px !important;
        min-height: 2.6rem;
        margin: 0.35rem 0 0 !important;
    }
    .dt-paging .pagination { flex-wrap: wrap; justify-content: center; }
    .dt-paging .page-link { min-width: 2.4rem; min-height: 2.4rem; }
    .dt-info, .dataTables_info { text-align: center; }
}

/* ---- Expenses total row ---- */
.expenses-total-row th {
    background: var(--primary-bg);
    border-top: 2px solid var(--primary);
    font-weight: 800;
    color: var(--primary-dark);
    font-size: 0.95rem;
}

/* ---- Day Appointments: clickable patient name ---- */
.day-patient-link {
    color: var(--primary-dark);
    font-weight: 700;
    transition: color 0.2s ease;
}
.day-patient-link:hover {
    color: var(--primary-light);
    text-decoration: underline;
}

/* ---- Patient Search Dropdown (Add Appointment Modal) ---- */
.patient-search-spinner {
    position: absolute;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    color: var(--primary);
    font-size: 1rem;
    pointer-events: none;
    z-index: 3;
}
.patient-search-results {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    z-index: 1080;
    max-height: 220px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 0 0 8px 8px;
}

/* ---- Premium Calendar ---- */
.fc {
    font-family: 'Cairo', sans-serif !important;
    direction: rtl;
    --fc-border-color: transparent;
    --fc-today-bg-color: transparent;
    background: #e9edf2;
    border: 1px solid #dfe4ea;
    border-radius: 20px;
    padding: 1.5rem;
    box-shadow: 0 10px 30px rgba(13, 148, 136, 0.06);
}

/* Remove grid lines - day cells become floating cards */
.fc .fc-scrollgrid,
.fc .fc-scrollgrid td,
.fc .fc-scrollgrid th {
    border: none !important;
}

/* Toolbar */
.fc .fc-header-toolbar {
    margin-bottom: 1.5rem !important;
}
.fc .fc-toolbar-title {
    font-weight: 800;
    font-size: 1.5rem;
    color: transparent;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-light) 100%);
    -webkit-background-clip: text;
    background-clip: text;
}
.fc .fc-button-primary {
    background: #fff !important;
    color: var(--primary-dark) !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 12px !important;
    font-weight: 700;
    padding: 0.45rem 1rem;
    box-shadow: 0 2px 8px rgba(15, 118, 110, 0.08);
    transition: all 0.25s ease !important;
}
.fc .fc-button-primary:hover {
    background: var(--primary) !important;
    color: #fff !important;
    border-color: var(--primary) !important;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(13, 148, 136, 0.25);
}
.fc .fc-button-primary:not(:disabled):active, .fc .fc-button-primary:not(:disabled).fc-button-active {
    background: var(--primary-dark) !important;
    color: #fff !important;
    transform: translateY(0);
}
.fc .fc-today-button {
    background: linear-gradient(135deg, var(--primary), var(--primary-light)) !important;
    color: #fff !important;
    border: none !important;
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.3);
}
.fc .fc-today-button:disabled {
    background: #f1f5f9 !important;
    color: #94a3b8 !important;
    border: 1px solid #e2e8f0 !important;
    box-shadow: none;
    opacity: 1;
}
.fc-button-group > .fc-button {
    margin: 0 2px;
}

/* Weekday headers */
.fc .fc-col-header-cell {
    background: transparent;
    padding: 10px 0 14px;
}
.fc .fc-col-header-cell-cushion {
    color: var(--primary-dark) !important;
    font-weight: 800;
    font-size: 0.82rem !important;
    letter-spacing: 0.5px;
}

/* Day cells as floating cards */
.fc .fc-daygrid-day {
    padding: 4px;
}
.fc .fc-daygrid-day-frame {
    position: relative;
    background: #f8fafc;
    border: 1px solid #eef2f7;
    border-radius: 14px;
    min-height: 112px !important;
    overflow: hidden;
    transition: transform 0.22s ease, box-shadow 0.22s ease, background 0.22s ease, border-color 0.22s ease;
}
.fc .fc-daygrid-day:not(.fc-day-other):hover .fc-daygrid-day-frame {
    background: #ffffff;
    border-color: rgba(13, 148, 136, 0.35);
    box-shadow: 0 10px 22px rgba(13, 148, 136, 0.14);
    transform: translateY(-3px);
    cursor: pointer;
}

/* "+" hint that appears when hovering a day */
.fc .fc-daygrid-day:not(.fc-day-other) .fc-daygrid-day-frame::after {
    content: '+';
    position: absolute;
    bottom: 7px;
    left: 8px;
    width: 22px;
    height: 22px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    font-size: 15px;
    font-weight: 800;
    line-height: 22px;
    text-align: center;
    box-shadow: 0 3px 8px rgba(13, 148, 136, 0.35);
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}
.fc .fc-daygrid-day:not(.fc-day-other):hover .fc-daygrid-day-frame::after {
    opacity: 1;
    transform: scale(1);
}

/* Day numbers */
.fc .fc-daygrid-day-number {
    color: #334155 !important;
    font-weight: 700;
    font-size: 0.92rem;
    padding: 8px 12px;
}

/* Weekend (Fri/Sat) subtle teal tint */
.fc .fc-day-fri:not(.fc-day-other) .fc-daygrid-day-frame,
.fc .fc-day-sat:not(.fc-day-other) .fc-daygrid-day-frame {
    background: linear-gradient(180deg, #f0fdfa 0%, #f8fafc 100%);
}

/* Other-month days */
.fc .fc-day-other .fc-daygrid-day-frame {
    background: transparent;
    border: 1px dashed #b8c0cc;
}
.fc .fc-day-other .fc-daygrid-day-number {
    color: #1e293b !important;
    font-weight: 600;
}

/* Today */
.fc .fc-day-today .fc-daygrid-day-frame {
    background: linear-gradient(150deg, rgba(20, 184, 166, 0.12) 0%, rgba(13, 148, 136, 0.04) 55%, #ffffff 100%);
    border: 2px solid var(--primary);
    box-shadow: 0 8px 22px rgba(13, 148, 136, 0.18);
}
.fc .fc-day-today .fc-daygrid-day-number {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary-light));
    color: #fff !important;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 6px;
    padding: 0;
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.4);
}
.fc .fc-day-today .fc-daygrid-day-frame::before {
    content: 'اليوم';
    position: absolute;
    bottom: 7px;
    right: 50%;
    transform: translateX(50%);
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff;
    font-size: 0.63rem;
    font-weight: 700;
    padding: 1px 10px 2px;
    border-radius: 20px;
    box-shadow: 0 3px 8px rgba(13, 148, 136, 0.35);
    pointer-events: none;
}

/* Appointment dots — column direction so dots fill top→bottom, then wrap to a new column */
.fc .fc-daygrid-day-events {
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: wrap !important;
    gap: 3px !important;
    padding: 2px 3px 3px !important;
    max-height: 60px !important;
    min-height: unset !important;
    align-content: flex-start !important;
    overflow: hidden !important;
}
.fc .fc-daygrid-event-harness {
    width: auto !important;
    flex: 0 0 auto !important;
    margin: 0 !important;
    position: static !important;
}
/* Event Styling */
.fc .fc-event,
.fc .fc-daygrid-event,
.fc .fc-h-event,
.fc .fc-v-event {
    background: transparent !important;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 0 !important;
    transition: transform 0.2s ease;
    width: 12px !important;
    height: 12px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}
.fc-daygrid-event:hover {
    transform: scale(1.35);
    cursor: pointer;
    z-index: 5;
}
.fc .fc-event-main {
    background: transparent !important;
    color: transparent !important;
    width: 12px !important;
    height: 12px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Appointment dots (rendered by dashboard.js eventContent) */
.appt-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #fff;
}
.appt-dot-pending {
    background: radial-gradient(circle at 30% 30%, #fca5a5, #dc2626);
    animation: apptPulse 2.4s ease-out infinite;
}
.appt-dot-done {
    background: radial-gradient(circle at 30% 30%, #86efac, #16a34a);
    box-shadow: 0 2px 6px rgba(22, 163, 74, 0.4);
}
@keyframes apptPulse {
    0%   { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.45); }
    70%  { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

/* Event Dot (if list-item is used) */
.fc .fc-daygrid-event-dot {
    border-color: #ffffff !important;
}
/* More elegant scrollbar for calendar */
.fc-scroller::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.fc-scroller::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}
.fc-scroller::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
.fc-scroller::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ---- DataTables RTL ---- */
.dataTables_wrapper {
    direction: rtl;
}
.dataTables_wrapper .dataTables_filter {
    text-align: right !important;
}
.dataTables_wrapper .dataTables_info {
    text-align: right !important;
}
table.dataTable thead th {
    font-weight: 700;
    color: var(--primary-dark);
    border-bottom: 2px solid var(--primary-bg);
    font-size: 0.9rem;
    text-align: right !important;
}
table.dataTable tbody tr:hover {
    background: var(--primary-bg) !important;
}

.patient-note-trigger {
    color: inherit !important;
    font-size: 0.95rem;
    font-weight: 400;
    line-height: 1.5;
    white-space: normal;
    text-decoration: none !important;
}
.patient-note-trigger:hover,
.patient-note-trigger:focus {
    color: var(--primary-dark) !important;
    text-decoration: none !important;
}

/* ---- Login Page ---- */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f766e 0%, #0d9488 30%, #14b8a6 60%, #2dd4bf 100%);
    position: relative;
    overflow: hidden;
}
.login-body::before {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    background: rgba(255,255,255,0.05);
    border-radius: 50%;
    top: -100px;
    right: -100px;
}
.login-body::after {
    content: '';
    position: absolute;
    width: 300px;
    height: 300px;
    background: rgba(255,255,255,0.05);
    border-radius: 50%;
    bottom: -80px;
    left: -80px;
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 1rem;
    position: relative;
    z-index: 1;
}
.login-card {
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    padding: 2.5rem;
    animation: fadeInUp 0.6s ease-out;
}
.login-header {
    text-align: center;
    margin-bottom: 2rem;
}
.login-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    box-shadow: 0 8px 25px rgba(13,148,136,0.3);
}
.login-icon i {
    font-size: 2rem;
    color: #fff;
}
/* The logo art is a square with its own dark background and gold ring, so it needs
   no white plate behind it — and no circular mask, which would clip the wordmark. */
.login-logo {
    width: 150px;
    height: auto;
    object-fit: contain;
    border-radius: 16px;
    margin: 0 auto 1.25rem;
    display: block;
    box-shadow: 0 10px 30px rgba(15,23,42,0.28);
}
.login-title {
    color: #1e3a5f;
    font-size: 1.4rem;
}
.login-form .form-control {
    border-radius: 10px;
    padding: 0.75rem 1rem;
    border: 2px solid #e2e8f0;
    transition: border-color 0.3s, box-shadow 0.3s;
}
.login-form .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13,148,136,0.15);
}
.login-form .form-floating > label {
    right: 1rem;
    left: auto;
}
.login-btn {
    border-radius: 10px;
    padding: 0.8rem;
    font-weight: 700;
    font-size: 1.1rem;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    border: none;
    box-shadow: 0 4px 15px rgba(13,148,136,0.3);
    transition: transform 0.2s, box-shadow 0.2s;
}
.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(13,148,136,0.4);
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}
.login-footer {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
}

/* ---- Footer ---- */
.clinic-footer {
    background: #fff;
    border-top: 1px solid #e2e8f0;
    margin-top: auto;
}

/* ---- Animations ---- */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(30px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .summary-card { padding: 1rem; }
    .summary-value { font-size: 1.2rem; }
    .summary-icon { width: 45px; height: 45px; font-size: 1.2rem; }
    .patient-image { width: 110px; height: 110px; }
    .login-card { padding: 1.5rem; }
    .patient-name-cell,
    .patient-phone-cell,
    .patient-date-cell {
        font-size: 0.8rem;
        line-height: 1.25;
    }
    .patient-date-cell .badge {
        font-size: 0.68rem;
        padding: 0.35rem 0.45rem;
    }
    .patient-note-trigger {
        font-size: 0.78rem;
        line-height: 1.25;
        display: inline-block;
        max-width: 160px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Calendar Mobile Fixes */
    .fc {
        padding: 0.5rem !important;
        border-radius: 12px !important;
    }
    .fc .fc-toolbar-title {
        font-size: 1.1rem !important;
    }
    .fc .fc-button-primary {
        padding: 0.3rem 0.6rem !important;
        font-size: 0.8rem !important;
    }
    .fc .fc-col-header-cell-cushion {
        font-size: 0.55rem !important;
        padding: 1px !important;
        display: block !important;
        text-align: center !important;
    }
    .fc .fc-daygrid-day-number {
        font-size: 0.75rem !important;
        padding: 4px !important;
    }
    .fc .fc-daygrid-day {
        padding: 2px;
    }
    .fc .fc-daygrid-day-frame {
        min-height: 50px !important;
        border-radius: 8px;
    }
    .fc .fc-day-today .fc-daygrid-day-number {
        width: 24px !important;
        height: 24px !important;
        margin: 3px !important;
    }
    /* Hide decorative badges on small cells */
    .fc .fc-daygrid-day-frame::before,
    .fc .fc-daygrid-day-frame::after {
        display: none !important;
    }
    .appt-dot {
        width: 9px;
        height: 9px;
        border-width: 1px;
    }
    .fc .fc-daygrid-day-events {
        gap: 2px !important;
        padding: 1px 2px 2px !important;
        max-height: 44px !important;
    }
    .fc .fc-event,
    .fc .fc-daygrid-event,
    .fc .fc-h-event,
    .fc .fc-v-event,
    .fc .fc-event-main {
        width: 9px !important;
        height: 9px !important;
        margin: 0 !important;
    }

    /* Table & Field Shrinking on Mobile */
    table th, table.dataTable thead th {
        font-size: 0.75rem !important;
        padding: 8px 4px !important;
    }
    table td, table.dataTable tbody td {
        font-size: 0.75rem !important;
        padding: 8px 4px !important;
    }
    .form-label, label, .form-floating > label {
        font-size: 0.78rem !important;
    }
    .form-control, .form-select, select, input {
        font-size: 0.8rem !important;
        padding: 0.375rem 0.75rem !important;
    }
    .form-floating > .form-control {
        padding-top: 1.625rem !important;
        padding-bottom: 0.625rem !important;
    }
    .form-floating > label {
        padding: 1rem 0.75rem !important;
    }
    .card-header h5, .modal-title {
        font-size: 0.95rem !important;
    }
    .btn:not(.navbar-toggler) {
        font-size: 0.8rem !important;
        padding: 0.3rem 0.6rem !important;
    }
    .btn-lg {
        font-size: 0.95rem !important;
        padding: 0.5rem 1rem !important;
    }
    .dataTables_wrapper .dataTables_filter label,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate,
    .dataTables_wrapper .dataTables_length label {
        font-size: 0.72rem !important;
    }
    .dataTables_wrapper .dataTables_filter input {
        font-size: 0.75rem !important;
        padding: 0.2rem 0.5rem !important;
    }
}

/* ---- Print ---- */
@media print {
    .clinic-navbar, .clinic-footer, .btn, .image-upload-btn { display: none !important; }
    .clinic-card { box-shadow: none; border: 1px solid #ddd; }
    body { background: #fff; }
}
