/* Hotel Desk — a Frappe Desk–style shell over the hotel API.
 *
 * Tokens are three layers: primitives (raw values) → semantic (purpose)
 * → component. Components only ever read semantic/component tokens, so the
 * dark theme is a remap of the semantic layer and nothing else.
 * Layout uses logical properties throughout, so dir="rtl" flips it for free.
 */

/* ------------------------------------------------------------ primitives */
:root {
  --gray-0: #ffffff;
  --gray-25: #fcfcfc;
  --gray-50: #f8f8f8;
  --gray-100: #f3f3f3;
  --gray-200: #ededed;
  --gray-300: #e2e2e2;
  --gray-400: #c7c7c7;
  --gray-500: #999999;
  --gray-600: #7c7c7c;
  --gray-700: #525252;
  --gray-800: #383838;
  --gray-900: #171717;
  --gray-950: #0f0f0f;

  --blue-50: #e6f4ff;  --blue-500: #0289f7;  --blue-700: #0070cc;
  --green-50: #e4faeb; --green-500: #30a66d; --green-700: #16794c;
  --orange-50: #fff1e7; --orange-500: #f5821f; --orange-700: #bd3e0c;
  --red-50: #fff0f0;   --red-500: #e03636;   --red-700: #b52a2a;
  --yellow-50: #fff7d3; --yellow-700: #9a6a00;
  --purple-50: #f5f0ff; --purple-700: #6846e3;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px;
  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px; --radius-full: 999px;
  --font-xs: 11px; --font-sm: 12px; --font-base: 13px; --font-md: 14px;
  --font-lg: 16px; --font-xl: 20px; --font-2xl: 24px;
  --font-sans: "Inter", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* -------------------------------------------------------------- semantic */
:root {
  --bg-canvas: var(--gray-50);
  --bg-surface: var(--gray-0);
  --bg-subtle: var(--gray-100);
  --bg-hover: var(--gray-100);
  --bg-active: var(--gray-200);
  --bg-control: var(--gray-100);
  --text-strong: var(--gray-900);
  --text-body: var(--gray-800);
  --text-muted: var(--gray-600);
  --text-faint: var(--gray-500);
  --text-inverse: var(--gray-0);
  --border: var(--gray-200);
  --border-strong: var(--gray-300);
  --focus-ring: 0 0 0 2px var(--gray-400);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .08), 0 0 0 1px rgba(0, 0, 0, .04);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .12), 0 0 0 1px rgba(0, 0, 0, .04);
  --primary: var(--gray-900);
  --primary-hover: var(--gray-800);
  --link: var(--blue-700);
  --danger: var(--red-500);
  --overlay: rgba(0, 0, 0, .35);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-canvas: #141414; --bg-surface: #1c1c1c; --bg-subtle: #242424;
    --bg-hover: #262626; --bg-active: #303030; --bg-control: #262626;
    --text-strong: #f5f5f5; --text-body: #dcdcdc; --text-muted: #a3a3a3;
    --text-faint: #7c7c7c; --text-inverse: #171717;
    --border: #2c2c2c; --border-strong: #3a3a3a; --focus-ring: 0 0 0 2px #525252;
    --primary: #f5f5f5; --primary-hover: #dcdcdc; --link: #5cb3ff;
    --blue-50: #0d2a45; --green-50: #0f2e1f; --orange-50: #3a2210; --red-50: #3a1515;
    --yellow-50: #332a0a; --purple-50: #261d45;
    --blue-700: #7cc2ff; --green-700: #6fdca5; --orange-700: #ffae70; --red-700: #ff8a8a;
    --yellow-700: #f0c75e; --purple-700: #b8a4ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg-canvas: #141414; --bg-surface: #1c1c1c; --bg-subtle: #242424;
  --bg-hover: #262626; --bg-active: #303030; --bg-control: #262626;
  --text-strong: #f5f5f5; --text-body: #dcdcdc; --text-muted: #a3a3a3;
  --text-faint: #7c7c7c; --text-inverse: #171717;
  --border: #2c2c2c; --border-strong: #3a3a3a; --focus-ring: 0 0 0 2px #525252;
  --primary: #f5f5f5; --primary-hover: #dcdcdc; --link: #5cb3ff;
  --blue-50: #0d2a45; --green-50: #0f2e1f; --orange-50: #3a2210; --red-50: #3a1515;
  --yellow-50: #332a0a; --purple-50: #261d45;
  --blue-700: #7cc2ff; --green-700: #6fdca5; --orange-700: #ffae70; --red-700: #ff8a8a;
  --yellow-700: #f0c75e; --purple-700: #b8a4ff;
  color-scheme: dark;
}

