/* Admin UI (RTL, no build step) */
:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #f8fafb;
    --border: #e2e7ec;
    --text: #1d2733;
    --muted: #5c6875;
    --primary: #0f5fa8;
    --primary-hover: #0c4f8c;
    --primary-soft: #e7f0f9;
    --success: #177443;
    --success-soft: #e5f5ec;
    --warning: #a35c00;
    --warning-soft: #fdf1df;
    --danger: #b42318;
    --danger-soft: #fdeceb;
    --info: #3b4fb8;
    --info-soft: #eceffc;
    --sidebar: #12263a;
    --sidebar-text: #c9d5e1;
    --radius: 10px;
    --radius-md: 8px;
    --radius-sm: 6px;
    --border-strong: #cfd6dd;
    --danger-border: #f1b8b3;
    --row-hover: #fafcfe;
    --on-color: #fff;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    color-scheme: light;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", "Geeza Pro", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.3; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: embed; }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 230px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
    padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { color: var(--on-color); font-weight: 700; font-size: 1.1rem; padding: .25rem .5rem 1rem; display: block; }
.brand small { display: block; font-weight: 400; color: var(--sidebar-text); font-size: .8rem; }
.nav a {
    display: block; color: var(--sidebar-text); padding: .5rem .75rem; border-radius: var(--radius-md); margin-bottom: 2px;
}
.nav a:hover { background: rgba(255, 255, 255, .07); text-decoration: none; color: var(--on-color); }
.nav a.active { background: var(--primary); color: var(--on-color); }
.nav .section { font-size: .8rem; opacity: .7; padding: .9rem .75rem .25rem; }
.main { flex: 1; min-width: 0; }
.topbar {
    background: var(--surface); border-bottom: 1px solid var(--border); padding: .6rem 1.25rem;
    display: flex; align-items: center; gap: 1rem; justify-content: space-between;
}
.topbar form.search { flex: 1; max-width: 420px; }
.topbar .user { display: flex; align-items: center; gap: .75rem; }
.menu-toggle { display: none; }
.content { padding: 1.25rem; max-width: 1280px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.card > h2:first-child, .card > h3:first-child { margin-bottom: .75rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.45rem; font-weight: 700; }
.stat .hint { font-size: .8rem; color: var(--muted); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--border); background: var(--surface);
    color: var(--text); padding: .45rem .9rem; border-radius: var(--radius-md); font: inherit; font-size: .92rem; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-color); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); border-color: var(--success); color: var(--on-color); }
