:root{
  --blue:#2E9BD6; --blue-d:#1B7FB5; --blue-l:#E8F4FD; --blue-xl:#F5FAFE;
  --ink:#12303F; --muted:#7492A3; --line:#DCEAF4; --white:#fff;
  --ok:#17A67B; --bad:#E2574C; --r:16px;
}
*{box-sizing:border-box;margin:0;padding:0}
body{font-family:"Noto Sans Thai","Inter",-apple-system,"Segoe UI",sans-serif;
  background:var(--blue-xl);color:var(--ink);padding-bottom:48px;-webkit-font-smoothing:antialiased}

.topbar{position:sticky;top:0;z-index:20;display:flex;justify-content:space-between;align-items:center;
  gap:12px;padding:14px 18px;background:var(--white);border-bottom:1px solid var(--line)}
.brand{display:flex;align-items:center;gap:12px}
.logo{width:40px;height:40px;border-radius:12px;display:grid;place-items:center;font-size:20px;
  color:#fff;background:transparent}
h1{font-size:17px;font-weight:700}
.sub{font-size:12px;color:var(--muted)}
.tools{display:flex;gap:8px}
#menuBtn{padding:6px 13px;}
#langBtn{font-family:"Noto Sans Thai","Inter",-apple-system,"Segoe UI",sans-serif}
.chip{border:1px solid var(--line);background:var(--white);color:var(--blue-d);font-weight:700;
  padding:8px 10px;border-radius:999px;cursor:pointer;font-size:13px;transition:.15s;margin-right: 4px;}
.chip:hover{background:var(--blue-l)}

.menu{position:fixed;right:18px;top:70px;z-index:30;background:#fff;border:1px solid var(--line);
  border-radius:14px;padding:6px;display:flex;flex-direction:column;min-width:230px}
.menu button{border:0;background:none;text-align:left;padding:11px 14px;border-radius:10px;
  cursor:pointer;font-size:14px;color:var(--ink);font-family:inherit}
.menu button:hover{background:var(--blue-l)}
.menu .danger{color:var(--bad)}
.menu-section{padding:8px 10px 10px}
.menu-label{font-size:11.5px;color:var(--muted);font-weight:600;margin-bottom:6px}
.menu-section select{width:100%;font-size:13px;padding:8px 10px;border-radius:10px}
.menu-sep{height:1px;background:var(--line);margin:2px 6px 6px}
:root[data-theme="dark"] .menu-section select{background:#10232d;color:var(--ink);border-color:var(--line)}
.hidden{display:none}
.tabs{
  position:fixed;
  left:0; right:0; bottom:0;
  z-index:100;
  display:flex;
  background:#fff;
  border-top:1px solid #e5e7eb;
  /* iPhone home-indicator gap */
  padding-bottom:env(safe-area-inset-bottom,0px);
  box-shadow:0 -1px 8px rgba(0,0,0,.06);
}

.tabs .tab{
  flex:1 1 0;                 /* equal width, no overflow */
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:2px;
  min-height:56px;            /* comfortable tap target */
  border:0; background:none;
  font-family:"Noto Sans Thai","Inter",-apple-system,"Segoe UI",sans-serif;
  font-size:14px;
  color:#5b5e64;
  cursor:pointer;
  -webkit-tap-highlight-color:transparent;
}

.tabs .tab span{ line-height:1; }
.tabs .tab.active{ color:#2563eb; font-weight:600; }

/* keep content clear of the bar */
body{
  padding-bottom:calc(56px + env(safe-area-inset-bottom,0px));
}
main{padding:8px 8px 28px;max-width:960px;margin:0 auto}
.page{display:none;animation:fade .22s ease}
.page.active{display:block}
@keyframes fade{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}

.card{background:var(--white);border:1px solid var(--line);border-radius:var(--r);
  padding:8px;margin-bottom:16px}
.card-head{display:flex;justify-content:space-between;align-items:center;gap:10px;margin-bottom:14px}
h2{font-size:15px;font-weight:700}
h3{font-size:15px;margin-bottom: 10px}
.btn-primary{background:var(--blue);color:#fff;border:0;padding:6px 12px;margin:8px 0; border-radius:50px;
  font-weight:600;font-size:12px;cursor:pointer;font-family:inherit;transition:.15s}
.btn-primary:hover{background:var(--blue-d)}

/*.table-wrap{overflow-x:auto;margin:0 -4px}
table{width:100%;border-collapse:collapse;min-width:520px}
th{font-size:12px;color:var(--muted);font-weight:600;text-align:left;padding:8px 6px;border-bottom:1px solid var(--line)}
td{padding:5px 6px;border-bottom:1px solid var(--blue-xl)}*/
th.num,td.num{text-align:right}
#cfTable {
  width: 100%;
  table-layout: fixed;
}

#cfTable th:nth-child(1) { width: 20%; }
#cfTable th:nth-child(2) { width: 38%; }
#cfTable td:nth-child(2) { 
  font-size: 16px; }
#cfTable th:nth-child(3) { width: 38%; }
#cfTable td:nth-child(3) { 
  font-size: 16px; }