/* ------------------------------------------------------------- component */
:root {
  --navbar-h: 48px;
  --sidebar-w: 224px;
  --control-h: 28px;
  --control-bg: var(--bg-control);
  --btn-h: 28px;
  --row-h: 40px;
}

/* ------------------------------------------------------------------ base */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg-canvas);
  color: var(--text-body);
  font: 400 var(--font-base)/1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.hidden { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }

/* ---------------------------------------------------------------- navbar */
.navbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--navbar-h);
  display: flex; align-items: center; gap: var(--space-3);
  padding-inline: var(--space-4);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.navbar .brand { display: flex; align-items: center; gap: var(--space-2); font-weight: 600; color: var(--text-strong); white-space: nowrap; }
.brand-mark {
  width: 26px; height: 26px; border-radius: var(--radius-sm);
  display: grid; place-items: center;
  background: var(--primary); color: var(--text-inverse); font-size: 13px; font-weight: 700;
}
.awesomebar { position: relative; flex: 0 1 440px; margin-inline-start: auto; }
.awesomebar input {
  width: 100%; height: 30px; border: 0; border-radius: var(--radius-md);
  background: var(--control-bg); padding-inline: 32px 56px;
}
.awesomebar .icon { position: absolute; inset-inline-start: 10px; top: 7px; color: var(--text-faint); }
.awesomebar kbd {
  position: absolute; inset-inline-end: 8px; top: 6px;
  font: 500 10px var(--font-sans); color: var(--text-faint);
  border: 1px solid var(--border-strong); border-radius: 4px; padding: 1px 5px;
}
.awesome-results {
  position: absolute; inset-inline: 0; top: 36px;
  background: var(--bg-surface); border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  padding: var(--space-1); max-height: 420px; overflow: auto;
}
.awesome-results .item { display: flex; gap: var(--space-2); align-items: center; padding: 7px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.awesome-results .item.active, .awesome-results .item:hover { background: var(--bg-hover); }
.awesome-results .group { padding: 6px 10px 2px; font-size: var(--font-xs); color: var(--text-faint); font-weight: 500; }
.nav-right { display: flex; align-items: center; gap: var(--space-2); margin-inline-start: auto; }
.avatar {
  width: 28px; height: 28px; border-radius: var(--radius-full);
  display: grid; place-items: center; flex: none;
  background: var(--bg-active); color: var(--text-strong); font-weight: 600; font-size: var(--font-sm);
  border: 0; cursor: pointer;
}
.nav-toggle { display: none; }

/* --------------------------------------------------------------- layout */
.layout { display: flex; min-height: calc(100vh - var(--navbar-h)); }
.sidebar {
  position: sticky; top: var(--navbar-h); align-self: flex-start;
  width: var(--sidebar-w); flex: none; height: calc(100vh - var(--navbar-h));
  overflow-y: auto; padding: var(--space-3) var(--space-2);
}
.sidebar .section-label { padding: var(--space-3) var(--space-2) var(--space-1); font-size: var(--font-xs); font-weight: 500; color: var(--text-faint); }
.sidebar a {
  display: flex; align-items: center; gap: 10px; height: 32px;
  padding-inline: var(--space-2); border-radius: var(--radius-md); color: var(--text-body);
}
.sidebar a:hover { background: var(--bg-hover); }
.sidebar a.active { background: var(--bg-surface); color: var(--text-strong); font-weight: 500; box-shadow: var(--shadow-sm); }
.sidebar a .badge-count { margin-inline-start: auto; font-size: var(--font-xs); color: var(--text-muted); background: var(--bg-active); border-radius: var(--radius-full); padding: 0 7px; }
.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.main { flex: 1; min-width: 0; padding: 0 var(--space-6) var(--space-8); }

/* ------------------------------------------------------------ page head */
.page-head {
  position: sticky; top: var(--navbar-h); z-index: 20;
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-4) 0 var(--space-3);
  background: var(--bg-canvas);
}
.page-head h1 { margin: 0; font-size: var(--font-xl); font-weight: 600; color: var(--text-strong); letter-spacing: -.01em; }
.page-head .crumbs { display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
.page-head .crumbs a:hover { color: var(--text-strong); }
.page-actions { margin-inline-start: auto; display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--btn-h); padding: 0 12px; border-radius: var(--radius-sm);
  border: 0; cursor: pointer; white-space: nowrap; font-weight: 500;
  background: var(--bg-subtle); color: var(--text-strong);
}
.btn:hover { background: var(--bg-active); }
.btn-primary { background: var(--primary); color: var(--text-inverse); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--red-50); color: var(--red-700); }
.btn-danger:hover { filter: brightness(.97); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-sm { height: 24px; padding: 0 8px; font-size: var(--font-sm); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-group { display: inline-flex; background: var(--bg-subtle); border-radius: var(--radius-sm); padding: 2px; }
.btn-group .btn { height: 24px; background: transparent; }
.btn-group .btn.active { background: var(--bg-surface); box-shadow: var(--shadow-sm); }

/* ------------------------------------------------------------- dropdown */
.dropdown { position: relative; }
.menu {
  position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 50; min-width: 200px;
  background: var(--bg-surface); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: var(--space-1);
}
.menu button, .menu a {
  display: flex; width: 100%; align-items: center; gap: var(--space-2);
  padding: 7px 10px; border: 0; background: none; border-radius: var(--radius-sm);
  cursor: pointer; text-align: start; color: var(--text-body);
}
.menu button:hover, .menu a:hover { background: var(--bg-hover); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.menu .menu-head { padding: 8px 10px; }
.menu .menu-head b { display: block; color: var(--text-strong); }

/* ------------------------------------------------------------ indicators */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px;
  border-radius: var(--radius-full); font-size: var(--font-sm); font-weight: 500; white-space: nowrap;
  background: var(--bg-subtle); color: var(--text-muted);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.green { background: var(--green-50); color: var(--green-700); }
.pill.orange { background: var(--orange-50); color: var(--orange-700); }
.pill.red { background: var(--red-50); color: var(--red-700); }
.pill.blue { background: var(--blue-50); color: var(--blue-700); }
.pill.yellow { background: var(--yellow-50); color: var(--yellow-700); }
.pill.purple { background: var(--purple-50); color: var(--purple-700); }

/* ----------------------------------------------------------------- cards */
.card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.card-pad { padding: var(--space-4) var(--space-5); }
.card-title { margin: 0 0 var(--space-3); font-size: var(--font-md); font-weight: 600; color: var(--text-strong); }

/* ------------------------------------------------------------- workspace */
.ws-grid { display: grid; gap: var(--space-4); }
.number-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--space-3); }
.number-card { padding: var(--space-4); }
.number-card .label { color: var(--text-muted); font-size: var(--font-sm); }
.number-card .value { font-size: var(--font-2xl); font-weight: 600; color: var(--text-strong); margin-top: 2px; }
.number-card .sub { font-size: var(--font-sm); color: var(--text-muted); }
.shortcuts { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--space-2); }
.shortcut {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-surface);
}
.shortcut:hover { background: var(--bg-hover); }
.shortcut .count { margin-inline-start: auto; }
.ws-section-title { margin: var(--space-5) 0 var(--space-2); font-size: var(--font-lg); font-weight: 600; color: var(--text-strong); }
.chart-box { position: relative; height: 260px; }

