/* Royal Management — design system. Tokens first; components below. RTL-native (logical properties). */
@font-face { font-family: Cairo; font-weight: 400; font-display: swap; src: url(../vendor/cairo/cairo-arabic-400.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Cairo; font-weight: 600; font-display: swap; src: url(../vendor/cairo/cairo-arabic-600.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Cairo; font-weight: 700; font-display: swap; src: url(../vendor/cairo/cairo-arabic-700.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Cairo; font-weight: 400; font-display: swap; src: url(../vendor/cairo/cairo-latin-400.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: Cairo; font-weight: 600; font-display: swap; src: url(../vendor/cairo/cairo-latin-600.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: Cairo; font-weight: 700; font-display: swap; src: url(../vendor/cairo/cairo-latin-700.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }

:root {
  color-scheme: light dark;
  --navy: #1B2A4A;
  --navy-2: #24375f;
  --bg: #F3F5F8;
  --surface: #FFFFFF;
  --surface-2: #F8F9FB;
  --line: #E1E5EC;
  --line-strong: #C9D0DB;
  --ink: #16213A;
  --ink-2: #4A5672;
  --ink-3: #6B7690;
  --accent: #1B2A4A;
  --on-accent: #FFFFFF;
  --done: #1E8E5A;   --done-bg: #E5F4EC;
  --pend: #B86A0E;   --pend-bg: #FDF0DD;   /* text-safe orange (4.5:1 on its bg) */
  --urg: #C8372D;    --urg-bg: #FBE7E5;
  --info: #2F5BA8;   --info-bg: #E6EDF9;
  --focus: #3D7BF7;
  --radius: 12px;
  --radius-s: 8px;
  --shadow: 0 1px 2px rgb(22 33 58 / .06), 0 4px 12px rgb(22 33 58 / .06);
  --tap: 48px;
  --nav-h: 64px;
  --font: Cairo, "Segoe UI", Tahoma, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1626;
    --surface: #15203A;
    --surface-2: #1A2744;
    --line: #26355A;
    --line-strong: #34466F;
    --ink: #E8EDF7;
    --ink-2: #B4BED3;
    --ink-3: #8E9AB5;
    --accent: #6E92E0;
    --on-accent: #0E1626;
    --done: #4CC38A;   --done-bg: #12332A;
    --pend: #F0A64A;   --pend-bg: #3A2A12;
    --urg: #F07167;    --urg-bg: #3D1A1A;
    --info: #8FB0F0;   --info-bg: #1B2B4F;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 16px rgb(0 0 0 / .3);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 16px/1.65 var(--font); font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
::selection { background: color-mix(in srgb, var(--accent) 25%, transparent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
a { color: var(--accent); text-underline-offset: 3px; }
h1, h2, h3 { line-height: 1.3; margin: 0; text-wrap: balance; }
h1 { font-size: 1.375rem; font-weight: 700; }
h2 { font-size: 1.125rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--ink-3); }
.small { font-size: .875rem; }
.icon { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ltr { direction: ltr; unicode-bidi: isolate; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--navy); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 12px;
}
.topbar .brand { font-weight: 700; font-size: 1.0625rem; letter-spacing: 0; color: #fff; text-decoration: none; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .8125rem; opacity: .8; }
.iconbtn { position: relative; display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; color: inherit; background: transparent; border: 0; cursor: pointer; }
.iconbtn:hover { background: rgb(255 255 255 / .1); }
.badge { position: absolute; top: 6px; inset-inline-end: 6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--urg); color: #fff; font-size: .6875rem; font-weight: 700; line-height: 18px; text-align: center; }

.layout { display: block; }
main { padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); max-width: 980px; margin-inline: auto; }

.bottomnav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 20; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 6px; min-height: var(--nav-h); color: var(--ink-3); text-decoration: none; font-size: .75rem; font-weight: 600; position: relative; }
.bottomnav a[aria-current="page"] { color: var(--accent); }
.bottomnav .badge { top: 4px; inset-inline-end: calc(50% - 22px); }

.sidebar { display: none; }
@media (min-width: 900px) {
  .layout { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 64px); }
  .sidebar { display: block; background: var(--surface); border-inline-end: 1px solid var(--line); padding: 16px 12px; }
  .sidebar a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-s); color: var(--ink-2); text-decoration: none; font-weight: 600; }
  .sidebar a:hover { background: var(--surface-2); }
  .sidebar a[aria-current="page"] { background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--accent); }
  .sidebar .group { margin: 16px 12px 6px; font-size: .75rem; color: var(--ink-3); font-weight: 600; }
  .bottomnav { display: none; }
  main { padding: 24px 32px 48px; margin-inline: 0; }
}

/* ---------- page header ---------- */
.pagehead { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.pagehead h1 { flex: 1; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-3); text-decoration: none; font-size: .875rem; margin-bottom: 8px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap);
  padding: 0 18px; border-radius: var(--radius-s); border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); font: 600 1rem var(--font); cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, transform .08s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.htmx-request { opacity: .55; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-done { background: var(--done); border-color: var(--done); color: var(--on-accent); }
.btn-danger { color: var(--urg); border-color: color-mix(in srgb, var(--urg) 45%, var(--line)); }
.btn-danger:hover { background: var(--urg-bg); }
.btn-block { width: 100%; }
.btn-s { min-height: 38px; padding: 0 12px; font-size: .875rem; }
.actions { display: grid; gap: 10px; }
.actions.two { grid-template-columns: 1fr 1fr; }

/* ---------- surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel + .panel { margin-top: 12px; }
.panel h2 { margin-bottom: 12px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* ---------- status chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 13px; font-size: .8125rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--ink-2); }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.waiting_tech, .chip.waiting_approval, .chip.waiting_closure { background: var(--pend-bg); color: var(--pend); }
.chip.in_progress { background: var(--info-bg); color: var(--info); }
.chip.paused { background: var(--surface-2); color: var(--ink-2); }
.chip.done { background: var(--done-bg); color: var(--done); }
.chip.approval_rejected { background: var(--urg-bg); color: var(--urg); }
.prio { font-size: .8125rem; font-weight: 700; }
.prio.urgent { color: var(--urg); }
.prio.high { color: var(--pend); }
.prio.normal { color: var(--ink-3); }
.flag { font-size: .75rem; font-weight: 700; color: var(--urg); }

/* ---------- request list ---------- */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px 16px; color: inherit; text-decoration: none; }
.item:hover { background: var(--surface-2); }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { grid-column: 1 / -1; display: flex; gap: 10px; flex-wrap: wrap; font-size: .8125rem; color: var(--ink-3); }
.empty { padding: 40px 16px; text-align: center; color: var(--ink-3); }
.empty strong { display: block; color: var(--ink-2); margin-bottom: 4px; }

/* ---------- tabs / filters ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 12px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 10px 12px; color: var(--ink-3); text-decoration: none; font-weight: 600; font-size: .9375rem; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--accent); border-color: var(--accent); }
.tabs .count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--surface-2); font-size: .75rem; line-height: 20px; text-align: center; }
.tabs .count.hot { background: var(--urg); color: #fff; }

/* ---------- forms ---------- */
label, .label { display: block; font-weight: 600; font-size: .9375rem; margin-bottom: 6px; }
.field + .field { margin-top: 16px; }
.hint { font-size: .8125rem; color: var(--ink-3); margin-top: 4px; }
.err { font-size: .8125rem; color: var(--urg); margin-top: 4px; }
input[type=text], input[type=password], input[type=tel], input[type=number], input[type=datetime-local], input[type=date], input[type=time], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  background: var(--surface); color: var(--ink); font: 400 1rem var(--font);
}
textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
::placeholder { color: var(--ink-3); opacity: 1; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tiles > .tile:last-child:nth-child(odd) { grid-column: 1 / -1; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(4, 1fr); } .tiles > .tile:last-child:nth-child(odd) { grid-column: auto; } }
.tile input, .seg input { position: absolute; opacity: 0; pointer-events: none; }
.tile span { display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: var(--radius-s); background: var(--surface); font-weight: 600; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.tile input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tile input:focus-visible + span, .seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line-strong); border-radius: var(--radius-s); overflow: hidden; }
.seg label { margin: 0; position: relative; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: var(--tap); font-weight: 600; cursor: pointer; background: var(--surface); }
.seg label + label span { border-inline-start: 1px solid var(--line-strong); }
.seg input:checked + span { background: var(--accent); color: var(--on-accent); }
.seg input[value=urgent]:checked + span { background: var(--urg); color: var(--on-accent); }
.seg input[value=high]:checked + span { background: var(--pend); color: var(--on-accent); }
.photo { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px dashed var(--line-strong); border-radius: var(--radius-s); cursor: pointer; color: var(--ink-2); font-weight: 600; margin: 0; }
.photo input { display: none; }
.photo img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; }
.sticky-submit { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); margin-top: 20px; }
@media (min-width: 900px) { .sticky-submit { position: static; } }

