/* =========================================================================
   COMMISSION DEALER & AGENT — Stylesheet
   ========================================================================= */

:root {
  --bg: #eef2f8;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #e3e9f2;
  --line-strong: #cbd5e1;
  --primary: #1657d8;
  --primary-dark: #0d3f9e;
  --primary-soft: #e8efff;
  --teal: #0f766e;
  --teal-soft: #e6f6f4;
  --amber: #b45309;
  --amber-soft: #fdf3e3;
  --rose: #be123c;
  --rose-soft: #fdeaee;
  --green: #047857;
  --green-soft: #e7f7ef;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
  --shadow-md: 0 10px 30px -12px rgba(15, 23, 42, .18), 0 2px 8px rgba(15, 23, 42, .05);
  --font: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 40px;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; }

button, input, select { font-family: inherit; font-size: inherit; color: inherit; }

.hidden { display: none !important; }

/* ------------------------------ Header ------------------------------ */
.app-header {
  background: linear-gradient(120deg, #0b1f4b 0%, #123a86 55%, #1657d8 100%);
  color: #fff;
  padding: 22px clamp(16px, 4vw, 44px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 16px; }

.brand-mark {
  width: 52px; height: 52px;
  border-radius: 15px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 19px; letter-spacing: .5px;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .28);
  backdrop-filter: blur(4px);
}

.brand-text h1 { font-size: clamp(18px, 2.2vw, 23px); font-weight: 700; }
.brand-text h1 span { font-weight: 500; opacity: .85; font-size: .82em; letter-spacing: .04em; }
.brand-text p { margin: 3px 0 0; font-size: 13.5px; opacity: .78; }

.header-actions .btn-ghost {
  border-color: rgba(255, 255, 255, .35);
  color: #fff;
  background: rgba(255, 255, 255, .1);
}
.header-actions .btn-ghost:hover { background: rgba(255, 255, 255, .2); }

/* ------------------------------ Tabs ------------------------------ */
.tabs {
  position: sticky; top: 0; z-index: 40;
  display: flex; gap: 6px;
  padding: 10px clamp(16px, 4vw, 44px);
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  border: 0;
  background: transparent;
  padding: 9px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14.5px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background .18s ease, color .18s ease;
}
.tab-btn:hover { background: var(--primary-soft); color: var(--primary-dark); }
.tab-btn.active { background: var(--primary); color: #fff; box-shadow: 0 6px 16px -8px rgba(22, 87, 216, .9); }

/* ------------------------------ Layout ------------------------------ */
main { padding: 22px clamp(16px, 4vw, 44px) 40px; max-width: 1500px; margin: 0 auto; }

.tab-panel { display: none; animation: fade .22s ease; }
.tab-panel.active { display: block; }

@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.calc-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(340px, .85fr); gap: 20px; align-items: start; }
.calc-main { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.calc-side { position: sticky; top: 74px; }

@media (max-width: 1080px) {
  .calc-grid { grid-template-columns: 1fr; }
  .calc-side { position: static; }
}

/* ------------------------------ Card ------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px 22px;
}

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 16px;
}
.card-head h2 { font-size: 16.5px; display: flex; align-items: center; gap: 10px; }

.step {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 9px;
  background: var(--primary-soft); color: var(--primary-dark);
  font-size: 13.5px; font-weight: 700;
}

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------ Buttons ------------------------------ */
.btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink-soft);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600; font-size: 14px;
  cursor: pointer;
  transition: all .16s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-soft); }

.btn-primary {
  background: var(--primary); border-color: var(--primary); color: #fff;
  box-shadow: 0 8px 18px -10px rgba(22, 87, 216, .9);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }

.btn-ghost { background: transparent; border-color: var(--line-strong); }
.btn-block { width: 100%; }
.btn-danger { border-color: #f3c6d2; color: var(--rose); background: #fff; }
.btn-danger:hover { background: var(--rose-soft); border-color: var(--rose); color: var(--rose); }

.btn-icon {
  border: 0; background: transparent; cursor: pointer;
  width: 30px; height: 30px; border-radius: 8px;
  color: var(--muted); font-size: 15px; line-height: 1;
  transition: all .15s ease;
}
.btn-icon:hover { background: var(--rose-soft); color: var(--rose); }

/* ------------------------------ Forms ------------------------------ */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}
.form-grid .span-2 { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }

