/* Administration shell: tokens, layout, and every shared component. Logical properties keep LTR/RTL identical. */
:root {
    --bg: #f4f6f9; --surface: #fff; --line: #e2e7ee; --line-strong: #cfd7e2;
    --ink: #172235; --muted: #667085; --navy: #12263f; --navy-soft: #1c3554;
    --brand: #0f766e; --brand-dark: #0b5f59; --brand-soft: #e4f3f1;
    --danger: #b42335; --danger-soft: #fdecee; --warn: #8a5a10; --warn-soft: #fdf3dc; --info: #1c4e80; --info-soft: #e8f1fb;
    --radius: 10px; --radius-sm: 8px; --shadow: 0 1px 2px rgba(18, 38, 63, .05), 0 8px 24px rgba(18, 38, 63, .06);
    --sidebar-w: 248px; --topbar-h: 60px; --focus: 0 0 0 3px rgba(15, 118, 110, .28);
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
body.admin { margin: 0; background: var(--bg); color: var(--ink); font: 400 14px/1.55 system-ui, "Segoe UI", Roboto, "Noto Kufi Arabic", Tahoma, sans-serif; }
:where(body.admin) a { color: var(--brand-dark); }
body.admin h1, body.admin h2, body.admin h3 { margin: 0; line-height: 1.3; font-weight: 700; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
body.dialog-open { overflow: hidden; }

/* Layout */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; gap: 18px; height: 100vh; padding: 16px 12px; overflow-y: auto; background: var(--navy); color: #cbd6e2; z-index: 40; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; color: #fff; font-weight: 800; font-size: 1rem; text-decoration: none; }
.sidebar-brand img { width: 34px; height: 34px; border-radius: 8px; background: #fff; object-fit: contain; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-link { display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 12px; border-radius: var(--radius-sm); color: #cbd6e2; font-weight: 600; text-decoration: none; transition: background .15s, color .15s; }
.sidebar-link i { width: 18px; text-align: center; opacity: .85; }
.sidebar-link:hover { background: var(--navy-soft); color: #fff; }
.sidebar-link.is-active { background: var(--brand); color: #fff; }
.sidebar-link:focus-visible { outline: 0; box-shadow: var(--focus); }
.scrim { display: none; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; height: var(--topbar-h); padding-inline: 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-title { flex: 1; min-width: 0; font-size: 1.05rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar .menu-toggle { display: none; }
.content { flex: 1; width: 100%; max-width: 1280px; margin-inline: auto; padding: 24px; }
.footer { padding: 16px 24px; color: var(--muted); font-size: .8rem; text-align: center; border-top: 1px solid var(--line); background: var(--surface); }
.footer p { margin: 0; }
.avatar { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--brand); color: #fff; font-size: .75rem; font-weight: 800; }

/* Page structure */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head h1 { font-size: 1.35rem; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.stack { display: grid; gap: 18px; }
.stack > * { min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; }
.toolbar-group { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.grid { display: grid; gap: 16px; }
.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)); }
.span-all { grid-column: 1 / -1; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: plaintext; text-align: start; }
.text-end { text-align: end; }

/* Card */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 1rem; }
.card-body { padding: 18px; }
a.card-link { display: flex; align-items: center; gap: 14px; padding: 18px; color: var(--ink); text-decoration: none; transition: border-color .15s, transform .15s; }
a.card-link:hover { border-color: var(--brand); transform: translateY(-1px); }
a.card-link small { display: block; color: var(--muted); }
.icon-tile { display: grid; place-items: center; flex: none; width: 42px; height: 42px; border-radius: var(--radius-sm); background: var(--brand-soft); color: var(--brand-dark); font-size: 1.05rem; }
.stat { display: flex; align-items: center; gap: 14px; padding: 16px 18px; }
.stat div > span { display: block; color: var(--muted); font-size: .82rem; }
.stat strong { display: block; font-size: 1.5rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.empty { padding: 36px 18px; color: var(--muted); text-align: center; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font-weight: 600; font-size: .875rem; line-height: 1; text-decoration: none; white-space: nowrap; cursor: pointer; transition: background .15s, border-color .15s, color .15s; }
.btn:hover { background: var(--brand-soft); border-color: #a7cdc8; color: var(--brand-dark); }
.btn:focus-visible { outline: 0; box-shadow: var(--focus); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn i { font-size: .9em; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-danger { background: var(--danger-soft); border-color: #efc4ca; color: var(--danger); }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: .8rem; }
.btn-icon { width: 38px; padding: 0; }
.btn-group { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.topbar .btn-ghost { color: var(--ink); }

/* Forms */
.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .label { font-size: .8rem; font-weight: 700; color: #344054; }
.input, .select, .textarea { display: block; width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); }
.textarea { min-height: 88px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 0; border-color: var(--brand); box-shadow: var(--focus); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--bg); color: var(--muted); cursor: not-allowed; }
.input[type="file"] { padding: 6px; }
.input::file-selector-button { margin-inline-end: 10px; padding: 5px 10px; border: 0; border-radius: 6px; background: var(--brand-soft); color: var(--brand-dark); cursor: pointer; }
.hint { color: var(--muted); font-size: .8rem; }
.check { display: inline-flex; align-items: center; gap: 8px; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.disclosure { padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); }
.disclosure > summary { cursor: pointer; font-weight: 700; color: var(--brand-dark); }
.disclosure[open] > summary { margin-bottom: 12px; }

/* Table */
.table-wrap { width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
.table { width: 100%; border-collapse: collapse; text-align: start; }
.table th, .table td { padding: 11px 16px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: middle; }
.table thead th { background: #f8fafc; color: #475467; font-size: .74rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f8fbfb; }
.table td.actions { text-align: end; white-space: nowrap; }
.table td.actions .btn-group { flex-wrap: nowrap; justify-content: flex-end; }
.badge { white-space: nowrap; }
.thumb { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; background: var(--bg); }

/* Badge / alert */
.badge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; background: var(--bg); color: var(--muted); font-size: .76rem; font-weight: 700; }
.badge-success { background: var(--brand-soft); color: var(--brand-dark); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.alert { padding: 12px 16px; border-radius: var(--radius-sm); border-inline-start: 4px solid currentColor; }
.alert-success { background: var(--brand-soft); color: var(--brand-dark); }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-warning { background: var(--warn-soft); color: var(--warn); }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert .input { margin-top: 8px; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { padding: 10px 16px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-weight: 700; white-space: nowrap; cursor: pointer; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { border-bottom-color: var(--brand); color: var(--brand-dark); }
.tab:focus-visible { outline: 0; box-shadow: var(--focus); }

/* Dropdown */
.dropdown { position: relative; }
.menu { position: fixed; z-index: 60; min-width: 180px; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); box-shadow: var(--shadow); }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--ink); font-weight: 500; text-align: start; text-decoration: none; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { outline: 0; background: var(--brand-soft); color: var(--brand-dark); }
.menu-item.is-active { font-weight: 700; color: var(--brand-dark); }

/* Modal (native dialog) */
dialog.modal { width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; border: 0; border-radius: var(--radius); background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgba(12, 27, 45, .3); }
dialog.modal::backdrop { background: rgba(12, 20, 33, .55); }
dialog.modal[open] { display: flex; flex-direction: column; }
dialog.modal > form, dialog.modal > .modal-inner { display: flex; flex-direction: column; min-height: 0; margin: 0; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 1.05rem; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: #f8fafc; border-radius: 0 0 var(--radius) var(--radius); }

/* Window polish */
dialog.modal[open] { animation: modal-in .18s ease-out; }
dialog.modal[open]::backdrop { animation: fade-in .18s ease-out; }
dialog.modal-lg { width: min(820px, calc(100vw - 24px)); }
dialog.modal-xl { width: min(1080px, calc(100vw - 24px)); }
.modal-head { position: sticky; top: 0; z-index: 1; background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; }
.modal-foot { position: sticky; bottom: 0; }
.modal-foot .hint { margin-inline-end: auto; align-self: center; }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.btn[data-busy] { position: relative; color: transparent !important; }
.btn[data-busy]::after { content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn-primary[data-busy]::after { border-color: #fff; border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toasts */
.toast-stack { position: fixed; inset-block-start: 72px; inset-inline-end: 20px; z-index: 80; display: grid; gap: 8px; width: min(360px, calc(100vw - 32px)); }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); box-shadow: 0 12px 30px rgba(18, 38, 63, .18); animation: toast-in .22s ease-out; }
.toast i.lead { color: var(--brand); }
.toast span { flex: 1; font-weight: 600; }
.toast.is-leaving { opacity: 0; transform: translateY(-6px); transition: opacity .25s, transform .25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

.copy-row { display: flex; gap: 8px; margin: 8px 0 6px; }
.copy-row .input { flex: 1; min-width: 0; margin-top: 0; }
.check-list { display: grid; gap: 4px; max-height: 280px; overflow-y: auto; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.check-list .check { padding: 6px 8px; border-radius: 6px; }
.check-list .check:hover { background: var(--bg); }

/* Full-page forms */
.form-page { max-width: 920px; }
.form-section { padding: 18px 20px; border-bottom: 1px solid var(--line); }
.form-section > h2 { margin-bottom: 14px; font-size: .95rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 14px 20px; background: #f8fafc; border-radius: 0 0 var(--radius) var(--radius); }
.back-link { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 6px; color: var(--muted); font-weight: 600; text-decoration: none; }
.back-link:hover { color: var(--brand-dark); }
[dir="rtl"] .back-link i { transform: scaleX(-1); }

/* Partner identity */
.partner-cell { display: flex; align-items: center; gap: 10px; }
.logo-tile { display: grid; place-items: center; flex: none; width: 36px; height: 36px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--muted); }
.logo-tile img { width: 100%; height: 100%; object-fit: contain; }
.logo-field { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 16px; align-items: start; }
.logo-preview { position: relative; display: grid; place-items: center; width: 96px; height: 96px; overflow: hidden; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--bg); color: var(--muted); font-size: 1.6rem; }
.logo-preview img { position: absolute; inset: 0; width: 100%; height: 100%; padding: 6px; object-fit: contain; background: var(--surface); }
.logo-preview img[hidden] { display: none; }

/* Locations workspace */
.split { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 18px; align-items: start; }
.split-map { position: sticky; top: calc(var(--topbar-h) + 16px); }
.split-map .card { overflow: hidden; }
.map-box { height: min(560px, 70vh); min-height: 320px; direction: ltr; isolation: isolate; z-index: 0; background: #e9eef3; }
.loc-list { display: grid; margin: 0; padding: 0; list-style: none; max-height: min(560px, 70vh); overflow-y: auto; }
.loc-item { display: grid; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.loc-item:last-child { border-bottom: 0; }
.loc-item.is-inactive .loc-name { color: var(--muted); }
.loc-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.loc-name { font-weight: 700; }
.loc-address { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.loc-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.loc-actions { display: flex; gap: 6px; }
.partner-delete-form { display: inline-flex; margin: 0; }
.calendar-weekdays { display: grid; grid-template-columns: repeat(auto-fit, minmax(124px, 1fr)); gap: 8px; }
.calendar-weekdays .check { min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); }
.partner-settings-grid { align-items: start; }
.import-error-list { max-height: 180px; overflow: auto; margin: 0; padding-inline-start: 22px; color: var(--danger); font-size: .82rem; }
.overtime-verdict-form { display: grid; min-width: 220px; gap: 7px; }
.overtime-verdict-form .input { min-width: 0; }

/* Location window */
.picker { display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); gap: 20px; }
.picker-side { display: grid; gap: 14px; align-content: start; }
.picker-col { position: sticky; top: 0; align-self: start; }
.picker-map { position: relative; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; height: min(540px, calc(100vh - 210px)); min-height: 300px; }
.picker-map .map-box { height: 100%; min-height: 0; }
.picker-hint { position: absolute; top: 10px; right: 10px; z-index: 500; max-width: calc(100% - 80px); padding: 6px 10px; border-radius: 999px; background: rgba(18, 38, 63, .86); color: #fff; font-size: .78rem; pointer-events: none; }
.search-row { display: flex; gap: 8px; }
.search-row .input { flex: 1; min-width: 0; }
.results { display: grid; gap: 4px; margin-top: 6px; }
.results:empty { display: none; }
.result { display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); text-align: start; cursor: pointer; }
.result:hover, .result:focus-visible { outline: 0; border-color: var(--brand); background: var(--brand-soft); }
.result i { margin-top: 3px; color: var(--brand); }
.coords { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.radius-group { display: grid; gap: 8px; }
.radius-group.is-off { opacity: .5; }
.radius-row { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 12px; align-items: center; }
input[type="range"] { width: 100%; accent-color: var(--brand); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; border-radius: var(--radius-sm); background: var(--bg); border: 1px solid var(--line); }
.segmented label { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 4px 8px; border-radius: 6px; font-weight: 600; text-align: center; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--surface); color: var(--brand-dark); box-shadow: 0 1px 3px rgba(18, 38, 63, .15); }
.segmented label:has(input:focus-visible) { box-shadow: var(--focus); }
.map-note { min-height: 1.2em; color: var(--danger); font-size: .82rem; }
.leaflet-container { font: inherit; }
.map-credit { margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 14px; text-align: end; }
.map-credit a { color: inherit; }

/* Responsive */
@media (max-width: 1000px) {
    .split, .picker { grid-template-columns: 1fr; }
    .split-map { position: static; order: -1; }
    .picker-map, .picker-map .map-box { min-height: 300px; }
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
    .shell { display: block; }
    .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(var(--sidebar-w), 86vw); transform: translateX(-100%); transition: transform .2s ease; }
    [dir="rtl"] .sidebar { transform: translateX(100%); }
    .shell.nav-open .sidebar { transform: none; }
    .shell.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(12, 20, 33, .5); }
    .topbar .menu-toggle { display: inline-flex; }
    .topbar, .content, .footer { padding-inline: 16px; }
    .content { padding-block: 18px; }
}
@media (max-width: 560px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .toolbar-group > .field, .toolbar-group > .btn { flex: 1 1 100%; }
    .profile-name { display: none; }
    dialog.modal { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
    .modal-head, .modal-foot { border-radius: 0; }
    .modal-body { flex: 1; }
    .toast-stack { inset-inline: 16px; width: auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
