/* Al Khaleej Elevators — one small stylesheet.
   Colours are design tokens; light and dark themes swap the tokens only.
   Layout uses logical properties (margin-inline-start etc.) so Arabic RTL mirrors automatically. */

:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef1ec;
  --text: #1b1f1c;
  --text-muted: #5b635d;
  --border: #d5dad4;
  --brand: #1f7a3a;          /* logo green */
  --brand-strong: #155c2a;
  --brand-contrast: #ffffff;
  --accent-soft: #e3f1e6;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warning: #8a5a00;
  --warning-soft: #fff3d6;
  --info: #1c5a8a;
  --info-soft: #e5f0fa;
  --focus: #0b57d0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --font: "Segoe UI", "Noto Sans", "Noto Naskh Arabic", "Tahoma", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121513; --surface: #1b1f1c; --surface-2: #242a26; --text: #e8ece9; --text-muted: #a6afa8;
    --border: #353d38; --brand: #4cb86a; --brand-strong: #6fd08a; --brand-contrast: #0c1a10;
    --accent-soft: #1f3526; --danger: #ff8a80; --danger-soft: #3a1d1b; --warning: #ffcc66;
    --warning-soft: #3a2f14; --info: #8cc4f0; --info-soft: #182b3a; --focus: #8ab4f8; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121513; --surface: #1b1f1c; --surface-2: #242a26; --text: #e8ece9; --text-muted: #a6afa8;
  --border: #353d38; --brand: #4cb86a; --brand-strong: #6fd08a; --brand-contrast: #0c1a10;
  --accent-soft: #1f3526; --danger: #ff8a80; --danger-soft: #3a1d1b; --warning: #ffcc66;
  --warning-soft: #3a2f14; --info: #8cc4f0; --info-soft: #182b3a; --focus: #8ab4f8; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.5; }
a { color: var(--brand-strong); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; inset-inline-start: -999px; }
.skip-link:focus { inset-inline-start: 8px; top: 8px; background: var(--surface); padding: 8px; z-index: 10; }

/* Header */
.topbar { background: var(--surface); border-block-end: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar-inner { display: flex; align-items: center; gap: 12px; max-width: 1280px; margin: 0 auto; padding: 8px 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand img { height: 36px; width: auto; border-radius: 6px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; margin-inline-start: 8px; }
.nav a { padding: 10px 10px; white-space: nowrap; border-radius: 8px; color: var(--text); text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.nav a[aria-current="page"], .nav a:hover { background: var(--accent-soft); color: var(--brand-strong); }
.topbar-tools { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; }
.btn.menu-toggle { display: none; }
.topbar-tools .btn { white-space: nowrap; }
/* Many menu items: show only the logo (no name) on laptops so the menu stays on one line. */
@media (min-width: 1200px) and (max-width: 1440px) { .brand span { display: none; } .nav { margin-inline-start: 0; } }

/* Phones and tablets: the menu folds behind the "Menu" button. */
@media (max-width: 1199px) {
  .topbar-inner { flex-wrap: wrap; }
  .nav { display: none; width: 100%; flex-direction: column; margin: 0; }
  .nav.open { display: flex; }
  .btn.menu-toggle { display: inline-flex; }
}
@media (max-width: 767px) { .topbar-tools .hide-sm { display: none; } }

/* Layout */
main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-block: 8px 16px; }
.page-head h1 { font-size: 1.5rem; margin: 0; }
.page-head .actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
@media (min-width: 768px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
/* Counters on the home page: as many per row as fit, never one left alone. */
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card h2 { font-size: 1.1rem; margin: 0 0 12px; }
.muted { color: var(--text-muted); }
.stat { font-size: 2rem; font-weight: 700; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); font-weight: 600; }
.btn-primary:hover { background: var(--brand-strong); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-small { min-height: 36px; padding: 4px 10px; font-size: .9rem; }
form.inline { display: inline; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: 10px 12px; border-block-end: 1px solid var(--border); text-align: start; vertical-align: top; }
th { font-size: .85rem; color: var(--text-muted); font-weight: 600; background: var(--surface-2); }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Numbers read left-to-right in Arabic too (keeps "−4,000.00" and "5%" in order); aligned to the end. */
td.num { direction: ltr; }
[dir="rtl"] td.num { text-align: left; }
tr:hover td { background: var(--surface-2); }
.totals td { font-weight: 600; }

/* Badges */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border); white-space: nowrap; }
.badge-good { background: var(--accent-soft); color: var(--brand-strong); border-color: transparent; }
.badge-warn { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: transparent; }

/* Forms */
.form-grid { display: grid; gap: 12px 16px; }
@media (min-width: 768px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .wide { grid-column: 1 / -1; } }
.field label { display: block; font-weight: 600; margin-block-end: 4px; }
.field .help { font-size: .85rem; color: var(--text-muted); }
.field .errorlist, .errorlist { color: var(--danger); margin: 4px 0; padding: 0; list-style: none; font-size: .9rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=url],
input[type=search], input[type=file], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; }
textarea { min-height: 60px; }
input[type=checkbox] { width: 20px; height: 20px; }
.checkbox-list ul, ul.checkbox-list { list-style: none; padding: 0; margin: 0; }
.checkbox-list li label { font-weight: 400; display: flex; gap: 8px; align-items: center; min-height: 36px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-block-end: 12px; align-items: end; }
.filters > * { flex: 1 1 160px; }
.filters .btn { flex: 0 0 auto; }

/* Messages */
.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 12px 16px; border-radius: 8px; margin-block-end: 8px; background: var(--info-soft); color: var(--info); }
.messages li.success { background: var(--accent-soft); color: var(--brand-strong); }
.messages li.error { background: var(--danger-soft); color: var(--danger); }
.messages li.warning { background: var(--warning-soft); color: var(--warning); }

/* Line editor */
.line-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-block-end: 12px; background: var(--surface); }
.line-grid { display: grid; gap: 8px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 1024px) { .line-grid { grid-template-columns: repeat(6, 1fr); } .line-grid .span-2 { grid-column: span 2; } .line-grid .span-3 { grid-column: span 3; } }
.line-grid .field label { font-size: .85rem; }
.line-total { font-weight: 700; text-align: end; }
.sticky-totals { position: sticky; bottom: 0; background: var(--surface); border-block-start: 1px solid var(--border); padding: 12px 16px; display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.sticky-totals .actions { margin-inline-start: auto; display: flex; gap: 8px; }

.pagination { display: flex; gap: 8px; align-items: center; margin-block-start: 12px; }
dl.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.details dt { color: var(--text-muted); }
dl.details dd { margin: 0; }
.login-box { max-width: 380px; margin: 10vh auto; }
.rtl-text { direction: rtl; text-align: right; }