.field input[type="date"],
.field input[type="number"],
.field input[type="text"],
.field select,
.search {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  font-size: 14.5px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field select:focus, .field input:focus, .search:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22, 87, 216, .14);
}

.check-field { justify-content: flex-start; }
.check-line { display: flex; align-items: center; gap: 8px; padding: 8px 0; font-size: 14px; color: var(--ink-soft); }
.check-line input { width: 17px; height: 17px; accent-color: var(--primary); }

.install-box {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--primary-soft);
  border: 1px dashed #b8ccf8;
}

.hint { color: var(--muted); font-size: 13px; margin: 12px 0 0; line-height: 1.6; }

.round-hint {
  margin: 16px 0 0;
  padding: 11px 14px;
  border-radius: 12px;
  background: var(--teal-soft);
  color: #0b5c56;
  font-size: 13.5px;
  font-weight: 500;
  border-left: 3px solid var(--teal);
}

/* ------------------------------ Items table ------------------------------ */
.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--line); }

table { width: 100%; border-collapse: collapse; }

.items-table th, .rate-table th {
  background: #f7f9fd;
  text-align: left;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-transform: uppercase;
  letter-spacing: .02em;
  white-space: nowrap;
}

.items-table td, .rate-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  vertical-align: middle;
}
.items-table tbody tr:last-child td, .rate-table tbody tr:last-child td { border-bottom: 0; }
.items-table tbody tr:hover, .rate-table tbody tr:hover { background: #fafcff; }

.items-table select,
.items-table input[type="number"] {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  font-size: 13.5px;
}
.items-table select:focus, .items-table input:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22, 87, 216, .12);
}

.items-table input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--teal); cursor: pointer; }

.num { text-align: right; font-variant-numeric: tabular-nums; }
.center { text-align: center; }

.cell-rate { font-weight: 600; color: var(--ink-soft); }
.cell-total { font-weight: 700; color: var(--primary-dark); }
.row-prior { background: #fbfdff; }
.row-prior .cell-total { color: var(--teal); }

.empty-row td {
  text-align: center; color: var(--muted); padding: 26px 12px; font-size: 14px;
}

/* ------------------------------ Summary ------------------------------ */
.summary-card { border: 1px solid #cfdcf6; box-shadow: var(--shadow-md); }

.sum-top {
  border-radius: 13px;
  padding: 18px 18px 16px;
  background: linear-gradient(135deg, #0b1f4b 0%, #123a86 60%, #1657d8 100%);
  color: #fff;
}

.sum-label { font-size: 12.5px; opacity: .82; letter-spacing: .03em; }
.sum-value { font-size: 33px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; margin-top: 2px; }
.sum-sub { font-size: 12.5px; opacity: .8; margin-top: 4px; }

.sum-badges { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700;
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .28);
  color: #fff;
}
.badge.tier1 { background: rgba(255, 255, 255, .18); }
.badge.tier2 { background: #ffd166; border-color: #ffd166; color: #4a2c00; }
.badge.tier3 { background: #34d399; border-color: #34d399; color: #04352a; }

.pct-tag {
  display: inline-block;
  margin-left: 4px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--primary-dark);
  background: var(--primary-soft);
  border-radius: 999px;
  padding: 0 5px;
  vertical-align: middle;
}

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0 4px; }

.stat {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fbfcff;
}
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 12px; color: var(--muted); font-weight: 600; }

.alert {
  margin-top: 12px;
  padding: 10px 13px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.55;
}
.alert-warn { background: var(--amber-soft); color: #7c4a03; border-left: 3px solid var(--amber); }
.alert-ok { background: var(--green-soft); color: #045c42; border-left: 3px solid var(--green); }
.alert-info { background: var(--primary-soft); color: var(--primary-dark); border-left: 3px solid var(--primary); }

.sum-section-title {
  font-size: 12.5px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  margin: 18px 0 8px;
}

.breakdown { list-style: none; margin: 0; padding: 0; }
.breakdown li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 7px 0;
  font-size: 13.8px;
  border-bottom: 1px dashed var(--line);
}
.breakdown li:last-child { border-bottom: 0; }
.breakdown li span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.breakdown li.minus span:last-child { color: var(--rose); }
.breakdown li.plus span:last-child { color: var(--green); }
.breakdown li.total { font-size: 15px; font-weight: 700; padding-top: 10px; color: var(--primary-dark); }

.payout-table td, .payout-table th { font-size: 12.8px; padding: 8px 9px; }
.payout-table tbody tr.sum-install td { font-weight: 700; }

.sum-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }

/* ------------------------------ Rebate box ------------------------------ */
.rebate-box {
  border: 1px solid #cfe9dc;
  background: #f4fbf7;
  border-radius: 12px;
  padding: 12px 14px;
}
.rb-row {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 13.5px;
  padding: 5px 0;
  color: var(--ink-soft);
}
.rb-row span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.rb-total { border-top: 1px dashed #cfe9dc; margin-top: 4px; padding-top: 8px; font-weight: 700; color: var(--green); }
.rb-total em { font-style: normal; font-weight: 600; font-size: 12px; color: var(--amber); }
.rb-note { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.55; }
.rb-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft); margin-top: 10px; }
.rb-check input { width: 16px; height: 16px; accent-color: var(--green); }
.rb-status {
  margin-top: 8px; padding: 8px 11px; border-radius: 9px;
  font-size: 13px; font-weight: 700;
}
.rb-status.ready { background: var(--green-soft); color: #045c42; }
.rb-status.wait { background: var(--amber-soft); color: #7c4a03; }

/* ------------------------------ Rates page ------------------------------ */
.rate-table td { font-variant-numeric: tabular-nums; }
.rate-table .grp { color: var(--muted); font-size: 12.8px; }
.rate-table .prod { font-weight: 600; }
.qual-badge {
  display: inline-block; margin-left: 6px;
  font-size: 10.5px; font-weight: 700;
  padding: 1.5px 7px; border-radius: 999px;
  background: var(--teal-soft); color: #0b5c56;
  vertical-align: middle;
}
.price-cell { color: var(--muted); }
.rate-hi { font-weight: 700; color: var(--primary-dark); }
.rate-lo { font-weight: 600; color: var(--ink-soft); }
.rate-mid { font-weight: 700; color: var(--teal); }

/* ------------------------------ Agents ------------------------------ */
.agent-list { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }

.agent-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  background: #fbfcff;
}
.agent-card .agent-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }

.pill {
  font-size: 11.5px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.pill-fix { background: var(--primary-soft); color: var(--primary-dark); border-color: #c7d8fb; }
.pill-pct { background: var(--teal-soft); color: #0b5c56; border-color: #bfe6e1; }
.pill-dr  { background: var(--amber-soft); color: #7c4a03; border-color: #f3ddb7; }

.agent-card .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.agent-card .field > span { font-size: 12px; }
.agent-card .field input, .agent-card .field select { padding: 7px 10px; font-size: 13.5px; }
.agent-card .field input:disabled { background: #f1f5f9; color: #94a3b8; cursor: not-allowed; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: #fff;
  font-size: 12.5px; font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.chip input { width: 14px; height: 14px; accent-color: var(--teal); }
.chip.on { background: var(--teal-soft); border-color: #a8dcd5; color: #0b5c56; }

.chk-rebate-line { font-size: 13px; color: var(--ink-soft); }
.agent-card .agent-head input {
  flex: 1; font-weight: 700; font-size: 15.5px;
  border: 1px solid transparent; background: transparent;
  padding: 6px 8px; border-radius: 8px;
}
.agent-card .agent-head input:hover { border-color: var(--line-strong); background: #fff; }
.agent-card .agent-head input:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(22, 87, 216, .12); }

.agent-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 10px; flex-wrap: wrap; }
.agent-actions .note { font-size: 12.3px; color: var(--muted); flex: 1; min-width: 140px; }

/* ------------------------------ Schedule / result lines ------------------------------ */
.schedule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
@media (max-width: 900px) { .schedule-grid { grid-template-columns: 1fr; } }

.result-lines { display: grid; gap: 10px; margin-top: 16px; }
.result-line {
  display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  padding: 12px 14px;
  border-radius: 11px;
  background: #f7f9fd;
  border: 1px solid var(--line);
  font-size: 14px;
}
.result-line .lbl { color: var(--muted); font-weight: 600; }
.result-line .val { font-weight: 700; color: var(--primary-dark); }

/* ------------------------------ History ------------------------------ */
.history-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: #fbfcff;
}
.history-item .h-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.history-item .h-title { font-weight: 700; }
.history-item .h-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.history-item .h-net { font-size: 19px; font-weight: 700; color: var(--primary-dark); font-variant-numeric: tabular-nums; }
.history-item details { margin-top: 10px; }
.history-item summary { cursor: pointer; font-size: 13px; color: var(--primary-dark); font-weight: 600; }

/* ------------------------------ Tier explain ------------------------------ */
.tier-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.tier-card {
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 14px 15px;
  background: #fbfcff;
}
.tier-card .tier-name { font-weight: 700; color: var(--primary-dark); font-size: 14.5px; }
.tier-card .tier-range { font-size: 13px; color: var(--muted); font-weight: 600; margin: 2px 0 6px; }
.tier-card p { margin: 0; font-size: 12.8px; color: var(--ink-soft); line-height: 1.6; }
.tier-card.tier2 { background: #fffaec; border-color: #f3e0b5; }
.tier-card.tier2 .tier-name { color: var(--amber); }
.tier-card.retro { background: var(--teal-soft); border-color: #bfe6e1; }
.tier-card.retro .tier-name { color: #0b5c56; }

.mini-title {
  font-size: 13.5px; font-weight: 700; color: var(--muted);
  margin: 18px 0 8px;
  padding-left: 10px;
  border-left: 3px solid var(--primary);
}

/* ------------------------------ Footer ------------------------------ */
.app-footer {
  max-width: 1500px;
  margin: 0 auto;
  padding: 8px clamp(16px, 4vw, 44px) 0;
  color: var(--muted);
  font-size: 12.5px;
}

/* ------------------------------ Structure table ------------------------------ */
.struct-table { width: 100%; border-collapse: collapse; }
.struct-table th {
  background: #f7f9fd;
  text-align: left;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-transform: uppercase;
  letter-spacing: .02em;
  white-space: nowrap;
}
.struct-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.struct-table tbody tr:last-child td { border-bottom: 0; }
.struct-table tbody tr:hover { background: #fafcff; }
.struct-table input, .struct-table select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  font-size: 13.5px;
}
.struct-table input:focus, .struct-table select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22, 87, 216, .12);
}
.struct-table .st-net { font-weight: 700; color: var(--green); font-variant-numeric: tabular-nums; }

.btn-mini {
  border: 1px solid #f3c6d2;
  background: #fff;
  color: var(--rose);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: background .15s ease, border-color .15s ease;
}
.btn-mini:hover { background: var(--rose-soft); border-color: var(--rose); }

.struct-summary { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.chip-stat {
  font-size: 12.5px; font-weight: 700;
  padding: 5px 11px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-dark);
}

.struct-notice {
  display: none;
  margin-top: 12px;
  padding: 10px 13px;
  border-radius: 11px;
  background: var(--teal-soft);
  color: #0b5c56;
  font-size: 13.5px;
  font-weight: 600;
  border-left: 3px solid var(--teal);
}
.struct-notice.show { display: block; }

/* ------------------------------ ค่าตอบแทน (คำนวณจากยอดขาย) ------------------------------ */
.calc-adv {
  margin-top: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  padding: 10px 14px;
  background: #fbfcff;
}
.calc-adv summary { cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--primary-dark); }
.tier-details summary {
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary-dark);
  padding: 4px 0;
  list-style: none;
}
.tier-details summary::-webkit-details-marker { display: none; }
.tier-details summary::before { content: '\25B8  '; color: var(--primary); }
.tier-details[open] summary::before { content: '\25BE  '; }
.tier-details[open] summary { margin-bottom: 10px; }
#calcRoundInfo { margin-top: 14px; }
.calc-diag {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  background: #fbfcff;
}
.calc-diag:empty { display: none; }
.calc-diag .cd-title { font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.calc-diag .cd-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.calc-diag .cd-hint {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #7c4a03;
  background: var(--amber-soft);
  border-left: 3px solid #d9930a;
  border-radius: 8px;
  padding: 8px 11px;
  line-height: 1.55;
}
.calc-diag .cd-ok {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #045c42;
  background: var(--green-soft);
  border-left: 3px solid #12a37a;
  border-radius: 8px;
  padding: 8px 11px;
}
.calc-diag-status {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  font-size: 13px;
  font-weight: 600;
}
.calc-diag-status:empty { display: none; }
.cd-status-ok { color: #045c42; }
.cd-status-warn { color: #7c4a03; }
.cd-open-btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: background .15s ease, border-color .15s ease;
}
.cd-open-btn:hover { background: var(--primary-soft); border-color: var(--primary); }
.cd-open-btn-warn { border-color: #f0c14b; color: #7c4a03; }
.cd-open-btn-warn:hover { background: var(--amber-soft); border-color: #d9930a; }
.calc-detail { margin-top: 18px; }
.calc-detail:empty { display: none; }
.row-upd { background: #f4f8ff; }

/* ------------------------------ Import modal ------------------------------ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 24px 60px -18px rgba(15, 23, 42, .45);
  width: min(1080px, 100%);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  padding: 20px 22px 18px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.modal-head h2 { font-size: 17px; }
.modal-sm { width: min(680px, 100%); }
.modal .calc-diag {
  margin: 0;
  border: none;
  padding: 0;
  background: transparent;
}
.modal .hint { margin-top: 0; margin-bottom: 14px; }
.modal .form-grid { margin-bottom: 14px; }

.import-preview {
  max-height: 46vh;
  overflow: auto;
  margin-bottom: 14px;
}
.import-preview th { position: sticky; top: 0; z-index: 1; }

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.modal-actions .spacer { flex: 1; }

.imp-badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}
.imp-badge.new { background: var(--green-soft); color: #045c42; }
.imp-badge.upd { background: var(--primary-soft); color: var(--primary-dark); }
.imp-badge.rep { background: var(--amber-soft); color: #7c4a03; }
.imp-note { font-size: 11px; color: var(--muted); font-weight: 600; }
.imp-row-upd { background: #f7faff; }

@media print {
  .modal-overlay { display: none !important; }
}

/* ------------------------------ Payee box ------------------------------ */
.payee-box {
  border: 1px solid var(--line);
  background: #fbfcff;
  border-radius: 12px;
  padding: 10px 13px;
}
.payee-box .pb-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13.3px; padding: 4px 0; }
.payee-box .pb-row span:first-child { color: var(--muted); font-weight: 600; }
.payee-box .pb-row span:last-child { font-weight: 700; text-align: right; }

.mono { font-variant-numeric: tabular-nums; font-size: 12.5px; color: #0b5c56; display: inline-block; margin-top: 4px; }

/* ------------------------------ Agents: accordion + detail ------------------------------ */
.agent-split {
  display: grid;
  grid-template-columns: minmax(230px, 310px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
@media (max-width: 900px) { .agent-split { grid-template-columns: 1fr; } }

.agent-acc { display: flex; flex-direction: column; gap: 8px; }

.acc-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcff;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
  font-family: inherit;
}
.acc-item:hover { border-color: var(--primary); background: #f4f8ff; }
.acc-item.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 6px 16px -12px rgba(22, 87, 216, .8);
}
.acc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.acc-name {
  font-weight: 700; font-size: 14.5px; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.acc-sub { font-size: 12px; color: var(--muted); font-weight: 600; }
.acc-chev { color: var(--primary); font-size: 18px; font-weight: 700; transition: transform .15s ease; }
.acc-item.active .acc-chev { transform: rotate(90deg); }

.agent-detail { min-width: 0; }
.detail-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--line-strong);
}
.detail-title { font-size: 16px; font-weight: 700; }
.agent-detail .agent-card { background: #fff; }

/* ------------------------------ Round cards ------------------------------ */
.round-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.round-card {
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 14px 16px;
  background: #fbfcff;
}
.round-card.pay { background: var(--teal-soft); border-color: #bfe6e1; }
.round-card .rc-k { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.round-card .rc-v { font-size: 17px; font-weight: 700; color: var(--primary-dark); margin-top: 2px; }
.round-card.pay .rc-v { color: #0b5c56; }

.round-meta {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-top: 12px;
  font-size: 13px; color: var(--muted);
}
.round-status { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.round-status.wait { background: var(--amber-soft); color: #7c4a03; }
.round-status.open { background: var(--green-soft); color: #045c42; }
.round-status.done { background: var(--primary-soft); color: var(--primary-dark); }

.btn:disabled { opacity: .5; cursor: not-allowed; }
.field select:disabled, .field input:disabled { background: #f1f5f9; color: #94a3b8; cursor: not-allowed; }

/* ------------------------------ Settings module ------------------------------ */
.subtabs {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin: 0 0 18px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
}
.subtab-btn {
  border: 0;
  background: transparent;
  padding: 9px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  transition: background .16s ease, color .16s ease;
}
.subtab-btn:hover { background: var(--primary-soft); color: var(--primary-dark); }
.subtab-btn.active { background: var(--primary); color: #fff; }

.tab-subpanel { display: none; animation: fade .18s ease; }
.tab-subpanel.active { display: block; }

/* current user picker (header) */
.user-pick { display: flex; align-items: center; gap: 8px; }
.user-pick-label { font-size: 12.5px; opacity: .82; }
.user-pick select {
  padding: 7px 10px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 13.5px;
  max-width: 240px;
}
.user-pick select option { color: #0f172a; }

/* permission matrix */
.perm-table { width: 100%; border-collapse: collapse; }
.perm-table th, .perm-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.perm-table th {
  background: #f7f9fd;
  font-weight: 700;
  font-size: 12.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .02em;
  white-space: nowrap;
}
.perm-table tbody tr:last-child td { border-bottom: 0; }
.perm-table input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.perm-table input[type="checkbox"]:disabled { cursor: not-allowed; opacity: .5; }

/* ------------------------------ Sales module ------------------------------ */
.sale-wrap { max-height: 68vh; overflow: auto; }
.sale-table { width: 100%; border-collapse: collapse; }
.sale-table th {
  position: sticky; top: 0; z-index: 2;
  background: #f7f9fd;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.sale-table td { padding: 4px 6px; border-bottom: 1px solid var(--line); }
.sale-table tbody tr:hover { background: #fafcff; }
.sale-table input {
  width: 100%;
  padding: 6px 7px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--ink);
}
.sale-table input:hover { border-color: var(--line-strong); background: #fff; }
.sale-table input:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(22, 87, 216, .12); }
.sale-table input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }

.sale-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.sale-round-bar {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfcff;
}
.sale-round-side { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-bottom: 2px; }

/* ------------------------------ Report / Dashboard ------------------------------ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.kpi {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  background: linear-gradient(160deg, #fbfdff 0%, #f2f7ff 100%);
}
.kpi .kpi-k { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.kpi .kpi-v { font-size: 22px; font-weight: 700; color: var(--primary-dark); margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .kpi-s { font-size: 12px; color: var(--muted); margin-top: 2px; }

.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.chart-bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 10px; align-items: center; }
.bar-label {
  font-size: 12.5px; font-weight: 600; color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar-track { height: 12px; background: #eef2f8; border-radius: 999px; overflow: hidden; }
.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #1657d8, #4f8ef7);
  transition: width .3s ease;
}
.bar-value { font-size: 12.5px; font-weight: 700; color: var(--primary-dark); font-variant-numeric: tabular-nums; }

.chart-columns {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding-top: 10px;
  overflow-x: auto;
  min-height: 190px;
}
.col-item { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 56px; }
.col-value { font-size: 11.5px; font-weight: 700; color: var(--primary-dark); font-variant-numeric: tabular-nums; }
.col-bar {
  width: 34px;
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, #4f8ef7, #1657d8);
}
.col-label { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }

/* ------------------------------ Print ------------------------------ */
@media print {
  body { background: #fff; padding: 0; font-size: 12px; }
  .no-print, .tabs, .app-footer { display: none !important; }
  .app-header { background: #fff !important; color: #000; padding: 0 0 12px; border-bottom: 2px solid #000; }
  .brand-mark { display: none; }
  .brand-text p { color: #444; }
  .calc-grid { grid-template-columns: 1fr 1fr; }
  .calc-side { position: static; }
  .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
  .sum-top { background: #f1f5f9 !important; color: #000; }
  .badge { border-color: #999; background: #fff; color: #000; }
  .tab-panel { display: none !important; }
  .tab-panel.active { display: block !important; }
  .tab-subpanel { display: none !important; }
  .tab-subpanel.active { display: block !important; }
  .subtabs { display: none !important; }
  .tier-explain { display: none; }
}
