/* Dogo Loyalty admin — pastel dashboard style (theo reference user 07/2026):
   nền gradient pastel nhẹ, sidebar trắng mờ, card trắng bo 20px shadow mềm,
   stat cards nhuộm pastel, CTA đen bo lớn, badge/tag dạng pill. */

:root {
  --ink: #17151f;
  --on-ink: #ffffff;
  --charcoal: #2b2833;
  --slate: #55515f;
  --steel: #6f6b7b;
  --stone: #8a8797;
  --muted: #aca9b8;

  --canvas: #ffffff;
  --wash-a: #f4f1fb;
  --wash-b: #fdf2f4;
  --wash-c: #eff4fd;
  --surface: #f7f6fa;
  --surface-soft: #f2f1f6;
  --hairline: #ecebf1;
  --hairline-soft: #f1f0f5;

  --accent: #6d5ae0;
  --accent-soft: #eeeafb;

  --sidebar-bg: rgba(255, 255, 255, .68);
  --sidebar-border: rgba(255, 255, 255, .9);
  --sidebar-hover: rgba(255, 255, 255, .85);

  --tint-blue: #dbe7fb;    --tint-blue-ink: #2f5fae;
  --tint-purple: #e6defb;  --tint-purple-ink: #6742c9;
  --tint-pink: #fbdcee;    --tint-pink-ink: #c0399a;
  --tint-peach: #fde8d2;   --tint-peach-ink: #c07220;
  --tint-green: #d8f4e3;   --tint-green-ink: #1e9e63;
  --tint-red: #fcdcd7;     --tint-red-ink: #cf4a38;

  --success: #1e9e63;
  --danger: #d45656;
  --danger-bg: #fceceb;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-full: 9999px;

  --shadow-card: 0 6px 24px rgba(64, 52, 110, .07);
  --shadow-pop: 0 10px 32px rgba(64, 52, 110, .12);
  --shadow-cta: 0 6px 16px rgba(23, 21, 31, .22);

  color-scheme: light;
}

/* ---- Dark mode: đảo token, giữ nguyên chất pastel (tint mờ trên nền tối) ---- */
:root[data-theme="dark"] {
  --ink: #f2f0f7;
  --on-ink: #17151f;
  --charcoal: #dcd9e6;
  --slate: #b6b2c4;
  --steel: #9d99ac;
  --stone: #837f92;
  --muted: #6a6678;

  --canvas: #1e1b27;
  --wash-a: #171420;
  --wash-b: #1d1622;
  --wash-c: #141723;
  --surface: #262231;
  --surface-soft: #2b2737;
  --hairline: #322e3f;
  --hairline-soft: #2a2636;

  --accent: #8f7df2;
  --accent-soft: rgba(143, 125, 242, .16);

  --sidebar-bg: rgba(24, 21, 32, .72);
  --sidebar-border: rgba(255, 255, 255, .06);
  --sidebar-hover: rgba(255, 255, 255, .06);

  --tint-blue: rgba(96, 140, 215, .3);    --tint-blue-ink: #a7c4f2;
  --tint-purple: rgba(148, 118, 240, .28); --tint-purple-ink: #c5b2f5;
  --tint-pink: rgba(228, 105, 185, .24);  --tint-pink-ink: #f0a6d6;
  --tint-peach: rgba(240, 160, 75, .24);  --tint-peach-ink: #f2c48f;
  --tint-green: rgba(66, 200, 132, .22);  --tint-green-ink: #8fe0b8;
  --tint-red: rgba(238, 108, 88, .24);    --tint-red-ink: #f2a396;

  --success: #4cc98d;
  --danger: #ee8577;
  --danger-bg: rgba(230, 100, 80, .16);

  --shadow-card: 0 6px 24px rgba(0, 0, 0, .35);
  --shadow-pop: 0 10px 32px rgba(0, 0, 0, .5);
  --shadow-cta: 0 6px 16px rgba(0, 0, 0, .4);

  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: "DM Sans", Inter, "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(60% 80% at 85% 0%, var(--wash-b) 0%, transparent 60%),
    radial-gradient(50% 70% at 10% 10%, var(--wash-a) 0%, transparent 65%),
    linear-gradient(160deg, var(--wash-a) 0%, var(--wash-c) 55%, var(--wash-b) 100%);
  background-attachment: fixed;
}

a { color: inherit; text-decoration: none; }

