/* REMAX Island · Follow-up */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --line: #dbe1ec;
  --ink: #16213a;
  --muted: #5b6780;
  --accent: #1f4fbf;
  --accent-ink: #ffffff;
  --accent-soft: #e4ebfb;
  --crit: #c62828;
  --crit-soft: #fdecec;
  --warn: #a35f00;
  --warn-soft: #fff3de;
  --ok: #1b7a43;
  --ok-soft: #e5f5ec;
  --shadow: 0 1px 2px rgba(22, 33, 58, .06), 0 8px 24px rgba(22, 33, 58, .08);
  --radius: 10px;
  --font: "IBM Plex Sans Thai", "Noto Sans Thai", "Leelawadee UI", Tahoma, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1422; --surface: #151d2f; --surface-2: #1b2539; --line: #28334b;
    --ink: #e5eaf4; --muted: #95a1b8; --accent: #6f98ff; --accent-ink: #0b1224; --accent-soft: #1c2a4c;
    --crit: #ff7b7b; --crit-soft: #3a1c22; --warn: #f0b458; --warn-soft: #3a2c14; --ok: #5fd08e; --ok-soft: #173325;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1422; --surface: #151d2f; --surface-2: #1b2539; --line: #28334b;
  --ink: #e5eaf4; --muted: #95a1b8; --accent: #6f98ff; --accent-ink: #0b1224; --accent-soft: #1c2a4c;
  --crit: #ff7b7b; --crit-soft: #3a1c22; --warn: #f0b458; --warn-soft: #3a2c14; --ok: #5fd08e; --ok-soft: #173325;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
