:root {
  --tuong: #e7dccb;
  --fur: #e9974c;
  --fur-d: #b9662a;
  --kem: #fbe7cf;
  --hong: #e98a97;
  --mat: #2a2118;
  --may: #a9b1ba;
  --bg: #f7f5f0;
  --card: #ffffff;
  --card-alt: #fcfbfa;
  --ink: #1c1b19;
  --mute: #6b675f;
  --line: #e6e1d6;
  --pos: #1f7a4d;
  --pos-bg: #eaf6ef;
  --neg: #b3412e;
  --neg-bg: #fbeeed;
  --warn: #b86e00;
  --warn-bg: #fff4e0;
  --accent: #2f5bd3;
  --accent-hover: #21439c;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412;
    --tuong: #24221f;
    --card: #1d1c1a;
    --card-alt: #24221f;
    --ink: #ece9e2;
    --mute: #9c978c;
    --line: #2e2c28;
    --pos: #52c48a;
    --pos-bg: #1a3324;
    --neg: #ef7a64;
    --neg-bg: #381a17;
    --warn: #f0a63a;
    --warn-bg: #2d2414;
    --accent: #7f9ef0;
    --accent-hover: #9bb7f7;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #141412;
  --tuong: #24221f;
  --card: #1d1c1a;
  --card-alt: #24221f;
  --ink: #ece9e2;
  --mute: #9c978c;
  --line: #2e2c28;
  --pos: #52c48a;
  --pos-bg: #1a3324;
  --neg: #ef7a64;
  --neg-bg: #381a17;
  --warn: #f0a63a;
  --warn-bg: #2d2414;
  --accent: #7f9ef0;
  --accent-hover: #9bb7f7;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  --bg: #f7f5f0;
  --tuong: #e7dccb;
  --card: #ffffff;
  --card-alt: #fcfbfa;
  --ink: #1c1b19;
  --mute: #6b675f;
  --line: #e6e1d6;
  --pos: #1f7a4d;
  --pos-bg: #eaf6ef;
  --neg: #b3412e;
  --neg-bg: #fbeeed;
  --warn: #b86e00;
  --warn-bg: #fff4e0;
  --accent: #2f5bd3;
  --accent-hover: #21439c;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 16px 80px;
}

/* Header & Controls */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
}

.brand-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--pos-bg);
  color: var(--pos);
  border: 1px solid var(--pos);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.btn:hover {
  background: var(--card-alt);
  border-color: var(--mute);
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #ffffff;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

/* Screen & Scene (Màn hình của ConCat) */
.man {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  margin: 0 0 24px;
  box-shadow: var(--shadow);
}

.canh {
  position: relative;
  container-type: inline-size;
  background: var(--tuong);
  overflow: hidden;
}

.meo {
  width: 100%;
  height: auto;
  display: block;
}

.canh .go {
  position: absolute;
  left: 47.5%;
  top: 26.5%;
  width: 37.8%;
  height: 38.8%;
  padding: 0;
  min-height: 0;
  background: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  font-size: max(10px, 2.5cqw);
  line-height: 1.35;
  font-weight: 700;
  pointer-events: none;
}

.canh:has(.meo.ngu) .go {
  opacity: 0.35;
}

.canh:has(.meo.tat) .go {
  visibility: hidden;
}

.meo .bien,
.meo .khoi {
  display: none;
}

.meo.thuc .khoi,
.meo.thu .bien {
  display: inline;
}

.meo.thuc .zzz,
.meo.tat .zzz,
.meo.tat .hoi,
.meo.tat .cham-mh {
  display: none;
}

.meo.tat .man-hinh {
  fill: #08090a;
}

.meo.tat .den {
  fill: var(--mute);
}

.anh-meo {
  transform-origin: 155px 262px;
}

.meo.thuc .anh-meo {
  animation: gat 3s ease-in-out infinite;
}

.meo.ngu .anh-meo,
.meo.tat .anh-meo {
  transform: rotate(4deg);
  filter: brightness(0.85);
}

.meo.thuc .phim {
  animation: go-phim 0.35s ease-in-out infinite alternate;
}

.meo.thuc .phim.sau {
  animation-delay: 0.17s;
}

.hoi text {
  opacity: 0;
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: hoi 9s ease-in-out infinite;
}

.hoi text + text {
  animation-delay: 0.25s;
}

.khoi path {
  animation: bay 3s ease-in-out infinite;
  opacity: 0;
}

.khoi path + path {
  animation-delay: 1.5s;
}

.zzz text {
  animation: bay 3s ease-in-out infinite;
  opacity: 0;
}

.zzz text:nth-child(2) {
  animation-delay: 1s;
}

.zzz text:nth-child(3) {
  animation-delay: 2s;
}

.bien {
  transform-origin: 535px 44px;
  animation: lac 2.4s ease-in-out infinite;
}

@keyframes bay {
  0% { opacity: 0; transform: translateY(6px); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px); }
}

@keyframes lac {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}

@keyframes gat {
  50% { transform: rotate(1.5deg); }
}

@keyframes go-phim {
  to { transform: translateY(-3px); }
}

@keyframes hoi {
  0%, 62%, 100% { opacity: 0; transform: scale(0.4); }
  68% { opacity: 1; transform: scale(1.15); }
  72%, 90% { opacity: 1; transform: scale(1); }
}