/* ---- Shell: sidebar nổi + content ---- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  backdrop-filter: blur(14px);
  border-right: 1px solid var(--sidebar-border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar__brand {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  padding: 4px 10px 22px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar__brand-dot {
  width: 30px; height: 30px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  box-shadow: 0 4px 10px rgba(109, 90, 224, .35);
  position: relative;
}
.sidebar__brand-dot::after {
  content: ""; position: absolute; inset: 9px;
  border-radius: var(--r-full); background: rgba(255, 255, 255, .85);
}

.sidebar__section {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 18px 12px 8px;
}

.sidebar__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  color: var(--slate);
  font-size: 14px;
  font-weight: 500;
}

.sidebar__item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .75; }

.sidebar__item:hover { background: var(--sidebar-hover); color: var(--ink); }

.sidebar__item--active {
  background: var(--canvas);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--shadow-card);
}
.sidebar__item--active svg { opacity: 1; color: var(--accent); }

.sidebar__footer {
  margin-top: auto;
  background: var(--canvas);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  padding: 12px;
  font-size: 13px;
}

.sidebar__avatar {
  width: 32px; height: 32px; border-radius: var(--r-full); flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}

.sidebar__user {
  display: flex; align-items: center; gap: 10px; min-width: 0;
  padding-bottom: 10px; margin-bottom: 10px;
  border-bottom: 1px solid var(--hairline-soft);
}
.sidebar__user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.sidebar__user-name { font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__user-email { font-size: 11px; color: var(--stone); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar__footer-row { display: flex; align-items: center; gap: 8px; }
.sidebar__footer-row form { flex: 1; }
.sidebar__logout { width: 100%; justify-content: center; }

/* ---- Nút đổi theme sáng/tối ---- */
.theme-toggle {
  width: 32px; height: 32px; border-radius: var(--r-full);
  border: 1px solid var(--hairline); background: var(--canvas);
  color: var(--steel); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; padding: 0;
}
.theme-toggle:hover { color: var(--ink); }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

.main { flex: 1; min-width: 0; padding: 28px 36px 64px; width: 100%; }

/* ---- Page headers ---- */

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-head h1 { font-size: 28px; font-weight: 700; line-height: 1.25; letter-spacing: -0.5px; }
.page-head .sub { color: var(--steel); font-size: 14px; margin-top: 4px; }

/* ---- Subnav (tab pill trong khu Cài đặt) ---- */

.subnav { display: flex; gap: 8px; margin-bottom: 20px; }

/* Filter thời gian dashboard */
.range-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.range-bar__custom { display: inline-flex; gap: 6px; align-items: center; margin-left: 8px; }
.range-bar__custom input[type="date"] {
  width: auto; height: 34px; font-size: 13px;
  border-radius: var(--r-full); padding: 0 12px;
  background: var(--canvas); border: 1px solid var(--hairline);
}
.range-bar__custom .subnav__item { border: 0; cursor: pointer; font-family: inherit; }
.subnav__item {
  padding: 7px 16px;
  border-radius: var(--r-full);
  font-size: 13px;
  font-weight: 600;
  color: var(--steel);
  background: var(--canvas);
  box-shadow: var(--shadow-card);
}
.subnav__item--active { background: var(--ink); color: var(--on-ink); }

/* ---- Buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  padding: 10px 20px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

.btn--primary { background: var(--ink); color: var(--on-ink); box-shadow: var(--shadow-cta); }
.btn--primary:active { background: var(--charcoal); }
.btn--secondary { background: var(--accent-soft); color: var(--accent); }
.btn--tertiary { background: var(--canvas); color: var(--ink); border-color: var(--hairline); box-shadow: 0 2px 8px rgba(64, 52, 110, .06); }
.btn--sm { padding: 6px 14px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: default; box-shadow: none; }

/* ---- Cards ---- */

.card {
  background: var(--canvas);
  border: 0;
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-card);
  padding: 24px;
}

.card + .card, .card + .table-card, .table-card + .card { margin-top: 20px; }

/* ---- Dashboard charts ---- */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px; }
.charts-grid > *, .detail-grid > *, .stats > * { min-width: 0; } /* cho phép grid con co lại, tránh tràn ngang mobile */
@media (max-width: 1100px) { .charts-grid { grid-template-columns: 1fr; } }
.chart-card { padding: 20px 16px 8px 16px; }
.chart-card .card__title { padding: 0 8px; margin-bottom: 8px; }
.charts-grid .table-card { margin-top: 0; }
.apexcharts-tooltip { font-family: inherit !important; }

.card__title { font-size: 16px; font-weight: 700; margin-bottom: 16px; }

