:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --line: #e4e8f1;
  --text: #1b2233;
  --muted: #6b7590;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --ok: #0f9d58;
  --ok-soft: #e6f6ec;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --info: #2563eb;
  --info-soft: #e0ecff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 10px 24px -14px rgba(16, 24, 40, 0.18);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

h2, h3, h4 { margin: 0; line-height: 1.3; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
b { color: var(--bad); font-weight: 700; }
a { color: var(--primary); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1220px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff; display: grid; place-items: center; font-size: 15px; flex: none;
}
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; padding-bottom: 2px; }
.nav::-webkit-scrollbar { display: none; }
.nav-link {
  white-space: nowrap; padding: 8px 12px; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 13.5px;
}
.nav-link i { margin-right: 4px; }
.nav-link:hover { background: #f1f3fa; color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }

/* ---------- layout ---------- */
main#app { max-width: 1220px; margin: 0 auto; padding: 18px 16px 70px; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
}
.page-head p { margin: 4px 0 0; font-size: 13px; }
.muted { color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card { margin-top: 14px; }

.grid-2 { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 900px) {
  .grid-2 { grid-template-columns: 1.35fr 1fr; }
}

/* ---------- stat cards ---------- */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center;
}
.stat .ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 15px; flex: none; }
.stat .v { font-size: 21px; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.ic.c1 { background: var(--primary-soft); color: var(--primary); }
.ic.c2 { background: var(--info-soft); color: var(--info); }
.ic.c3 { background: var(--warn-soft); color: var(--warn); }
.ic.c4 { background: var(--ok-soft); color: var(--ok); }
.ic.c5 { background: var(--bad-soft); color: var(--bad); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-decoration: none; font-family: inherit; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: #f6f7fc; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.icon-btn {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.icon-btn:hover { background: #f1f3fa; color: var(--text); }
.icon-btn.danger:hover { background: var(--bad-soft); color: var(--bad); }

/* ---------- form controls ---------- */
.input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font-size: 13.5px; font-family: inherit; color: var(--text); outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12); }
textarea.input { resize: vertical; line-height: 1.5; }
select.input { appearance: none; background-image: none; }
input[type="file"].input { padding: 7px; }

.filters { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .filters { grid-template-columns: 1.4fr 1fr 1fr; } }
@media (min-width: 1024px) { .filters { grid-template-columns: 1.6fr 1fr 1fr 0.8fr 1fr; } }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; font-weight: 600; color: #3a4358; }
.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } .field.span2 { grid-column: span 2; } }

.checks { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #3a4358; cursor: pointer; }
.chk input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 820px; }
thead th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--muted); font-weight: 700; padding: 10px 8px; border-bottom: 1px solid var(--line);
  white-space: nowrap; background: #fbfcfe;
}
tbody td { padding: 10px 8px; border-bottom: 1px solid #f0f2f8; vertical-align: middle; }
tbody tr:hover { background: #fafbff; }
tbody tr:last-child td { border-bottom: none; }
.cell-name { font-weight: 600; }
.cell-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 2px; justify-content: flex-end; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap;
}
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.type { background: #f1f3fa; color: #444f68; }
.badge.type.dcp { background: #e6f7f6; color: #0f766e; }
.due-late { color: var(--bad); font-weight: 700; }

/* ---------- progress ---------- */
.cust-row + .cust-row { margin-top: 12px; }
.cust-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; margin-bottom: 5px; }
.bar { height: 8px; background: #eef1f7; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #6366f1, #8b5cf6); border-radius: 999px; }
.bar-fill.full { background: linear-gradient(90deg, #10b981, #34d399); }

/* ---------- lists ---------- */
.row-item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid #f1f3f9;
}
.row-item:last-child { border-bottom: none; }
.row-item .t { font-weight: 600; }
.row-item .s { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- misc ---------- */
.loading, .empty {
  padding: 40px 16px; text-align: center; color: var(--muted); font-size: 13.5px;
}
.loading i, .empty i { margin-right: 6px; }
.empty h4 { margin: 10px 0 4px; color: var(--text); font-size: 15px; }
.empty .btn { margin-top: 12px; }

.row-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16, 24, 40, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 20px 12px; z-index: 100; overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 620px;
  box-shadow: 0 24px 48px -12px rgba(16, 24, 40, 0.35); margin: auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.modal-body { padding: 16px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line);
}

/* ---------- permissions ---------- */
.perm-layout { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .perm-layout { grid-template-columns: 320px 1fr; align-items: start; } }
.perm-list { display: flex; flex-direction: column; gap: 6px; max-height: 460px; overflow-y: auto; }
.perm-emp {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; text-align: left; font-family: inherit; font-size: 13px;
}
.perm-emp:hover { background: #f7f8fd; }
.perm-emp.active { border-color: var(--primary); background: var(--primary-soft); }
.perm-emp .s { font-size: 11.5px; color: var(--muted); }
.perm-custs { display: grid; gap: 8px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .perm-custs { grid-template-columns: 1fr 1fr; } }
.perm-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 10px; font-size: 13px; cursor: pointer;
}
.perm-item:hover { background: #f7f8fd; }
.perm-item input { width: 16px; height: 16px; accent-color: var(--primary); }

/* ---------- toasts ---------- */
.toast-fallback {
  position: fixed; right: 16px; bottom: 16px; z-index: 200;
  background: #1b2233; color: #fff; padding: 11px 15px; border-radius: 10px;
  font-size: 13px; box-shadow: var(--shadow); max-width: 320px;
}
.toast-fallback.bad { background: var(--bad); }
