/* ---------------------------------------------------------------------------
   P2P Merchant Desk - application shell
   Light, spacious admin idiom: white sidebar with grouped nav, search topbar,
   soft rounded cards, sparkline KPIs, roomy data tables. Bootstrap 5 provides
   the grid and utilities; everything below is this app's own design layer.
   Light and dark are both driven by [data-bs-theme].
   --------------------------------------------------------------------------- */

:root {
  --app-sidebar-w: 268px;
  --app-topbar-h: 68px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --app-font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

[data-bs-theme="light"] {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --ink: #0f1420;
  --ink-2: #454c5e;
  --muted: #7b8396;
  --line: #eceef4;
  --line-2: #e3e6ef;
  --brand: #2f5bff;
  --brand-soft: #eef2ff;
  --ok: #12a150;
  --warn: #c98a00;
  --bad: #e5484d;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 4px 16px rgba(16, 24, 40, .07);
}

[data-bs-theme="dark"] {
  --bg: #0b0f18;
  --surface: #121722;
  --surface-2: #161c29;
  --ink: #f2f4f8;
  --ink-2: #c3cad9;
  --muted: #8b94a8;
  --line: #1f2634;
  --line-2: #273043;
  --brand: #6b8cff;
  --brand-soft: #182142;
  --ok: #2bc16b;
  --warn: #e0aa1f;
  --bad: #ff6b6e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 6px 24px rgba(0, 0, 0, .45);
}

* { -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  font-family: var(--app-font);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
}

/* ============================================================ shell ====== */
.app-shell { display: flex; min-height: 100vh; }

.app-main {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column;
  margin-left: var(--app-sidebar-w);
}

.app-content { flex: 1 1 auto; padding: 24px clamp(16px, 2.4vw, 30px) 40px; }

.app-footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 16px clamp(16px, 2.4vw, 30px);
  font-size: 12px; color: var(--muted);
}

/* ========================================================== sidebar ====== */
.app-sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--app-sidebar-w);
  display: flex; flex-direction: column; z-index: 1040;
  background: var(--surface);
  border-right: 1px solid var(--line);
  transition: transform .22s ease;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 11px;
  height: var(--app-topbar-h); padding: 0 22px; flex: none;
}

.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; flex: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), #6b46ff);
  color: #fff; font-weight: 700; font-size: 11.5px; letter-spacing: .02em;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 15px; letter-spacing: -.01em; color: var(--ink); }
.brand-text small { font-size: 10.5px; color: var(--muted); }

.sidebar-nav { flex: 1 1 auto; overflow-y: auto; padding: 6px 14px 20px; }

.nav-section {
  padding: 18px 10px 8px;
  font-size: 10px; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted);
}
.nav-section:first-child { padding-top: 6px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin-bottom: 3px;
  border: 1px solid transparent; border-radius: var(--r-md);
  color: var(--ink-2); text-decoration: none;
  font-size: 13.5px; font-weight: 500;
}
.nav-item i { font-size: 16.5px; width: 19px; text-align: center; color: var(--muted); }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item:hover i { color: var(--ink-2); }

.nav-item.active {
  background: var(--surface);
  border-color: var(--brand);
  color: var(--brand);
  font-weight: 600;
  box-shadow: var(--shadow);
}
.nav-item.active i { color: var(--brand); }

.nav-item.disabled { color: var(--muted); cursor: not-allowed; }
.nav-item.disabled i { opacity: .55; }

.phase-tag {
  margin-left: auto; font-style: normal;
  font-size: 9.5px; font-weight: 600; letter-spacing: .06em;
  padding: 3px 7px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--line);
}

.sidebar-foot { flex: none; padding: 14px 18px 18px; border-top: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.who-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.who-text strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-text small { font-size: 10.5px; letter-spacing: .06em; color: var(--muted); }

.avatar {
  display: grid; place-items: center; width: 34px; height: 34px; flex: none;
  border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  font-weight: 600; font-size: 12.5px;
}
.avatar-sm { width: 24px; height: 24px; font-size: 10px; display: inline-grid; vertical-align: -7px; }

.btn-ghost {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--line-2); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink-2);
  font-size: 13px; font-weight: 500; text-decoration: none;
}
.btn-ghost:hover { border-color: var(--bad); color: var(--bad); }

/* =========================================================== topbar ====== */
.app-topbar {
  position: sticky; top: 0; z-index: 1020;
  display: flex; align-items: center; gap: 14px;
  height: var(--app-topbar-h); padding: 0 clamp(16px, 2.4vw, 30px);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--line);
}

