:root {
  --green: #1d5a3a;
  --green-dark: #143f29;
  --green-soft: #e6efe8;
  --brown: #8b5e34;
  --brown-soft: #f3e9dd;
  --bg: #f6f3ed;
  --card: #ffffff;
  --ink: #1f2a24;
  --muted: #66736b;
  --line: #e3ddd2;
  --red: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 40, 30, .06), 0 6px 20px rgba(20, 40, 30, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.45; }
a { color: var(--green); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--green-dark); color: #e9f1ec; padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; }
.brand .mark { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #2f7a50, var(--brown)); display: grid; place-items: center; font-weight: 700; color: #fff; }
.brand b { display: block; font-size: 14px; letter-spacing: .02em; }
.brand span { font-size: 12px; color: #a9c2b3; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; color: #d5e4da; text-decoration: none; font-size: 14px; }
.nav a:hover { background: rgba(255, 255, 255, .07); }
.nav a.on { background: rgba(255, 255, 255, .13); color: #fff; font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.side .who { margin-top: auto; font-size: 12px; color: #a9c2b3; padding: 10px 8px 0; border-top: 1px solid rgba(255, 255, 255, .1); }
.side .who button { background: none; border: 0; color: #fff; text-decoration: underline; padding: 0; cursor: pointer; font-size: 12px; }
.main { padding: 26px 30px 60px; max-width: 1180px; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.topbar .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.mobilebar { display: none; }

/* ---------- elements ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.card h2 { margin-bottom: 4px; }
.card .hint { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 9px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #cfc6b6; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.brown { background: var(--brown); border-color: var(--brown); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--red); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: #34413a; }
label.f small { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=tel], select, textarea {
  width: 100%; border: 1px solid #d9d2c5; background: #fffdf9; border-radius: 9px; padding: 9px 11px; font-weight: 400; font-size: 14.5px; outline: none;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(29, 90, 58, .12); }
.seg { display: inline-flex; border: 1px solid #d9d2c5; border-radius: 9px; overflow: hidden; background: #fffdf9; }
.seg label { padding: 8px 14px; cursor: pointer; font-size: 14px; font-weight: 500; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--green); color: #fff; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fffdf9; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--green); }
.check b { display: block; font-size: 14px; }
.check span { font-size: 12.5px; color: var(--muted); }
.checks { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--brown-soft); color: var(--brown); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.grey { background: #eeeae3; color: #6b6458; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat b { font-size: 28px; display: block; color: var(--green); }
.stat span { font-size: 13px; color: var(--muted); }
.hero { background: linear-gradient(120deg, var(--green-dark), var(--green) 60%, #2c6e48); color: #fff; border-radius: 16px; padding: 22px 24px; display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.hero p { margin: 6px 0 0; color: #cfe2d6; font-size: 14px; max-width: 560px; }
.hero .btn { background: #fff; color: var(--green-dark); border-color: #fff; }

/* list */
.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.list td { padding: 11px 10px; border-bottom: 1px solid #efeae1; vertical-align: middle; font-size: 14px; }
.list tr:last-child td { border-bottom: 0; }
.list tr.click { cursor: pointer; }
.list tr.click:hover td { background: #faf7f1; }
.list .name { font-weight: 600; }
.empty { text-align: center; padding: 34px 10px; color: var(--muted); }
.search { max-width: 360px; }

/* form sections */
.form-sec { margin-bottom: 16px; }
.sec-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sec-head .num { width: 26px; height: 26px; border-radius: 50%; background: var(--green-soft); color: var(--green); display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.stickybar { position: sticky; bottom: 0; background: rgba(246, 243, 237, .94); backdrop-filter: blur(6px); padding: 12px 0; margin-top: 10px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; border-top: 1px solid var(--line); z-index: 5; }

/* ---------- document editor ---------- */
.ed-layout { display: grid; grid-template-columns: 1fr 260px; gap: 18px; align-items: start; }
.toolbar { position: sticky; top: 0; z-index: 6; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; box-shadow: var(--shadow); margin-bottom: 14px; }
.toolbar .sep { width: 1px; height: 24px; background: var(--line); margin: 0 2px; }
.toolbar select { width: auto; padding: 6px 8px; font-size: 13px; }
.tb { border: 1px solid transparent; background: none; border-radius: 7px; padding: 6px 9px; cursor: pointer; font-size: 13px; font-weight: 600; display: inline-flex; gap: 6px; align-items: center; }
.tb:hover { background: #f2eee6; }
.tb svg { width: 16px; height: 16px; }
.paper-wrap { overflow-x: auto; padding-bottom: 10px; }
.paper { background: #fff; width: 100%; max-width: 820px; margin: 0 auto; box-shadow: 0 2px 4px rgba(0, 0, 0, .06), 0 12px 32px rgba(0, 0, 0, .08); border-radius: 4px; padding: 0 64px 60px; font-family: Tinos, "Times New Roman", Times, serif; font-size: 15.5px; line-height: 1.45; color: #111; }
.paper .lh { margin: 0 -64px 16px; display: block; width: calc(100% + 128px); height: auto; border-radius: 4px 4px 0 0; }
.paper .lh-crop { margin: 0 -64px 14px; overflow: hidden; }
.paper .lh-crop img { width: 100%; display: block; }
.blk { position: relative; display: flex; gap: 6px; padding: 2px 6px; margin: 0 -6px 6px; border-radius: 5px; border: 1px dashed transparent; }
.blk:hover { border-color: #e8e1d3; }
.blk.sel { border-color: #9cc3ab; background: #f5faf6; }
.blk .lab { flex: none; width: 30px; user-select: none; }
.blk[data-t=i] .lab, .blk[data-t=a] .lab { margin-left: 34px; }
.blk .tx { flex: 1; outline: none; text-align: justify; min-height: 1.3em; }
.blk[data-t=title] .tx { text-align: center; font-weight: 700; font-size: 17px; }
.blk[data-t=h] .tx { font-weight: 700; margin-top: 8px; text-align: left; }
.blk[data-t=sub] .tx { text-decoration: underline; text-align: left; }
.blk[data-t=c] .tx { text-align: center; }
.blk .tx:empty::before { content: "Type here…"; color: #b5ad9f; }
.blk.special { justify-content: center; }
.chip { font-family: "Segoe UI", system-ui, sans-serif; font-size: 12.5px; font-weight: 700; background: var(--brown-soft); color: var(--brown); padding: 6px 12px; border-radius: 8px; width: 100%; text-align: center; border: 1px dashed #d9c3a8; }
.ph { background: var(--green-soft); color: var(--green); border-radius: 4px; padding: 0 3px; font-family: "Segoe UI", system-ui, sans-serif; font-size: .82em; font-weight: 700; }
.side-panel { position: sticky; top: 10px; }
.side-panel .card { padding: 14px 16px; }
.fields { display: flex; flex-direction: column; gap: 4px; max-height: 60vh; overflow: auto; }
.fields button { text-align: left; border: 1px solid var(--line); background: #fffdf9; border-radius: 7px; padding: 6px 8px; cursor: pointer; font-size: 12.5px; }
.fields button code { color: var(--green); font-weight: 700; }
.fields button span { display: block; color: var(--muted); font-size: 11.5px; }
.notice { background: var(--brown-soft); border: 1px solid #e6d3bb; color: #5c3d1f; border-radius: 10px; padding: 10px 14px; font-size: 13.5px; margin-bottom: 14px; }
.notice.green { background: var(--green-soft); border-color: #c4dccb; color: var(--green-dark); }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 20% 10%, #e8f0ea, transparent 50%), radial-gradient(circle at 90% 90%, #f1e5d6, transparent 45%), var(--bg); }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth .brand { color: var(--ink); padding: 0 0 18px; }
.auth .brand span { color: var(--muted); }
.auth form { display: flex; flex-direction: column; gap: 14px; }
.err { color: var(--red); font-size: 13px; min-height: 1em; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, .2); z-index: 50; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.bad { background: var(--red); }
.busy { position: fixed; inset: 0; background: rgba(246, 243, 237, .65); display: grid; place-items: center; z-index: 40; font-weight: 600; color: var(--green-dark); }

/* lists inside settings */
.item { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fffdf9; }
.item + .item { margin-top: 10px; }
.lh-preview { width: 100%; max-width: 260px; border: 1px solid var(--line); border-radius: 6px; display: block; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .mobilebar { display: flex; position: sticky; top: 0; z-index: 20; background: var(--green-dark); color: #fff; padding: 10px 14px; align-items: center; justify-content: space-between; }
  .mobilebar b { font-size: 15px; }
  .mobilebar button { background: none; border: 1px solid rgba(255, 255, 255, .3); color: #fff; border-radius: 8px; padding: 6px 10px; }
  .side.open { display: flex; position: fixed; inset: 0; width: 100%; z-index: 30; height: 100vh; }
  .main { padding: 18px 14px 80px; }
  .grid, .grid.three { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .stats { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .stat { padding: 12px; }
  .stat b { font-size: 22px; }
  .ed-layout { grid-template-columns: 1fr; }
  .side-panel { position: static; }
  .paper { padding: 0 22px 40px; font-size: 14.5px; }
  .paper .lh, .paper .lh-crop { margin-left: -22px; margin-right: -22px; width: calc(100% + 44px); }
  .list .hide-m { display: none; }
}
@font-face { font-family: Tinos; src: url(/fonts/Tinos-Regular.ttf) format("truetype"); font-weight: 400; }
@font-face { font-family: Tinos; src: url(/fonts/Tinos-Bold.ttf) format("truetype"); font-weight: 700; }
