:root {
  --bg: #f5f3ef; --surface: #ffffff; --surface-2: #faf8f5; --ink: #1c2630; --muted: #66727d; --line: #e3ded6;
  --brand: #1d3a4a; --brand-ink: #ffffff; --accent: #b8863b;
  --red: #c0392b; --red-bg: #fbe9e6; --amber: #b7791f; --amber-bg: #fdf1d8; --grey: #5f6b76; --grey-bg: #eceae6;
  --green: #2e7d4f; --green-bg: #e1f2e7; --blue: #2b6a9b; --blue-bg: #e2eef7;
  --radius: 14px; --shadow: 0 1px 2px rgba(20,30,40,.06), 0 4px 14px rgba(20,30,40,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12181d; --surface: #1a2229; --surface-2: #202a32; --ink: #e8ecef; --muted: #9aa7b2; --line: #2d3a44;
    --brand: #2c5568; --brand-ink: #fff; --accent: #d9a95a;
    --red: #ff8a7a; --red-bg: #3a1f1c; --amber: #f0c060; --amber-bg: #38301a; --grey: #aab4bd; --grey-bg: #2a333b;
    --green: #6fcf97; --green-bg: #1c3326; --blue: #7fb8e6; --blue-bg: #1b2d3b;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: 'Cairo', 'Tajawal', system-ui, sans-serif; font-size: 16px; line-height: 1.55; overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
[hidden] { display: none !important; }

/* top bar */
.top { background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 20; padding-top: env(safe-area-inset-top); }
.top .wrap { display: flex; align-items: center; gap: 10px; min-height: 56px; }
.top img { width: 34px; height: 34px; border-radius: 8px; background: #fff; padding: 3px; object-fit: contain; }
.top h1 { font-size: 1.05rem; margin: 0; font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .who { font-size: .8rem; opacity: .85; display: none; }
.icon-btn { background: rgba(255,255,255,.14); border: 0; color: inherit; min-width: 44px; height: 44px; border-radius: 12px; cursor: pointer; font-size: 1rem; padding: 0 10px; }
.icon-btn:active { background: rgba(255,255,255,.28); }
.tabs { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 19; }
.tabs .wrap { display: flex; gap: 4px; overflow-x: auto; }
.tabs a { padding: 12px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap; min-height: 48px; }
.tabs a.on { color: var(--brand); border-color: var(--accent); }
@media (prefers-color-scheme: dark) { .tabs a.on { color: var(--ink); } }
.demo-banner { background: var(--amber-bg); color: var(--amber); text-align: center; font-size: .85rem; padding: 6px 12px; font-weight: 600; }
main { padding: 16px 0 96px; }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--red); border-color: var(--red); background: transparent; }
.btn.sm { min-height: 40px; padding: 0 12px; font-size: .9rem; }
.btn:disabled { opacity: .5; }
.fab { position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); inset-inline-start: 16px; z-index: 30; box-shadow: 0 6px 18px rgba(0,0,0,.28); border-radius: 28px; min-height: 56px; padding: 0 22px; font-size: 1.05rem; }
input, select, textarea { width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.err { background: var(--red-bg); color: var(--red); padding: 10px 12px; border-radius: 10px; margin: 10px 0; font-weight: 600; }
.muted { color: var(--muted); }
h2 { font-size: 1.15rem; margin: 4px 0 12px; }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 99px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.p-عاجل { background: var(--red-bg); color: var(--red); } .p-مهم { background: var(--amber-bg); color: var(--amber); } .p-عادي { background: var(--grey-bg); color: var(--grey); }
.s-لم-يبدأ { background: var(--grey-bg); color: var(--grey); } .s-جاري { background: var(--blue-bg); color: var(--blue); } .s-تم { background: var(--green-bg); color: var(--green); }
.chip.late { background: var(--red); color: #fff; }
.statusbtn { border: 0; cursor: pointer; min-height: 40px; padding: 0 14px; font-size: .9rem; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.login .card { width: 100%; max-width: 380px; padding: 24px; }
.login img { display: block; margin: 0 auto 8px; max-width: 220px; width: 70%; }
.login h1 { text-align: center; font-size: 1.2rem; margin: 6px 0 14px; }
.hint { font-size: .8rem; color: var(--muted); text-align: center; margin-top: 12px; }

/* dashboard */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.kpi b { font-size: 1.5rem; display: block; line-height: 1.2; }
.kpi span { color: var(--muted); font-size: .85rem; }
.kpi.bad b { color: var(--red); }
.dept-cards { display: grid; gap: 10px; }
.dept { display: block; width: 100%; text-align: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; box-shadow: var(--shadow); }
.dept h3 { margin: 0 0 8px; font-size: 1.02rem; display: flex; justify-content: space-between; gap: 8px; }
.dept .nums { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; text-align: center; font-size: .75rem; color: var(--muted); }
.dept .nums b { display: block; font-size: 1.1rem; color: var(--ink); }
.dept .nums .od b { color: var(--red); }
.dept .cost { margin-top: 8px; font-size: .85rem; color: var(--muted); }
.sumtable { display: none; width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.sumtable th, .sumtable td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: center; }
.sumtable th { background: var(--surface-2); font-size: .85rem; color: var(--muted); }
.sumtable td:first-child, .sumtable th:first-child { text-align: start; }
.sumtable tbody tr { cursor: pointer; } .sumtable tbody tr:hover { background: var(--surface-2); }
.sumtable tfoot td { font-weight: 700; background: var(--surface-2); }
.sumtable .od { color: var(--red); font-weight: 700; }

/* filters */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.filters .full { grid-column: 1 / -1; }
.filters select, .filters input { min-height: 44px; }
.chk { display: flex; align-items: center; gap: 8px; min-height: 44px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; font-weight: 600; margin: 0; }
.chk input { width: 22px; min-height: 22px; height: 22px; }
.count { color: var(--muted); font-size: .85rem; margin: 4px 0 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* request cards */
.cards { display: grid; gap: 10px; }
.rcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); border-inline-start: 5px solid var(--grey-bg); cursor: pointer; }
.rcard.pr-عاجل { border-inline-start-color: var(--red); } .rcard.pr-مهم { border-inline-start-color: var(--amber); }
.rcard.late { background: var(--red-bg); }
.rcard .l1 { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 4px; }
.rcard .client { font-weight: 700; }
.rcard .txt { margin: 4px 0 8px; overflow-wrap: anywhere; }
.rcard .meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: .82rem; color: var(--muted); align-items: center; }
.rcard .l3 { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 8px; }
.late-t { color: var(--red); font-weight: 700; }
.table { display: none; width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); font-size: .92rem; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
.table th { background: var(--surface-2); color: var(--muted); font-size: .8rem; white-space: nowrap; }
.table tbody tr { cursor: pointer; } .table tbody tr:hover { background: var(--surface-2); }
.table tr.late { background: var(--red-bg); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

/* detail */
.grid-d { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.grid-d .f b { display: block; font-size: .78rem; color: var(--muted); font-weight: 600; }
.grid-d .full { grid-column: 1 / -1; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button { min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 700; }
.seg button.on.s-لم-يبدأ { background: var(--grey-bg); } .seg button.on.s-جاري { background: var(--blue-bg); color: var(--blue); border-color: var(--blue); } .seg button.on.s-تم { background: var(--green-bg); color: var(--green); border-color: var(--green); }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; cursor: zoom-in; border: 1px solid var(--line); background: var(--grey-bg); }
.log { list-style: none; margin: 0; padding: 0; }
.log li { padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.log time { color: var(--muted); font-size: .78rem; display: block; }
.section { margin-top: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 100; display: grid; place-items: center; padding: 12px; }
#lightbox img { max-width: 100%; max-height: 92vh; border-radius: 8px; }
#lightbox button { position: absolute; top: 12px; inset-inline-start: 12px; }
#toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px); background: #222; color: #fff; padding: 10px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .25s; z-index: 200; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
.userrow { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.userrow.off { opacity: .55; }
.userrow .acts { display: flex; gap: 6px; flex-wrap: wrap; }

@media (min-width: 700px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .filters { grid-template-columns: repeat(6, 1fr); }
  .filters .full { grid-column: span 2; }
  .dept-cards { grid-template-columns: repeat(2, 1fr); }
  .photos { grid-template-columns: repeat(5, 1fr); }
  .top .who { display: block; }
}
@media (min-width: 960px) {
  .dept-cards { display: none; } .sumtable { display: table; }
  .cards { display: none; } .table { display: table; }
  .grid-d { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.row2 > *, .grid-d > * { min-width: 0; }
input[type=date], input[type=number] { min-width: 0; max-width: 100%; -webkit-appearance: none; appearance: none; }