/* -------------------------------------------------------------- list view */
.list-card { overflow: hidden; }
.list-filters { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.list-filters .control { width: 170px; }
.list-filters .grow { flex: 1; }
.list-table { width: 100%; border-collapse: collapse; }
.list-table th {
  height: 36px; padding: 0 var(--space-3); text-align: start; white-space: nowrap;
  font-size: var(--font-sm); font-weight: 500; color: var(--text-muted);
  background: var(--bg-surface); border-bottom: 1px solid var(--border);
}
.list-table td { height: var(--row-h); padding: 0 var(--space-3); border-bottom: 1px solid var(--border); white-space: nowrap; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.list-table tbody tr { cursor: pointer; }
.list-table tbody tr:hover td { background: var(--bg-hover); }
.list-table tbody tr:last-child td { border-bottom: 0; }
.list-table .subject { color: var(--text-strong); font-weight: 500; }
.list-table .end { text-align: end; }
.list-table input[type=checkbox] { margin: 0; }
.list-footer { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border); }
.list-footer .count { margin-inline-start: auto; color: var(--text-muted); }
.table-scroll { overflow-x: auto; }
.empty { padding: 48px var(--space-4); text-align: center; color: var(--text-muted); }
.empty .icon { width: 32px; height: 32px; margin-bottom: var(--space-2); color: var(--text-faint); }

/* -------------------------------------------------------------- controls */
.control {
  width: 100%; height: var(--control-h); border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--control-bg); padding: 0 var(--space-2);
}
.control:hover { border-color: var(--border-strong); }
.control:focus { outline: none; background: var(--bg-surface); border-color: var(--gray-400); box-shadow: var(--focus-ring); }
textarea.control { height: auto; min-height: 72px; padding: 6px var(--space-2); resize: vertical; }
.control[readonly], .control[disabled] { background: transparent; border-color: var(--border); color: var(--text-muted); }
.checkbox { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.checkbox input { width: 14px; height: 14px; accent-color: var(--primary); }
.checkbox input[disabled] + span { color: var(--text-muted); }

/* ------------------------------------------------------------------- form */
.form-card { padding: 0; }
.form-section { padding: var(--space-5); border-bottom: 1px solid var(--border); }
.form-section:last-child { border-bottom: 0; }
.form-section h3 { margin: 0 0 var(--space-4); font-size: var(--font-md); font-weight: 600; color: var(--text-strong); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4) var(--space-8); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field label { display: block; margin-bottom: 4px; font-size: var(--font-sm); color: var(--text-muted); }
.field .reqd::after { content: " *"; color: var(--danger); }
.field .static { min-height: var(--control-h); display: flex; align-items: center; color: var(--text-strong); }
.field .help { font-size: var(--font-xs); color: var(--text-faint); margin-top: 3px; }
.field.span-2 { grid-column: span 2; }
.child-table { width: 100%; border-collapse: collapse; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.child-table th { background: var(--bg-subtle); font-size: var(--font-sm); font-weight: 500; color: var(--text-muted); text-align: start; padding: 6px 10px; }
.child-table td { border-top: 1px solid var(--border); padding: 4px 10px; }
.child-table td .control { background: transparent; }

/* --------------------------------------------------------------- timeline */
.timeline { position: relative; padding-inline-start: 22px; }
.timeline::before { content: ""; position: absolute; inset-inline-start: 7px; top: 4px; bottom: 4px; width: 1px; background: var(--border-strong); }
.timeline-item { position: relative; padding: 6px 0 12px; }
.timeline-item::before { content: ""; position: absolute; inset-inline-start: -19px; top: 12px; width: 9px; height: 9px; border-radius: 50%; background: var(--bg-surface); border: 2px solid var(--gray-400); }
.timeline-item .when { color: var(--text-faint); font-size: var(--font-sm); }

/* -------------------------------------------------------------- dialog */
.modal-backdrop { position: fixed; inset: 0; z-index: 80; background: var(--overlay); display: flex; align-items: flex-start; justify-content: center; padding: 10vh var(--space-4) var(--space-4); }
.modal { width: 100%; max-width: 460px; background: var(--bg-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.modal.wide { max-width: 680px; }
.modal-head { display: flex; align-items: center; padding: var(--space-4) var(--space-5) 0; }
.modal-head h2 { margin: 0; font-size: var(--font-lg); font-weight: 600; color: var(--text-strong); }
.modal-head .btn { margin-inline-start: auto; }
.modal-body { padding: var(--space-4) var(--space-5); display: grid; gap: var(--space-3); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: 0 var(--space-5) var(--space-4); }
.form-error { color: var(--red-700); font-size: var(--font-sm); min-height: 18px; }

/* ----------------------------------------------------------------- toast */
.toasts { position: fixed; inset-inline-end: var(--space-4); bottom: var(--space-4); z-index: 90; display: grid; gap: var(--space-2); }
.toast { min-width: 240px; max-width: 380px; padding: 10px 14px; border-radius: var(--radius-md); background: var(--bg-surface); box-shadow: var(--shadow-lg); display: flex; gap: var(--space-2); align-items: flex-start; }
.toast .dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--green-500); flex: none; }
.toast.error .dot { background: var(--red-500); }

/* ----------------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--space-4); background: var(--bg-canvas); }
.login-card { width: 100%; max-width: 380px; padding: var(--space-8) var(--space-6); }
.login-brand { display: flex; justify-content: center; margin-bottom: var(--space-3); }
.login-name { text-align: center; font-size: var(--font-xl); font-weight: 600; color: var(--text-strong); }
.login-card h1 { margin: 2px 0 var(--space-5); text-align: center; font-size: var(--font-md); font-weight: 400; color: var(--text-muted); }

/* Brand mark: the admin's logo when there is one (fitted, never cropped or
 * stretched), otherwise the first letter of the brand name. */
/* inline-flex, not grid: a grid cell would stretch the image to the max width. */
.brand-mark.has-logo { display: inline-flex; align-items: center; width: auto; background: transparent; border-radius: 0; overflow: visible; }
.brand-mark.has-logo img { height: 100%; width: auto; max-width: min(240px, 45vw); object-fit: contain; display: block; }
.login-brand .brand-mark.has-logo img { max-width: min(320px, 80vw); }
.brand > span { display: inline-flex; align-items: center; }
.brand [data-brand-name] { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.login-card .field { margin-bottom: var(--space-3); }
.login-card .btn { width: 100%; height: 34px; }
.login-foot { margin-top: var(--space-4); text-align: center; }

/* ------------------------------------------------------ permission matrix */
.matrix { border-collapse: collapse; width: 100%; }
.matrix th, .matrix td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: start; }
.matrix thead th { font-size: var(--font-sm); font-weight: 500; color: var(--text-muted); }
.matrix .group td { background: var(--bg-subtle); font-weight: 600; color: var(--text-strong); text-align: start; }
.yes { color: var(--green-700); font-weight: 600; }
.no { color: var(--text-faint); }

.skeleton { height: 12px; border-radius: 4px; background: linear-gradient(90deg, var(--bg-subtle), var(--bg-active), var(--bg-subtle)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

.two-col { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--space-4); align-items: start; }
.stack { display: grid; gap: var(--space-4); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--space-4); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; color: var(--text-strong); }

/* ------------------------------------------------------------ responsive */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: auto; }
}
/* Long unbroken values (permission lists, ids, phone numbers) never push the
 * page sideways; wide tables scroll inside their own card. */
