:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1f2733;
  --muted: #6b7785;
  --line: #e2e7ee;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --ok-bg: #e7f6ec; --ok-ink: #1b7a3d;
  --err-bg: #fdecec; --err-ink: #b32525;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; gap: 18px;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 0 20px; height: 56px; box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-weight: 700; font-size: 17px; color: var(--ink); }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  color: var(--muted); padding: 7px 12px; border-radius: 7px; font-weight: 500;
}
.topbar nav a:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; }
.btn-logout { color: var(--muted); font-size: 13px; }

.lang-switch { display: inline-flex; gap: 2px; }
.lang-switch a { padding: 3px 9px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); }
.lang-switch a:hover { background: var(--bg); text-decoration: none; }
.lang-switch a.active { background: var(--brand); color: #fff; }
.lang-switch a.active:hover { background: var(--brand-dark); }
.lang-float {
  position: fixed; top: 14px; inset-inline-end: 18px; z-index: 30;
  background: var(--card); border: 1px solid var(--line); border-radius: 9px;
  padding: 3px; box-shadow: var(--shadow);
}

/* RTL adjustments */
[dir="rtl"] th, [dir="rtl"] td { text-align: right; }
[dir="rtl"] th.num, [dir="rtl"] td.num { text-align: left; }
[dir="rtl"] .right { text-align: left; }
[dir="rtl"] .dash-card::before { left: auto; right: 0; }
[dir="rtl"] .dash-pct { margin-left: 0; margin-right: 4px; }

main { max-width: 1040px; margin: 24px auto; padding: 0 20px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px;
}
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head .spacer { flex: 1; }

h2 { font-size: 16px; margin: 0 0 14px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--brand); color: #fff; border: 1px solid var(--brand);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600;
  cursor: pointer; line-height: 1; min-height: 36px;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { background: var(--bg); }
.btn.danger { background: #fff; color: var(--err-ink); border-color: #f3c4c4; }
.btn.danger:hover { background: var(--err-bg); }
.btn.small { padding: 5px 10px; min-height: 30px; font-size: 13px; }
.btn[disabled] { opacity: .65; cursor: progress; }

.spinner {
  width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; display: inline-block; animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 4px; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--brand); }
textarea { resize: vertical; min-height: 64px; }
.field { margin-bottom: 14px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.row-inline { display: flex; gap: 10px; align-items: flex-end; }
.row-inline > * { flex: 1; }
.row-inline .shrink { flex: 0 0 auto; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }

.flashes { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; font-weight: 500; }
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash.err { background: var(--err-bg); color: var(--err-ink); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.pending { background: #fef3c7; color: #92600a; }
.pill.open { background: #fef3c7; color: #92600a; }
.pill.repaired { background: var(--ok-bg); color: var(--ok-ink); }
.pill.not_repaired { background: var(--err-bg); color: var(--err-ink); }
.pill.done { background: #dbeafe; color: #1e40af; }
.pill.delivered { background: var(--ok-bg); color: var(--ok-ink); }
.pill.cap { text-transform: capitalize; }

.muted { color: var(--muted); }
.right { text-align: right; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.profit-pos { color: var(--ok-ink); font-weight: 600; }
.profit-neg { color: var(--err-ink); font-weight: 600; }

.part-row { display: grid; grid-template-columns: 1fr 150px 110px 36px; gap: 10px; margin-bottom: 8px; align-items: center; }
.part-row .cost-hint { font-size: 12px; color: var(--muted); }

.dash { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 8px; }
.dash-card {
  position: relative; display: flex; gap: 14px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 18px 20px; box-shadow: 0 1px 2px rgba(16,24,40,.05);
  transition: transform .16s ease, box-shadow .16s ease; overflow: hidden;
}
.dash-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent);
}
.dash-card:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(16,24,40,.12); }
a.dash-card { text-decoration: none; color: inherit; cursor: pointer; }
a.dash-card:hover { text-decoration: none; }
.dash-icon {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center; background: var(--accent-bg); color: var(--accent);
}
.dash-icon svg { width: 17px; height: 17px; flex: 0 0 auto; }
.dash-body { min-width: 0; }
.dash-label {
  color: var(--muted); font-size: 11.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
}
.dash-value {
  font-size: 30px; font-weight: 800; line-height: 1.12; margin-top: 3px;
  color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: -.01em;
}
.dash-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.dash-pct {
  font-size: 13px; font-weight: 700; vertical-align: middle; margin-left: 4px;
  padding: 1px 7px; border-radius: 999px; background: var(--accent-bg); color: var(--accent);
}
.dash-blue   { --accent: #2563eb; --accent-bg: #eef4ff; }
.dash-green  { --accent: #15a05a; --accent-bg: #e8f8ef; }
.dash-violet { --accent: #7c3aed; --accent-bg: #f3edff; }
.dash-amber  { --accent: #d97706; --accent-bg: #fff4e2; }
.dash-red    { --accent: #dc2626; --accent-bg: #fdecec; }
.dash-teal   { --accent: #0891b2; --accent-bg: #e4f6fb; }
.dash-amber .dash-value { color: var(--ok-ink); }
.dash-red .dash-value { color: var(--err-ink); }
@media (max-width: 960px) { .dash { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px) { .dash { grid-template-columns: 1fr 1fr; } }
@media (max-width: 400px) { .dash { grid-template-columns: 1fr; } }

.searchbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.searchbar input { max-width: 320px; }
.searchbar input[type="date"] { max-width: 170px; }
.searchbar .lbl { color: var(--muted); font-size: 13px; }

/* Tom Select — match the app's native inputs */
.ts-wrapper { width: 100%; }
.ts-control {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px;
  min-height: 38px; font: inherit; background: #fff;
}
.ts-wrapper.focus .ts-control { outline: 2px solid #bfdbfe; border-color: var(--brand); }
.ts-dropdown { border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); margin-top: 4px; }
.ts-dropdown .active { background: var(--bg); color: var(--ink); }
.ts-dropdown .create { color: var(--brand); }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

.login-wrap { max-width: 360px; margin: 8vh auto; }
.login-wrap h1 { text-align: center; }

@media (max-width: 720px) {
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px; }
  .part-row { grid-template-columns: 1fr 1fr; }
}