/* ---- Stat cards: pastel như các cột board trong reference ---- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 24px; }

.stat {
  border: 0;
  border-radius: var(--r-xl);
  padding: 20px 22px;
  box-shadow: var(--shadow-card);
}

.stats .stat:nth-child(6n+1) { background: var(--tint-blue); }
.stats .stat:nth-child(6n+2) { background: var(--tint-purple); }
.stats .stat:nth-child(6n+3) { background: var(--tint-peach); }
.stats .stat:nth-child(6n+4) { background: var(--tint-green); }
.stats .stat:nth-child(6n+5) { background: var(--tint-pink); }
.stats .stat:nth-child(6n+6) { background: var(--tint-red); }

.stat__value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat__label { font-size: 13px; font-weight: 600; color: var(--charcoal); opacity: .75; margin-top: 2px; }
.stat__hint { font-size: 12px; color: var(--slate); opacity: .7; margin-top: 6px; }
.stat--alert { background: var(--tint-red) !important; }
.stat--alert .stat__value { color: var(--tint-red-ink); }

/* ---- Data tables trong card trắng ---- */

.table-card {
  background: var(--canvas);
  border: 0;
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-card);
  overflow-x: auto; /* bảng rộng cuộn ngang trong card, không cắt cụt cột cuối */
}

.table-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--hairline-soft);
}

.table-card__title { font-size: 15px; font-weight: 700; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th {
  background: transparent;
  color: var(--stone);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  text-align: left;
  padding: 12px 20px 8px;
  white-space: nowrap;
}

td {
  padding: 13px 20px;
  border-bottom: 1px solid var(--hairline-soft);
  vertical-align: middle;
}

tr:last-child td { border-bottom: 0; }
tr.row-link:hover td { background: var(--surface); cursor: pointer; }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.cell-main { font-weight: 600; color: var(--ink); }
.cell-sub { font-size: 13px; color: var(--stone); }

/* ---- Badges: pill pastel như tag #website #client ---- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
  padding: 3px 11px;
  border-radius: var(--r-full);
  white-space: nowrap;
}

.badge--success { background: var(--tint-green); color: var(--tint-green-ink); }
.badge--info { background: var(--tint-blue); color: var(--tint-blue-ink); }
.badge--neutral { background: var(--surface-soft); color: var(--steel); }
.badge--danger { background: var(--tint-red); color: var(--tint-red-ink); }
.badge--dark { background: var(--ink); color: var(--on-ink); }
.badge--tier { color: #fff; } /* nền là tier.color (inline, luôn đậm) — chữ trắng ở cả 2 theme */

/* Store identity chip */
.store-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--charcoal);
  background: var(--canvas); border: 1px solid var(--hairline);
  border-radius: var(--r-full); padding: 2px 10px 2px 7px;
}
.store-chip__dot { width: 8px; height: 8px; border-radius: var(--r-full); flex-shrink: 0; }

/* Points coloring */
.pts { font-variant-numeric: tabular-nums; font-weight: 700; }
.pts--plus { color: var(--success); }
.pts--minus { color: var(--danger); }
.pts--pending { color: var(--stone); }

/* ---- Forms ---- */

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--charcoal); margin-bottom: 6px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  height: 42px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 0 14px;
  outline: none;
}

textarea { height: auto; padding: 10px 14px; }

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-pill {
  height: 42px;
  background: var(--canvas);
  border: 1px solid transparent;
  border-radius: var(--r-full);
  color: var(--steel);
  font-size: 14px;
  padding: 0 18px;
  min-width: 300px;
  box-shadow: var(--shadow-card);
}

.scope-checks { display: flex; gap: 14px; flex-wrap: wrap; padding: 6px 0; }
.scope-checks__item {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; font-weight: 500; cursor: pointer;
}
.scope-checks__item input { width: auto; height: auto; }

.form-inline { display: flex; gap: 10px; align-items: flex-end; }
.form-inline .field { margin-bottom: 0; flex: 1; }

/* ---- Flash ---- */

.flash { border-radius: var(--r-md); padding: 11px 16px; margin-bottom: 20px; font-size: 14px; font-weight: 600; }
.flash--notice { background: var(--tint-green); color: var(--tint-green-ink); }
.flash--alert { background: var(--danger-bg); color: var(--danger); }

/* ---- Auth page ---- */

.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-card {
  width: 400px;
  background: var(--canvas);
  border-radius: 24px;
  box-shadow: var(--shadow-pop);
  padding: 36px;
}
.auth-card h1 { font-size: 24px; font-weight: 700; line-height: 1.3; margin-bottom: 4px; letter-spacing: -0.3px; }
.auth-card .sub { color: var(--steel); margin-bottom: 24px; }
.auth-card .btn { width: 100%; justify-content: center; }

/* ---- Member detail ---- */

.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 1024px) { .detail-grid { grid-template-columns: 1fr; } }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--hairline-soft); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv dt { color: var(--steel); }
.kv dd { font-weight: 600; text-align: right; }