.btn-success:hover { filter: brightness(.95); background: var(--success); }
.btn-danger { background: var(--surface); border-color: var(--danger-border); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: .25rem .6rem; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.inline { display: inline; }

/* Forms */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
.field { margin-bottom: .85rem; }
.field .hint { font-size: .8rem; color: var(--muted); font-weight: 400; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local],
input[type=tel], input[type=search], input[type=month], select, textarea {
    width: 100%; padding: .5rem .65rem; border: 1px solid var(--border-strong); border-radius: var(--radius-md); font: inherit; background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { min-height: 90px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.form-grid .full { grid-column: 1 / -1; }
.error { color: var(--danger); font-size: .85rem; margin-top: .2rem; }
.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.checkbox input { width: auto; }
input[type=checkbox], input[type=radio] { width: 1.15rem; height: 1.15rem; accent-color: var(--primary); flex-shrink: 0; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { margin: 0; min-width: 140px; }
.filters .grow { flex: 1; min-width: 200px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); text-align: right; vertical-align: middle; }
.table th { background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: .82rem; white-space: nowrap; }
.table tbody tr:hover { background: var(--row-hover); }
.table td.actions { white-space: nowrap; text-align: left; }
.table td.num { white-space: nowrap; }
.table tfoot td { font-weight: 700; background: var(--surface-2); }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
dl.details { display: grid; grid-template-columns: 150px 1fr; gap: .35rem 1rem; margin: 0; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; }

/* Badges & alerts */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.alert { padding: .7rem 1rem; border-radius: var(--radius-md); margin-bottom: 1rem; border: 1px solid transparent; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-info { background: var(--info-soft); color: var(--info); }

/* Pagination */
.pagination { display: flex; gap: .25rem; list-style: none; padding: 0; margin: 1rem 0 0; flex-wrap: wrap; }
.pagination a, .pagination span { display: block; padding: .3rem .7rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.pagination .active span { background: var(--primary); color: var(--on-color); border-color: var(--primary); }
.pagination .disabled span { color: var(--muted); }

/* Tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .5rem .9rem; border-bottom: 2px solid transparent; color: var(--muted); }
.tabs a.active { border-color: var(--primary); color: var(--primary); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth .card { width: 100%; max-width: 380px; padding: 1.75rem; }

.photos { display: flex; gap: .5rem; flex-wrap: wrap; }
.photos figure { margin: 0; position: relative; }
.photos img { width: 120px; height: 90px; object-fit: cover; border-radius: var(--radius-md); border: 1px solid var(--border); }

@media (max-width: 900px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
    .shell { display: block; }
    .sidebar { position: fixed; inset: 0 0 0 auto; z-index: 20; transform: translateX(100%); transition: transform .2s; height: 100vh; }
    .sidebar.open { transform: none; box-shadow: -8px 0 24px rgba(0, 0, 0, .2); }
    .menu-toggle { display: inline-flex; }
    .topbar { padding: .6rem 1rem; flex-wrap: wrap; }
    .topbar form.search { order: 3; max-width: none; flex-basis: 100%; }
    .content { padding: 1rem; }
    .grid-2, .grid-3, .grid-4, .form-grid { grid-template-columns: minmax(0, 1fr); }
    dl.details { grid-template-columns: 110px 1fr; }
}
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    body { background: #fff; }
    .content { padding: 0; }
    .card { box-shadow: none; border: 0; }
}

/* plan name under the sidebar navigation */
.plan-tag { margin: 1rem .9rem; padding: .35rem .6rem; border: 1px solid rgba(255, 255, 255, .25); border-radius: var(--radius-sm); font-size: .8rem; opacity: .85; text-align: center; }

/* Keyboard users: jump past the navigation */
.skip-link { position: absolute; inset-inline-start: .5rem; top: -3rem; background: var(--surface); color: var(--text, #1d2733); padding: .5rem .9rem; border-radius: var(--radius-sm); z-index: 100; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
.skip-link:focus { top: .5rem; }
main:focus { outline: none; }

/* Fingers need bigger targets than a mouse pointer does */
@media (pointer: coarse) {
    .btn, .nav a, select, input:not([type=checkbox]):not([type=radio]), .menu-toggle { min-height: 44px; }
    .btn-sm { min-height: 40px; padding-inline: .9rem; }
    .table td a:not(.btn) { display: inline-block; padding-block: .55rem; min-width: 2.75rem; }
    .checkbox { min-height: 44px; }
}

/* Report bars: the width comes from the data as an SVG attribute, so no inline style is needed */
.bar { display: block; width: 100%; height: .55rem; }
.bar rect { fill: var(--primary); opacity: .75; }

/* A row of small figures that stays side by side on phones */
.stats-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.stats-row .stat { padding: .7rem .8rem; }
.stats-row .stat .label { font-size: .8rem; }

/* Spacing, width and text helpers: use these instead of style attributes (the CSP forbids them) */
.m-0 { margin: 0; }
.mt-quarter { margin-top: .3rem; }
.mt-half { margin-top: .5rem; }
.mt-075 { margin-top: .75rem; }
.mt-1 { margin-top: 1rem; }
.mb-quarter { margin-bottom: .35rem; }
.mb-half { margin-bottom: .5rem; }
.mb-1 { margin-bottom: 1rem; }
.narrow-sm { max-width: 520px; }
.narrow { max-width: 640px; }
.narrow-lg { max-width: 760px; }
.min-w-6 { min-width: 90px; }
.min-w-7 { min-width: 105px; }
.min-w-9 { min-width: 9rem; }
.w-22 { width: 22%; }
.w-45 { width: 45%; }
.text-center { text-align: center; }
.text-lg { font-size: 1.1rem; }
.text-danger { color: var(--danger); }
.dimmed { opacity: .6; }
.pre-line { white-space: pre-line; }
.pad-sm { padding: .45rem .7rem; }
.btn-block { width: 100%; justify-content: center; }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.cell-wrap { max-width: 380px; word-break: break-word; }
.summary-title { cursor: pointer; font-weight: 600; margin-bottom: .75rem; }
@media (max-width: 760px) {
    .hide-sm { display: none; }
}

/* Phones: figures sit two to a row, and the busiest lists read as cards instead of a sideways-scrolling table */
@media (max-width: 760px) {
    .grid:has(> .stat) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
    .grid > .stat { padding: .7rem .8rem; }
    .grid > .stat .value { font-size: 1.25rem; }

    .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; }
    .table-cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    .table-cards tbody tr { border: 1px solid var(--border); border-radius: var(--radius-md); padding: .45rem .8rem; margin-bottom: .6rem; background: var(--surface); }
    .table-cards tbody tr:hover { background: var(--surface); }
    .table-cards td { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding: .3rem 0; border: 0; text-align: start; }
    .table-cards td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .8rem; flex-shrink: 0; }
    .table-cards td[data-label] > * { text-align: end; }
    .table-cards td.empty { display: block; text-align: center; }
    .table-cards td:first-child { font-weight: 700; border-bottom: 1px solid var(--border); padding-bottom: .45rem; margin-bottom: .2rem; }
}

/* Brand mark */
.brand img { vertical-align: middle; margin-inline-end: .45rem; }
.auth-mark { display: block; margin-bottom: .6rem; }
.brand-system { display: flex; align-items: center; font-size: 1.25rem; }
.brand-workshop { display: block; margin-top: .45rem; padding-top: .45rem; border-top: 1px solid rgba(255, 255, 255, .14); font-weight: 600; font-size: .92rem; color: var(--on-color); }
