* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --green-900: #0B3D2E;
  --green-800: #11503C;
  --green-600: #1A7A57;
  --green-400: #34C08A;
  --accent: #0FDC78;
  --bg: #F4F7F5;
  --card: #FFFFFF;
  --line: #E2EAE5;
  --text: #17251F;
  --muted: #6B8079;
  --red: #D9453B;
  --amber: #C8860D;
  --blue: #2A6FB0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11,61,46,.06), 0 8px 24px rgba(11,61,46,.06);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
}
body { background: var(--bg); color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased; }
a { color: var(--green-600); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- 登录 ---------- */
#login { position: fixed; inset: 0; background: linear-gradient(135deg, #062A20, #0B3D2E 55%, #12543F); display: flex; align-items: center; justify-content: center; z-index: 90; }
.login-card { width: 380px; background: #fff; border-radius: 16px; padding: 36px 32px; box-shadow: 0 24px 80px rgba(0,0,0,.35); }
.login-card h1 { font-size: 26px; letter-spacing: 2px; color: var(--green-900); }
.login-card p { color: var(--muted); margin: 6px 0 26px; font-size: 13px; }
.login-card input { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; margin-bottom: 12px; font-size: 14px; outline: none; }
.login-card input:focus { border-color: var(--green-400); box-shadow: 0 0 0 3px rgba(52,192,138,.12); }
.login-card .btn-primary { width: 100%; height: 42px; margin-top: 8px; }
.login-tip { margin-top: 18px; font-size: 12px; color: var(--muted); line-height: 1.8; }
.err { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* ---------- 布局 ---------- */
#app { display: none; min-height: 100vh; grid-template-columns: 210px 1fr; }
#app.ready { display: grid; }
#side { background: var(--green-900); color: #D7E6DF; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 22px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand b { font-size: 19px; letter-spacing: 3px; color: #fff; display: block; }
.brand span { font-size: 11px; color: #7FA695; }
#nav { padding: 10px 8px; overflow-y: auto; flex: 1; }
#nav a { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 8px; color: #B9D2C6; font-size: 13.5px; margin-bottom: 2px; }
#nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
#nav a.on { background: var(--green-600); color: #fff; font-weight: 600; }
#nav .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.side-foot { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: #7FA695; }

#main { min-width: 0; display: flex; flex-direction: column; }
#topbar { height: 58px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 14px; padding: 0 22px; position: sticky; top: 0; z-index: 20; }
#topbar h2 { font-size: 16px; color: var(--green-900); font-weight: 600; }
#topbar .spacer { flex: 1; }
select, input[type=text], input[type=number], input[type=date], input[type=password], textarea {
  height: 34px; border: 1px solid var(--line); border-radius: 7px; padding: 0 10px; font-size: 13px; outline: none; background: #fff; color: var(--text);
}
select:focus, input:focus, textarea:focus { border-color: var(--green-400); }
textarea { height: auto; min-height: 70px; padding: 8px 10px; width: 100%; resize: vertical; }
#topbar select { width: 190px; }
.who { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--green-600); color: #fff; display: grid; place-items: center; font-size: 12px; }

#view { padding: 20px 22px 60px; }

/* ---------- 按钮 ---------- */
.btn { height: 32px; padding: 0 14px; border-radius: 7px; border: 1px solid var(--line); background: #fff; color: var(--text); font-size: 13px; }
.btn:hover { border-color: var(--green-400); color: var(--green-600); }
.btn-primary { background: var(--green-600); border-color: var(--green-600); color: #fff; }
.btn-primary:hover { background: var(--green-800); color: #fff; }
.btn-danger { color: var(--red); border-color: #F2C7C3; }
.btn-danger:hover { background: #FDF1F0; border-color: var(--red); color: var(--red); }
.btn-sm { height: 26px; padding: 0 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 卡片/工具条 ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.card-head h3 { font-size: 14px; color: var(--green-900); }
.card-body { padding: 16px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 24px; font-weight: 700; color: var(--green-900); margin-top: 8px; letter-spacing: -.5px; }
.stat .s { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat.accent .v { color: var(--green-600); }
.stat.warn .v { color: var(--amber); }
.stat.bad .v { color: var(--red); }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
th { background: #F7FAF8; color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
tbody tr:hover { background: #FAFCFB; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 40px; text-align: center; color: var(--muted); font-size: 13px; }
.tbl-wrap { overflow-x: auto; }
.acts { display: flex; gap: 6px; flex-wrap: wrap; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; line-height: 18px; background: #EEF3F0; color: var(--muted); white-space: nowrap; }
.badge.green { background: #E4F7EC; color: #167C4E; }
.badge.amber { background: #FCF3E0; color: var(--amber); }
.badge.red { background: #FBEBE9; color: var(--red); }
.badge.blue { background: #E8F0F8; color: var(--blue); }
.badge.gray { background: #EEF0EF; color: #7A8A84; }

/* ---------- 模态框 ---------- */
#mask { position: fixed; inset: 0; background: rgba(8,32,24,.45); display: none; z-index: 60; }
#mask.on { display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 50px 16px; }
.modal { background: #fff; border-radius: 14px; width: 520px; max-width: 100%; box-shadow: 0 24px 80px rgba(0,0,0,.28); animation: pop .16s ease-out; }
.modal.wide { width: 760px; }
@keyframes pop { from { transform: translateY(-6px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-head h3 { font-size: 15px; color: var(--green-900); flex: 1; }
.modal-head .x { border: 0; background: none; font-size: 20px; color: var(--muted); line-height: 1; }
.modal-body { padding: 18px 20px; max-height: 66vh; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.form-row label b { color: var(--red); font-weight: 400; margin-left: 2px; }
.form-row input, .form-row select { width: 100%; height: 36px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-row .help { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.form-row .help.err { color: #D93025; }
.check { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text); }
.check input { width: 15px; height: 15px; }
.hint { background: #F2F9F5; border: 1px solid #DCEFE3; color: #2C6B4F; padding: 10px 12px; border-radius: 8px; font-size: 12.5px; line-height: 1.7; }
.section-title { font-size: 13px; font-weight: 600; color: var(--green-900); margin: 18px 0 10px; padding-left: 8px; border-left: 3px solid var(--green-400); }

/* ---------- 明细网格 ---------- */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 18px; }
.kv .i { font-size: 13px; }
.kv .i .k { color: var(--muted); font-size: 12px; margin-bottom: 3px; }
.kv .i .v { color: var(--text); font-weight: 500; }

/* ---------- 签名 ---------- */
#signpad { width: 100%; height: 200px; border: 1px dashed #B9CFC5; border-radius: 10px; background: #FBFDFC; touch-action: none; display: block; }

/* ---------- toast ---------- */
#toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.tmsg { padding: 10px 18px; border-radius: 8px; font-size: 13px; color: #fff; background: #23372F; box-shadow: 0 10px 30px rgba(0,0,0,.2); animation: pop .18s; }
.tmsg.err { background: var(--red); }
.tmsg.ok { background: var(--green-600); }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  #side { position: fixed; left: 0; top: 0; bottom: 0; width: 210px; transform: translateX(-100%); transition: transform .2s; z-index: 50; }
  #side.open { transform: none; }
  #view { padding: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal { width: 96vw; }
}
.menu-btn { display: none; }
@media (max-width: 900px) { .menu-btn { display: inline-block; } }

/* ---------- 合同正文（A4 纸面） ---------- */
.modal.doc { width: 880px; }
.doc-a4 {
  background: #fff; color: #1a1a1a; font-size: 13px; line-height: 1.9;
  font-family: "Songti SC", "SimSun", "Noto Serif CJK SC", serif;
}
.doc-title { text-align: center; font-size: 22px; font-weight: 700; letter-spacing: 8px; margin: 8px 0 6px; }
.doc-no { text-align: right; font-size: 12px; margin-bottom: 10px; }
.doc-party { width: 100%; border-collapse: collapse; margin: 8px 0 14px; }
.doc-party td { border: 1px solid #333; padding: 8px 10px; vertical-align: top; width: 50%; }
.doc-party .k { display: inline-block; min-width: 6.5em; color: #333; }
.doc-fill { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.doc-sec { font-weight: 700; margin: 12px 0 4px; }
.doc-p { text-indent: 2em; margin: 2px 0; }
.doc-sub { text-indent: 2em; margin: 2px 0; }
.doc-sign { display: flex; gap: 50px; margin-top: 30px; }
.doc-sign > div { flex: 1; }
.doc-sign .line { margin-top: 42px; border-top: 1px solid #333; padding-top: 6px; font-size: 12px; }
.doc-sign img { display: block; max-height: 70px; margin: 4px 0 -6px 40px; }
.doc-sign .sig-empty { color: #999; font-size: 12px; }
.doc-stamp { color: #666; font-size: 12px; }

/* ---------- 资源树：房间卡片网格 ---------- */
.tree-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 10px;
  padding: 12px;
  background: #fbfdfc;
}
.room-card {
  border: 1px solid #e4e8e6; border-radius: 10px; background: #fff;
  padding: 10px 12px; box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
  transition: box-shadow .15s ease, transform .15s ease;
}
.room-card:hover { box-shadow: 0 6px 18px rgba(16, 24, 40, .08); transform: translateY(-1px); }
.room-card .rc-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.room-card .rc-top b { font-size: 15px; }
.room-card .rc-line { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; line-height: 1.9; }
.room-card .rc-label { color: #8A8F98; white-space: nowrap; }
.room-card .rc-val { color: #2b3833; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-card .rc-acts { display: flex; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px dashed #eef1ef; }

/* ---------- 列表分页 ---------- */
.tbl-pager { display: flex; align-items: center; gap: 10px; padding: 10px 2px 2px; font-size: 12px; color: #6B8079; }
.tbl-pager .btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- 打印：只输出弹窗内容 ---------- */
@media print {
  @page { size: A4; margin: 16mm 16mm; }
  body > *:not(#mask) { display: none !important; }
  #mask { position: static !important; background: none !important; display: block !important; padding: 0 !important; overflow: visible !important; }
  #mask .modal { width: 100% !important; max-width: 100% !important; border-radius: 0; box-shadow: none !important; animation: none; }
  #mask .modal-head { border-bottom: 2px solid #333; }
  #mask .modal-head .x, #mask .modal-foot, #mask .noprint { display: none !important; }
  #mask .modal-body { max-height: none !important; overflow: visible !important; padding: 0 !important; }
  #mask img { max-width: 320px !important; }
  #mask a[href^="/storage"], #mask a[href^="storage"] { text-decoration: none; color: inherit; }
  .doc-a4 { font-size: 12pt; line-height: 1.9; }
  .doc-sec, .doc-party { break-inside: avoid; }
}