.empty { padding: 40px 16px; text-align: center; color: var(--stone); font-size: 14px; }

/* ---- Mobile ---- */

.topbar { display: none; }

@media (max-width: 900px) {
  .shell { display: block; }

  /* Topbar sticky với hamburger */
  .topbar {
    position: sticky; top: 0; z-index: 90;
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--hairline-soft);
  }
  .topbar .sidebar__brand { padding: 0; font-size: 16px; }

  /* Sidebar thành drawer trượt */
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 100;
    width: 264px; height: 100dvh;
    background: var(--canvas);
    transform: translateX(-105%);
    transition: transform .22s ease;
  }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow-pop); }
  body.nav-open { overflow: hidden; }

  .sidebar__backdrop { display: none; position: fixed; inset: 0; z-index: 99; background: rgba(12, 10, 20, .45); }
  body.nav-open .sidebar__backdrop { display: block; }

  .main { padding: 16px 14px 48px; }
  .page-head { flex-wrap: wrap; align-items: flex-start; }
  .page-head h1 { font-size: 22px; }
  .page-head form { width: 100%; }
  .search-pill { min-width: 0; width: 100%; }

  .stats { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat { padding: 14px 16px; }
  .stat__value { font-size: 22px; }

  .form-inline { flex-direction: column; align-items: stretch; }
  .form-inline .field { width: 100%; }

  /* Bảng list: giữ bố cục, cuộn ngang trong card */
  .table-card table { min-width: 560px; }

  .card { padding: 16px; }
  .charts-grid { gap: 14px; }

  .auth-wrap { padding: 16px; }
  .auth-card { width: 100%; max-width: 400px; padding: 26px; }

  .btn { padding: 11px 20px; } /* touch target ~44px */
  .btn--sm { padding: 8px 14px; }
}

/* ---- Pagination ---- */

.pagination {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 16px;
  flex-wrap: wrap;
}
.pagination__info { font-size: 13px; color: var(--stone); margin-right: auto; }
.pagination__page {
  min-width: 32px; height: 32px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-full);
  font-size: 13px; font-weight: 600; color: var(--steel);
  background: var(--canvas); border: 1px solid var(--hairline);
}
.pagination__page:hover { color: var(--ink); }
.pagination__page--active { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.pagination__gap { color: var(--muted); padding: 0 2px; }

/* ---- Skeleton shimmer: placeholder trong Turbo Frame lazy ---- */
.skeleton {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg,
    rgba(128, 128, 140, .14) 25%,
    rgba(128, 128, 140, .07) 50%,
    rgba(128, 128, 140, .14) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s ease-in-out infinite;
}
.skeleton--chart { height: 240px; border-radius: 12px; }
@keyframes skeleton-shimmer { to { background-position: -200% 0; } }
turbo-frame { display: block; }

/* ---- Filter row: search-pill + select pill trên các trang danh sách ---- */
.filter-row { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.select-pill {
  height: 42px;
  width: auto;
  background: var(--canvas);
  border: 1px solid transparent;
  border-radius: var(--r-full);
  color: var(--steel);
  font-size: 14px;
  padding: 0 36px 0 16px;
  box-shadow: var(--shadow-card);
}
@media (max-width: 760px) {
  .filter-row { align-items: stretch; }
  .filter-row .search-pill, .filter-row .select-pill { width: 100%; }
}

/* Khối JSON trong bảng (Klaviyo events → Properties) */
.code-json {
  margin: 0;
  padding: 10px 12px;
  background: var(--surface-soft);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--charcoal);
  max-height: 150px;
  max-width: 380px;
  overflow: auto;
  white-space: pre;
}
.code-json + .badge { margin-top: 6px; display: inline-block; }

/* Dải metric Klaviyo (trang Klaviyo events) — đủ bộ tên metric kể cả chưa bắn */
.metric-strip { margin-bottom: 20px; }
.metric-strip__list { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.metric-strip__item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 12px; border: 1px solid var(--hairline); border-radius: 12px;
  text-decoration: none; color: inherit; background: var(--surface-soft);
}
.metric-strip__item:hover { border-color: var(--steel); }
.metric-strip__item--off { opacity: 0.5; }

/* Store switcher (sidebar) — mỗi brand một chương trình riêng */
.store-switcher { display: flex; align-items: center; gap: 8px; margin: 4px 12px 14px; }
.store-switcher select { flex: 1; min-width: 0; font-size: 13px; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--hairline, #e5e5ea); background: var(--surface, #fff); color: inherit; }
.store-switcher__dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.sibling-list { display: flex; flex-direction: column; gap: 8px; }
.sibling-list__item { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