.main { overflow-x: clip; }
/* iOS Safari before 16 ignores "clip"; "hidden" is the fallback there. */
@supports not (overflow: clip) { .main { overflow-x: hidden; } }
/* Charts are sized by Chart.js from their box: the box must be the one
 * thing that decides the width, or a canvas can grow past its card. */
.spark-box, .chart-box { position: relative; width: 100%; min-width: 0; overflow: hidden; }
.spark-box { height: 34px; margin: 4px 0; }
.spark-box canvas, .chart-box canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.number-card { min-width: 0; overflow: hidden; }
.timeline-item, .card-pad, .static, .list-table td { overflow-wrap: anywhere; }
.btn-group { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.btn-group::-webkit-scrollbar { display: none; }
.btn-group .btn { flex: none; }

.nav-backdrop, .bottom-nav { display: none; }

/* ---------------------------------------------------------------- mobile
 * Phones: 44px touch targets, 16px text in fields (iOS zooms anything
 * smaller on focus), tables as stacked cards, dialogs as bottom sheets, a
 * bottom tab bar for the main screens and the full menu in a drawer. */
@media (max-width: 760px) {
  :root {
    --navbar-h: 56px;
    --control-h: 44px;
    --btn-h: 44px;
    --bottom-nav-h: 60px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
  }
  body { font-size: 15px; }
  input, select, textarea, .control { font-size: 16px !important; }

  /* navbar */
  .navbar { gap: var(--space-2); padding-inline: max(var(--space-3), env(safe-area-inset-left)) max(var(--space-3), env(safe-area-inset-right)); padding-top: env(safe-area-inset-top); height: calc(var(--navbar-h) + env(safe-area-inset-top)); }
  .nav-toggle { display: inline-flex; width: 44px; padding: 0; }
  .navbar .brand [data-brand-name] { display: none; }
  .awesomebar { flex: 1 1 auto; margin: 0; min-width: 0; }
  .awesomebar input { height: 44px; padding-inline: 36px 12px; }
  .awesomebar .icon { top: 14px; }
  .awesomebar kbd { display: none; }
  .awesome-results { position: fixed; inset-inline: var(--space-3); top: calc(var(--navbar-h) + env(safe-area-inset-top) + 4px); max-height: 60vh; }
  .awesome-results .item { min-height: 44px; }
  .nav-right { margin-inline-start: 0; gap: 4px; }
  .nav-right .btn { width: 44px; padding: 0; }
  #sync-badge { display: none !important; }
  .avatar { width: 40px; height: 40px; }
  .menu { position: fixed; inset-inline: var(--space-3); top: auto; bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 8px); min-width: 0; }
  .menu button, .menu a, .menu label { min-height: 44px; }

  /* drawer + backdrop */
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 60;
    width: min(300px, 85vw); height: 100%; padding-top: calc(var(--space-4) + env(safe-area-inset-top));
    padding-bottom: calc(var(--space-6) + var(--safe-bottom));
    background: var(--bg-canvas); border-inline-end: 1px solid var(--border); box-shadow: var(--shadow-lg);
    transform: translateX(-105%); transition: transform .2s ease; visibility: hidden;
  }
  [dir="rtl"] .sidebar { transform: translateX(105%); }
  body.nav-open .sidebar { transform: none; visibility: visible; }
  .sidebar a { height: 44px; }
  .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 55; background: var(--overlay); opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }

  /* bottom tab bar */
  .bottom-nav {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
    height: calc(var(--bottom-nav-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
    background: var(--bg-surface); border-top: 1px solid var(--border);
  }
  .bottom-nav a, .bottom-nav button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 44px; border: 0; background: none; color: var(--text-muted);
    font: 500 11px var(--font-sans); cursor: pointer;
  }
  .bottom-nav .icon { width: 22px; height: 22px; }
  .bottom-nav .active { color: var(--text-strong); }
  .bottom-nav .active .icon { stroke-width: 2.2; }
  .toasts { inset-inline: var(--space-3); bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 8px); }
  .toast { max-width: none; min-width: 0; }

  /* page */
  .main { padding: 0 var(--space-3) calc(var(--bottom-nav-h) + var(--safe-bottom) + var(--space-6)); }
  .page-head { position: static; padding-top: var(--space-4); gap: var(--space-2); }
  .page-head h1 { font-size: 19px; }
  .page-head .crumbs { width: 100%; }
  .page-actions { width: 100%; margin-inline-start: 0; }
  .page-actions > .btn, .page-actions > div { flex: 1 1 auto; }
  .page-actions > div > .btn { width: 100%; }
  .btn { min-height: 44px; }
  .btn-sm { height: 44px; min-width: 44px; padding: 0 12px; font-size: 14px; }
  .btn-group { width: 100%; }
  .btn-group .btn { height: 40px; min-height: 40px; }
  .checkbox { min-height: 44px; }
  .checkbox input { width: 20px; height: 20px; }
  .pill { height: 24px; }

  .number-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
  .number-card { padding: var(--space-3); }
  .number-card .value { font-size: 20px; }
  .shortcuts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .shortcut { min-height: 48px; }
  .chart-box { height: 220px; }
  .ws-section-title { font-size: 15px; }

  .list-filters { display: grid; grid-template-columns: 1fr; padding: var(--space-3); }
  .list-filters .control { width: 100% !important; }
  .list-filters > span { margin-inline-start: 0 !important; }
  .list-footer { flex-wrap: wrap; justify-content: center; }
  .list-footer .count { margin-inline-start: 0; width: 100%; text-align: center; }

  /* tables become cards: each row a card, each cell "label  value" */
  .list-table.stacked thead { display: none; }
  .list-table.stacked, .list-table.stacked tbody, .list-table.stacked tr, .list-table.stacked td { display: block; width: 100%; }
  .list-table.stacked tr { padding: var(--space-2) 0; border-bottom: 1px solid var(--border); }
  .list-table.stacked tr:last-child { border-bottom: 0; }
  .list-table.stacked td {
    display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3);
    height: auto; min-height: 28px; max-width: none; padding: 3px var(--space-4);
    border: 0; white-space: normal; text-align: end;
  }
  .list-table.stacked td::before { content: attr(data-label); flex: none; max-width: 45%; color: var(--text-muted); font-size: 13px; text-align: start; }
  .list-table.stacked td[data-label=""]::before, .list-table.stacked td[colspan]::before { display: none; }
  .list-table.stacked td[data-label=""] { justify-content: flex-start; }
  .list-table.stacked td:first-child { font-size: 15px; }
  .list-table.stacked tbody tr:hover td { background: transparent; }
  .list-table.stacked tbody tr:active { background: var(--bg-hover); }
  .table-scroll { overflow-x: visible; }
  .child-table { display: block; overflow-x: auto; }

  /* forms */
  .form-section { padding: var(--space-4); }
  .form-grid, .form-grid.cols-3 { gap: var(--space-3); }

  /* dialogs as bottom sheets */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal-backdrop .modal { max-width: none !important; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding-bottom: var(--safe-bottom); }
  .modal-foot { position: sticky; bottom: 0; background: var(--bg-surface); padding-top: var(--space-3); }
  .modal-foot .btn { flex: 1; }

  .login-card { padding: var(--space-6) var(--space-4); }
  .login-card .btn { height: 48px; }
  .matrix th, .matrix td { padding: 8px 6px; font-size: 13px; }
}

