/* Kmedix Loyalty - UI. Layout follows the reference dashboard: left nav, top bar, KPI cards, white panels. */
:root {
  --bg: #f3f4f6; --card: #fff; --line: #e5e7eb; --line-soft: #f0f1f4;
  --ink: #16324f; --logo: #0d3d5c; --text: #1f2937; --muted: #6b7280; --faint: #9ca3af;
  --brand: #6d5bf0; --brand-2: #a855f7; --brand-soft: #efecff;
  --good: #0ca30c; --good-soft: #e6f6e6; --warn: #b7791f; --warn-soft: #fdf3dc; --bad: #d03b3b; --bad-soft: #fbe9e9; --info: #2a78d6; --info-soft: #e7f0fc;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --sidebar: 268px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 Inter, "Segoe UI", system-ui, -apple-system, sans-serif; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--ink); margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--good); font-weight: 600; } .neg { color: var(--bad); font-weight: 600; }
.ic { width: 18px; height: 18px; stroke-width: 1.8; vertical-align: middle; flex: none; }
.ic.sm { width: 15px; height: 15px; }

/* ---------- shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex: none; }
.brand { padding: 20px 20px 14px; border-bottom: 1px solid var(--line); }
.brand-row { display: flex; align-items: center; gap: 12px; font-weight: 700; color: var(--ink); font-size: 16px; }
.avatar { line-height: 1; width: 32px; height: 32px; border-radius: 50%; background: #e5e7eb; color: var(--ink); display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: none; }
.avatar.brand { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }
.portal-pill { margin-top: 12px; background: var(--logo); color: #fff; border-radius: 8px; padding: 9px 12px; font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.side-search { padding: 14px 16px 6px; position: relative; }
.side-search input { width: 100%; height: 38px; border: 1px solid var(--line); background: #f9fafb; border-radius: 9px; padding: 0 12px 0 36px; font: inherit; }
.side-search .ic { position: absolute; left: 28px; top: 25px; color: var(--muted); width: 16px; height: 16px; }
.search-pop { position: absolute; left: 16px; right: 16px; top: 56px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(16,24,40,.12); z-index: 50; max-height: 360px; overflow: auto; display: none; }
.search-pop a { display: block; padding: 8px 12px; color: var(--text); border-bottom: 1px solid var(--line-soft); }
.search-pop a small { display: block; color: var(--muted); }
.search-pop a:hover { background: #f8f8fc; text-decoration: none; }
.nav { padding: 10px 12px; flex: 1; overflow: auto; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin: 2px 0; border-radius: 9px; color: #374151; font-weight: 500; }
.nav a:hover { background: #f5f6f8; text-decoration: none; }
.nav a.active { background: #eef0f4; color: var(--ink); font-weight: 600; }
.nav a .cnt { margin-left: auto; background: var(--brand); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.side-foot { border-top: 1px solid var(--line); padding: 12px 16px; display: flex; align-items: center; gap: 10px; }
.side-foot .who { flex: 1; min-width: 0; } .side-foot .who b { display: block; font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .side-foot .who span { font-size: 12px; color: var(--muted); }
.side-foot button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; } .side-foot button:hover { background: #f3f4f6; color: var(--bad); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 68px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 0 32px; gap: 16px; position: sticky; top: 0; z-index: 20; }
.topbar h2 { font-size: 22px; font-weight: 700; }
.topbar .sp { flex: 1; }
.topbar .date { color: var(--muted); font-size: 14px; }
.topbar .sim { background: var(--warn-soft); color: var(--warn); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; }
.bell { position: relative; color: var(--muted); padding: 8px; border-radius: 9px; display: grid; } .bell:hover { background: #f3f4f6; }
.bell b { position: absolute; top: 2px; right: 2px; background: var(--bad); color: #fff; border-radius: 999px; font-size: 10px; min-width: 16px; height: 16px; display: grid; place-items: center; padding: 0 4px; }
.content { padding: 28px 32px 60px; max-width: 1500px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 27px; font-weight: 700; } .page-head p { margin: 4px 0 0; color: var(--muted); }
.page-head .grow { flex: 1; } .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- blocks ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; }
.card > .hd { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card > .hd h3 { font-size: 16px; font-weight: 600; } .card > .hd .sp { flex: 1; } .card > .hd small { color: var(--muted); }
.card > .bd { padding: 20px; } .card > .bd.flush { padding: 0; }
.grid { display: grid; gap: 20px; } .g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g21 { grid-template-columns: 2fr 1fr; } .g12 { grid-template-columns: 1fr 2fr; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 20px; margin-bottom: 20px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; box-shadow: var(--shadow); }
.kpi .l { font-size: 11.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 36px; font-weight: 700; color: var(--ink); margin: 8px 0 6px; letter-spacing: -.02em; line-height: 1.1; }
.kpi .s { font-size: 13px; color: var(--good); font-weight: 500; } .kpi .s.m { color: var(--muted); } .kpi .s.w { color: var(--warn); } .kpi .s.b { color: var(--bad); }
.kpi.primary { background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 55%, #a855f7 100%); border: 0; box-shadow: 0 8px 22px rgba(124,92,246,.35); }
.kpi.primary .l, .kpi.primary .s { color: rgba(255,255,255,.85); } .kpi.primary .v { color: #fff; }

.tabs { display: flex; gap: 4px; background: #eef0f6; border-radius: 12px; padding: 6px; margin-bottom: 22px; overflow-x: auto; }
.tabs a { padding: 9px 18px; border-radius: 9px; color: #4b5563; font-weight: 500; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--ink); } .tabs a.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

.btn { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 16px; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f8f9fb; text-decoration: none; } .btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; } .btn.primary:hover { background: #5b49dd; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; } .btn.danger { color: var(--bad); border-color: #f0c6c6; } .btn.danger:hover { background: var(--bad-soft); }
.btn.sm { height: 30px; padding: 0 11px; font-size: 13px; border-radius: 8px; } .btn.ghost { border-color: transparent; background: none; }
.inline { display: inline; margin: 0; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-green { background: var(--good-soft); color: #0a7a0a; } .b-amber { background: var(--warn-soft); color: var(--warn); } .b-red { background: var(--bad-soft); color: var(--bad); }
.b-blue { background: var(--info-soft); color: var(--info); } .b-gray { background: #eef0f3; color: #4b5563; }
.tier { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; color: var(--ink); } .tier i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.dt, table.plain { width: 100%; border-collapse: collapse; }
table.dt th, table.plain th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 12px 16px; background: #fafafb; border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none; }
table.dt th[data-sort] { cursor: pointer; } table.dt th[data-sort]:hover { color: var(--ink); }
table.dt th.asc::after { content: " ▲"; font-size: 9px; } table.dt th.desc::after { content: " ▼"; font-size: 9px; }
table.dt td, table.plain td { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.dt tbody tr:hover, table.plain tbody tr:hover { background: #fafaff; }
table.dt th.num, table.dt td.num, table.plain th.num, table.plain td.num { text-align: right; }
table.dt td.sel, table.dt th.sel { width: 36px; padding-right: 0; }
tr.is-off td { color: var(--faint); }
table.dt td:last-child { white-space: nowrap; }
.dt-bar { display: flex; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.dt-bar input[type=search] { height: 36px; border: 1px solid var(--line); border-radius: 9px; padding: 0 12px; min-width: 220px; font: inherit; background: #f9fafb; }
.dt-bar select { height: 36px; border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; font: inherit; background: #fff; max-width: 190px; }
.dt-bar .sp { flex: 1; }
.dt-foot { display: flex; align-items: center; gap: 10px; padding: 10px 16px; color: var(--muted); font-size: 13px; }
.dt-foot .sp { flex: 1; } .dt-foot button { border: 1px solid var(--line); background: #fff; border-radius: 8px; height: 30px; padding: 0 10px; cursor: pointer; } .dt-foot button:disabled { opacity: .4; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.totalbar { display: flex; gap: 16px; align-items: center; padding: 14px 20px; border-top: 1px solid var(--line); background: #fafafb; border-radius: 0 0 var(--radius) var(--radius); flex-wrap: wrap; }
.totalbar .t { font-weight: 700; color: var(--ink); font-size: 15px; } .totalbar .sp { flex: 1; }

/* ---------- forms ---------- */
label.f { display: block; font-size: 12.5px; font-weight: 600; color: #374151; margin-bottom: 5px; }
.fld { margin-bottom: 14px; } .fld small { display: block; color: var(--muted); margin-top: 4px; font-size: 12px; }
input[type=text], input[type=number], input[type=email], input[type=password], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; height: 40px; border: 1px solid #d5d9e0; border-radius: 9px; padding: 0 12px; font: inherit; color: var(--text); background: #fff; }
textarea { height: auto; padding: 10px 12px; min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(109,91,240,.25); border-color: var(--brand); }
.row { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); } .row.r3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .row.r4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; } .check input { width: 17px; height: 17px; accent-color: var(--brand); }
.set-list .item { display: grid; grid-template-columns: 1fr 320px; gap: 24px; padding: 16px 20px; border-bottom: 1px solid var(--line-soft); align-items: center; }
.set-list .item:last-child { border-bottom: 0; } .set-list .item b { color: var(--ink); } .set-list .item small { display: block; color: var(--muted); }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 24px 60px rgba(16,24,40,.28); }
dialog.wide { width: min(820px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(15,23,42,.45); }
dialog .dh { display: flex; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); } dialog .dh h3 { flex: 1; font-size: 17px; }
dialog .dh button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 22px; line-height: 1; }
dialog .db { padding: 20px 22px; max-height: 68vh; overflow: auto; } dialog .df { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #fafafb; border-radius: 0 0 14px 14px; }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; display: flex; gap: 10px; align-items: center; font-weight: 500; }
.flash.ok { background: var(--good-soft); color: #0a6a0a; } .flash.err { background: var(--bad-soft); color: var(--bad); } .flash.info { background: var(--info-soft); color: var(--info); }

/* ---------- widgets ---------- */
.bars .b { padding: 10px 0; } .bars .b .t { display: flex; justify-content: space-between; margin-bottom: 6px; font-weight: 500; } .bars .b .t span { color: var(--muted); font-weight: 400; }
.track { height: 8px; background: #eef0f4; border-radius: 999px; overflow: hidden; } .track i { display: block; height: 100%; border-radius: 999px; }
.feed .it { display: flex; gap: 14px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line-soft); } .feed .it:last-child { border: 0; }
.feed .dot { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none; font-weight: 700; }
.dot.g { background: var(--good-soft); color: var(--good); } .dot.a { background: var(--warn-soft); color: var(--warn); } .dot.r { background: var(--bad-soft); color: var(--bad); } .dot.b { background: var(--info-soft); color: var(--info); }
.feed .tx { flex: 1; min-width: 0; } .feed .tx b { display: block; color: var(--ink); font-weight: 600; } .feed .tx span { color: var(--muted); font-size: 13px; } .feed .pts { font-weight: 700; white-space: nowrap; }
.chart-box { position: relative; height: 280px; } .chart-box.tall { height: 340px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 8px; } .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.list-links a { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line-soft); color: var(--text); } .list-links a:last-child { border: 0; } .list-links a:hover { text-decoration: none; color: var(--brand); }
.pill-num { background: var(--warn-soft); color: var(--warn); border-radius: 999px; padding: 1px 9px; font-weight: 700; font-size: 13px; }
.explain { background: #f7f7fc; border: 1px dashed #d4d1f5; border-radius: 10px; padding: 14px 16px; }
.explain table { width: 100%; } .explain td { padding: 4px 0; }
.reward { border: 1px solid var(--line); border-radius: 12px; padding: 18px; background: #fff; display: flex; flex-direction: column; gap: 8px; }
.reward .rt { display: flex; align-items: center; gap: 10px; } .reward .ri { width: 42px; height: 42px; border-radius: 11px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; }
.reward h4 { margin: 0; color: var(--ink); font-size: 15px; } .reward .cost { font-size: 22px; font-weight: 700; color: var(--ink); } .reward .cost small { font-size: 13px; color: var(--muted); font-weight: 500; }
.timeline { border-left: 2px solid var(--line); margin-left: 8px; padding-left: 18px; } .timeline .tl { position: relative; padding: 0 0 16px; } .timeline .tl::before { content: ""; position: absolute; left: -25px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 10%, #e9e4ff 0, transparent 40%), var(--bg); }
.login .box { width: min(440px, 100%); background: #fff; border-radius: 16px; padding: 32px; box-shadow: 0 20px 50px rgba(16,24,40,.12); border: 1px solid var(--line); }
.login .demo { margin-top: 18px; border-top: 1px dashed var(--line); padding-top: 14px; font-size: 13px; color: var(--muted); } .login .demo button { display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: #fafafb; border-radius: 9px; padding: 8px 12px; margin-top: 6px; cursor: pointer; font: inherit; } .login .demo button:hover { border-color: var(--brand); }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, 1fr); } .g21, .g12, .g3 { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .topbar h2 { font-size: 17px; white-space: nowrap; } .topbar .date { display: none; }
  .sidebar { position: fixed; z-index: 60; left: -290px; transition: left .2s; } .sidebar.open { left: 0; }
  .content { padding: 20px 16px 50px; } .topbar { padding: 0 16px; } .g2, .g4, .row, .row.r3, .row.r4 { grid-template-columns: 1fr; } .set-list .item { grid-template-columns: 1fr; gap: 10px; }
}
@media print { .sidebar, .topbar, .actions, .dt-bar, .dt-foot { display: none !important; } .content { padding: 0; } }

/* ---------- logo ---------- */
.brand .logo { display: block; } .brand .logo img { display: block; height: 38px; width: auto; max-width: 100%; }
.brand-sub { margin-top: 6px; font-size: 11.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.login-logo { display: block; height: 56px; width: auto; max-width: 100%; margin: 0 0 14px; }
