/* Base design tokens + shared styles. Expanded in the dashboard task. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1f2933;
  --muted: #6b7785;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --green: #16a34a;
  --yellow: #d97706;
  --red: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  font-family: "Sarabun", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
  font-size: .95rem; min-height: 42px;
}
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-primary:hover { background: #1d4ed8; }

input, select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border);
  border-radius: 8px; font: inherit; background: var(--surface); color: var(--text);
  min-height: 42px;
}
textarea { min-height: 90px; }
label { display: block; font-size: .85rem; color: var(--muted); margin: .6rem 0 .25rem; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 2rem 1.6rem;
}
.login-card h1 { font-size: 1.25rem; margin: 0 0 1.2rem; text-align: center; }
.form-error { background: #fef2f2; color: var(--red); border: 1px solid #fecaca;
  padding: .6rem .8rem; border-radius: 8px; font-size: .9rem; margin-bottom: .8rem; }
.login-card .btn-primary { width: 100%; justify-content: center; margin-top: 1.1rem; }

/* ---- Authenticated layout ---- */
.topbar { display: flex; align-items: center; gap: 1rem; background: var(--surface);
  border-bottom: 1px solid var(--border); padding: .6rem 1rem; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; color: var(--text); }
.topnav { display: flex; gap: .3rem; margin-left: .5rem; }
.topnav a { padding: .4rem .7rem; border-radius: 7px; color: var(--muted); }
.topnav a:hover { background: #eef1f5; color: var(--text); text-decoration: none; }
.topuser { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.topuser .who { color: var(--muted); font-size: .9rem; }
.inline { display: inline; }
.btn-sm { min-height: 34px; padding: .3rem .7rem; font-size: .85rem; }
.container { max-width: 1100px; margin: 0 auto; padding: 1.3rem 1rem 3rem; }
.back { display: inline-block; color: var(--muted); margin-bottom: .6rem; font-size: .9rem; }
.page-title { font-size: 1.4rem; margin: .1rem 0 1rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.2rem 1.3rem; margin-bottom: 1.1rem; }
.card h2 { font-size: 1.05rem; margin: 0 0 .8rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
@media (max-width: 780px){ .grid-2 { grid-template-columns: 1fr; } }

.project-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.project-head .code { color: var(--muted); font-size: .85rem; font-weight: 600; letter-spacing: .03em; }
.head-actions { display: flex; align-items: center; gap: .5rem; }

.badge { display: inline-flex; align-items: center; padding: .25rem .6rem; border-radius: 999px;
  font-size: .82rem; background: #eef1f5; color: var(--text); }
.badge.status { background: #e7f1fb; color: #1d4ed8; }
.health-green { color: var(--green); background: #e5f4e4; }
.health-yellow { color: var(--yellow); background: #fdf2dc; }
.health-red { color: var(--red); background: #fdeaea; }

dl.fields { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0; }
dl.fields dt { color: var(--muted); font-size: .9rem; }
dl.fields dd { margin: 0; }
.note-box { margin-top: .9rem; padding: .7rem .9rem; background: #f8fafc; border-radius: 8px; white-space: pre-wrap; }
.empty { color: var(--muted); font-style: italic; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 3px solid var(--border); padding: 0 0 1rem 1rem; margin-left: .3rem; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: .35rem; width: 11px; height: 11px;
  border-radius: 50%; background: var(--primary); }
.t-meta { color: var(--muted); font-size: .82rem; margin-bottom: .2rem; }
.t-note { white-space: pre-wrap; }
.t-issue { color: var(--red); font-size: .9rem; margin-top: .2rem; }
.t-next { color: var(--muted); font-size: .9rem; margin-top: .2rem; }

.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th, .tbl td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
.tbl th { color: var(--muted); font-weight: 600; font-size: .82rem; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem 1.1rem; }
.form-grid .col-2 { grid-column: 1 / -1; }
.form-grid label { margin-top: .4rem; }
.form-actions { display: flex; gap: .6rem; margin-top: 1.1rem; }
@media (max-width: 680px){ .form-grid { grid-template-columns: 1fr; } }

/* update form */
.update-form { margin-bottom: 1.1rem; }
.update-form .uf-row { display: flex; gap: .6rem; margin-top: .5rem; flex-wrap: wrap; }
.update-form .uf-row > * { flex: 1 1 160px; }
.update-form .uf-row .btn-primary { flex: 0 0 auto; }

/* inline add-forms (quotes, contacts) */
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.inline-form > * { flex: 1 1 130px; }
.inline-form .btn-primary { flex: 0 0 auto; }

/* documents */
.doc-link-card { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.muted-text { color: var(--muted); margin: .2rem 0 0; font-size: .9rem; }
.doc-stage-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .6rem; flex-wrap: wrap; }
.doc-stage-head h2 { margin: 0; font-size: 1rem; }
.doc-stage-actions { display: flex; align-items: center; gap: .5rem; }
.badge.warn { background: #fdf2dc; color: var(--yellow); }
.file-list { list-style: none; margin: 0 0 .8rem; padding: 0; }
.file-list li { display: flex; justify-content: space-between; padding: .35rem 0; border-bottom: 1px solid var(--border); }
.file-size { color: var(--muted); font-size: .82rem; }
.doc-upload { display: flex; gap: .5rem; align-items: center; }
.doc-upload input[type=file] { flex: 1; }

/* ---- Dashboard ---- */
.dash-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.stat-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: .7rem; margin-bottom: 1.1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .8rem 1rem; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.stat-n { font-size: 1.6rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-l { color: var(--muted); font-size: .82rem; }
.stat-red { border-left: 4px solid var(--red); }
.stat-yellow { border-left: 4px solid var(--yellow); }
.stat-green { border-left: 4px solid var(--green); }
.stat-warn { border-left: 4px solid #9333ea; }
@media (max-width: 760px){ .stat-strip { grid-template-columns: repeat(2, 1fr); } }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input, .filters select { flex: 1 1 150px; min-width: 120px; }
.filters .btn { flex: 0 0 auto; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }

.table-card { padding: 0; overflow: hidden; }
.dash-tbl { font-size: .93rem; }
.dash-tbl th, .dash-tbl td { padding: .65rem .8rem; vertical-align: middle; }
.dash-tbl thead th { background: #fafbfc; position: sticky; top: 56px; }
.dash-tbl tbody tr:hover { background: #f8fafc; }
.dash-tbl .dot { font-size: 1rem; }
.dash-tbl .mono, .mono { font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.dash-tbl .sub { color: var(--muted); font-size: .8rem; }
.dash-tbl tr.stale { background: #fffdf5; }
.dash-tbl tr.stale:hover { background: #fdf8ec; }
.stale-tag { color: var(--yellow); font-weight: 600; font-size: .85rem; }
.dash-tbl tfoot td { background: #fafbfc; border-top: 2px solid var(--border); font-size: .9rem; }
@media (max-width: 760px){
  .dash-tbl thead { display: none; }
  .dash-tbl, .dash-tbl tbody, .dash-tbl tr, .dash-tbl td { display: block; width: 100%; }
  .dash-tbl tr { border-bottom: 1px solid var(--border); padding: .4rem 0; }
  .dash-tbl td { padding: .25rem .9rem; border: none; text-align: left !important; }
  .dash-tbl tfoot { display: none; }
}

/* ---- Meeting mode ---- */
.meeting-list { display: flex; flex-direction: column; gap: .7rem; }
.meeting-card { padding: 0; overflow: hidden; }
.mc-head { width: 100%; display: flex; align-items: center; gap: .8rem; padding: 1rem 1.2rem;
  background: none; border: none; cursor: pointer; text-align: left; font: inherit; }
.mc-head:hover { background: #f8fafc; }
.mc-head .dot { font-size: 1.1rem; }
.mc-code { color: var(--muted); font-size: .85rem; }
.mc-name { font-size: 1.15rem; font-weight: 600; flex: 1; }
.mc-pic { color: var(--muted); font-size: .9rem; }
.mc-body { padding: 0 1.2rem 1.2rem; }
.mc-body .update-form textarea { font-size: 1.05rem; min-height: 70px; }
.mc-open { display: inline-block; margin-top: .6rem; color: var(--muted); font-size: .9rem; }
.meeting-card.stale .mc-head { background: #fffdf5; }
@media (max-width: 680px){ .mc-head { flex-wrap: wrap; } .mc-name { flex: 1 1 100%; } }

/* admin */
.check-row { display: flex; align-items: center; }
.check { display: inline-flex; align-items: center; gap: .4rem; margin: 0; color: var(--text); font-size: .95rem; }
.check input { width: auto; min-height: auto; }
.edit-pop summary { list-style: none; display: inline-flex; }
.edit-pop[open] summary { margin-bottom: .5rem; }
.edit-form { display: flex; flex-direction: column; gap: .4rem; background: #f8fafc; padding: .7rem; border-radius: 8px; min-width: 240px; }

/* ---- Compact project page ---- */
.proj-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.proj-col { display: flex; flex-direction: column; gap: 1rem; }
@media (max-width: 860px){ .proj-grid { grid-template-columns: 1fr; } }
.card.pad-sm { padding: .9rem 1rem; margin-bottom: 0; }
.card.pad-sm h2 { font-size: .98rem; margin: 0 0 .55rem; }
dl.fields.tight { gap: .25rem .8rem; font-size: .92rem; }
.tbl.compact th, .tbl.compact td { padding: .32rem .5rem; font-size: .88rem; }
.update-form textarea { min-height: 64px; }
.hint { display: block; color: var(--muted); font-size: .8rem; margin-top: .25rem; }
.note-box { margin-top: .6rem; }

/* dashboard inline update row */
.dash-tbl .detail-row > td { background: #f8fafc; padding: .8rem 1rem; }
.inline-update { margin: 0; }
.inline-update textarea { min-height: 56px; }
.row-toggle { white-space: nowrap; }
@media (max-width: 760px){
  .dash-tbl .detail-row, .dash-tbl .detail-row > td { display: block; width: 100%; }
}

/* row double-click affordance */
.dash-tbl tr.row-link { cursor: pointer; }

/* settings sub-nav */
.subnav { display: flex; gap: .3rem; margin: -.3rem 0 1rem; border-bottom: 1px solid var(--border); }
.subnav a { padding: .5rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subnav a:hover { color: var(--text); text-decoration: none; }
.subnav a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* phase 2 finance summary */
.fin-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; }
@media (max-width: 760px){ .fin-summary { grid-template-columns: repeat(2, 1fr); } }
.fin-item { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: .5rem .7rem; display: flex; flex-direction: column; }
.fin-item.strong { background: #eef2ff; }
.fin-l { color: var(--muted); font-size: .78rem; }
.fin-v { font-variant-numeric: tabular-nums; font-weight: 600; }
.fin-v.neg { color: var(--red); }
.fin-v.pos { color: var(--green); }

/* ledgers: row actions + inline edit */
.ledgers > :only-child { grid-column: 1 / -1; }
.ledger-tbl td { vertical-align: top; }
.ledger-tbl th.actions, .ledger-tbl td.actions { width: 1%; white-space: nowrap; text-align: right; }
.ledger-tbl .del-form { display: inline; margin: 0; }
.link-btn { background: none; border: 0; padding: .15rem .35rem; font: inherit; font-size: .82rem;
  color: var(--primary); cursor: pointer; border-radius: 6px; min-height: 0; }
.link-btn:hover { background: #eef2ff; }
.link-btn.danger { color: var(--red); }
.link-btn.danger:hover { background: #fef2f2; }
.link-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.ledger-edit td { background: #f8fafc; padding: .6rem; }
.ledger-edit .inline-form { margin: 0; }
.row-note { color: var(--muted); font-size: .8rem; margin-top: .15rem; white-space: pre-wrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 760px){ .ledger-tbl td.actions { white-space: normal; } }
.ledger-form { align-items: flex-end; }
.fld-date { display: flex; flex-direction: column; gap: .15rem; margin: 0; }
.fld-date > span { font-size: .72rem; color: var(--muted); line-height: 1.2; }
.ledger-tbl td.date { white-space: nowrap; }
.fin-src { color: var(--muted); font-size: .72rem; margin-top: .1rem; }