.go {
  background: #17191d;
  color: #f2d77e;
  font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  padding: 14px 16px;
  min-height: 76px;
  overflow-wrap: anywhere;
}

.go::before {
  content: "> ";
  color: #7d8590;
}

.tro {
  display: inline-block;
  width: 0.6em;
  height: 1.1em;
  background: #f2d77e;
  vertical-align: -0.2em;
  margin-left: 2px;
  animation: nhay 1s steps(1) infinite;
}

.dong-tt,
.dong-xem {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  padding: 10px 18px;
  font-size: 14px;
  border-top: 1px solid var(--line);
}

.dong-tt span,
.dong-xem span {
  color: var(--mute);
}

.cham {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--mute);
}

.cham.xanh {
  background: var(--pos);
  animation: sang 2s ease-in-out infinite;
}

.cham.cam {
  background: var(--warn);
}

.dong-xem b {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

#hom-nay {
  margin-left: auto;
}

@keyframes nhay {
  50% { opacity: 0; }
}

@keyframes sang {
  50% { opacity: 0.35; }
}

/* Lời giới thiệu (Story Banner) */
.dau {
  margin: 0 0 24px;
}

.loi {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.loi::before {
  content: "";
  position: absolute;
  left: 22%;
  top: -8px;
  width: 14px;
  height: 14px;
  background: var(--card);
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: rotate(135deg);
}

.loi p {
  margin: 0 0 8px;
}

.loi p:last-child {
  margin: 0;
}

.loi .ten {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

#tt {
  font-weight: 600;
}

#tt.cu {
  color: var(--warn);
}

#thu {
  color: var(--warn);
  font-size: 14px;
  font-weight: 500;
  background: var(--warn-bg);
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--warn);
  display: inline-block;
  margin-top: 4px;
}

/* Hero Section (Số dư & Vốn) */
.hero {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px 22px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.nhan {
  color: var(--mute);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.so-du {
  font-size: 42px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  margin: 4px 0 6px;
  letter-spacing: -0.02em;
}

.pos {
  color: var(--pos);
}

.neg {
  color: var(--neg);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  color: var(--mute);
  font-size: 14px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.meta .cu {
  color: var(--warn);
  font-weight: 600;
}

/* KPI Grid */
.kpi {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}

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

.kpi b {
  display: block;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

@media (max-width: 640px) {
  .kpi {
    grid-template-columns: repeat(2, 1fr);
  }
  .so-du {
    font-size: 34px;
  }
}

/* Interactive Growth Chart */
.chart-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 32px;
  box-shadow: var(--shadow);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.chart-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.chart-legend {
  display: flex;
  gap: 14px;
  font-size: 13px;
  color: var(--mute);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-color {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.chart-svg-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.chart-svg {
  width: 100%;
  min-width: 580px;
  height: 220px;
  display: block;
}

/* Nhật ký (AI Diary) */
h2 {
  font-size: 19px;
  font-weight: 700;
  margin: 36px 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.filter-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.chip {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--mute);
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.chip:hover,
.chip.active {
  background: var(--ink);
  color: var(--card);
  border-color: var(--ink);
}

.ngay {
  margin: 0 0 20px;
}

.ngay h3 {
  font-size: 13px;
  color: var(--mute);
  margin: 0 0 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.dong {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 8px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  transition: border-color 0.2s ease;
}

.dong:hover {
  border-color: var(--mute);
}

.dong time {
  color: var(--mute);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  padding-top: 1px;
  flex: none;
  font-weight: 600;
}

.dong-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  flex: none;
}

.badge-tat { background: var(--neg-bg); color: var(--neg); }
.badge-tang { background: var(--pos-bg); color: var(--pos); }
.badge-chon_sp { background: var(--warn-bg); color: var(--warn); }
.badge-don_moi { background: #e8f0fe; color: #1a73e8; }

.trong {
  color: var(--mute);
  font-style: italic;
  padding: 20px;
  text-align: center;
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--line);
}

/* Bảng sản phẩm */
.cuon {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background: var(--card);
}

.bang-sp {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.bang-sp th,
.bang-sp td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bang-sp th:first-child,
.bang-sp td:first-child {
  text-align: left;
}

.bang-sp th {
  color: var(--mute);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--card-alt);
}

.bang-sp tr:last-child td {
  border-bottom: none;
}

.bang-sp tr:hover td {
  background: var(--card-alt);
}

.tt {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--bg);
}

.tt.chay {
  color: var(--pos);
  background: var(--pos-bg);
}

.tt.dung {
  color: var(--mute);
  background: var(--line);
}

.chu {
  color: var(--mute);
  font-size: 13px;
  margin-top: 32px;
  line-height: 1.6;
}

/* Modal Popup */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  max-width: 480px;
  width: 100%;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  transform: translateY(12px);
  transition: transform 0.2s ease;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal h3 {
  margin: 0 0 14px;
  font-size: 18px;
  font-weight: 700;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--mute);
  margin-bottom: 4px;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}

.form-control:focus {
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .meo * {
    animation: none !important;
  }
  .zzz text,
  .khoi path {
    opacity: 1;
  }
  .tro,
  .cham {
    animation: none !important;
  }
}
