:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #2563eb;
  --brand-d: #1d4ed8;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --info: #0891b2;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .06);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Arabic", sans-serif;
  background: #f1f5f9;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: linear-gradient(120deg, #0f172a, #1e3a8a);
  color: #fff;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.topbar .brand { display: flex; align-items: center; gap: 12px; }
.topbar .logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: rgba(255,255,255,.15);
  display: grid; place-items: center; font-weight: 800; font-size: 18px;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: .2px; }
.topbar .sub { font-size: 12px; opacity: .75; }
.topbar nav a { color: #cbd5e1; margin-left: 18px; font-size: 14px; }
.topbar nav a:hover { color: #fff; }

.container { max-width: 1180px; margin: 0 auto; padding: 26px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.filters {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input, .field select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 14px; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid #bfdbfe; border-color: var(--brand); }

.btn {
  padding: 10px 18px; border: none; border-radius: 10px; cursor: pointer;
  background: var(--brand); color: #fff; font-weight: 600; font-size: 14px;
}
.btn:hover { background: var(--brand-d); }
.btn.ghost { background: #eef2ff; color: var(--brand-d); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 22px 0; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 22px; font-weight: 800; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
tbody tr:hover { background: #f8fafc; cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.b-ok { background: #dcfce7; color: #166534; }
.b-warn { background: #fef3c7; color: #92400e; }
.b-bad { background: #fee2e2; color: #991b1b; }
.b-info { background: #cffafe; color: #155e75; }
.b-muted { background: #e2e8f0; color: #475569; }

.conf-bar { height: 8px; border-radius: 999px; background: #e2e8f0; overflow: hidden; min-width: 80px; }
.conf-bar > span { display: block; height: 100%; border-radius: 999px; }

.muted { color: var(--muted); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 16px; }

/* ---- LPO detail ---- */
.detail-head { display: flex; flex-wrap: wrap; gap: 20px; justify-content: space-between; align-items: flex-start; }
.detail-head .title { font-size: 26px; font-weight: 800; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; margin-top: 12px; }
.kv .k { color: var(--muted); font-weight: 600; }
.section-title { font-size: 16px; font-weight: 800; margin: 26px 0 12px; display: flex; align-items: center; gap: 10px; }
.section-title .count { background: #eef2ff; color: var(--brand-d); border-radius: 999px; padding: 1px 9px; font-size: 12px; }

.recon-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.recon-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.recon-card .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.recon-card .v { font-size: 20px; font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; }
.recon-card .d { font-size: 12px; margin-top: 4px; }

.timeline { position: relative; margin: 8px 0 0 8px; padding-left: 22px; border-left: 2px solid var(--line); }
.tl-item { position: relative; padding: 10px 0; }
.tl-item::before {
  content: ""; position: absolute; left: -29px; top: 16px;
  width: 12px; height: 12px; border-radius: 50%; background: var(--brand); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--brand);
}
.tl-item.pay::before { background: var(--ok); box-shadow: 0 0 0 2px var(--ok); }
.tl-item .when { font-size: 12px; color: var(--muted); }
.tl-item .what { font-size: 14px; font-weight: 600; }

.warnbox { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 12px; padding: 12px 16px; font-size: 14px; margin-top: 10px; }
.narr { font-size: 13px; color: #334155; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.reasons { font-size: 12px; color: var(--muted); margin: 4px 0 0; padding-left: 16px; }

.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---- bar charts ---- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr auto; align-items: center; gap: 12px; font-size: 13px; }
.bar-label { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: #eef2f7; border-radius: 999px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; min-width: 2px; }
.bar-val { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.bar-label a { color: var(--brand-d); }

/* column chart (year / month trend) */
.cols { display: flex; align-items: flex-end; gap: 8px; height: 180px; padding-top: 8px; overflow-x: auto; }
.col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 1 0 26px; min-width: 26px; height: 100%; }
.col-bar { width: 70%; border-radius: 6px 6px 0 0; transition: height .3s ease; }
.col-lbl { font-size: 10px; color: var(--muted); margin-top: 6px; white-space: nowrap; transform: rotate(-45deg); transform-origin: center; height: 22px; }

.btn-sm { display: inline-block; padding: 4px 10px; border-radius: 8px; background: var(--info, #2563eb); color: #fff; text-decoration: none; font-size: 12px; }
.btn-sm:hover { filter: brightness(1.08); }
.chk { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.chk input { width: auto; }

@media (max-width: 820px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .stats, .recon-grid { grid-template-columns: 1fr 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 90px 1fr auto; }
  .container { padding: 16px; }
  table { font-size: 13px; }
  th:nth-child(4), td:nth-child(4) { display: none; }
}