@media (max-width: 760px) {
  /* Links that stand alone as the thing to tap (record ids, names in a
   * timeline or card) get a full-height hit area; links inside a sentence
   * keep their normal size. */
  .timeline-item a, .crumbs a, .static a, .card-pad > div > a, td a { display: inline-flex; align-items: center; min-height: 40px; }
  input[type=file].control { min-height: 44px; }
}

@media (max-width: 760px) {
  .list-table.stacked td.m-hide { display: none; }
  /* The guest is the card's title; its row actions sit in the corner. */
  .list-table.stacked tr:has(td[data-col]) { display: flex; flex-direction: column; position: relative; }
  .list-table.stacked td[data-col="guest"] { order: -1; font-size: 16px; padding-inline-end: 56px; }
  .list-table.stacked td[data-col="guest"]::before { display: none; }
  .list-table.stacked td[data-col="actions"] { position: absolute; top: 4px; inset-inline-end: 4px; width: auto; padding: 0; }
  .list-table.stacked td[data-col="actions"]::before { display: none; }
}

.filters-toggle { display: none; }
@media (max-width: 760px) {
  .list-filters:has(.filters-toggle) > :not(input[type="search"]):not(.filters-toggle) { display: none; }
  .list-filters.open > :not(input[type="search"]):not(.filters-toggle) { display: revert; }
  .list-filters.open > .btn-group, .list-filters.open > .checkbox { display: flex; }
  .filters-toggle { display: inline-flex; justify-content: flex-start; }
}

