* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  background: #f2f5f7;
  color: #22303c;
  font-size: 15px;
}

a { color: #0e5a8a; }

.topbar {
  background: #0f2f46;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand { font-weight: 700; font-size: 17px; letter-spacing: .3px; white-space: nowrap; }
.topbar .brand small { display: block; font-weight: 400; font-size: 11px; opacity: .75; }
.topbar nav { display: flex; gap: 4px; margin-left: 8px; flex-wrap: wrap; }
.topbar nav a {
  color: #d6e4ee;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
}
.topbar nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.topbar nav a.active { background: #0e5a8a; color: #fff; }
.topbar .spacer { flex: 1; }
.topbar .logout {
  background: none; border: 1px solid rgba(255,255,255,.3); color: #d6e4ee;
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.topbar .logout:hover { background: rgba(255,255,255,.1); color: #fff; }

.wrap { max-width: 1080px; margin: 24px auto 60px; padding: 0 16px; }

.card {
  background: #fff;
  border: 1px solid #e3e9ee;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(16,40,60,.05);
}
.card h1 { margin: 0 0 4px; font-size: 22px; }
.card h2 { margin: 0 0 14px; font-size: 18px; }
.card .muted { color: #6b7a87; font-size: 13px; margin: 0 0 14px; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash.ok { background: #e8f5e9; color: #1e7d32; border: 1px solid #bfe5c4; }
.flash.error { background: #fdecea; color: #c62828; border: 1px solid #f5c6c0; }

.btn {
  display: inline-block;
  background: #0e5a8a;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}
.btn:hover { background: #0b4a73; }
.btn.secondary { background: #e8eef3; color: #0e5a8a; border: 1px solid #c9d8e4; }
.btn.secondary:hover { background: #dce7ef; }
.btn.ghost { background: transparent; color: #0e5a8a; border: 1px solid #b9ccda; }
.btn.ghost:hover { background: #eef4f8; }
.btn.green { background: #1e7d32; }
.btn.green:hover { background: #17692a; }
.btn.red { background: #c62828; }
.btn.red:hover { background: #a82323; }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: #fff; border: 1px solid #e3e9ee; border-radius: 10px; padding: 16px 18px; }
.stat .label { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: #6b7a87; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat .value.pos { color: #1e7d32; }
.stat .value.neg { color: #c62828; }

table.list { width: 100%; border-collapse: collapse; }
table.list th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
  color: #6b7a87; padding: 8px 10px; border-bottom: 2px solid #e3e9ee;
}
table.list td { padding: 10px; border-bottom: 1px solid #eef2f5; font-size: 14px; vertical-align: middle; }
table.list tr:hover td { background: #f8fafb; }
table.list .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
}
.badge.draft { background: #eef1f4; color: #556572; }
.badge.sent { background: #e3f2fd; color: #0d47a1; }
.badge.accepted { background: #fff3e0; color: #b45309; }
.badge.completed { background: #e8f5e9; color: #1e7d32; }
.badge.cancelled { background: #fdecea; color: #c62828; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a {
  padding: 6px 14px; border-radius: 20px; text-decoration: none; font-size: 13.5px;
  background: #e8eef3; color: #0e5a8a;
}
.tabs a.active { background: #0e5a8a; color: #fff; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 13px; font-weight: 600; color: #3d4f5e; margin-bottom: 5px; }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #c9d6e0; border-radius: 6px;
  font-size: 14px; font-family: inherit; background: #fff; color: #22303c;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9dc8ea; border-color: #0e5a8a; }
textarea { resize: vertical; min-height: 90px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.check input { width: 17px; height: 17px; }
.check span { font-weight: 500; font-size: 14px; }

.legend { font-size: 13px; color: #6b7a87; margin: 2px 0 0; }

/* editor item/milestone rows */
.rowline { display: grid; gap: 8px; align-items: center; margin-bottom: 8px; }
.rowline.items { grid-template-columns: 110px 1fr 70px 120px 110px 30px; }
.rowline.ms { grid-template-columns: 1fr 70px 120px 30px 30px 60px 60px 70px 30px; }
.rowline input, .rowline select { padding: 7px 9px; }
.rmbtn { background: none; border: none; color: #c62828; font-size: 18px; cursor: pointer; line-height: 1; }

/* doc view (document page) */
.doctoolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.doctoolbar .docno { font-weight: 700; font-size: 15px; color: #0f2f46; margin-right: auto; }

.doc {
  background: #fff; padding: 46px 50px; border: 1px solid #dfe7ee; border-radius: 4px;
  font-size: 14px; line-height: 1.55; color: #222; position: relative;
}
.doc.paid::after {
  content: 'PAID';
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 120px; font-weight: 800; color: rgba(198,40,40,.16);
  transform: rotate(-24deg); pointer-events: none; letter-spacing: 8px;
}
.doc .letterhead { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid #0e5a8a; padding-bottom: 14px; margin-bottom: 20px; }
.doc .letterhead .bname { font-size: 21px; font-weight: 800; color: #0e5a8a; }
.doc .letterhead .bmeta { font-size: 12px; color: #555; }
.doc .letterhead .doctitle { text-align: right; }
.doc .letterhead .doctitle .kind { font-size: 24px; font-weight: 800; color: #0e5a8a; }
.doc .letterhead .doctitle .num { font-size: 14px; font-weight: 700; margin-top: 2px; }
.doc .letterhead .doctitle .date { font-size: 12px; color: #555; }
.doc .letterhead .doctitle .valid { font-size: 12px; color: #c62828; font-weight: 600; }
.doc .parties { display: flex; gap: 40px; margin-bottom: 22px; }
.doc .parties .blk { flex: 1; }
.doc .parties .blk .h { font-size: 11px; font-weight: 700; color: #0e5a8a; letter-spacing: 1px; margin-bottom: 4px; }
.doc .parties .blk .name { font-weight: 700; font-size: 15px; }
.doc .parties .blk .m { font-size: 13px; color: #444; }

.doc .sechead { font-size: 13px; font-weight: 800; color: #0e5a8a; border-bottom: 1.5px solid #0e5a8a; padding-bottom: 4px; margin: 26px 0 8px; }
.doc table.items, .doc table.ms { width: 100%; border-collapse: collapse; font-size: 13px; }
.doc table.items th, .doc table.ms th { background: #0e5a8a; color: #fff; text-align: left; padding: 7px 10px; font-size: 12px; }
.doc table.items td, .doc table.ms td { padding: 7px 10px; border-bottom: 1px solid #e3e9ee; }
.doc table.items td.num, .doc table.ms td.num { text-align: right; }
.doc table.items td.ctr, .doc table.ms td.ctr { text-align: center; }
.doc table.items tr.ghead td { background: #eef4f8; color: #0e5a8a; font-weight: 700; font-size: 12px; letter-spacing: .5px; }
.doc table.ms td.tick { color: #1e7d32; font-weight: 800; }
.doc table.ms td.no { color: #999; }

.doc .totals { display: flex; justify-content: flex-end; margin-top: 10px; }
.doc .totals table { border-collapse: collapse; font-size: 13px; }
.doc .totals td { padding: 4px 12px; }
.doc .totals td.k { color: #555; }
.doc .totals td.v { text-align: right; font-weight: 600; }
.doc .totals tr.grand td { background: #eef4f8; font-size: 15px; }
.doc .totals tr.grand td.v { font-weight: 800; }

.doc .paybox { display: flex; gap: 10px; margin-top: 16px; }
.doc .paybox .box { flex: 1; border: 1px solid #d7e1e9; border-radius: 4px; padding: 10px 12px; text-align: center; }
.doc .paybox .box .h { font-size: 11px; font-weight: 700; color: #6b7a87; letter-spacing: 1px; }
.doc .paybox .box .v { font-size: 17px; font-weight: 800; margin-top: 2px; }
.doc .paybox .box.paid { border-color: #1e7d32; background: #f2faf3; }
.doc .paybox .box.paid .v { color: #1e7d32; }
.doc .paybox .box.pending { border-color: #c62828; background: #fdf7f6; }
.doc .paybox .box.pending .v { color: #c62828; }
.doc .paybox .box.settled .v { color: #1e7d32; }

.doc .textsec { font-size: 12px; color: #333; white-space: pre-line; margin: 6px 0 8px; }
.doc .sign { display: flex; gap: 40px; margin-top: 46px; }
.doc .sign .sig { flex: 1; border-top: 1px solid #777; padding-top: 6px; font-size: 12px; color: #555; }

.doc .banner { margin: 14px 0 0; padding: 10px 14px; border-radius: 4px; font-weight: 700; font-size: 14px; text-align: center; }
.doc .banner.green { background: #e8f5e9; color: #1e7d32; border: 1px solid #bfe5c4; }

/* ticks row under doc view */
.tickrow { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.tickrow form { margin: 0; }

.tickbtn { display: inline-flex; align-items: center; gap: 6px; }
input[type=checkbox].big { width: 18px; height: 18px; }

.celltick { display: inline; margin: 0; }
.celltick button { border: none; background: none; cursor: pointer; font-size: 15px; padding: 2px 4px; color: inherit; }
.celltick button:hover { background: rgba(0,0,0,0.08); border-radius: 4px; }

.paydep { display: flex; flex-wrap: wrap; gap: 20px 26px; align-items: center; }
.paydep-cell .h { font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: #6b7a87; }
.paydep-cell .v { font-size: 17px; font-weight: 800; color: #22303c; }
.paydep-cell .v.pos { color: #1e7d32; }
.paydep-cell.settled .v { color: #1e7d32; }
.paydep-cell.pending .v { color: #c62828; }
.paydep-pay form { display: inline-flex; align-items: center; gap: 8px; }

.addms { margin-top: 12px; }
.addms form { display: flex; gap: 8px; flex-wrap: wrap; }
.addms input { padding: 7px 9px; border: 1px solid #c9d4dc; border-radius: 6px; font-size: 13px; }
.addms .legend { margin: 6px 0 0; font-size: 12px; color: #6b7a87; }

/* login */
.loginwrap { max-width: 380px; margin: 90px auto; padding: 0 16px; }
.loginwrap .card { padding: 32px; }
.loginwrap h1 { text-align: center; font-size: 20px; color: #0f2f46; margin: 0 0 4px; }
.loginwrap .sub { text-align: center; color: #6b7a87; font-size: 13px; margin: 0 0 22px; }

@media (max-width: 800px) {
  .form-grid { grid-template-columns: 1fr; }
  .rowline.items { grid-template-columns: 1fr; }
  .rowline.ms { grid-template-columns: 1fr 1fr; }
  .doc { padding: 26px 20px; }
  .doc .letterhead { flex-direction: column; }
  .doc .letterhead .doctitle { text-align: left; }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 8px; }
  .fab { top: 118px; right: 14px; }
  .doc .paybox { flex-direction: column; }
  .doc .sign { flex-direction: column; gap: 30px; }
}

.fab { position: fixed; top: 66px; right: 22px; z-index: 50; }
.fab-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
  background: #0e5a8a; color: #fff; font-size: 24px; line-height: 1;
  box-shadow: 0 4px 14px rgba(14, 90, 138, 0.4);
  display: flex; align-items: center; justify-content: center;
}
.fab-btn:hover { background: #0b4a72; }
.fab .fab-menu[hidden] { display: none; }
.fab .fab-menu {
  position: absolute; right: 0; top: 52px; min-width: 170px;
  background: #fff; border: 1px solid #e3e9ee; border-radius: 10px;
  box-shadow: 0 6px 20px rgba(15, 47, 70, 0.15); padding: 6px; display: flex; flex-direction: column;
}
.fab .fab-menu a {
  display: block; padding: 10px 14px; border-radius: 7px;
  color: #0f2f46; text-decoration: none; font-size: 14px; font-weight: 600;
}
.fab .fab-menu a:hover { background: #eef4f8; }