/* ==========================================================================
   MEDIA MONITOR — نظام الرصد الإعلامي
   Newsroom dashboard theme. RTL-first; layered on top of Bootstrap 5 RTL.
   ========================================================================== */

:root {
    --mm-bg: #f1f5f9;
    --mm-surface: #ffffff;
    --mm-sidebar: #0f172a;
    --mm-sidebar-hover: #1e293b;
    --mm-sidebar-active: #2563eb;
    --mm-border: #e2e8f0;
    --mm-text: #0f172a;
    --mm-text-muted: #64748b;
    --mm-primary: #2563eb;
    --mm-success: #15803d;
    --mm-danger: #b91c1c;
    --mm-warning: #b45309;
    --mm-info: #0e7490;
    --mm-radius: .625rem;
    --mm-radius-sm: .375rem;
    --mm-shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
    --mm-shadow-lg: 0 4px 6px -1px rgba(15, 23, 42, .08), 0 2px 4px -2px rgba(15, 23, 42, .06);
    --mm-sidebar-width: 15.5rem;
    --mm-topbar-height: 3.75rem;
}

/* ---------- Arabic typography ----------
   System Arabic faces first, so no webfont download is needed and text
   renders correctly offline and on shared hosting.                        */
body {
    font-family: "Segoe UI", "Noto Naskh Arabic", "Tahoma", "Dubai",
                 "Geeza Pro", "Arabic Typesetting", system-ui, sans-serif;
    background: var(--mm-bg);
    color: var(--mm-text);
    font-size: .9375rem;
    line-height: 1.75;
    -webkit-font-smoothing: antialiased;
}

/* Latin fragments (URLs, tokens, codes) read left-to-right. */
code, pre, [dir="ltr"] {
    font-family: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
}

code {
    font-size: .8125em;
    color: var(--mm-danger);
    background: #f8fafc;
    padding: .1rem .3rem;
    border-radius: .25rem;
    word-break: break-all;
}

.mm-break { word-break: break-all; }
.mm-nowrap { white-space: nowrap; }

.skip-link {
    position: absolute;
    inset-inline-start: 1rem;
    top: .5rem;
    z-index: 2000;
    background: var(--mm-primary);
    color: #fff;
    padding: .5rem .9rem;
    border-radius: var(--mm-radius-sm);
}

/* ==========================================================================
   Shell
   ========================================================================== */
