/* AffilMatrix — gaya asas.
   Semua warna & fon dalam token di bawah. Untuk ikut identiti carimurah.my, ubah nilai token sahaja. */
@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@500&display=swap");

:root {
  --brand: #0d6a57;         /* warna utama: butang, pautan, kad hero */
  --brand-ink: #ffffff;     /* teks di atas warna utama */
  --brand-soft: #dcefe9;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --sunk: #eef2f0;
  --fg: #15201c;
  --muted: #5d6c67;
  --line: #dde4e1;
  --ok: #1b7444; --ok-soft: #e2f3e8;
  --warn: #965808; --warn-soft: #fcf0dd;
  --bad: #b1291f; --bad-soft: #fbe7e4;
  --info: #22599c; --info-soft: #e3edf9;
  --seg-cost: #a8b5b1; --seg-op: #d1a056; --seg-co: #15201c;
  --font: "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 32, 28, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #4cc19f; --brand-ink: #06231b; --brand-soft: #16302a;
    --bg: #0e1412; --surface: #151d1a; --sunk: #111816; --fg: #e4ece9; --muted: #95a49f; --line: #25312d;
    --ok: #63cf8f; --ok-soft: #15301f; --warn: #e3a54c; --warn-soft: #33260f; --bad: #ef7b71; --bad-soft: #3a1a17; --info: #7fb0ec; --info-soft: #172739;
    --seg-cost: #55625e; --seg-op: #b3863f; --seg-co: #e4ece9;
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; font-weight: 700; }
h2 { font-size: 1.08rem; font-weight: 700; }
h3 { font-size: .98rem; font-weight: 600; margin-top: 8px; }
p { margin: 0; }
input, select, textarea, button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.mono { font-family: var(--mono); font-size: .92em; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: .93em; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.center { text-align: center; }
.pre { white-space: pre-line; }
.label { display: block; font-size: .72rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.grow { flex: 1; }
.neg { color: var(--bad); }
.zero { color: var(--muted); }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Butang ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); padding: 8px 14px; border-radius: var(--radius-sm); font-weight: 600; font-size: .9rem; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--fg); }
.btn.pri { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.pri:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: .82rem; }
.btn.wide { width: 100%; padding: 11px 16px; }

/* ---------- Cip & notis ---------- */
.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .74rem; font-weight: 600; white-space: nowrap; text-decoration: none; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.mute { background: var(--sunk); color: var(--muted); }
.notice { padding: 11px 14px; border-radius: var(--radius-sm); background: var(--sunk); border: 1px solid var(--line); font-size: .9rem; }
.notice.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.notice.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.notice.bad { background: var(--bad-soft); border-color: transparent; color: var(--fg); }
.notice.bad b { color: var(--bad); }
.flash { margin: 0 0 16px; padding: 11px 14px; border-radius: var(--radius-sm); font-weight: 500; background: var(--ok-soft); color: var(--ok); }
.flash.bad { background: var(--bad-soft); color: var(--bad); }
body.shop > .flash { margin: 12px auto 0; max-width: 1040px; width: calc(100% - 32px); }

/* ---------- Rangka portal ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 10px max(16px, env(safe-area-inset-left)); background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; color: var(--fg); text-decoration: none; }
.brand .mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); font-weight: 700; }
.brand.big { font-size: 1.3rem; }
.brand.big .mark { width: 40px; height: 40px; font-size: 1.2rem; }
.area { font-size: .75rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); }
.switch { font-size: .85rem; font-weight: 600; text-decoration: none; }
.topbar form { margin: 0; }
.out { display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; font-size: .85rem; }
.out:hover { color: var(--bad); }
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: calc(100vh - 53px); }
.side { position: sticky; top: 53px; align-self: start; display: flex; flex-direction: column; gap: 2px; padding: 16px 12px; height: calc(100vh - 53px); border-right: 1px solid var(--line); background: var(--surface); }
.side a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--muted); text-decoration: none; font-weight: 500; }
.side a:hover { background: var(--sunk); color: var(--fg); }
.side a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.side .who { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); display: flex; flex-direction: column; font-size: .85rem; }
.side .who span { font-family: var(--mono); color: var(--muted); font-size: .8rem; }
.main { padding: 24px max(16px, env(safe-area-inset-right)) 64px 28px; display: flex; flex-direction: column; gap: 18px; min-width: 0; max-width: 1240px; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; }
.page-head .muted { margin-top: 3px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; top: 53px; z-index: 9; height: auto; flex-direction: row; overflow-x: auto; padding: 6px 10px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side a { flex: none; padding: 8px 10px; font-size: .88rem; }
  .side .who { display: none; }
  .main { padding: 18px max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left)); }
  .switch, .out span { display: none; }
}

/* ---------- Kad & grid ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 620px; }
.card.narrow-wide { max-width: 820px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; align-items: start; }
.row-between { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); }
.kpi .v { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 1.4rem; font-weight: 500; }
.kpi .v.small-v { font-size: 1rem; word-break: break-word; }
.kpi .s { font-size: .8rem; color: var(--muted); }
.kpi.hero { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.kpi.hero .label, .kpi.hero .s { color: var(--brand-ink); opacity: .82; }
.meter { height: 6px; border-radius: 99px; background: var(--sunk); overflow: hidden; margin: 4px 0 2px; }
.meter div { height: 100%; background: var(--brand); border-radius: 99px; }
.todo { display: flex; flex-wrap: wrap; gap: 10px; }
.todo-item { flex: 1 1 260px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); text-decoration: none; font-weight: 500; }
.todo-item b { font-family: var(--mono); font-size: 1.1rem; margin-right: 4px; }

/* bar */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar { display: grid; grid-template-columns: minmax(0, 150px) 1fr 100px; gap: 10px; align-items: center; font-size: .88rem; }
.bar .track { height: 10px; background: var(--sunk); border-radius: 4px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--brand); opacity: .55; border-radius: 4px; }
.bar.l1 .fill { opacity: 1; }
.bar .num { text-align: right; }
@media (max-width: 520px) { .bar { grid-template-columns: minmax(0, 1fr) 96px; } .bar .track { grid-column: 1 / -1; grid-row: 2; } }