.search-box {
  display: flex; align-items: center; gap: 9px;
  flex: 1 1 auto; max-width: 420px;
  padding: 9px 12px;
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  color: var(--muted);
}
.search-box i { font-size: 15px; }
.search-box input {
  flex: 1 1 auto; min-width: 0;
  border: 0; outline: 0; background: transparent;
  font: 400 13.5px var(--app-font); color: var(--ink);
}
.search-box input::placeholder { color: var(--muted); }
.search-box kbd {
  flex: none; padding: 3px 6px; border-radius: 6px;
  background: var(--brand-soft); color: var(--brand);
  font: 600 10.5px var(--app-font); border: 0;
}
.search-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

.topbar-title { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.icon-btn {
  position: relative;
  display: grid; place-items: center; width: 38px; height: 38px; flex: none;
  border: 1px solid var(--line-2); border-radius: 50%;
  background: var(--surface); color: var(--ink-2);
  font-size: 15px; cursor: pointer; text-decoration: none;
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand); }
.icon-btn .badge-dot {
  position: absolute; top: 7px; right: 8px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--bad); border: 1.5px solid var(--surface);
}

.presence-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line-2);
  font-size: 11.5px; font-weight: 600; letter-spacing: .04em; color: var(--ink-2);
}
.presence-pill .dot { width: 7px; height: 7px; border-radius: 50%; }

/* ==================================================== page furniture ===== */
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-head h2 { margin: 0 0 4px; font-size: 21px; font-weight: 600; letter-spacing: -.02em; }
.page-head p { margin: 0; font-size: 13px; color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 6px 12px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line-2);
  font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-2);
}

