:root {
  --green: #1f6f54;
  --green-dark: #155239;
  --green-soft: #e6f3ec;
  --amber: #e8a33d;
  --ink: #1c2420;
  --muted: #6b7670;
  --line: #e2e8e4;
  --bg: #f4f6f4;
  --card: #ffffff;
  --danger: #c0392b;
  --radius: 14px;
  --tabbar-h: 62px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }

/* App bar */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--green);
  color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 1px 4px rgba(0,0,0,.18);
}
.appbar-brand { display: flex; align-items: center; gap: 10px; }
.appbar-logo { width: 28px; height: 28px; border-radius: 8px; }
.appbar h1 { font-size: 19px; font-weight: 700; letter-spacing: .2px; }
.appbar-sub { font-size: 12px; opacity: .85; }

/* Main view */
.view {
  padding: 16px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 24px);
  max-width: 720px;
  margin: 0 auto;
}

.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 20px 2px 8px; }
.section-title:first-child { margin-top: 4px; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.card-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card h3 { font-size: 15.5px; font-weight: 650; margin-bottom: 2px; }
.card .meta { font-size: 13px; color: var(--muted); line-height: 1.45; }
.card .meta strong { color: var(--ink); font-weight: 600; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px;
}
.stat .num { font-size: 22px; font-weight: 750; }
.stat .lbl { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.stat.accent { background: var(--green-soft); border-color: #cfe5d9; }
.stat.warn .num { color: var(--danger); }

/* Pills / chips */
.pill {
  display: inline-block; font-size: 11.5px; font-weight: 650;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.pill.green { background: var(--green-soft); color: var(--green-dark); }
.pill.amber { background: #fdf1dc; color: #8a5c10; }
.pill.red { background: #fbe4e1; color: var(--danger); }
.pill.grey { background: #eef1ef; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--green); color: #fff;
  border-radius: 12px; padding: 11px 16px;
  font-weight: 650; font-size: 14.5px;
}
.btn:active { filter: brightness(.92); }
.btn.block { display: flex; width: 100%; }
.btn.ghost { background: var(--green-soft); color: var(--green-dark); }
.btn.outline { background: #fff; color: var(--green); border: 1.5px solid var(--green); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.fab {
  position: fixed; right: 16px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--green); color: #fff;
  font-size: 28px; line-height: 1; font-weight: 400;
  box-shadow: 0 4px 14px rgba(0,0,0,.28);
  z-index: 15;
}

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 25;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: #fff; border-top: 1px solid var(--line);
  display: flex;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 10.5px; font-weight: 600;
}
.tab svg { width: 23px; height: 23px; fill: currentColor; }
.tab.active { color: var(--green); }

/* Lists */
.list-item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #f0f3f1; color: var(--muted);
}
.icon-btn svg { width: 17px; height: 17px; fill: currentColor; }
.icon-btn.danger { background: #fbe4e1; color: var(--danger); }

.empty {
  text-align: center; color: var(--muted);
  padding: 34px 20px; font-size: 14px; line-height: 1.5;
}
.empty .big { font-size: 34px; display: block; margin-bottom: 8px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(10, 20, 15, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: #fff; width: 100%; max-width: 560px;
  max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(env(safe-area-inset-bottom, 0px) + 18px);
}
@media (min-width: 600px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: 18px; margin: 20px; }
}
.modal h2 { font-size: 17px; font-weight: 700; margin-bottom: 14px; }
.modal-close { float: right; color: var(--muted); font-size: 22px; line-height: 1; padding: 2px 6px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 650; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 15px; background: #fbfdfc;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--green); background: #fff;
}
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Chat */
.chat-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.bubble {
  max-width: 82%; padding: 9px 12px; border-radius: 14px;
  font-size: 14.5px; line-height: 1.4;
  background: #fff; border: 1px solid var(--line); align-self: flex-start;
}
.bubble.mine { background: var(--green); color: #fff; border-color: var(--green); align-self: flex-end; }
.bubble .who { font-size: 11.5px; font-weight: 700; opacity: .75; margin-bottom: 2px; }
.bubble .when { font-size: 10.5px; opacity: .65; margin-top: 3px; }
.chat-input {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 6px);
  display: flex; gap: 8px; background: var(--bg); padding: 8px 0 2px;
}
.chat-input select { width: 118px; border: 1.5px solid var(--line); border-radius: 12px; padding: 0 8px; background: #fff; font-size: 13.5px; }
.chat-input input { flex: 1; border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 12px; background: #fff; font-size: 15px; }

/* More menu */
.menu-item {
  display: flex; align-items: center; gap: 13px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 14px; margin-bottom: 9px; width: 100%; text-align: left;
}
.menu-item svg { width: 21px; height: 21px; fill: var(--green); flex-shrink: 0; }
.menu-item .t { font-size: 15px; font-weight: 650; }
.menu-item .d { font-size: 12.5px; color: var(--muted); margin-top: 1px; }

/* Lease document */
.lease-doc {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 20px; font-size: 13.5px; line-height: 1.65;
}
.lease-doc h2 { text-align: center; font-size: 16px; margin-bottom: 2px; }
.lease-doc .sub { text-align: center; color: var(--muted); font-size: 12px; margin-bottom: 16px; }
.lease-doc h4 { font-size: 13px; margin: 14px 0 4px; text-transform: uppercase; letter-spacing: .4px; }
.lease-doc p { margin-bottom: 6px; }
.sig-row { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 30px; }
.sig-line { border-top: 1px solid var(--ink); padding-top: 4px; font-size: 11.5px; color: var(--muted); }

/* Toast */
#toast-root { position: fixed; bottom: calc(var(--tabbar-h) + 24px); left: 0; right: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--ink); color: #fff; font-size: 13.5px; font-weight: 600;
  padding: 10px 18px; border-radius: 999px; box-shadow: 0 4px 12px rgba(0,0,0,.3);
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Welcome */
.welcome { text-align: center; padding: 40px 18px; }
.welcome img { width: 84px; height: 84px; }
.welcome h2 { font-size: 21px; margin: 14px 0 6px; }
.welcome p { color: var(--muted); font-size: 14px; line-height: 1.55; margin-bottom: 20px; }

.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.month-nav .m { font-size: 16px; font-weight: 700; }
.month-nav button { padding: 7px 13px; border-radius: 10px; background: #fff; border: 1px solid var(--line); font-weight: 650; color: var(--green); }

.divider { height: 1px; background: var(--line); margin: 10px 0; }
.small-note { font-size: 12px; color: var(--muted); line-height: 1.5; }

@media print {
  .appbar, .tabbar, .fab, .btn-row, .no-print { display: none !important; }
  .view { padding: 0; max-width: none; }
  .lease-doc { border: none; padding: 0; }
  body { background: #fff; }
}