#cfTable td:nth-child(1) {
  text-align: center;
}
.table-wrap{
  width: 100%;
  overflow-x: hidden;
  margin: 0;
}

#investTable{
  width: 100%;
  min-width: 0;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0 2px;
}

/* Type / Name / Amount / Delete */
#investTable th:nth-child(1),
#investTable td:nth-child(1){
  width: 22%;
}

#investTable th:nth-child(2),
#investTable td:nth-child(2){
  width: 38%;
}

#investTable th:nth-child(3),
#investTable td:nth-child(3){
  width: 30%;
}

#investTable th:nth-child(4),
#investTable td:nth-child(4){
  width: 10%;
}

/* Keep content inside cells */
#investTable th,
#investTable td{
  box-sizing: border-box;
  word-break: break-word;
  overflow-wrap: anywhere;
}


/* Give the delete button some breathing room */
#investTable td:nth-child(4){
  padding-left: 4px;
  padding-right: 4px;
}

#investTable th:nth-child(4){
  padding-left: 4px;
}

/* Inputs fill their columns */
#investTable td input,
#investTable td select{
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* Delete button */
#investTable .del{
  display: block;
  width: 34px;
  height: 34px;
  margin: auto;
}

/*.table-wrap{
  overflow-x: hidden;   /* was auto */
  /*margin: 0 -4px;
}*/

table{
  width: 100%;
  min-width: 0;          /* kill the 520px */
  table-layout: fixed;   /* columns share the width evenly */
  border-collapse: collapse;
}

th, td{
  word-break: break-word;   /* long text wraps instead of pushing width */
  overflow-wrap: anywhere;
}
/* Invest table: type / name / amount / delete */
/*#investWrap th:nth-child(1), #investWrap td:nth-child(1){ width: 30%; }
#investWrap th:nth-child(2), #investWrap td:nth-child(2){ width: 34%; }
#investWrap th:nth-child(3), #investWrap td:nth-child(3){ width: 26%; }
#investWrap th:nth-child(4), #investWrap td:nth-child(4){ width: 10%; }*/

@media (max-width: 480px){
  th{ padding: 4px 4px; font-size: 11px; }
  td{ padding: 4px 4px; font-size: 11px; }
  #investTable td:nth-child(1) input{
  padding-left: 2px;
  padding-right: 0;
  font-size: 11px;
}
}
td input, td select{
  width: 100%;
  min-width: 0;   /* important — inputs default to ~20ch */
  box-sizing: border-box;
}

input,select{width:100%;border:1px solid var(--line);background:var(--white);border-radius:10px;
  padding:10px 12px;font-size:14px;font-family:inherit;color:var(--ink);outline:none;transition:.15s}
input:focus,select:focus{border-color:var(--blue)}
input.num{text-align:right}
.del{border:0;background:var(--blue-xl);color:var(--bad);width:34px;height:34px;border-radius:10px;
  cursor:pointer;font-size:15px;line-height:1}
.del:hover{background:#FDECEA}

.item-list{display:flex;flex-direction:column;gap:12px}
.item{border:1px solid var(--line);border-radius:14px;padding:14px;background:var(--blue-xl)}
.item-top{display:flex;gap:8px;align-items:center;margin-bottom:10px}
.item-top input{flex:1;font-weight:600}
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:10px}
.f label{display:block;font-size:11.5px;color:var(--muted);margin-bottom:5px;font-weight:600}
.item-sum{margin-top:10px;text-align:right;font-size:13px;color:var(--blue-d);font-weight:700}

.total-bar{display:flex;justify-content:space-between;align-items:center;margin-top:16px;padding:14px 16px;
  background:var(--blue-l);border-radius:12px;font-size:14px;font-weight:600}
.total-bar b{font-size:19px;color:var(--blue-d)}

.hero-card{background:linear-gradient(135deg,var(--blue),var(--blue-d));color:#fff;border-radius:20px;
  padding:20px 20px 10px;text-align:center;margin-bottom:16px}
.hero-label{font-size:16px;opacity:.9}
.hero-card h2{font-size:34px;font-weight:800;margin:8px 0 4px;letter-spacing:-.5px}
.hero-sub{font-size:13px;opacity:.9}