body.noscroll { overflow: hidden; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 20px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.eyebrow { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.code, .codelink { font-family: var(--mono); font-size: 12.5px; letter-spacing: .01em; }
.grow { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* buttons & fields */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn.block { width: 100%; padding-block: 11px; }
.btn:disabled { opacity: .6; cursor: progress; }
.linkbtn { background: none; border: 0; padding: 4px 2px; color: var(--accent); cursor: pointer; font-weight: 500; }
.linkbtn:hover { text-decoration: underline; }
.danger-txt { color: var(--crit); }
.iconbtn { background: none; border: 1px solid transparent; border-radius: 8px; width: 34px; height: 34px; cursor: pointer; color: var(--muted); flex: none; }
.iconbtn:hover { border-color: var(--line); color: var(--ink); }
.fld { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fld > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); min-width: 0; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; white-space: nowrap; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.form-err { color: var(--crit); margin: 0; min-height: 1em; font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* language toggle */
.lang { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; }
.lang button { background: var(--surface); border: 0; padding: 5px 10px; cursor: pointer; font-size: 12.5px; color: var(--muted); }
.lang button[aria-pressed="true"] { background: var(--ink); color: var(--bg); font-weight: 600; }

/* mark */
.mark { width: 46px; height: 46px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--ink); color: var(--bg); font-family: var(--mono); font-weight: 600; font-size: 16px; letter-spacing: .04em;
  box-shadow: inset 0 -4px 0 var(--crit), inset 0 4px 0 var(--accent); }
.mark.sm { width: 34px; height: 34px; font-size: 12.5px; border-radius: 8px; box-shadow: inset 0 -3px 0 var(--crit), inset 0 3px 0 var(--accent); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 400px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.login-head { display: flex; align-items: center; gap: 14px; }
.login-head > div:nth-child(2) { flex: 1; }
.login p { margin: 0; }
.demo-pick { border-top: 1px dashed var(--line); padding-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.demo-roles { display: flex; flex-wrap: wrap; gap: 8px; }
.demo-roles .btn { flex: 1 1 100px; }

/* demo bar */
.demo-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 7px 16px; font-size: 12.5px;
  background: var(--warn-soft); color: var(--ink); border-bottom: 1px solid var(--line); }
.demo-tag { font-weight: 700; color: var(--warn); text-transform: uppercase; letter-spacing: .06em; font-size: 11.5px; }
.demo-bar select { width: auto; padding: 3px 8px; font-size: 12.5px; }

/* header */
.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-txt { display: flex; flex-direction: column; line-height: 1.15; }
.brand-txt strong { font-size: 15px; }
.brand-txt span { font-size: 11.5px; color: var(--muted); }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 7px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tabs button:hover { background: var(--surface-2); color: var(--ink); }
.tabs button[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.usermenu { position: relative; }
.usermenu summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 3px 6px; border-radius: 8px; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu summary:hover { background: var(--surface-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; flex: none; }
.who { display: flex; flex-direction: column; line-height: 1.2; }
.who strong { font-size: 13px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; z-index: 30; }
.menu button { text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }
.role-pill { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 1px 7px; border-radius: 99px;
  width: max-content; background: var(--surface-2); color: var(--muted); }
.role-pill.r-ceo { background: var(--ink); color: var(--bg); }
.role-pill.r-admin { background: var(--accent-soft); color: var(--accent); }

/* main */
.main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 48px; display: flex; flex-direction: column; gap: 14px; }
.page-title { font-size: 22px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* pipeline: the 7-step transfer path + two branches */
.pipeline { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: stretch; }
.pipe-flow { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.pipe-branch { display: grid; grid-template-columns: auto auto; grid-template-rows: auto 1fr; gap: 0 8px; }
.pipe-branch-label { grid-column: 1 / -1; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 0 2px 4px; }
.pipe-cell { position: relative; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; gap: 2px 8px; align-items: center; text-align: left;
  padding: 12px 12px 12px 14px; background: var(--surface); border: 0; cursor: pointer; min-width: 0; color: var(--ink); }
.pipe-flow .pipe-cell + .pipe-cell { border-left: 1px solid var(--line); }
.pipe-cell::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--c); opacity: .85; }
.pipe-branch .pipe-cell { border: 1px solid var(--line); border-radius: var(--radius); min-width: 128px; }
.pipe-branch .pipe-cell::before { border-radius: var(--radius) var(--radius) 0 0; }
.pipe-cell:hover { background: var(--surface-2); }
.pipe-cell.on { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.pipe-n { grid-row: 1; font-family: var(--mono); font-size: 11.5px; font-weight: 600; color: var(--c); }
.pipe-count { grid-row: 2; grid-column: 1 / -1; font-size: 26px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.pipe-label { grid-row: 1; font-size: 12px; font-weight: 600; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.attention { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.att-label { font-size: 12.5px; font-weight: 600; color: var(--muted); margin-right: 4px; }
.flag { display: inline-flex; align-items: center; gap: 7px; border-radius: 99px; padding: 5px 12px; border: 1px solid transparent; cursor: pointer; font-weight: 600; font-size: 13px; }
.flag .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.flag.crit { background: var(--crit-soft); color: var(--crit); }
.flag.warn { background: var(--warn-soft); color: var(--warn); }
.flag.on { border-color: currentColor; }
.flag:disabled { opacity: .45; cursor: default; }
.ok { color: var(--ok); font-weight: 600; font-size: 13px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.toolbar input[type=search] { flex: 1 1 240px; max-width: 360px; }
.toolbar select { width: auto; flex: 0 1 auto; }
.count { font-size: 12.5px; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); font-weight: 600;
  padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
th.r, td.r { text-align: right; }
table.deals tbody tr { cursor: pointer; }
table.deals tbody tr:hover, table.deals tbody tr:focus-visible { background: var(--surface-2); outline: none; }
tr.closed td { opacity: .62; }
td.prop strong, td strong { display: block; font-weight: 600; }
td.prop .small, td .small { display: block; }
td.code { white-space: nowrap; color: var(--muted); }
td.next { max-width: 240px; font-size: 13px; }
.due { display: block; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.due.late { color: var(--crit); font-weight: 600; }
td.upd { white-space: nowrap; font-size: 12.5px; color: var(--muted); }
td.upd.stale { color: var(--warn); font-weight: 600; }
td.actions { white-space: nowrap; }

.status { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }
.stage-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 2px 9px 2px 3px; border-radius: 99px;
  background: color-mix(in srgb, var(--c) 14%, var(--surface)); color: var(--ink); white-space: nowrap; }
.stage-chip b { display: inline-grid; place-items: center; width: 19px; height: 19px; border-radius: 50%; background: var(--c); color: #fff; font-family: var(--mono); font-size: 11px; }
.status .sub { font-size: 12.5px; color: var(--muted); padding-left: 3px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* drawer */
.drawer-back { position: fixed; inset: 0; background: rgba(10, 16, 30, .35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); z-index: 41; background: var(--bg); border-left: 1px solid var(--line);
  box-shadow: var(--shadow); display: flex; flex-direction: column; padding-top: env(safe-area-inset-top, 0px); }
.dr-head { display: flex; justify-content: space-between; gap: 12px; padding: 16px 18px 14px; background: var(--surface); border-bottom: 1px solid var(--line);
  border-top: 4px solid var(--c); }
.dr-head .code { color: var(--muted); }
.dr-body { flex: 1; overflow-y: auto; padding: 16px 18px calc(32px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 14px; }
.stepper-wrap { display: flex; flex-direction: column; gap: 8px; }
.stepper { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(7, 1fr); gap: 0; }
.step { position: relative; display: flex; justify-content: center; }
.step::before { content: ""; position: absolute; top: 50%; left: -50%; right: 50%; height: 3px; background: var(--line); transform: translateY(-50%); }
.step:first-child::before { display: none; }
.step span { position: relative; z-index: 1; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-family: var(--mono); font-size: 12px; font-weight: 600;
  background: var(--surface); border: 2px solid var(--line); color: var(--muted); }
.step.done::before, .step.now::before { background: var(--accent); }
.step.done span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.step.now span { border-color: var(--c); background: var(--c); color: #fff; box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 25%, transparent); }
.step.off span { opacity: .45; }
.branch-banner { font-weight: 600; font-size: 13px; padding: 7px 12px; border-radius: 8px; color: var(--ink);
  background: color-mix(in srgb, var(--c) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--c) 45%, var(--line)); }
.now-status { display: flex; flex-direction: column; gap: 6px; }
.next-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.next-box.late { border-color: var(--crit); background: var(--crit-soft); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.panel.update { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kvs { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.kv { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.kv dt { font-size: 12px; color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); display: flex; flex-direction: column; gap: 14px; }
.timeline li { position: relative; display: flex; flex-direction: column; gap: 3px; }
.timeline li::before { content: ""; position: absolute; left: -20px; top: 7px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.tl-main { font-size: 13.5px; }
.tl-note { font-size: 13px; background: var(--surface-2); border-radius: 6px; padding: 5px 9px; white-space: pre-wrap; }
.tl-meta { font-size: 12px; color: var(--muted); }
.dotc { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: 6px; vertical-align: 1px; }
.feed { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 18px 30px; border-left-width: 1px; }
.feed .tl-main { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.codelink { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-weight: 600; }
.codelink:hover { text-decoration: underline; }
.danger-zone { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; justify-content: flex-end; font-size: 13px; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(10, 16, 30, .45); z-index: 60; display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.modal { width: 100%; max-width: 620px; padding: 20px; }
.modal form { display: flex; flex-direction: column; gap: 12px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500; z-index: 80; transition: .2s; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--crit); color: #fff; }

/* responsive */
@media (max-width: 1080px) {
  .pipeline { grid-template-columns: 1fr; }
  .pipe-branch { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .pipe-flow { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .pipe-flow .pipe-cell { border-bottom: 1px solid var(--line); }
  .pipe-flow .pipe-cell:nth-child(5) { border-left: 0; }
  .pipe-count { font-size: 22px; }
  .who { display: none; }
  .brand-txt span { display: none; }
  .top { gap: 10px; }
  .tabs { order: 3; width: 100%; }
  .grid2, .kvs { grid-template-columns: 1fr; }
  .toolbar input[type=search] { max-width: none; flex-basis: 100%; }
  /* table → cards */
  .table-wrap { background: none; border: 0; overflow: visible; }
  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  tbody { display: flex; flex-direction: column; gap: 10px; }
  tbody tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; }
  td { padding: 0; border: 0; }
  table.deals td.code { grid-area: code; }
  table.deals td.upd { grid-area: upd; text-align: right; }
  table.deals td.prop { grid-area: prop; }
  table.deals td.st { grid-area: st; }
  table.deals td.next { grid-area: next; max-width: none; }
  table.deals td.next:empty { display: none; }
  table.deals td.client { grid-area: client; font-size: 13px; }
  table.deals td.agent { grid-area: agent; font-size: 13px; text-align: right; }
  table.deals td.client::before, table.deals td.agent::before { content: attr(data-l) " · "; color: var(--muted); font-size: 12px; }
  table.deals tbody tr { grid-template-areas: "code upd" "prop prop" "st st" "next next" "client agent"; }
  table.users td { grid-column: 1 / -1; }
  table.users td::before { content: attr(data-l); display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
  table.users td.actions::before { display: none; }
  td.actions { grid-column: 1 / -1; grid-row: auto; text-align: left; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
