/* ============================================================
   Shabakaty Gateway — design system
   RTL, Arabic, professional & calm.
   ============================================================ */

:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e6e9ee;
    --text: #0f172a;
    --muted: #64748b;
    --brand: #243e68;
    --brand-strong: #101e36;
    --brand-soft: #eaf0f8;
    --accent: #5276ad;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --warning: #b45309;
    --warning-soft: #fffbeb;
    --info: #2563eb;
    --info-soft: #eff6ff;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 6px 24px rgba(15, 23, 42, .06);
    --shadow-lg: 0 18px 48px rgba(15, 23, 42, .12);
    --font: "Tajawal", "Cairo", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    background:
        radial-gradient(1200px 400px at 100% -10%, #e7edf7 0, transparent 60%),
        var(--bg);
    color: var(--text);
    line-height: 1.65;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--brand);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ---------- Layout shell ---------- */
.app-header {
    background: linear-gradient(135deg, var(--brand-strong), var(--brand));
    color: #fff;
    padding: 18px 24px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 20;
}

.app-header .inner {
    max-width: 1120px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 18px;
    color: #fff;
}

.brand:hover {
    text-decoration: none;
}

.brand .logo {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: rgba(255, 255, 255, .16);
    display: grid;
    place-items: center;
    font-size: 20px;
}

.wrap {
    max-width: 1120px;
    margin: 0 auto;
    padding: 28px 20px 64px;
}

.page-title {
    font-size: 26px;
    font-weight: 800;
    margin: 6px 0 4px;
}

.page-sub {
    color: var(--muted);
    margin: 0 0 24px;
}

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.card h2 {
    margin: 0 0 4px;
    font-size: 19px;
    font-weight: 800;
}

.card .hint {
    color: var(--muted);
    margin: 0 0 18px;
    font-size: 14px;
}

/* ---------- Buttons ---------- */
.btn {
    appearance: none;
    border: 0;
    border-radius: var(--radius-sm);
    padding: 12px 20px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--brand);
    color: #fff;
    transition: transform .06s ease, box-shadow .15s ease, background .15s ease;
    box-shadow: 0 6px 16px rgba(36, 62, 104, .25);
}

.btn:hover {
    background: var(--brand-strong);
    text-decoration: none;
}

.btn:active {
    transform: translateY(1px);
}

.btn.ghost {
    background: var(--surface);
    color: var(--brand-strong);
    border: 1px solid var(--border);
    box-shadow: none;
}

.btn.ghost:hover {
    background: var(--surface-2);
}

.btn.sm {
    padding: 8px 14px;
    font-size: 13px;
    box-shadow: none;
}

.btn.block {
    width: 100%;
}

/* ---------- Inputs ---------- */
.field {
    display: block;
    margin-bottom: 14px;
}

.field label {
    display: block;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[readonly] {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 15px;
    background: var(--surface);
    color: var(--text);
    transition: border .15s ease, box-shadow .15s ease;
}

input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--brand-soft);
}

select {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 15px;
    background: var(--surface);
    color: var(--text);
    transition: border .15s ease, box-shadow .15s ease;
}

select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--brand-soft);
}

.mono {
    direction: ltr;
    text-align: left;
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
    letter-spacing: .3px;
}

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.6;
}

.badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.badge.ok {
    background: var(--brand-soft);
    color: var(--brand-strong);
}

.badge.wait {
    background: var(--warning-soft);
    color: var(--warning);
}

.badge.info {
    background: var(--info-soft);
    color: var(--info);
}

.badge.bad {
    background: var(--danger-soft);
    color: var(--danger);
}

/* ---------- Meta rows ---------- */
.meta {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 0;
    border-bottom: 1px dashed var(--border);
    font-size: 15px;
}

.meta:last-child {
    border-bottom: 0;
}

.meta .k {
    color: var(--muted);
}

.meta .v {
    font-weight: 700;
    word-break: break-all;
}

/* ---------- Flash / alerts ---------- */
.alert {
    border-radius: var(--radius-sm);
    padding: 13px 16px;
    margin-bottom: 18px;
    font-weight: 600;
    font-size: 14px;
}

.alert.error {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert.ok {
    background: var(--brand-soft);
    color: var(--brand-strong);
    border: 1px solid #c7d5eb;
}

.alert.wait {
    background: var(--warning-soft);
    color: var(--warning);
    border: 1px solid #fde68a;
}

.alert.info {
    background: var(--info-soft);
    color: var(--info);
    border: 1px solid #bfdbfe;
}

/* ---------- Instance grid ---------- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    transition: transform .12s ease, box-shadow .12s ease;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tile:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.tile h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 800;
}

.tile .sub {
    color: var(--muted);
    font-size: 13px;
    direction: ltr;
    text-align: left;
}

.tile .foot {
    margin-top: auto;
    padding-top: 12px;
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 40px 20px;
}

.empty .big {
    font-size: 40px;
    margin-bottom: 8px;
}

/* ---------- Centered auth card ---------- */
.center-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    padding: 34px 30px;
    text-align: center;
}