.kpi-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:12px;margin-bottom:16px}
.kpi{background:#fff;border:1px solid var(--line);border-radius:14px;padding:14px}
.kpi span{display:block;font-size:12px;color:var(--muted);margin-bottom:6px}
.kpi b{display: block;font-size:19px;text-align: right;}
.pos{color:var(--ok)} .neg{color:var(--bad)}
tr.hit td{background:#E6F7F1;font-weight:700;color:var(--ok)}
@media(max-width:520px){.hero-card h2{font-size:28px}}
.sug,.btn-ghost{margin: 10px 10px 0 0;padding: 2px 10px;font-family:"Noto Sans Thai";border-radius: 30px;border:#31c2f7 0.1px solid}
/* suggestion strip under each list */
.chips-bar{margin-top:18px;padding-top:16px;border-top:1px dashed #d8dee7;
  display:flex;flex-wrap:wrap;gap:12px 10px;justify-content:center}

/* already-added suggestion */
.sug.used{opacity:.38;cursor:default;pointer-events:none;
  border-style:solid;filter:grayscale(1)}
/* minimal confirm dialog */
.modal{position:fixed;inset:0;z-index:80;display:flex;align-items:center;justify-content:center;
  background:rgba(15,23,42,.45);padding:20px}
.modal.hidden{display:none}
.modal-card{background:#fff;border-radius:16px;padding:24px 20px 16px;width:100%;max-width:320px;
  box-shadow:0 18px 50px rgba(0,0,0,.22);text-align:center;animation:pop .15s ease-out}
@keyframes pop{from{opacity:0;transform:scale(.94)}to{opacity:1;transform:none}}
.modal-card p{margin:0 0 18px;font-size:.96rem;line-height:1.5;color:#1f2937}
.modal-actions{display:flex;gap:10px}
.modal-actions button{flex:1;padding:11px 12px;border-radius:10px;font-size:.9rem;cursor:pointer}
.btn-cancel{font-family:"Noto Sans Thai","Inter",-apple-system,"Segoe UI",sans-serif;border:1px solid #d8dee7;background:#fff;color:#475569}
.btn-danger{font-family:"Noto Sans Thai","Inter",-apple-system,"Segoe UI",sans-serif;border:1px solid #e5484d;background:#e5484d;color:#fff;font-weight:600}

/* % of revenue hint */
.note-pct{margin-top:7px;font-size:.76rem;line-height:1.4;color:#d92d20}
/* ---------- guide accordion body ---------- */
.guide {
  margin: 0 0 20px 0;
}

.guide > summary {
  color: #2563eb;
  padding: 12px 16px;
  border-radius: 12px;
}

.guide > ul,
.guide > ol {
  margin: 0;
  padding-top: 14px;
  padding-bottom: 16px;
  padding-left: 50px;
  padding-right: 18px;

  background: #f7f9fc;
  border: 1px solid #e4e9f0;
  border-top: 0;
  border-radius: 0 0 12px 12px;

  list-style-position: outside;
}

.guide > ul li,
.guide > ol li {
  margin: 0 0 8px;
  line-height: 1.55;
  padding-left: 2px;
}

.guide > ul li:last-child,
.guide > ol li:last-child {
  margin-bottom: 0;
}

.guide-body li:last-child{margin-bottom:0}

/* the clickable header */
.guide-head{
  padding:12px 16px;
  border-radius:12px;
}
.chart-card{padding:14px 14px 10px}
.chart-head{display:flex;justify-content:space-between;align-items:center;
  flex-wrap:wrap;gap:8px;margin-bottom:6px}
.chart-head h3{margin:0;font-size:15px;font-weight:700}
.chart-legend{display:flex;gap:14px;font-size:11.5px;color:#6B7280}
.chart-legend span{display:flex;align-items:center;gap:5px}
.chart-legend i{width:16px;height:0;border-top:2.6px solid #1F9D6B;border-radius:2px}
.chart-legend i.lg-dash{border-top:2px dashed #C1432B}
.bep-chart{width:100%;height:auto;display:block;overflow:visible}
.chart-empty{margin:18px 0;text-align:center;color:#9aa3af;font-size:13px}
.hidden{display:none}
:root {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --blue: #58b7ec;
  --blue-d: #349ed6;
  --blue-l: #163c52;
  --blue-xl: #0f202a;
  --ink: #e7f1f7;
  --muted: #9db3c0;
  --line: #294553;
  --white: #172a34;
  --ok: #35c99a;
  --bad: #ff756b;
}

body,
.topbar,
.card,
.chip,
.menu,
.modal-card,
input,
select,
textarea,
button {
  transition:
    background-color 0.25s ease,
    border-color 0.25s ease,
    color 0.25s ease;
}

:root[data-theme="dark"] body {
  background: #0b1820;
  color: var(--ink);
}

:root[data-theme="dark"] .topbar,
:root[data-theme="dark"] .card,
:root[data-theme="dark"] .menu,
:root[data-theme="dark"] .modal-card,
:root[data-theme="dark"] .chart-card {
  background: var(--white);
  color: var(--ink);
  border-color: var(--line);
}

:root[data-theme="dark"] .chip,
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea {
  background: #10232d;
  color: var(--ink);
  border-color: var(--line);
}

:root[data-theme="dark"] input::placeholder,
:root[data-theme="dark"] textarea::placeholder {
  color: var(--muted);
}

#themeBtn {
  min-width: 42px;
  cursor: pointer;
}
#themeBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 36px;
  padding: 8px 10px;
  flex-shrink: 0;
}
:root[data-theme="dark"] .modal-card {
  background: #172a34;
  color: #e7f1f7;
}

:root[data-theme="dark"] .modal-card p,
:root[data-theme="dark"] #confirmMsg {
  color: #e7f1f7;
}

:root[data-theme="dark"] .btn-cancel {
  background: #10232d;
  color: #e7f1f7;
  border-color: #294553;
}
/* =========================
   DARK MODE UI OVERRIDES
   ========================= */

/* Page */
:root[data-theme="dark"] body {
  background: #0b1820;
  color: var(--ink);
}

/* Cards */
:root[data-theme="dark"] .card,
:root[data-theme="dark"] .kpi,
:root[data-theme="dark"] .chart-card {
  background: #172a34;
  color: var(--ink);
  border-color: var(--line);
}

/* Hero */
:root[data-theme="dark"] .hero-card {
  background: linear-gradient(135deg, #16445d, #102f42);
  color: #e7f1f7;
}

:root[data-theme="dark"] .hero-label,
:root[data-theme="dark"] .hero-sub {
  color: #d5e8f2;
}

/* Guide */
:root[data-theme="dark"] .guide > summary,
:root[data-theme="dark"] .guide-head {
  background: #172a34;
  color: var(--ink);
}

:root[data-theme="dark"] .guide > ul,
:root[data-theme="dark"] .guide > ol {
  background: #10232d;
  color: var(--ink);
  border-color: var(--line);
}

/* Footer / bottom navigation */
:root[data-theme="dark"] .tabs {
  background: #172a34;
  border-top-color: var(--line);
  box-shadow: 0 -1px 8px rgba(0,0,0,.25);
}

:root[data-theme="dark"] .tabs .tab {
  color: var(--muted);
}

:root[data-theme="dark"] .tabs .tab.active {
  color: var(--blue-d);
}

/* Inner items */
:root[data-theme="dark"] .item,
:root[data-theme="dark"] .total-bar {
  background: #10232d;
  color: var(--ink);
  border-color: var(--line);
}
.ramp-opt {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 8px;
}

.ramp-opt input {
  margin-top: 3px;
}
/* ---------- Responsive: expense & income item layout ---------- */
/*@media (max-width: 520px){
  .item .grid{
    grid-template-columns: 1fr 1fr;   /* two fields per row */
    /*gap: 10px;
  }*/
  /* type / mode dropdown sits alone on its own row */
  /*.item .grid > .f:first-child{
    grid-column: 1 / -1;
  }*/
  /* a lone amount / percent field takes the full row */
  /*.item .grid > .f:nth-child(2):last-child{
    grid-column: 1 / -1;
  }
  .item .grid .f label{
    line-height: 1.3;
  }
}*/
/* ---------- Responsive: expense (unit x qty) & income (daily) layout ----------
   Only grids with 3+ children are affected:
   - expense unit mode: mode, unit price, qty
   - income daily mode: mode, wAmt, wDay, hAmt, hDay
   Fixed / percent / monthly modes (2 children) keep the original layout. */
@media (max-width: 520px){
  .item .grid:has(> .f:nth-child(3)){
    grid-template-columns: 1fr 1fr;   /* two fields per row */
  }
  /* type / mode dropdown alone on its own row */
  .item .grid:has(> .f:nth-child(3)) > .f:first-child{
    grid-column: 1 / -1;
  }
  .item .grid:has(> .f:nth-child(3)) .f label{
    line-height: 1.3;
  }
}
/* selected business type tag */
.head-title{display:flex;align-items:center;flex-wrap:wrap;gap:8px;min-width:0}
.biz-tag{display:inline-block;font-size:18px;font-weight:600;line-height:1;padding:5px 10px;border-radius:50px;
  background:#E3F2FB;color:var(--blue-d);white-space:nowrap}
.biz-tag[hidden]{display:none}
.biz-banner{text-align:center;margin-bottom:8px}
.biz-banner:has(.biz-tag[hidden]){display:none}
:root[data-theme="dark"] .biz-tag{background:rgba(46,155,214,.18);color:#8FD0F2}