/* ---------- detail ---------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: .9375rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding-inline-start: 22px; padding-bottom: 14px; }
.timeline li::before { content: ""; position: absolute; inset-inline-start: 5px; top: 10px; bottom: -4px; width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: ""; position: absolute; inset-inline-start: 0; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--line-strong); }
.timeline li.k-rejected::after, .timeline li.k-closure_rejected::after, .timeline li.k-approval_rejected::after, .timeline li.k-escalated::after { border-color: var(--urg); background: var(--urg); }
.timeline li.k-closed::after { border-color: var(--done); background: var(--done); }
.timeline .when { font-size: .75rem; color: var(--ink-3); }
.timeline .what { font-weight: 600; }
.timeline .note { color: var(--ink-2); font-size: .9375rem; margin-top: 2px; white-space: pre-line; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: var(--radius-s); border: 1px solid var(--line); }
.reason { margin-top: 10px; }
details.more > summary { list-style: none; cursor: pointer; }
details.more > summary.btn { display: flex; white-space: nowrap; }
details.more[open] > summary.btn { border-color: var(--accent); }
details.more > summary::-webkit-details-marker { display: none; }

/* ---------- messages ---------- */
.msg { padding: 12px 14px; border-radius: var(--radius-s); margin-bottom: 12px; font-weight: 600; background: var(--info-bg); color: var(--info); }
.msg.error { background: var(--urg-bg); color: var(--urg); }
.msg.success { background: var(--done-bg); color: var(--done); }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); padding: 14px 16px; color: inherit; text-decoration: none; display: block; }
.stat:hover { background: var(--surface-2); }
.stat .n { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
.stat .l { font-size: .8125rem; color: var(--ink-3); }
.stat.hot .n { color: var(--urg); }
.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: 9rem 1fr 2.5rem; align-items: center; gap: 10px; font-size: .875rem; }
.bar .track, .bar .fill { display: block; }
.bar .track { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 5px; }
.bar .v { text-align: end; font-weight: 600; }

/* ---------- tables (shifts, users) ---------- */
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .875rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: start; white-space: nowrap; }
th { color: var(--ink-3); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
tr.today td { background: color-mix(in srgb, var(--accent) 7%, transparent); }
td select { min-height: 36px; padding: 4px 8px; font-size: .875rem; min-width: 8rem; }

/* ---------- login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--navy); }
.auth .card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px; padding: 28px 24px; box-shadow: 0 10px 40px rgb(0 0 0 / .25); }
.auth .mark { width: 52px; height: 52px; border-radius: 14px; background: var(--navy); display: grid; place-items: center; margin-bottom: 16px; }
.auth h1 { margin-bottom: 4px; }

/* ---------- install ---------- */
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: s; position: relative; padding-inline-start: 40px; min-height: 32px; margin-bottom: 14px; }
.steps li::before { content: counter(s); position: absolute; inset-inline-start: 0; top: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--on-accent); font-weight: 700; display: grid; place-items: center; font-size: .875rem; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