.auth-card .logo {
    width: 60px;
    height: 60px;
    border-radius: 16px;
    margin: 0 auto 14px;
    background: linear-gradient(135deg, var(--brand-strong), var(--accent));
    display: grid;
    place-items: center;
    font-size: 30px;
    color: #fff;
}

.auth-card h1 {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 800;
}

.auth-card p {
    color: var(--muted);
    margin: 0 0 22px;
}

/* ---------- Copy row ---------- */
.copy-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.copy-row input {
    flex: 1;
}

/* ---------- Utilities ---------- */
.row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.spread {
    justify-content: space-between;
}

.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #0f172a;
    color: #fff;
    padding: 12px 22px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease, transform .25s ease;
    z-index: 60;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (max-width: 560px) {
    .wrap { padding: 20px 14px 48px; }
    .page-title { font-size: 22px; }
}

/* ============================================================
   Message audit (per-instance log, trace timeline, sessions)
   ============================================================ */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    box-shadow: var(--shadow);
}

.stat .n {
    font-size: 24px;
    font-weight: 800;
    line-height: 1.2;
    color: var(--brand-strong);
}

.stat .n.bad { color: var(--danger); }
.stat .n.wait { color: var(--warning); }
.stat .n.info { color: var(--info); }

.stat .l {
    font-size: 12.5px;
    color: var(--muted);
    font-weight: 600;
    margin-top: 2px;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 16px;
}

.filter-bar .f {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 130px;
}

.filter-bar label {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--muted);
}

.filter-bar input,
.filter-bar select {
    padding: 9px 11px;
    font-size: 14px;
}

.chk {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    font-size: 14px;
}

.chk input { width: auto; }

.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

table.audit {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    background: var(--surface);
}

table.audit th,
table.audit td {
    text-align: right;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    white-space: nowrap;
}

table.audit th {
    background: var(--surface-2);
    font-size: 12.5px;
    color: var(--muted);
    font-weight: 800;
    position: sticky;
    top: 0;
}

table.audit tbody tr:hover { background: var(--surface-2); }
table.audit tbody tr:last-child td { border-bottom: 0; }

table.audit td.wrap {
    white-space: normal;
    max-width: 320px;
    word-break: break-word;
}

.cell-main { font-weight: 700; }
.cell-sub { font-size: 12px; color: var(--muted); }

.pill {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
}

.pill.ok { background: var(--brand-soft); color: var(--brand-strong); border-color: #c7d5eb; }
.pill.bad { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.pill.wait { background: var(--warning-soft); color: var(--warning); border-color: #fde68a; }
.pill.info { background: var(--info-soft); color: var(--info); border-color: #bfdbfe; }

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 16px;
    font-size: 14px;
}

/* ---------- Trace timeline ---------- */
.timeline {
    position: relative;
    margin: 6px 0 0;
    padding-inline-start: 26px;
}

.timeline::before {
    content: "";
    position: absolute;
    inset-block: 6px;
    inset-inline-start: 8px;
    width: 2px;
    background: var(--border);
}

.tl-item {
    position: relative;
    padding: 0 0 18px;
}

.tl-item:last-child { padding-bottom: 0; }

.tl-dot {
    position: absolute;
    inset-inline-start: -26px;
    top: 3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--surface);
    border: 3px solid var(--muted);
}

.tl-dot.ok { border-color: var(--accent); }
.tl-dot.bad { border-color: var(--danger); }
.tl-dot.wait { border-color: var(--warning); }
.tl-dot.info { border-color: var(--info); }

.tl-title { font-weight: 800; font-size: 14.5px; }
.tl-time { font-size: 12px; color: var(--muted); direction: ltr; display: inline-block; }
.tl-detail { font-size: 13px; color: var(--muted); margin-top: 2px; word-break: break-word; }

.kv {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 8px 14px;
    font-size: 14px;
}

.kv .k { color: var(--muted); font-weight: 600; }
.kv .v { font-weight: 700; word-break: break-word; }

.bubble {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 14px;
}

.subhead {
    font-size: 15px;
    font-weight: 800;
    margin: 4px 0 10px;
}

@media (max-width: 560px) {
    .kv { grid-template-columns: 1fr; gap: 2px 0; }
    .kv .v { margin-bottom: 8px; }
}

/* Shabakaty identity and administrator ownership notice. */
.identity-note { color: var(--muted); font-size: 13px; line-height: 1.8; padding: 12px; background: var(--brand-soft); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.auth-card .logo { background: var(--brand-strong); color: #fff; font-weight: 800; }
.brand .logo, .connect-hero .logo { font-weight: 800; }
