:root {
  --bg: #f3f5f9; --card: #ffffff; --text: #17202e; --muted: #5e6a7d; --line: #dde2ea;
  --brand: #1f4072; --brand-2: #2c5aa0; --ok: #1e7b34; --ok-bg: #e3f4e1;
  --warn: #8a5a00; --warn-bg: #fff3d6; --bad: #b42318; --bad-bg: #fde2e2;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand-2); }
h1 { font-size: 1.5rem; margin: .3em 0 .6em; }
h2 { font-size: 1.15rem; margin: 1.4em 0 .6em; }
.card h2:first-child, .card h1:first-child { margin-top: 0; }

/* header */
.top { background: var(--brand); color: #fff; display: flex; align-items: center; flex-wrap: wrap; padding: 0 16px; min-height: 56px; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; margin-right: auto; padding: 14px 0; }
.nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.nav a, .nav .linkish { color: #fff; text-decoration: none; padding: 8px 10px; border-radius: 6px; font-size: .95rem; }
.nav a:hover, .nav .linkish:hover { background: rgba(255,255,255,.14); }
.menu-btn { display: none; background: none; border: 0; color: #fff; font-size: 1.6rem; padding: 6px 4px; cursor: pointer; }
@media (max-width: 760px) {
  .menu-btn { display: block; }
  .nav { display: none; width: 100%; flex-direction: column; align-items: stretch; padding-bottom: 10px; }
  .nav-open .nav { display: flex; }
  .nav form { display: block; }
  .nav .linkish { width: 100%; text-align: left; }
}

.wrap { max-width: 1000px; margin: 0 auto; padding: 16px 16px 60px; }
.narrow { max-width: 420px; margin: 24px auto; }
.medium { max-width: 640px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 14px; }
.empty { color: var(--muted); text-align: center; padding: 28px 18px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.danger { color: var(--bad); font-weight: 600; }

/* forms */
label { display: block; margin-bottom: 14px; font-weight: 600; font-size: .95rem; }
input, select, textarea { display: block; width: 100%; margin-top: 5px; padding: 11px 12px; font: inherit; font-weight: 400;
  border: 1px solid #c4ccd8; border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: var(--brand-2); }
input[type=checkbox], input[type=radio] { display: inline-block; width: 20px; height: 20px; margin: 0 8px 0 0; vertical-align: -4px; }
label.check { font-weight: 400; display: block; position: relative; padding-left: 30px; margin-bottom: 10px; }
label.check input { position: absolute; left: 0; top: 2px; margin: 0; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 4px; margin: 0 0 16px; }
legend { font-weight: 700; padding: 0 6px; }
.picker { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 2px; margin-bottom: 12px; background: #fafbfd; }
form.inline { display: inline; }

.btn { display: inline-block; padding: 11px 18px; border-radius: 8px; border: 1px solid #c4ccd8; background: #fff; color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; text-align: center; }
.btn:hover { background: #f0f3f8; }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.primary:hover { background: var(--brand); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.full { width: 100%; }
.small-btn { padding: 6px 12px; font-size: .875rem; }
.linkish { background: none; border: 0; padding: 0; color: var(--brand-2); font: inherit; cursor: pointer; text-decoration: underline; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row label { flex: 1; min-width: 140px; }
.wrap-row { margin: 10px 0 16px; }
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid; }
.flash.ok { background: var(--ok-bg); border-color: #b6e0b0; color: #144d22; }
.flash.error { background: var(--bad-bg); border-color: #f4b4ae; color: #7a1610; }
.notice { background: var(--warn-bg); border: 1px solid #f0d58f; color: #5c3d00; padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #e8ecf2; color: var(--muted); vertical-align: middle; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }

/* lists */
.list .item { display: flex; justify-content: space-between; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.list .item:hover { border-color: var(--brand-2); }
.item.overdue { border-left: 4px solid var(--bad); }
.item-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; text-align: right; }
@media (max-width: 560px) {
  .list .item { flex-direction: column; align-items: stretch; }
  .item-side { align-items: flex-start; text-align: left; }
}
.bar { height: 6px; background: #e8ecf2; border-radius: 3px; overflow: hidden; margin-top: 6px; max-width: 320px; }
.bar span { display: block; height: 100%; background: var(--ok); }
.invite { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.copy-row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.copy-row input { margin: 0; font-size: .85rem; padding: 7px 9px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; font-size: .85rem; color: var(--muted); }
.stat .num { font-size: 1.5rem; font-weight: 700; color: var(--text); }
.stat.bad .num { color: var(--bad); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 16px; }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }

/* tables */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f6f8fb; font-size: .85rem; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
.row-ok td { background: #f5fbf4; }
.row-bad td { background: #fff6f5; }
.row-muted { opacity: .55; }
td.actions { white-space: nowrap; }
td.actions > * { margin-right: 10px; }

/* document view */
.pages { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.page { width: 100%; max-width: 860px; margin: 0 auto; display: block; background: #fff; border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.signbox { max-width: 640px; margin: 0 auto 30px; border: 2px solid var(--brand-2); }
.pad-wrap { position: relative; margin-bottom: 12px; }
#pad { display: block; width: 100%; height: 200px; background: #fff; border: 1px dashed #8a97ab; border-radius: 10px; touch-action: none; cursor: crosshair; }
.pad-line { position: absolute; left: 20px; right: 20px; bottom: 44px; border-top: 1px solid #c4ccd8; font-size: .75rem; color: #9aa5b5; padding-top: 2px; pointer-events: none; }
@media (max-width: 560px) { .stats { grid-template-columns: 1fr 1fr 1fr; gap: 6px; } .stat .num { font-size: 1.2rem; } }