/* greeting panel */
.greet {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  padding: 26px 28px; margin-bottom: 18px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.greet-body { flex: 1 1 320px; min-width: 0; }
.greet h1 { margin: 0 0 8px; font-size: 26px; font-weight: 700; letter-spacing: -.025em; line-height: 1.2; }
.greet p { margin: 0; font-size: 13.5px; color: var(--muted); max-width: 52ch; }
.greet-side { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.greet-metric { font-size: 27px; font-weight: 700; letter-spacing: -.02em; }
.greet-label { white-space: nowrap; font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

/* ============================================================== KPIs ===== */
.kpi-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  margin-bottom: 18px;
}

.kpi {
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px 20px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.kpi:hover { box-shadow: var(--shadow-lg); }

.kpi-top { display: flex; align-items: flex-start; gap: 13px; }
.kpi-icon {
  display: grid; place-items: center; width: 40px; height: 40px; flex: none;
  border-radius: var(--r-md); font-size: 18px;
  background: var(--brand-soft); color: var(--brand);
}
.kpi-icon.tone-ok   { background: color-mix(in srgb, var(--ok) 12%, transparent);   color: var(--ok); }
.kpi-icon.tone-warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.kpi-icon.tone-bad  { background: color-mix(in srgb, var(--bad) 12%, transparent);  color: var(--bad); }
.kpi-icon.tone-ink  { background: var(--surface-2); color: var(--ink-2); }

.kpi-text { display: flex; flex-direction: column; min-width: 0; }
.kpi-label, .kpi-value { display: block; }
.kpi-label { font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 3px; }
.kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }

.kpi-foot {
  display: flex; align-items: center; gap: 8px;
  padding-top: 12px; border-top: 1px dashed var(--line-2);
  font-size: 11.5px; color: var(--muted);
}
.kpi-foot .delta { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.kpi-foot .delta.up { color: var(--ok); }
.kpi-foot .delta.down { color: var(--bad); }

/* sparkline strip: one <i> per bucket, height set inline as a percentage */
.spark { display: flex; align-items: flex-end; gap: 3px; height: 32px; margin-left: auto; flex: none; }
.spark i { display: block; width: 4px; min-height: 3px; border-radius: 2px; background: var(--brand); opacity: .85; }
.spark.tone-ok i   { background: var(--ok); }
.spark.tone-warn i { background: var(--warn); }
.spark.tone-bad i  { background: var(--bad); }
.spark.flat i { width: 4px; height: 3px !important; border-radius: 2px; background: var(--line-2); opacity: 1; }

/* ============================================================= cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 18px 20px; background: transparent; border-bottom: 1px solid var(--line);
}
.card-header h3 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.card-header .header-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.card-body { padding: 20px; }
.card-body.p-0 { padding: 0; }

/* ============================================================= table ===== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data thead th {
  padding: 12px 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: 10.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); text-align: left; white-space: nowrap;
}
table.data tbody td {
  padding: 15px 20px; border-bottom: 1px solid var(--line);
  font-size: 13.5px; vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .num { font-variant-numeric: tabular-nums; }

.cell-person { display: flex; align-items: center; gap: 11px; min-width: 0; }
.cell-person .who-text strong { font-weight: 600; font-size: 13.5px; }
.cell-person .who-text small { font-size: 11.5px; letter-spacing: 0; }

.status {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 600;
}
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.is-ok { color: var(--ok); }
.status.is-warn { color: var(--warn); }
.status.is-bad { color: var(--bad); }
.status.is-idle { color: var(--muted); }

.row-actions { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.row-actions a, .row-actions button {
  display: grid; place-items: center; width: 30px; height: 30px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--muted);
  font-size: 13px; cursor: pointer; text-decoration: none;
}
.row-actions a:hover { border-color: var(--brand); color: var(--brand); }

.pager {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 20px; border-top: 1px solid var(--line);
  font-size: 12.5px; color: var(--muted);
}
.pager .pager-nav { margin-left: auto; display: flex; gap: 6px; }
.pager .pager-nav a, .pager .pager-nav span {
  display: grid; place-items: center; min-width: 30px; height: 30px; padding: 0 8px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink-2); text-decoration: none; font-size: 12.5px;
}
.pager .pager-nav .is-disabled { opacity: .45; pointer-events: none; }

/* ======================================================= empty state ===== */
.empty-state { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty-state .ico {
  display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 14px;
  border-radius: 50%; background: var(--surface-2); color: var(--muted); font-size: 22px;
}
.empty-state strong { display: block; color: var(--ink); font-size: 14.5px; margin-bottom: 5px; }
.empty-state p { margin: 0 auto; max-width: 46ch; font-size: 13px; line-height: 1.6; }
.empty-state code {
  padding: 2px 5px; border-radius: 5px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 12px; color: var(--ink-2);
}

/* ================================================== module placeholder == */
.soon-list { list-style: none; margin: 0; padding: 0; }
.soon-list li {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 9px 0; border-bottom: 1px dashed var(--line-2);
  font-size: 13.5px; line-height: 1.6; color: var(--ink-2);
}
.soon-list li:last-child { border-bottom: 0; }
.soon-list i { color: var(--brand); font-size: 17px; line-height: 1.3; flex: none; }

.soon-meta { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.soon-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.soon-chips code {
  padding: 4px 9px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 11.5px; color: var(--ink-2);
}
.soon-meta p { margin: 0; font-size: 12.5px; color: var(--muted); max-width: 66ch; }

/* ============================================================== auth ===== */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.auth-card {
  width: 100%; max-width: 410px; padding: 30px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: var(--shadow-lg);
}
.auth-head { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-head strong { display: block; font-size: 16.5px; letter-spacing: -.01em; }
.auth-head small { display: block; font-size: 11.5px; color: var(--muted); }
.auth-note { margin: 18px 0 0; font-size: 11.5px; line-height: 1.6; color: var(--muted); }

.form-label { font-size: 12.5px; font-weight: 500; color: var(--ink-2); margin-bottom: 6px; }
.form-control, .form-select {
  border-color: var(--line-2); border-radius: var(--r-md);
  padding: 10px 13px; font-size: 13.5px;
  background: var(--surface); color: var(--ink);
}
.form-control:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.btn-primary {
  --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: color-mix(in srgb, var(--brand) 88%, #000);
  --bs-btn-hover-border-color: color-mix(in srgb, var(--brand) 88%, #000);
  border-radius: var(--r-md); padding: 10px 16px; font-weight: 600; font-size: 13.5px;
}
.alert { border-radius: var(--r-md); border-color: var(--line-2); font-size: 13px; }

/* ======================================================== responsive ===== */
@media (max-width: 1199.98px) {
  .search-box { max-width: 260px; }
}
@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); box-shadow: none; }
  .app-sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(15, 20, 32, .45); }
  .app-main { margin-left: 0; }
  .topbar-title { display: none; }
}
@media (max-width: 575.98px) {
  .search-box { display: none; }
  .greet { padding: 20px; }
  .greet h1 { font-size: 22px; }
}