/* Guest page on a phone: contact, WhatsApp and tags before the history. */
@media (max-width: 900px) {
  .guest-page > .stack { order: -1; }
}

/* ------------------------------------------------------------ maintenance */
/* Work-order board, unit tiles and meters, built from the same tokens as
 * every other Desk screen: hairline borders, neutral surfaces, colour only
 * inside pills (always with their text), one primary button per page. */
.kanban { display: flex; gap: var(--space-3); overflow-x: auto; align-items: flex-start; padding-bottom: var(--space-2); }
.kanban-col { flex: 1 0 220px; min-width: 220px; background: var(--bg-subtle); border-radius: var(--radius-lg); padding: var(--space-2); }
.kanban-col > h3 { display: flex; align-items: center; gap: var(--space-2); margin: var(--space-1) var(--space-2) var(--space-3); font-size: var(--font-base); font-weight: 600; color: var(--text-strong); }
.kanban-col > h3 .count { margin-inline-start: auto; color: var(--text-muted); font-weight: 500; }
.kanban-col .empty { padding: var(--space-6) var(--space-2); font-size: var(--font-sm); }
.wo-card {
  display: grid; gap: 6px; width: 100%; text-align: start; cursor: pointer;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--space-3); margin-bottom: var(--space-2); box-shadow: var(--shadow-sm);
}
.wo-card:hover { border-color: var(--border-strong); }
.wo-card:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.wo-card .row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-width: 0; }
.wo-card .ref { color: var(--text-muted); font-size: var(--font-sm); }
.wo-card .title { color: var(--text-strong); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wo-card .desc { color: var(--text-muted); font-size: var(--font-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wo-card .meta { color: var(--text-faint); font-size: var(--font-sm); display: inline-flex; align-items: center; gap: 4px; }
.wo-card .meta .icon { width: 13px; height: 13px; }
.wo-card .meta.warn { color: var(--orange-700); }
.wo-card .actions { display: flex; justify-content: flex-end; gap: var(--space-2); padding-top: 6px; border-top: 1px solid var(--border); }
.wo-grid { display: grid; gap: var(--space-2); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.wo-grid .wo-card { margin-bottom: 0; }
.unit-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: var(--space-2); margin-bottom: var(--space-4); }
.unit-tile {
  display: grid; gap: 6px; justify-items: start; cursor: pointer; padding: var(--space-2) var(--space-3);
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.unit-tile:hover { border-color: var(--border-strong); }
.unit-tile:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.unit-tile b { font-size: var(--font-md); font-weight: 600; color: var(--text-strong); }
.unit-tile small { color: var(--text-muted); font-size: var(--font-xs); }
.unit-tile small.warn { color: var(--orange-700); }
.unit-tile.off { background: var(--bg-subtle); }
.meter { height: 4px; border-radius: var(--radius-full); background: var(--bg-subtle); overflow: hidden; margin-top: 6px; }
.meter > span { display: block; height: 100%; background: var(--text-faint); border-radius: inherit; }
.breakdown { display: grid; gap: var(--space-3); }
.breakdown .line { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.alert-card { margin-bottom: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--yellow-50); color: var(--text-body); }
.alert-card.red { background: var(--red-50); }
.alert-card ul { margin: 6px 0 0; padding-inline-start: 18px; display: grid; gap: 2px; }
.alert-card .alert-title { font-weight: 600; color: var(--text-strong); }
.chip-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip-row .btn.active, .btn-group .btn.active { background: var(--primary); color: var(--text-inverse); }
.btn-group .btn .num { margin-inline-start: 4px; opacity: .7; }
.photo-grid { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.photo-grid img { width: 96px; height: 96px; object-fit: cover; border-radius: var(--radius-md); border: 1px solid var(--border); cursor: zoom-in; }
.step-cell { display: inline-flex; align-items: center; gap: 6px; }
.step-btn { height: 26px; padding: 0 10px; border-radius: var(--radius-full); border: 1px solid var(--border); background: var(--bg-surface); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: var(--font-sm); color: var(--text-muted); }
.step-btn::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--gray-400); }
.step-btn.s1 { color: var(--yellow-700); border-color: transparent; background: var(--yellow-50); }
.step-btn.s1::before { background: currentColor; }
.step-btn.s2 { color: var(--green-700); border-color: transparent; background: var(--green-50); }
.step-btn.s2::before { background: currentColor; }
.step-btn:hover { filter: brightness(.97); }
.step-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.time-in { width: 128px; }
@media (max-width: 760px) {
  .kanban-col { flex-basis: 84vw; min-width: 84vw; }
  .unit-tiles { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}

