:root {
  --brand: #0b6e69;
  --brand-600: #095a56;
  --brand-50: #e7f3f2;
  --ink: #17212b;
  --ink-2: #4a5866;
  --ink-3: #7b8794;
  --line: #e2e7ec;
  --bg: #f4f6f8;
  --card: #ffffff;
  --ok: #157f3b;
  --ok-bg: #e6f4ea;
  --warn: #9a5b00;
  --warn-bg: #fff3dc;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --info: #1d4ed8;
  --info-bg: #e8effd;
  --muted-bg: #eef1f4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --sidebar: 248px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 1.45rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 600; margin-block-end: .75rem; }
small { color: var(--ink-3); }
pre { white-space: pre-wrap; word-break: break-word; font-size: 12px; background: var(--muted-bg); padding: 8px; border-radius: 6px; margin: 6px 0 0; text-align: left; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.skip { position: absolute; inset-inline-start: -999px; }
.skip:focus { inset-inline-start: 8px; top: 8px; z-index: 100; background: #fff; padding: 6px 10px; }

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 500; font-size: .92rem;
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  white-space: nowrap; text-decoration: none !important;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--muted-bg); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { background: #912018; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--muted-bg); }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px;
  border: 0; background: transparent; border-radius: 8px; cursor: pointer; color: var(--ink-2); font-size: 15px;
}
.icon-btn:hover { background: var(--muted-bg); color: var(--ink); }
.icon-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }

/* ------------------------------------------------------------ forms */
input, select, textarea {
  font: inherit; font-size: .93rem; color: var(--ink);
  border: 1px solid #cdd5dd; border-radius: 8px; padding: 8px 10px; background: #fff;
  min-width: 0; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
input:disabled { background: var(--muted-bg); color: var(--ink-2); }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--brand); }
input[type=number] { text-align: end; }
textarea { resize: vertical; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: .85rem; font-weight: 500; color: var(--ink-2); }
.field small { font-size: .78rem; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: .92rem; cursor: pointer; white-space: nowrap; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; align-items: end; }
.form-grid .wide { grid-column: 1 / -1; }
.contents { display: contents; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.form-error { color: var(--bad); background: var(--bad-bg); padding: 8px 12px; border-radius: 8px; margin: 0; font-size: .9rem; }

/* ------------------------------------------------------------ layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--sidebar);
  background: #0c3b3a; color: #d6e7e5; display: flex; flex-direction: column; z-index: 40;
  overflow-y: auto;
}
.sidebar .brand { padding: 18px 18px 14px; color: #fff; }
.sidebar .brand small { color: #9cc4c0; }
.sidebar nav { display: flex; flex-direction: column; padding: 6px 10px 20px; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px;
  color: #cfe3e1; text-decoration: none; font-size: .93rem;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.sidebar nav a.active { background: rgba(255, 255, 255, .13); color: #fff; font-weight: 600; }
.sidebar nav svg { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand strong { display: block; font-size: 1.02rem; }
.brand small { display: block; font-size: .78rem; }
.logo { width: 40px; height: 40px; border-radius: 10px; background: var(--brand); display: grid; place-items: center; flex: none; }
.logo svg { width: 24px; height: 24px; fill: #fff; }
.main-col { flex: 1; min-width: 0; margin-inline-start: var(--sidebar); display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px;
  padding: 10px 24px; background: rgba(255, 255, 255, .92); backdrop-filter: blur(6px); border-block-end: 1px solid var(--line);
}
.grow { flex: 1; }
.menu-btn { display: none; }
.user-chip { display: flex; align-items: center; gap: 10px; text-decoration: none !important; color: var(--ink); padding: 4px 8px; border-radius: 8px; }
.user-chip:hover { background: var(--muted-bg); }
.user-chip .who { display: flex; flex-direction: column; line-height: 1.25; }
.user-chip .who strong { font-size: .9rem; font-weight: 600; }
.user-chip .who small { font-size: .76rem; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-50); color: var(--brand); display: grid; place-items: center; font-weight: 700; }
main { padding: 24px; max-width: 1400px; width: 100%; outline: none; }
.scrim { display: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-block-end: 18px; }
.page-head h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-head h1 small { font-size: .85rem; font-weight: 400; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-block; font-size: .85rem; margin-block-end: 4px; }
[dir=rtl] .back::before { content: '→ '; }
[dir=ltr] .back::before { content: '← '; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-block-end: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card .pad, .card h2.pad { padding: 16px 18px 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-block-end: 8px; }
.card-head h2 { margin: 0; }
.card-head.pad { padding-block-end: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; align-items: start; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-block-end: 14px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; max-width: 240px; }
.toolbar label:not(.check) { display: inline-flex; align-items: center; gap: 6px; font-size: .88rem; color: var(--ink-2); }
.toolbar label input { width: auto; }

.tabs { display: flex; gap: 4px; border-block-end: 1px solid var(--line); margin-block-end: 14px; overflow-x: auto; scrollbar-width: thin; }
.tabs a { padding: 8px 14px; color: var(--ink-2); border-block-end: 2px solid transparent; white-space: nowrap; text-decoration: none; font-size: .92rem; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--brand); border-color: var(--brand); font-weight: 600; }

/* ------------------------------------------------------------ tables */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th, .tbl td { padding: 10px 14px; text-align: start; border-block-end: 1px solid var(--line); vertical-align: middle; }
.tbl thead th { background: #f8fafb; color: var(--ink-2); font-weight: 600; font-size: .8rem; white-space: nowrap; }
.tbl tfoot th { background: #f8fafb; }
.tbl tbody tr:hover { background: #fafcfc; }
.tbl tbody tr:last-child td { border-block-end: 0; }
.tbl .num { text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl td.empty, .list .empty { text-align: center; color: var(--ink-3); padding: 26px; }
.tbl tr.dim td { color: var(--ink-3); }
.tbl tr.bad-row td { background: #fff8f7; }
.tbl.lines td { padding: 6px 8px; }
.tbl.lines input.qty { max-width: 120px; }
.tbl input[type=number] { max-width: 130px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82em; color: var(--ink-3); direction: ltr; unicode-bidi: isolate; }
td small.code, h1 small.code { margin-inline-start: 6px; }
.nowrap { white-space: nowrap; }
.row-actions { white-space: nowrap; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }
.warn-text { color: var(--warn); }

/* ------------------------------------------------------------ badges & alerts */
.badge { display: inline-block; font-size: .76rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--muted-bg); color: var(--ink-2); white-space: nowrap; vertical-align: middle; }
.st-submitted, .st-pending, .st-partially_received, .st-partially_issued { background: var(--warn-bg); color: var(--warn); }
.st-approved, .st-ordered { background: var(--info-bg); color: var(--info); }
.st-received, .st-issued { background: var(--ok-bg); color: var(--ok); }
.st-rejected { background: var(--bad-bg); color: var(--bad); }
.st-cancelled, .st-closed { background: var(--muted-bg); color: var(--ink-3); }
.alert { padding: 10px 14px; border-radius: 8px; margin: 0 0 16px; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }

/* ------------------------------------------------------------ dashboard */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-block-end: 18px; }
.kpi {
  display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--ink); text-decoration: none !important;
  border-inline-start: 4px solid var(--line);
}
a.kpi:hover { border-color: var(--brand); }
.kpi-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: .9rem; font-weight: 400; }
.kpi-label { font-size: .83rem; color: var(--ink-2); }
.kpi.attn { border-inline-start-color: var(--info); }
.kpi.warn { border-inline-start-color: #e7a33e; }
.kpi.bad { border-inline-start-color: var(--bad); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-block-end: 1px solid var(--line); flex-wrap: wrap; }
.list li:last-child { border-block-end: 0; }
.list li > span { display: inline-flex; align-items: center; gap: 8px; }
.files li a { word-break: break-all; }

.meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 20px; margin: 0 0 18px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card .meta { border: 0; padding: 0; margin: 0 0 8px; }
.meta.single { grid-template-columns: 1fr; }
.meta .wide { grid-column: 1 / -1; }
.meta dt { font-size: .8rem; color: var(--ink-3); }
.meta dd { margin: 2px 0 0; font-weight: 500; }
.meta dd small { display: block; font-weight: 400; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0 6px; padding-inline-start: 16px; border-inline-start: 2px solid var(--brand-50); position: relative; display: flex; flex-direction: column; }
.timeline li::before { content: ''; position: absolute; inset-inline-start: -5px; top: 13px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 220px) 1fr auto; gap: 12px; align-items: center; font-size: .88rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--muted-bg); border-radius: 4px; height: 12px; overflow: hidden; }
.bar { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.bar-value { font-variant-numeric: tabular-nums; white-space: nowrap; }
.total-line { margin: 12px 0 0; text-align: end; }
.report-actions { display: flex; justify-content: flex-end; gap: 8px; margin-block-end: 12px; }

.loading, .empty-state { padding: 60px 20px; text-align: center; color: var(--ink-3); }
.empty-state.error { color: var(--bad); }
.center { text-align: center; }

/* ------------------------------------------------------------ dialog & toast */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); color: var(--ink); }
dialog.wide { width: min(860px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(15, 23, 32, .45); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-block-end: 1px solid var(--line); }
.dlg-head h2 { margin: 0; font-size: 1.08rem; }
.dlg-body { padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-block-start: 1px solid var(--line); background: #fafbfc; }
#toasts { position: fixed; inset-block-end: 20px; inset-inline-end: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: #17212b; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-size: .92rem; transition: opacity .3s, transform .3s; max-width: 360px; }
.toast-error { background: var(--bad); }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ------------------------------------------------------------ auth */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, #0c3b3a 0%, #0b6e69 55%, #e7f3f2 55.1%); }
.auth-top { position: fixed; top: 12px; inset-inline-end: 12px; }
.auth-top .btn { color: #fff; border-color: rgba(255, 255, 255, .4); }
.auth-top .btn:hover { background: rgba(255, 255, 255, .12); }
.auth-card { width: min(420px, 100%); background: #fff; border-radius: 16px; padding: 28px; box-shadow: 0 20px 50px rgba(0, 0, 0, .18); }
.auth-card .brand { margin-block-end: 22px; }
.auth-card h1 { font-size: 1.25rem; margin-block-end: 14px; }

.print-only { display: none; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  [dir=rtl] .sidebar { transform: translateX(100%); }
  .nav-open .sidebar { transform: none; }
  .nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 35; }
  .main-col { margin-inline-start: 0; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 8px 16px; }
  .user-chip .who { display: none; }
  main { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .toolbar input[type=search], .toolbar select { max-width: none; flex: 1 1 160px; }
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-track { grid-column: 1 / -1; grid-row: 2; }
  h1 { font-size: 1.2rem; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 1.2rem; }
}

/* ------------------------------------------------------------ print */
@media print {
  body { background: #fff; font-size: 12px; }
  .sidebar, .topbar, .no-print, .toolbar, .tabs, #toasts { display: none !important; }
  .print-only { display: block; }
  .main-col { margin: 0; }
  main { padding: 0; max-width: none; }
  .card, .meta { box-shadow: none; border-color: #bbb; break-inside: avoid; }
  .tbl th, .tbl td { padding: 5px 8px; }
  a { color: inherit; }
  .grid-2 { grid-template-columns: 1fr; }
  .signatures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 30px; margin-top: 50px; }
  .signatures div { border-top: 1px solid #333; padding-top: 6px; text-align: center; }
}