.mm-shell {
    display: flex;
    min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.mm-sidebar {
    width: var(--mm-sidebar-width);
    flex: 0 0 var(--mm-sidebar-width);
    background: var(--mm-sidebar);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1040;
}

.mm-brand {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: 1.1rem 1.15rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.mm-brand-mark {
    display: grid;
    place-items: center;
    width: 2.375rem;
    height: 2.375rem;
    flex-shrink: 0;
    border-radius: var(--mm-radius-sm);
    background: var(--mm-sidebar-active);
    color: #fff;
}

.mm-brand-mark-lg {
    width: 3.25rem;
    height: 3.25rem;
    margin-inline: auto;
    margin-bottom: .75rem;
}

.mm-brand-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.mm-brand-text strong { color: #fff; font-size: .9rem; letter-spacing: .02em; }
.mm-brand-text small { color: #94a3b8; font-size: .75rem; }

.mm-nav {
    padding: .75rem .6rem;
    display: flex;
    flex-direction: column;
    gap: .15rem;
    overflow-y: auto;
    flex: 1;
}

.mm-nav-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .6rem .75rem;
    border-radius: var(--mm-radius-sm);
    color: #cbd5e1;
    text-decoration: none;
    font-size: .875rem;
    transition: background .15s ease, color .15s ease;
}

.mm-nav-link:hover,
.mm-nav-link:focus-visible {
    background: var(--mm-sidebar-hover);
    color: #fff;
}

.mm-nav-link.active {
    background: var(--mm-sidebar-active);
    color: #fff;
    font-weight: 600;
}

.mm-nav-icon { display: grid; place-items: center; flex-shrink: 0; opacity: .9; }
.mm-nav-badge { margin-inline-start: auto; font-size: .6875rem; }

.mm-sidebar-foot {
    padding: .85rem 1.15rem;
    border-top: 1px solid rgba(255, 255, 255, .08);
}

.mm-version { font-size: .75rem; color: #64748b; }

.mm-sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    z-index: 1035;
}

/* ---------- Main column ---------- */
.mm-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.mm-topbar {
    height: var(--mm-topbar-height);
    background: var(--mm-surface);
    border-bottom: 1px solid var(--mm-border);
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: 0 1.1rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.mm-page-title {
    font-size: 1.0625rem;
    font-weight: 600;
    margin: 0;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mm-topbar-actions { display: flex; align-items: center; gap: .5rem; }

.mm-clock {
    font-size: .8125rem;
    color: var(--mm-text-muted);
    font-variant-numeric: tabular-nums;
    padding-inline: .4rem;
}

.mm-avatar {
    display: grid;
    place-items: center;
    width: 1.625rem;
    height: 1.625rem;
    border-radius: 50%;
    background: var(--mm-primary);
    color: #fff;
    font-size: .8125rem;
    font-weight: 600;
}

.mm-content { padding: 1.25rem 1.1rem; flex: 1; }

.mm-footer {
    padding: .9rem 1.1rem;
    border-top: 1px solid var(--mm-border);
    background: var(--mm-surface);
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    flex-wrap: wrap;
    font-size: .8125rem;
    color: var(--mm-text-muted);
}

/* ==========================================================================
   Cards, stats
   ========================================================================== */
.mm-card {
    background: var(--mm-surface);
    border: 1px solid var(--mm-border);
    border-radius: var(--mm-radius);
    box-shadow: var(--mm-shadow);
    overflow: hidden;
}

.mm-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    flex-wrap: wrap;
    padding: .85rem 1.1rem;
    border-bottom: 1px solid var(--mm-border);
    background: #fbfcfe;
}

.mm-card-title { font-size: .9375rem; font-weight: 600; margin: 0; }
.mm-card-body { padding: 1.1rem; }
.mm-card-foot { padding: .85rem 1.1rem; border-top: 1px solid var(--mm-border); background: #fbfcfe; }

.mm-stat {
    background: var(--mm-surface);
    border: 1px solid var(--mm-border);
    border-radius: var(--mm-radius);
    box-shadow: var(--mm-shadow);
    padding: 1rem;
    display: flex;
    align-items: flex-start;
    gap: .85rem;
    height: 100%;
    position: relative;
    overflow: hidden;
}

/* Tone accent on the inline-start edge (right in RTL). */
.mm-stat::before {
    content: "";
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    width: 3px;
    background: var(--mm-primary);
}

.mm-stat-success::before { background: var(--mm-success); }
.mm-stat-info::before    { background: var(--mm-info); }
.mm-stat-warning::before { background: var(--mm-warning); }

.mm-stat-icon {
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    flex-shrink: 0;
    border-radius: var(--mm-radius-sm);
    background: #eff6ff;
    color: var(--mm-primary);
}

.mm-stat-success .mm-stat-icon { background: #f0fdf4; color: var(--mm-success); }
.mm-stat-info .mm-stat-icon    { background: #ecfeff; color: var(--mm-info); }
.mm-stat-warning .mm-stat-icon { background: #fffbeb; color: var(--mm-warning); }

.mm-stat-body { min-width: 0; }

.mm-stat-value {
    font-size: 1.625rem;
    font-weight: 700;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}

.mm-stat-label { font-size: .8125rem; font-weight: 600; color: #334155; }
.mm-stat-hint { font-size: .75rem; color: var(--mm-text-muted); }

/* ==========================================================================
   Definition lists, lists, chips
   ========================================================================== */
.mm-deflist {
    display: grid;
    grid-template-columns: minmax(7.5rem, auto) 1fr;
    gap: .4rem .85rem;
    margin: 0;
    font-size: .8125rem;
}

.mm-deflist dt { color: var(--mm-text-muted); font-weight: 500; }
.mm-deflist dd { margin: 0; font-weight: 500; min-width: 0; word-break: break-word; }

.mm-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .7rem; }

.mm-list-item {
    padding-bottom: .7rem;
    border-bottom: 1px solid var(--mm-border);
}

.mm-list-item:last-child { border-bottom: 0; padding-bottom: 0; }
.mm-list-text { font-size: .8125rem; color: var(--mm-text-muted); margin: .2rem 0 0; }

.mm-errcode {
    font-size: .6875rem;
    background: #fef2f2;
    color: var(--mm-danger);
    padding: .05rem .3rem;
    display: inline-block;
    margin-top: .15rem;
}

.mm-chips { display: flex; flex-wrap: wrap; gap: .45rem; }

.mm-chip {
    font-size: .78125rem;
    background: var(--mm-surface);
    border: 1px solid var(--mm-border);
    border-radius: 2rem;
    padding: .22rem .75rem;
    color: #334155;
}

.mm-chip-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.mm-chip-danger  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

.mm-steps { padding-inline-start: 1.1rem; margin: 0; }
.mm-steps li { margin-bottom: .45rem; }

/* ==========================================================================
   Toolbar & filters
   ========================================================================== */
.mm-toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: .85rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.mm-filters {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
    align-items: flex-end;
}

.mm-filter { display: flex; flex-direction: column; min-width: 8.75rem; }
.mm-filter .form-label { font-size: .78125rem; margin-bottom: .2rem; color: var(--mm-text-muted); }
.mm-filter-actions { flex-direction: row; gap: .4rem; align-items: center; min-width: 0; }
.mm-toolbar-cta { white-space: nowrap; display: inline-flex; align-items: center; gap: .35rem; }

/* ==========================================================================
   Tables
   ========================================================================== */
.mm-table { font-size: .875rem; margin: 0; }

.mm-table thead th {
    background: #f8fafc;
    font-size: .78125rem;
    font-weight: 600;
    color: var(--mm-text-muted);
    text-transform: none;
    border-bottom: 1px solid var(--mm-border);
    white-space: nowrap;
    padding: .65rem .75rem;
}

.mm-table tbody td { padding: .65rem .75rem; vertical-align: middle; }

/* ==========================================================================
   Posts
   ========================================================================== */
.mm-post-list { display: flex; flex-direction: column; gap: .85rem; }

.mm-post {
    background: var(--mm-surface);
    border: 1px solid var(--mm-border);
    border-radius: var(--mm-radius);
    box-shadow: var(--mm-shadow);
    padding: 1rem 1.1rem;
    transition: box-shadow .15s ease;
}

.mm-post:hover { box-shadow: var(--mm-shadow-lg); }

.mm-post.is-new {
    border-color: #86efac;
    background: #f7fefa;
    animation: mm-fade-in .45s ease;
}

@keyframes mm-fade-in {
    from { opacity: 0; transform: translateY(-.4rem); }
    to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .mm-post.is-new { animation: none; }
}

.mm-post-head {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    flex-wrap: wrap;
    align-items: flex-start;
    margin-bottom: .6rem;
}

.mm-post-meta { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }

.mm-post-page {
    font-weight: 600;
    font-size: .9375rem;
    color: var(--mm-text);
    text-decoration: none;
}

.mm-post-page:hover { color: var(--mm-primary); text-decoration: underline; }

.mm-post-dates {
    font-size: .75rem;
    color: var(--mm-text-muted);
    display: flex;
    gap: .35rem;
    flex-wrap: wrap;
    align-items: center;
}

.mm-dot { opacity: .6; }

.mm-post-text {
    margin: 0;
    white-space: pre-line;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    line-height: 1.95;
}

.mm-post-fulltext {
    white-space: pre-line;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    line-height: 2;
    font-size: 1rem;
}

.mm-post-foot {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    align-items: center;
    margin-top: .85rem;
    padding-top: .75rem;
    border-top: 1px solid var(--mm-border);
}

.mm-post-foot .btn { display: inline-flex; align-items: center; gap: .3rem; }

/* ==========================================================================
   Chart (7-day trend)
   ========================================================================== */
.mm-chart {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: .35rem;
    height: 10rem;
}

.mm-chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .25rem; min-width: 0; }
.mm-chart-bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }

.mm-chart-bar {
    width: 100%;
    max-width: 2.25rem;
    background: linear-gradient(to top, var(--mm-primary), #60a5fa);
    border-radius: var(--mm-radius-sm) var(--mm-radius-sm) 0 0;
    min-height: 3px;
}

.mm-chart-value { font-size: .75rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.mm-chart-label { font-size: .6875rem; color: var(--mm-text-muted); direction: ltr; }

/* ==========================================================================
   Notifications
   ========================================================================== */
.mm-notify-menu { width: min(21.875rem, calc(100vw - 2rem)); padding: 0; }
.mm-notify-menu .dropdown-header { padding: .65rem .9rem; font-size: .8125rem; }
.mm-notify-list { max-height: 21.875rem; overflow-y: auto; }

.mm-notify-item {
    display: block;
    padding: .6rem .9rem;
    border-bottom: 1px solid var(--mm-border);
    text-decoration: none;
    color: inherit;
}

.mm-notify-item:last-child { border-bottom: 0; }
.mm-notify-item:hover { background: #f8fafc; }
.mm-notify-item strong { font-size: .8125rem; display: block; }
.mm-notify-item p { font-size: .75rem; color: var(--mm-text-muted); margin: .15rem 0 0; }
.mm-notify-item time { font-size: .6875rem; color: #94a3b8; }

.mm-notify-page-list { list-style: none; margin: 0; padding: 0; }

.mm-notify-row {
    display: flex;
    gap: 1rem;
    padding: .9rem 1.1rem;
    border-bottom: 1px solid var(--mm-border);
    flex-wrap: wrap;
    align-items: flex-start;
}

.mm-notify-row:last-child { border-bottom: 0; }
.mm-notify-row.is-unread { background: #f8fbff; }
.mm-notify-main { flex: 1; min-width: 13rem; }
.mm-notify-excerpt { font-size: .8125rem; color: #475569; margin: 0; line-height: 1.8; }
.mm-notify-actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

.mm-unread-dot {
    width: .5rem;
    height: .5rem;
    border-radius: 50%;
    background: var(--mm-primary);
    display: inline-block;
    flex-shrink: 0;
}

/* ==========================================================================
   Empty states, errors, pagination
   ========================================================================== */
.mm-empty {
    text-align: center;
    padding: 3rem 1.25rem;
    background: var(--mm-surface);
    border: 1px dashed var(--mm-border);
    border-radius: var(--mm-radius);
}

.mm-empty-icon { color: #cbd5e1; margin-bottom: .75rem; }
.mm-empty-title { font-size: 1rem; font-weight: 600; margin-bottom: .4rem; }
.mm-empty-text { font-size: .875rem; color: var(--mm-text-muted); max-width: 31.25rem; margin: 0 auto 1rem; }

.mm-error-page { text-align: center; padding: 3rem 1.25rem; }
.mm-error-code { font-size: 3.5rem; font-weight: 700; color: #cbd5e1; line-height: 1; }
.mm-error-title { font-size: 1.25rem; font-weight: 600; margin: .5rem 0; }
.mm-error-message { color: var(--mm-text-muted); max-width: 34rem; margin: 0 auto 1.25rem; }

.mm-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .85rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.mm-pagination-info { font-size: .8125rem; color: var(--mm-text-muted); }

/* ==========================================================================
   Flash & toasts
   ========================================================================== */
.mm-flash-stack { margin-bottom: 1rem; }
.mm-flash-stack .alert { font-size: .875rem; }

.mm-toast-stack {
    position: fixed;
    bottom: 1.25rem;
    inset-inline-start: 1.25rem;
    z-index: 1090;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    max-width: min(23.75rem, calc(100vw - 2.5rem));
}

/* ==========================================================================
   Login / plain pages
   ========================================================================== */
.mm-plain {
    background: linear-gradient(160deg, #0f172a 0%, #1e293b 55%, #243b63 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.mm-plain-wrap { width: 100%; max-width: 26.25rem; }

.mm-login-card {
    background: var(--mm-surface);
    border-radius: var(--mm-radius);
    box-shadow: 0 1.25rem 2.5rem rgba(0, 0, 0, .3);
    padding: 2rem 1.75rem;
}

.mm-login-brand { text-align: center; margin-bottom: 1.5rem; }
.mm-login-brand h1 { font-size: 1.125rem; font-weight: 700; letter-spacing: .03em; margin: 0; }
.mm-login-brand p { font-size: .875rem; color: var(--mm-text-muted); margin: .15rem 0 0; }

.mm-login-note {
    font-size: .75rem;
    color: var(--mm-text-muted);
    text-align: center;
    margin: 1.25rem 0 0;
    line-height: 1.7;
}

/* ==========================================================================
   Tabs, detail header
   ========================================================================== */
.mm-tabs { border-bottom: 1px solid var(--mm-border); margin-bottom: 1.1rem; }
.mm-tabs .nav-link { font-size: .875rem; color: var(--mm-text-muted); border: 0; border-bottom: 2px solid transparent; }
.mm-tabs .nav-link:hover { color: var(--mm-primary); border-color: transparent; }
.mm-tabs .nav-link.active { color: var(--mm-primary); font-weight: 600; background: transparent; border-bottom-color: var(--mm-primary); }

.mm-detail-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: flex-start;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 991.98px) {
    .mm-sidebar {
        position: fixed;
        inset-block: 0;
        inset-inline-end: 0;
        transform: translateX(100%);
        transition: transform .22s ease;
        box-shadow: -.5rem 0 1.5rem rgba(0, 0, 0, .25);
    }

    /* The sidebar slides in from the right in RTL and the left in LTR. */
    html[dir="ltr"] .mm-sidebar { inset-inline-end: auto; inset-inline-start: 0; transform: translateX(-100%); }

    .mm-sidebar.is-open { transform: translateX(0); }
    .mm-content { padding: 1rem .85rem; }
    .mm-page-title { font-size: .9375rem; }
    .mm-filters { width: 100%; }
    .mm-filter { flex: 1 1 10rem; min-width: 0; }
    .mm-toolbar-cta { width: 100%; justify-content: center; }
}

@media (max-width: 575.98px) {
    .mm-stat { padding: .85rem; gap: .6rem; }
    .mm-stat-value { font-size: 1.375rem; }
    .mm-stat-icon { width: 2.125rem; height: 2.125rem; }
    .mm-deflist { grid-template-columns: 1fr; gap: .15rem .5rem; }
    .mm-deflist dt { margin-top: .5rem; }
    .mm-post { padding: .85rem; }
    .mm-post-foot .btn { flex: 1 1 auto; justify-content: center; }
    .mm-footer { flex-direction: column; gap: .3rem; }
    .mm-chart { height: 8rem; }
    .mm-pagination { justify-content: center; }
    .mm-login-card { padding: 1.5rem 1.15rem; }
}

@media print {
    .mm-sidebar, .mm-topbar, .mm-footer, .mm-toolbar, .mm-pagination, .btn { display: none !important; }
    .mm-post, .mm-card { break-inside: avoid; box-shadow: none; }
    body { background: #fff; }
}
