:root {
  --bg: #f5f8fc; --surface: #ffffff; --surface-2: #f8fbff; --line: #e3e9f2; --line-2: #eef2f8;
  --ink: #0f2147; --ink-2: #334155; --muted: #64748b; --faint: #94a3b8;
  --primary: #2563eb; --primary-ink: #1d4ed8; --primary-soft: #e8f0fe;
  --green: #16a34a; --green-soft: #e7f7ee; --orange: #ea8a0c; --orange-soft: #fff4e5;
  --red: #dc2626; --red-soft: #fdecec; --purple: #7c3aed; --purple-soft: #f3edff; --teal: #0d9488; --teal-soft: #e6f6f4;
  --grey-soft: #f1f5f9; --shadow: 0 1px 2px rgba(15, 33, 71, .04), 0 4px 14px rgba(15, 33, 71, .05);
  --radius: 12px; --sidebar: 248px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink-2); font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
.hidden { display: none !important; }
a { color: var(--primary); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--ink-2); }
.muted { color: var(--muted); }

/* layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); background: var(--surface); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 12px; flex-shrink: 0; z-index: 40; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 14px; padding: 10px 24px; min-height: 64px; }
.view { padding: 22px 24px 40px; outline: none; }

.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 16px; }
.brand-mark { width: 36px; height: 40px; border-radius: 8px 8px 18px 18px; background: linear-gradient(160deg, #3b82f6, #1d4ed8); position: relative; flex-shrink: 0; }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; background: #fff; border-radius: 2px; left: 50%; top: 45%; transform: translate(-50%, -50%); }
.brand-mark::before { width: 16px; height: 5px; } .brand-mark::after { width: 5px; height: 16px; }
.brand-name { font-weight: 800; color: var(--ink); font-size: 19px; line-height: 1.1; }
.brand-sub { font-size: 12px; color: var(--teal); font-weight: 500; }
.brand-lg .brand-name { font-size: 22px; }

#nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px; color: var(--ink-2); font-weight: 500; border: 0; background: transparent; text-align: left; width: 100%; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.nav-ico { width: 20px; text-align: center; font-size: 16px; opacity: .85; }
.nav-count { margin-left: auto; font-size: 11px; background: var(--grey-soft); color: var(--muted); border-radius: 999px; padding: 1px 7px; }
.side-foot { margin-top: auto; border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-size: 12px; color: var(--ink-2); }
.side-foot-ico { width: 26px; height: 26px; border-radius: 50%; background: var(--teal-soft); margin-bottom: 6px; }

.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 17px; position: relative; display: inline-flex; align-items: center; justify-content: center; }
.menu-btn { display: none !important; }
.range { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; background: var(--surface); }
.range select, .range input { border: 0; background: transparent; outline: none; }
.range-ico { font-size: 15px; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.bell-wrap, .user-wrap { position: relative; }
.bell-count { position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; min-width: 19px; height: 19px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; }
.user { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 4px; border-radius: 10px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; }
.user-text { display: flex; flex-direction: column; align-items: flex-start; }
.user-name { font-weight: 700; color: var(--ink); }
.user-role { font-size: 12px; color: var(--muted); }
.menu { position: absolute; right: 0; top: calc(100% + 8px); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); min-width: 280px; padding: 8px; z-index: 50; }
.menu-item { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 8px; border: 0; background: transparent; color: var(--ink-2); }
.menu-item:hover { background: var(--surface-2); }
.menu-head { font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 10px 8px; }

/* headings */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
h1.page-title { margin: 0; font-size: 28px; font-weight: 800; color: var(--ink); letter-spacing: -.01em; }
.page-sub { margin: 4px 0 0; color: var(--muted); }
.stamp { font-size: 12px; color: var(--faint); }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card-title { font-size: 17px; font-weight: 700; color: var(--ink); margin: 0 0 14px; display: flex; align-items: center; gap: 8px; justify-content: space-between; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); margin-bottom: 16px; }
.row2 { grid-template-columns: 1.15fr 1.25fr .8fr; margin-bottom: 16px; }
.row3 { grid-template-columns: 1fr; }
@media (min-width: 1750px) { .row3 { grid-template-columns: 2.15fr 1fr; } }
.kpi { display: flex; gap: 14px; align-items: flex-start; padding: 18px; }
.kpi-ico { width: 46px; height: 46px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.kpi-title { font-weight: 600; color: var(--ink-2); }
.kpi-val { font-size: 30px; font-weight: 800; color: var(--ink); line-height: 1.15; margin-top: 4px; }
.kpi-delta { font-size: 12px; font-weight: 600; margin-top: 2px; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.k-blue { background: #f4f8ff; } .k-blue .kpi-ico { background: #dce8ff; color: var(--primary); }
.k-orange { background: #fffaf2; } .k-orange .kpi-ico { background: #ffe9c7; color: var(--orange); }
.k-green { background: #f3fbf6; } .k-green .kpi-ico { background: #d3f2df; color: var(--green); }
.k-red { background: #fff6f6; } .k-red .kpi-ico { background: #fdd9d9; color: var(--red); }
.k-purple { background: #faf6ff; } .k-purple .kpi-ico { background: #ebe1ff; color: var(--purple); }
.up { color: var(--green); } .down { color: var(--red); } .flat { color: var(--muted); }

/* donut + legend */
.donut-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.donut { position: relative; flex-shrink: 0; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.donut-num { font-size: 30px; font-weight: 800; color: var(--ink); line-height: 1; }
.donut-lbl { font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 12px; }
.legend-row { display: grid; grid-template-columns: 14px 1fr auto auto; gap: 10px; align-items: center; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.legend-n { font-weight: 700; color: var(--ink); text-align: right; } .legend-p { color: var(--muted); min-width: 48px; text-align: right; }

/* services */
.svc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.svc { border: 1px solid var(--line); border-radius: 10px; padding: 14px; cursor: pointer; background: var(--surface); text-align: left; }
.svc:hover { border-color: #c7d6ee; }
.svc-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.svc-ico { width: 42px; height: 42px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; font-size: 19px; }
.svc-name { font-weight: 700; color: var(--ink); } .svc-count { color: var(--muted); font-size: 13px; }
.svc-line { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 0; }
.svc-line span:first-child { display: flex; align-items: center; gap: 8px; }

/* role */
.role-pill { display: inline-block; background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; border-radius: 8px; padding: 6px 12px; margin: 4px 0 14px; }
.perm { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.perm-ico { width: 18px; height: 18px; border-radius: 50%; background: var(--green); color: #fff; font-size: 11px; display: inline-flex; align-items: center; justify-content: center; }
.label-sm { font-weight: 700; color: var(--ink); margin: 6px 0 4px; }

/* table */
.tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; font-size: 13px; font-weight: 400; }
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; min-width: 230px; background: var(--surface); }
.search input { border: 0; outline: none; width: 100%; background: transparent; }
.sel { border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: var(--surface); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line-2); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
th { background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
td { font-size: 13px; }
tbody tr:hover { background: #fbfdff; }
.cid { font-weight: 700; color: var(--ink); white-space: nowrap; }
.sub { display: block; font-size: 12px; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 7px; padding: 3px 9px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.b-green { background: var(--green-soft); color: #15803d; border-color: #c9ecd6; }
.b-orange { background: var(--orange-soft); color: #c2410c; border-color: #fbe0b9; }
.b-red { background: var(--red-soft); color: #b91c1c; border-color: #f8cccc; }
.b-blue { background: var(--primary-soft); color: var(--primary-ink); border-color: #cfe0fd; }
.b-purple { background: var(--purple-soft); color: #6d28d9; border-color: #e3d6fd; }
.b-grey { background: var(--grey-soft); color: #475569; border-color: #e2e8f0; }
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 9px; padding: 8px 14px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:hover { border-color: #c7d6ee; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.teal { background: var(--teal); color: #fff; border-color: var(--teal); }
.btn.outline { color: var(--primary); border-color: #b9cdf7; }
.btn.sm { padding: 5px 12px; font-size: 12px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }

/* result */
.res-wrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.res-list { flex: 1; min-width: 200px; }
.res-row { display: grid; grid-template-columns: 22px 1fr auto auto; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line-2); }
.res-row:last-child { border: 0; }
.res-ico { width: 20px; height: 20px; border-radius: 5px; color: #fff; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; }
.mini th, .mini td { padding: 7px 8px; } .mini table { min-width: 0; table-layout: fixed; }
.mini td.reason { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; } .actions .btn { flex: 1; min-width: 140px; padding: 11px; }

/* detail */
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.kv { display: grid; grid-template-columns: minmax(110px, 40%) 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; color: var(--ink); font-weight: 500; word-break: break-word; }
.span2 { grid-column: span 2; } .span3 { grid-column: 1 / -1; }
.reason-list { margin: 0; padding-left: 18px; } .reason-list li { margin: 4px 0; }
.src { font-size: 11px; color: var(--faint); }
.back { display: inline-flex; gap: 6px; align-items: center; margin-bottom: 8px; }

/* states */
.state { padding: 30px 12px; text-align: center; color: var(--muted); }
.state.err { color: var(--red); }
.skel { background: linear-gradient(90deg, #eef2f7 25%, #f6f8fb 50%, #eef2f7 75%); background-size: 200% 100%; animation: sh 1.2s infinite; border-radius: 8px; height: 14px; }
@keyframes sh { to { background-position: -200% 0; } }
.note { font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 100; max-width: 90vw; }

/* login */
.login { position: fixed; inset: 0; background: linear-gradient(160deg, #eef4ff, #f7fbff); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 60; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 26px; display: flex; flex-direction: column; gap: 6px; }
.login-card h1 { font-size: 20px; color: var(--ink); margin: 6px 0 6px; }
.login-card label { font-size: 12px; font-weight: 600; color: var(--muted); margin-top: 6px; }
.login-card input { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; outline: none; }
.login-card input:focus { border-color: var(--primary); }
.login-card .btn { margin-top: 12px; padding: 11px; }
.form-msg { background: var(--red-soft); color: #b91c1c; border-radius: 8px; padding: 8px 10px; font-size: 13px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 33, 71, .45); display: flex; align-items: center; justify-content: center; z-index: 70; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 460px; padding: 22px; box-shadow: var(--shadow); max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0 0 12px; font-size: 18px; color: var(--ink); }
.modal label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
.modal select, .modal input[type=file] { width: 100%; }
.modal .row-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* responsive */
@media (max-width: 1280px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } .row2 { grid-template-columns: 1fr 1fr; } .row2 > :last-child { grid-column: 1 / -1; } }
@media (max-width: 1080px) { .detail-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(15,33,71,.35); z-index: 35; }
  .menu-btn { display: inline-flex !important; }
  .row2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .user-text { display: none; }
  .topbar { padding: 10px 16px; } .view { padding: 16px 16px 30px; }
}
@media (max-width: 600px) {
  .kpis { grid-template-columns: 1fr; } .svc-grid { grid-template-columns: 1fr; } .detail-grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; } h1.page-title { font-size: 22px; }
  .range select { max-width: 110px; } .search { min-width: 0; flex: 1; }
}
@media print {
  .sidebar, .topbar, .tools, .actions, .pager, .btn, .scrim { display: none !important; }
  body { background: #fff; } .card { box-shadow: none; break-inside: avoid; } .view { padding: 0; }
}
