:root {
  --bg: #f6f7f3;
  --surface: #ffffff;
  --surface-2: #f0f2ec;
  --ink: #24211d;
  --muted: #6e6a61;
  --line: #dedbd2;
  --line-strong: #c9c3b8;
  --brand: #7c2638;
  --brand-2: #a43f52;
  --teal: #2f6c62;
  --gold: #b07b28;
  --green: #3f7b53;
  --red: #b23a48;
  --violet: #5b4c8f;
  --shadow: 0 18px 40px rgba(37, 33, 29, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: #fbfbf8;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 6px 22px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  text-align: left;
}

.nav-item svg,
.top-actions svg,
.button svg,
.primary svg,
.search svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.nav-item.is-active {
  color: #fff;
  background: var(--ink);
}

.workspace {
  min-width: 0;
}

.topbar {
  min-height: 92px;
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 243, 0.92);
  backdrop-filter: blur(10px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 19px;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 8px;
  font-size: 15px;
  letter-spacing: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.search {
  min-width: min(320px, 100%);
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.search input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

select,
input {
  min-height: 40px;
  padding: 0 10px;
}

textarea {
  min-height: 82px;
  padding: 10px;
  resize: vertical;
}

.primary,
.button,
.ghost,
.danger {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  white-space: nowrap;
}

.primary {
  color: #fff;
  border-color: var(--brand);
  background: var(--brand);
}

.primary:hover {
  background: var(--brand-2);
}

.button {
  color: var(--ink);
  background: #fff;
}

.ghost {
  color: var(--muted);
  background: transparent;
}

.danger {
  color: #fff;
  border-color: var(--red);
  background: var(--red);
}

.content {
  padding: 24px 28px 44px;
}

.loading,
.empty {
  min-height: 220px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 18px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-header {
  min-height: 56px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-body {
  padding: 18px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.kpi-card {
  min-height: 118px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  align-content: space-between;
  box-shadow: 0 10px 24px rgba(37, 33, 29, 0.05);
}

.kpi-card span {
  color: var(--muted);
  font-size: 13px;
}

.kpi-card strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  letter-spacing: 0;
}

.kpi-card em {
  font-style: normal;
  color: var(--teal);
  font-size: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
  background: #fbfbf8;
}

tbody tr:hover {
  background: #fbfaf5;
}

.money {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

.small {
  font-size: 12px;
}

.status-pill,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--ink);
  white-space: nowrap;
}

.status-tu_van { background: #eef1fb; color: #3f4f8f; }
.status-cho_coc { background: #fff2d8; color: #8c601c; }
.status-dat_nguon { background: #e8f2ef; color: #2f6c62; }
.status-san_xuat { background: #f2e9f6; color: #6e477f; }
.status-cho_giao { background: #e8f6f1; color: #24704f; }
.status-dang_giao { background: #eaf2ff; color: #275e9d; }
.status-hoan_tat { background: #e8f5e9; color: #2e6d3d; }
.status-huy_hoan { background: #fde8eb; color: #a12f3d; }

.overdue {
  color: var(--red);
  font-weight: 750;
}

.charts {
  min-height: 300px;
}

.donut-layout {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
}

.donut {
  width: 170px;
  height: 170px;
  border-radius: 50%;
  position: relative;
  background: conic-gradient(var(--teal) 0 35%, var(--brand) 35% 60%, var(--gold) 60% 80%, var(--violet) 80% 100%);
}

.donut::after {
  content: "";
  position: absolute;
  inset: 28px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--line);
}

.legend {
  display: grid;
  gap: 9px;
}

.legend-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  color: var(--muted);
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.bar-list {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 110px;
  gap: 12px;
  align-items: center;
}

.bar-track {
  height: 14px;
  background: #ebece6;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.line-chart {
  width: 100%;
  height: 260px;
  display: block;
}

.kanban {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(260px, 1fr);
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.kanban-column {
  min-height: 360px;
  background: #f9faf6;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.kanban-title {
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  font-weight: 750;
}

.deal-card {
  margin: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  display: grid;
  gap: 8px;
  cursor: pointer;
}

.deal-card:hover {
  border-color: var(--line-strong);
}

.deal-card strong {
  line-height: 1.25;
}

.metric-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.metric-row:last-child {
  border-bottom: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.source-lines {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}

.source-line {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(140px, 1.3fr) 120px;
  gap: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(36, 33, 29, 0.38);
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal {
  width: min(860px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: 0 28px 80px rgba(36, 33, 29, 0.25);
}

.modal-header,
.modal-footer {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-footer {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-end;
}

.modal-body {
  padding: 18px;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.65fr);
  gap: 18px;
}

.timeline {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 10px;
}

.timeline-dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--teal);
}

.toast-host {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  display: grid;
  gap: 8px;
}

.toast {
  min-width: min(340px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  box-shadow: var(--shadow);
}

.mobile-tabs {
  display: none;
}

@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .grid-2,
  .grid-3,
  .detail-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .sidebar {
    position: sticky;
    z-index: 20;
    height: auto;
    top: 0;
    width: 100%;
    min-width: 0;
    max-width: 100vw;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px;
  }

  .workspace {
    width: 100%;
    min-width: 0;
    max-width: 100vw;
  }

  .brand {
    padding: 0 4px 10px;
  }

  .nav {
    display: flex;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-item {
    width: auto;
    min-width: fit-content;
  }

  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .search {
    width: 100%;
  }

  .content {
    padding: 18px;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .source-line {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .donut-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .top-actions {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .top-actions > * {
    min-width: 0;
  }

  .top-actions .search {
    width: 100%;
  }

  .top-actions select,
  .top-actions .primary,
  .top-actions .button {
    width: 100%;
    min-width: 0;
  }

  .bar-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .panel-header,
  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .modal-footer {
    flex-direction: column-reverse;
  }

  .modal-footer button {
    width: 100%;
  }
}
