:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-light: #64748b;
  --brand: #ee4d2d;
  --brand-dark: #d73211;
  --brand-soft: #fff1ee;
  --brand-border: #fdbaaa;
  --navy: #0f172a;
  --emerald: #059669;
  --emerald-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "Noto Sans Thai", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.topbar {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 65%, #331812 100%);
  color: #fff;
  padding: 22px 24px 26px;
  border-bottom: 3px solid var(--brand);
}

.container {
  max-width: 1280px;
  margin: 0 auto;
}

.topbar-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

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

.brand-badge {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, #ee4d2d, #ff7337);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  color: #fff;
  box-shadow: 0 4px 14px rgba(238, 77, 45, 0.4);
  flex-shrink: 0;
}

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

.brand-sub {
  margin: 3px 0 0;
  font-size: 13px;
  color: #cbd5e1;
}

.rosy-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  color: #f8fafc;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.25);
}

/* KPI Strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.kpi-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px 14px;
}

.kpi-val {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}

.kpi-lbl {
  font-size: 11.5px;
  color: #cbd5e1;
}

/* Search Hero Box */
.search-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 18px 20px;
  margin: -16px auto 20px;
  position: relative;
  z-index: 5;
}

.search-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.search-input-wrap {
  position: relative;
  flex: 1;
}

.search-icon {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  font-size: 18px;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 14px 42px 14px 44px;
  font-size: 16px;
  font-family: inherit;
  border: 2px solid var(--border-strong);
  border-radius: 11px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  color: var(--text);
  background: #fff;
}

.search-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(238, 77, 45, 0.12);
}

.clear-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: var(--surface-alt);
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: none;
  align-items: center;
  justify-content: center;
}

.clear-btn.visible {
  display: inline-flex;
}

.search-btn {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 11px;
  padding: 14px 22px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.search-btn:hover {
  background: var(--brand-dark);
}

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
  align-items: center;
}

.chip-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  margin-right: 4px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
}

.chip:hover,
.chip.active {
  background: var(--brand-soft);
  border-color: var(--brand-border);
  color: var(--brand-dark);
  font-weight: 600;
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.tab-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 9px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}

.tab-btn:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.tab-btn.active {
  background: var(--navy);
  color: #fff;
}

.tab-count {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.16);
}

.tab-btn.active .tab-count {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* Main Content */
.main-wrap {
  padding: 0 20px 60px;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.section-block {
  margin-bottom: 28px;
}

.section-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.section-hdr h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Rule Cards */
.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 14px;
}

.rule-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rule-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

.badge-code {
  background: var(--brand-soft);
  color: var(--brand-dark);
  border: 1px solid var(--brand-border);
}

.badge-domain {
  background: var(--blue-soft);
  color: var(--blue);
}

.badge-mall {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.badge-nonmall {
  background: var(--emerald-soft);
  color: var(--emerald);
  border: 1px solid #a7f3d0;
}

.rule-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
  color: var(--text);
}

.rule-title-th {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.threshold-box {
  background: var(--amber-soft);
  border-left: 3px solid var(--amber);
  padding: 8px 11px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: #92400e;
}

.rule-answer {
  font-size: 13.5px;
  color: var(--text);
  margin: 0;
}

.action-box {
  background: var(--emerald-soft);
  border: 1px solid #a7f3d0;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  color: #065f46;
}

.rule-footer {
  font-size: 11.5px;
  color: var(--text-light);
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}

/* Fee Table & Cards */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}

table.fee-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.fee-table th {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-weight: 700;
  text-align: left;
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.fee-table td {
  padding: 10px 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.fee-table tr:last-child td {
  border-bottom: none;
}

table.fee-table tr:hover td {
  background: #fcfcfd;
}

.num-strong {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.calc-mini-btn {
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  border-radius: 7px;
  padding: 4px 9px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.calc-mini-btn:hover {
  border-color: var(--brand);
  color: var(--brand-dark);
  background: var(--brand-soft);
}

/* Excerpt Cards */
.chunks-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 12px;
}

.chunk-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
}

.chunk-snippet {
  font-size: 13px;
  color: var(--text-muted);
  background: var(--surface-alt);
  padding: 10px 12px;
  border-radius: 8px;
  max-height: 165px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

mark {
  background: #fde68a;
  color: #78350f;
  padding: 0 2px;
  border-radius: 3px;
  font-weight: 600;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-outline,
.btn-primary-sm {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 7px;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}

.btn-outline {
  background: #fff;
  border: 1px solid var(--border-strong);
  color: var(--text);
}

.btn-outline:hover {
  background: var(--surface-alt);
}

.btn-primary-sm {
  background: var(--brand-soft);
  border: 1px solid var(--brand-border);
  color: var(--brand-dark);
}

.btn-primary-sm:hover {
  background: #ffe4de;
}

/* Calculator Grid */
.calc-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 18px;
  margin-bottom: 24px;
}

@media (max-width: 860px) {
  .calc-grid,
  .rules-grid,
  .chunks-list {
    grid-template-columns: 1fr;
  }
}

.card-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

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

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.field input,
.field select,
.filter-select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  align-items: center;
}

.filter-bar .filter-select {
  width: auto;
  min-width: 170px;
}

.payout-summary {
  background: linear-gradient(135deg, #0f172a, #1e293b);
  color: #fff;
  border-radius: 12px;
  padding: 18px;
}

.payout-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13.5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.payout-row:last-child {
  border-bottom: none;
}

.payout-big {
  font-size: 24px;
  font-weight: 800;
  color: #34d399;
}

/* Documents Vault Grid */
.docs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}

.doc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}

/* Modal Reader */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 100;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  background: var(--surface);
  border-radius: 16px;
  max-width: 960px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
}

.modal-hdr {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface-alt);
}

.modal-body {
  padding: 18px 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-page-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: #fff;
}

.modal-page-lbl {
  font-size: 12px;
  font-weight: 700;
  color: var(--brand-dark);
  margin-bottom: 6px;
}

.modal-page-txt {
  font-size: 13.5px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.hidden {
  display: none !important;
}
