:root {
  --md-rose: #c45c6a;
  --md-rose-dark: #a84855;
  --md-rose-deep: #8f3d4a;
  --md-rose-light: #fdf5f6;
  --md-border: #e8e4e5;
  --md-border-soft: #f3f0f1;
  --bg: #f3f1f2;
  --card: #ffffff;
  --text: #2a2224;
  --text-soft: #4a4043;
  --muted: #8a7e82;
  --accent: #d35400;
  --accent-soft: #fff4ec;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(42, 34, 36, 0.04), 0 8px 24px rgba(42, 34, 36, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 22px;
  background: #fff;
  border-bottom: 1px solid var(--md-border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; }
.brand-logo { height: 40px; width: auto; display: block; }

.breadcrumb {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.breadcrumb a {
  color: var(--md-rose-dark);
  text-decoration: none;
  font-weight: 600;
}

.breadcrumb a:hover { text-decoration: underline; }
.bc-sep { color: #cfc6c8; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn.ghost {
  background: #fff;
  border-color: var(--md-border);
  color: var(--text-soft);
}

.btn.ghost:hover {
  background: var(--md-rose-light);
  border-color: #ead3d7;
  color: var(--md-rose-deep);
}

.btn.ghost.danger {
  border-color: #f5c2c7;
  color: #c0392b;
}

.btn.ghost.danger:hover {
  background: #fdf0f0;
  border-color: #e74c3c;
  color: #c0392b;
}

.btn.primary {
  background: var(--md-rose);
  color: #fff;
}

.btn.primary:hover { background: var(--md-rose-dark); }

.page {
  width: min(1280px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 40px;
}

.view { display: block; }
.view[hidden] { display: none !important; }
[hidden] { display: none !important; }

/* ── List ── */
.list-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.list-title h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.list-title p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.list-search input {
  width: min(360px, 100%);
  padding: 10px 14px;
  border: 1px solid var(--md-border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

.list-search input:focus {
  outline: none;
  border-color: var(--md-rose);
  box-shadow: 0 0 0 3px rgba(196, 92, 106, 0.12);
}

.product-find-panel {
  background: #fff;
  border: 1px solid var(--md-border);
  border-radius: 12px;
  padding: 16px 18px 14px;
  margin-bottom: 14px;
}

.product-find-title {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 700;
  color: #111827;
  letter-spacing: -0.02em;
}

.product-find-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.product-find-input {
  padding: 11px 14px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  background: #fff;
  color: #111827;
  min-width: 160px;
}

.product-find-input--grow {
  flex: 1 1 280px;
  min-width: min(100%, 280px);
}

.product-find-input::placeholder {
  color: #9ca3af;
}

.product-find-input:focus {
  outline: none;
  border-color: var(--md-rose);
  box-shadow: 0 0 0 3px rgba(196, 92, 106, 0.12);
}

.product-find-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.dash-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

@media (max-width: 1200px) {
  .dash-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 620px) {
  .dash-grid { grid-template-columns: repeat(2, 1fr); }
}

.dash-card {
  background: #fff;
  border: 1px solid var(--md-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
}

.dash-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--md-border);
}

.dash-card--money::before { background: var(--md-rose); }
.dash-card--debt::before { background: #b45309; }

.dash-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
}

.dash-value {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--md-rose-dark);
  font-variant-numeric: tabular-nums;
}

.dash-value--ok { color: #15803d; }
.dash-value--warn { color: #b45309; }
.dash-value--debt { color: #dc2626; }

@media (max-width: 1000px) {
  .dash-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 620px) {
  .dash-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-value { font-size: 17px; }
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: #fff;
  border: 1px solid var(--md-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 150px;
  flex: 1 1 150px;
}

.filter-field > span {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
}

.filter-field--debt {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  min-width: auto;
}
.filter-field--debt input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.filter-field--debt > span {
  text-transform: none;
  font-size: 13px;
  font-weight: 500;
  color: inherit;
  cursor: pointer;
}

.filter-field select,
.filter-field input {
  padding: 8px 10px;
  border: 1px solid var(--md-border);
  border-radius: 8px;
  font: inherit;
  font-size: 16px;
  background: #fff;
}

.filter-field select:focus,
.filter-field input:focus {
  outline: none;
  border-color: var(--md-rose);
  box-shadow: 0 0 0 3px rgba(196, 92, 106, 0.12);
}

.filter-reset {
  height: 36px;
  flex: 0 0 auto;
}

.filter-export {
  position: relative;
  flex: 0 0 auto;
}

.filter-export .btn {
  height: 36px;
}

.export-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  min-width: 240px;
  background: #fff;
  border: 1px solid var(--md-border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(42, 34, 36, 0.16);
  padding: 6px;
  display: flex;
  flex-direction: column;
}

.export-menu button {
  text-align: left;
  padding: 9px 10px;
  border: 0;
  background: transparent;
  border-radius: 7px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}

.export-menu button:hover {
  background: #fdf1f2;
  color: var(--md-rose-dark);
}

.multi-select {
  position: relative;
}

.multi-select-btn {
  padding: 8px 10px;
  border: 1px solid var(--md-border);
  border-radius: 8px;
  font: inherit;
  font-size: 16px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  min-width: 160px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.multi-select-btn:focus,
.multi-select-btn.open {
  outline: none;
  border-color: var(--md-rose);
  box-shadow: 0 0 0 3px rgba(196, 92, 106, 0.12);
}

.multi-select-menu {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 20;
  min-width: 220px;
  max-height: 280px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--md-border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(42, 34, 36, 0.16);
  padding: 6px;
}

.multi-select-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}

.multi-select-option:hover {
  background: #fdf1f2;
}

.multi-select-option input[type="checkbox"] {
  cursor: pointer;
}

.multi-select-divider {
  height: 1px;
  background: var(--md-border);
  margin: 4px 2px;
}

.list-table tbody tr[data-code] {
  cursor: pointer;
}

.list-table tbody tr[data-code]:hover {
  background: #fdf5f6;
}

.order-code {
  color: var(--md-rose);
  text-decoration: none;
  font-weight: 600;
}

.order-code:hover {
  text-decoration: underline;
}


.list-table-wrap,
.od-table-wrap {
  background: #fff;
  border: 1px solid var(--md-border);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--md-border);
  border-radius: var(--radius);
}

.pager-info {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  min-width: 220px;
  text-align: center;
}

.pager-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.list-table,
.od-lines,
.pay-history {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.list-table th,
.od-lines th,
.pay-history th {
  text-align: left;
  padding: 11px 12px;
  background: #faf8f9;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--md-border);
  white-space: nowrap;
}

.list-table td,
.od-lines td,
.pay-history td {
  padding: 12px;
  border-bottom: 1px solid var(--md-border-soft);
  vertical-align: top;
}

.list-table tbody tr {
  cursor: pointer;
  transition: background 0.12s;
}

.list-table tbody tr:hover { background: #fcfafb; }
.list-table tbody tr:last-child td,
.od-lines tbody tr:last-child td,
.pay-history tbody tr:last-child td { border-bottom: none; }

.empty-cell {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px !important;
}

.order-code {
  color: var(--md-rose-dark);
  font-weight: 700;
  font-size: 13px;
}

.customer-cell strong { display: block; font-weight: 600; }
.customer-cell span { color: var(--muted); font-size: 12px; }

.money {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}

.money-accent { color: var(--accent) !important; }

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  background: #fff4e8;
  color: #a85c18;
  white-space: nowrap;
}

.status-badge--moi { background: #eef4ff; color: #3557a0; }
.status-badge--done { background: #eef7f2; color: #1f6b45; }

.chip {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f7f5f6;
  color: var(--text-soft);
  font-size: 11.5px;
  font-weight: 600;
  margin: 0 4px 4px 0;
}

.chip--eco { background: #eef7f2; color: #1f6b45; }
.chip--hn { background: #fdf0f2; color: var(--md-rose-deep); }

/* ── Detail ── */
.od-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.od-head__left {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.od-code-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.od-code-row h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.od-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.od-doc-title {
  margin: 8px 0 16px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
}

.od-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.od-main,
.side-card {
  background: #fff;
  border: 1px solid var(--md-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.od-main { padding: 18px 18px 22px; }

.od-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 28px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--md-border-soft);
}

.od-field {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 8px;
  padding: 6px 0;
  align-items: start;
}

.od-field span {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
}

.od-field strong {
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.od-lines .line-name {
  font-weight: 600;
  color: var(--text);
}

.od-lines .line-desc {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.od-lines .line-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
}

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

.od-totals {
  margin-top: 14px;
  margin-left: auto;
  width: min(320px, 100%);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.od-total-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 13px;
  color: var(--text-soft);
}

.od-total-row strong {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}

.od-total-row--grand {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--md-border);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.od-total-row--grand strong {
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
}

.od-extra {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--md-border-soft);
}

.od-extra h3 {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.od-extra p {
  margin: 0;
  white-space: pre-wrap;
  color: var(--text-soft);
}

.od-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.side-card {
  padding: 16px;
}

.side-card h3 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.side-pay-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.side-pay-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--text-soft);
}

.side-pay-row strong {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text);
}

.pay-history th,
.pay-history td {
  padding: 8px 6px;
  font-size: 12.5px;
}

.debt-pay-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.debt-pay-input {
  padding: 8px 10px;
  border: 1px solid var(--md-border);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  background: #fff;
  width: 100%;
}

.debt-pay-input:focus {
  outline: none;
  border-color: var(--md-rose);
  box-shadow: 0 0 0 3px rgba(196, 92, 106, 0.12);
}

.pay-note {
  color: var(--text-soft);
  line-height: 1.4;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: #2a2224;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: min(480px, calc(100% - 32px));
  font-size: 13px;
  font-weight: 500;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 980px) {
  .od-layout { grid-template-columns: 1fr; }
  .od-meta-grid { grid-template-columns: 1fr; }
  .od-field { grid-template-columns: 120px minmax(0, 1fr); }
}

@media (max-width: 640px) {
  .page { width: calc(100% - 16px); padding-top: 12px; }
  .topbar { padding: 10px 12px; flex-wrap: wrap; }
  .od-field { grid-template-columns: 1fr; gap: 2px; }
  .od-doc-title { font-size: 16px; }
}