/* jadual */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface); }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
.r { text-align: right; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--sunk); }
tfoot td { font-weight: 700; border-top: 1px solid var(--fg); border-bottom: 0; }
td.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
tr.locked td { color: var(--muted); }
table.mini { font-size: .84rem; }
table.mini th, table.mini td { padding: 6px 8px; }

/* senarai produk */
.prod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 16px; }
.card.prod { color: var(--fg); text-decoration: none; transition: border-color .15s; }
.card.prod:hover { border-color: var(--brand); }
.domain { color: var(--muted); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 0; }
.facts div { background: var(--sunk); border-radius: var(--radius-sm); padding: 8px 10px; }
.facts dt { font-size: .72rem; color: var(--muted); }
.facts dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 500; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 0; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.empty-state { align-items: flex-start; }

/* borang */
.form { display: flex; flex-direction: column; gap: 6px; }
.form > label { font-size: .84rem; font-weight: 600; margin-top: 8px; }
.form > button { margin-top: 14px; align-self: flex-start; }
.form > .btn.wide { align-self: stretch; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .span2 { grid-column: 1 / -1; }
@media (max-width: 860px) { .form-grid { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: .84rem; font-weight: 600; }
.cols2, .cols3 { display: grid; gap: 12px; }
.cols2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.cols3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 130px), 1fr)); }
input:not([type=checkbox]):not([type=hidden]), select, textarea { width: 100%; min-width: 0; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input[readonly] { background: var(--sunk); }
textarea { resize: vertical; }
.money { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.money:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.money span { padding-left: 11px; color: var(--muted); font-size: .85rem; }
.money input { border: 0 !important; box-shadow: none !important; font-family: var(--mono); background: transparent !important; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .9rem; margin-top: 8px; }
.check input { margin-top: 4px; accent-color: var(--brand); }
.levels { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 720px) { .levels { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.lvl label b { color: var(--brand); margin-right: 2px; }
.is-locked { opacity: .55; }
.is-locked label::after { content: " · dikunci"; color: var(--bad); font-weight: 500; }
.dns-help { display: flex; flex-direction: column; gap: 6px; }
.split { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; }
.stack { display: flex; height: 24px; border-radius: 6px; overflow: hidden; background: var(--sunk); }
.stack div { height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .82rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend b { color: var(--fg); font-weight: 500; }
.seg-cost { background: var(--seg-cost); } .seg-op { background: var(--seg-op); } .seg-co { background: var(--seg-co); }
.seg-l1 { background: var(--brand); } .seg-l2 { background: var(--brand); opacity: .78; } .seg-l3 { background: var(--brand); opacity: .6; } .seg-l4 { background: var(--brand); opacity: .44; } .seg-l5 { background: var(--brand); opacity: .3; }
.rules { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; font-size: .88rem; }
.rules li { display: flex; gap: 10px; align-items: baseline; }

/* bar alat */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; }
.segs { display: flex; gap: 4px; background: var(--sunk); padding: 4px; border-radius: 10px; overflow-x: auto; max-width: 100%; }
.seg { padding: 6px 12px; border-radius: 7px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .86rem; white-space: nowrap; }
.seg.on { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
.seg .cnt { font-family: var(--mono); font-size: .75rem; background: var(--warn-soft); color: var(--warn); padding: 0 6px; border-radius: 99px; }
.search { flex: 1 1 240px; max-width: 360px; }
.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.inline select { width: auto; }
.ship input { width: 150px; }
.inline-notice { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin: 0; }

/* aliran komisen */
.flow { display: flex; flex-direction: column; }
.step { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.step:last-child { border-bottom: 0; }
.step .lv { font-family: var(--mono); font-size: .78rem; text-align: center; padding: 4px 0; border-radius: 6px; background: var(--brand-soft); color: var(--brand); }
.step.none .lv { background: var(--sunk); color: var(--muted); }
.step .who { display: flex; flex-direction: column; min-width: 0; }
.step .who b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step .who small { color: var(--muted); font-family: var(--mono); }

/* penyata */
.stmt-top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; align-items: flex-end; }
.big { font-size: 1.9rem; font-weight: 500; }
.qual { min-width: 200px; flex: 0 1 260px; }
.qual.no .meter div { background: var(--warn); }

/* link */
.copy { display: flex; gap: 8px; }
.copy input { flex: 1; font-size: .84rem; }
.link-row { display: flex; flex-direction: column; gap: 6px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.link-row:last-child { border-bottom: 0; padding-bottom: 0; }
.sponsor { padding: 10px 12px; background: var(--brand-soft); border-radius: var(--radius-sm); }

/* pokok rangkaian */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-left: 18px; margin-left: 12px; border-left: 1px dashed var(--line); }
.mrow { display: flex; align-items: center; gap: 8px; padding: 5px 4px; min-width: 0; }
.tog { width: 24px; height: 24px; flex: none; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; font-size: .7rem; color: var(--muted); padding: 0; }
.tog.leaf { visibility: hidden; }
.gen { font-family: var(--mono); font-size: .72rem; color: var(--brand); width: 24px; flex: none; }
.nm { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.qty { font-family: var(--mono); font-size: .82rem; color: var(--muted); white-space: nowrap; }

/* ---------- Log masuk ---------- */
body.auth { display: grid; place-items: start center; min-height: 100vh; padding: 48px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left)); }
.auth-wrap { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 18px; align-items: stretch; margin: 48px auto; padding: 0 16px; }
body.auth .auth-wrap { margin: 0; padding: 0; }
.auth-wrap > .brand { align-self: center; }
.auth-card { padding: 24px; gap: 10px; }
.auth-card h1 { font-size: 1.35rem; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; }

/* ---------- Kedai produk ---------- */
body.shop { background: var(--bg); }
.shop-wrap { max-width: 1040px; margin: 0 auto; padding: 32px max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 24px; }
.shop-wrap.narrow { max-width: 560px; }
.shop-hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; align-items: start; }
@media (max-width: 760px) { .shop-hero { grid-template-columns: 1fr; gap: 20px; } }
.shop-img { aspect-ratio: 1; max-width: 100%; border-radius: var(--radius); overflow: hidden; background: var(--brand-soft); }
.shop-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mono-img { display: grid; place-items: center; width: 100%; height: 100%; font-size: 7rem; font-weight: 700; color: var(--brand); }
.shop-info { display: flex; flex-direction: column; gap: 12px; }
.shop-info h1 { font-size: 2rem; }
.tagline { font-size: 1.1rem; color: var(--muted); }
.price { font-family: var(--mono); font-size: 1.8rem; font-weight: 500; color: var(--brand); }
.desc { display: flex; flex-direction: column; gap: 10px; max-width: 60ch; }
.ref-note { font-size: .88rem; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--sunk); align-self: flex-start; }
.order-card { max-width: 680px; width: 100%; align-self: center; }
.total-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0 0; margin-top: 8px; border-top: 1px solid var(--line); font-size: 1.05rem; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; }
.done { gap: 14px; }
.done h1 { font-size: 1.6rem; }
.pay { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--sunk); font-family: var(--mono); font-size: .92rem; }
.shop-foot { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 18px; padding: 24px 16px 40px; color: var(--muted); font-size: .8rem; }

/* Google */
.btn.google { background: var(--surface); color: var(--fg); border-color: var(--line); gap: 10px; }
.btn.google:hover { border-color: var(--fg); }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .8rem; margin: 6px 0 2px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.alt { margin-top: 10px; font-size: .9rem; }
.alt summary { cursor: pointer; color: var(--muted); text-align: center; padding: 6px 0; }
.alt[open] summary { margin-bottom: 8px; }

/* Berbilang admin */
.tenant-name { font-size: .85rem; color: var(--muted); max-width: 30ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewing { padding: 8px max(16px, env(safe-area-inset-left)); background: var(--info-soft); color: var(--info); font-size: .86rem; }
.choice { display: grid; gap: 12px; }
.choice a { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--fg); text-decoration: none; }
.choice a:hover { border-color: var(--brand); }
.choice a b { font-size: 1rem; }
.choice a span { color: var(--muted); font-size: .88rem; }
@media (max-width: 860px) { .tenant-name { display: none; } }
