body {
    font-family: 'Microsoft JhengHei', 'PingFang TC', sans-serif;
    background-color: #e9ecef;
    margin: 0;
    padding: 0;
}

/* ======== 登入閘門 ======== */
.gate {
    position: fixed;
    inset: 0;
    background: rgba(33, 40, 52, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
}
.gate[hidden] { display: none; }   /* flex 蓋過 hidden 的修正 */
.gate-box {
    background: #fff;
    border-radius: 12px;
    padding: 34px 38px;
    width: 320px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
    text-align: center;
}
.gate-box h2 { margin: 0 0 4px; font-size: 20px; color: #274472; letter-spacing: 1px; }
.gate-sub { margin: 0 0 18px; color: #888; font-size: 13px; }
.gate-box input {
    width: 100%;
    box-sizing: border-box;
    padding: 11px 12px;
    margin-bottom: 12px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 15px;
}
.gate-box button {
    width: 100%;
    padding: 11px;
    border: none;
    border-radius: 8px;
    background: #274472;
    color: #fff;
    font-size: 15px;
    cursor: pointer;
}
.gate-box button:hover { background: #1d3657; }
.err { color: #c0392b; font-size: 13px; margin-bottom: 10px; }

/* ======== 主介面 ======== */
.topbar { background: #274472; color: #fff; padding: 12px 20px; }
.topbar-inner { max-width: 1100px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; }
.brand { font-size: 18px; font-weight: bold; letter-spacing: 1px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.whoami { font-size: 13px; opacity: 0.85; }
.btn-ghost {
    background: transparent; border: 1px solid rgba(255,255,255,0.6); color: #fff;
    border-radius: 6px; padding: 5px 12px; cursor: pointer; font-size: 13px;
}
.btn-ghost:hover { background: rgba(255,255,255,0.15); }

.tabs {
    max-width: 1100px; margin: 0 auto; padding: 16px 20px 0; display: flex; gap: 8px;
}
.tab {
    padding: 9px 18px; border: none; border-radius: 8px 8px 0 0; cursor: pointer;
    background: #d7dde5; color: #333; font-size: 15px; position: relative; top: 1px;
}
.tab.active { background: #fff; font-weight: bold; color: #274472; }

.view { max-width: 1100px; margin: 0 auto 40px; }

/* ======== 列表 ======== */
.list-toolbar { display: flex; align-items: center; gap: 12px; padding: 0 20px 12px; }
.list-toolbar input {
    flex: 1; padding: 10px 12px; border: 1px solid #ccc; border-radius: 8px; font-size: 14px;
}
.count { color: #888; font-size: 13px; white-space: nowrap; }
.list-table {
    width: calc(100% - 40px); margin: 0 20px; border-collapse: collapse; background: #fff;
    border-radius: 10px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.list-table th, .list-table td {
    border-bottom: 1px solid #eef0f3; padding: 10px 10px; font-size: 13px; text-align: left;
}
.list-table th { background: #f7f9fc; font-weight: 600; white-space: nowrap; }
.list-table td { color: #34495e; }
.list-table tr:hover td { background: #f8fafd; }
.empty { padding: 30px; text-align: center; color: #999; }
.op-btn { border: none; background: #274472; color: #fff; border-radius: 6px; padding: 5px 12px; cursor: pointer; font-size: 13px; }
.op-btn.danger { background: #c0392b; margin-left: 6px; }
.op-btn.danger:hover { background: #a93226; }
.op-btn:hover { background: #1d3657; }
.link-no {
    border: none; background: none; cursor: pointer; color: #274472; font-size: 13px;
    font-weight: bold; text-decoration: underline dotted; padding: 2px 0;
}
.link-no:hover { color: #c0392b; }

/* ======== 編輯器（紙本格式） ======== */
.editor-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 20px 14px;
}
.editor-head .btn-ghost { color: #274472; border-color: #274472; }
.editor-head .btn-ghost:hover { background: #eef2f8; }
.mode { font-size: 16px; font-weight: bold; color: #274472; }
.btn-primary {
    background: #27ae60; border: none; color: #fff; padding: 10px 22px;
    border-radius: 8px; font-size: 15px; cursor: pointer;
}
.btn-primary:hover { background: #219150; }

.container {
    background-color: white;
    width: 210mm; max-width: 100%;
    margin: 0 auto;
    padding: 30px;
    box-sizing: border-box;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.header-title {
    text-align: center; font-size: 28px; font-weight: bold;
    letter-spacing: 10px; margin-bottom: 20px;
}
.header-top {
    display: flex; justify-content: space-between; align-items: flex-end;
    margin-bottom: 10px; gap: 20px; flex-wrap: wrap;
}
.case-name { font-size: 16px; font-weight: bold; }
.case-name input {
    font-size: 18px; width: 300px; max-width: 60vw; border: none;
    border-bottom: 1px solid #333; color: #274472; font-family: inherit;
}
.checkbox-group {
    display: grid; grid-template-columns: auto auto auto auto; column-gap: 20px; row-gap: 10px; font-size: 14px;
}
.checkbox-group label { display: flex; align-items: center; }
.checkbox-group input { margin-right: 5px; }

table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid #000; padding: 8px 5px; text-align: center; font-size: 14px; height: 30px; }
th { background-color: #f9f9f9; font-weight: normal; white-space: nowrap; }
td input {
    width: 95%; border: none; background: transparent; text-align: center;
    font-size: 15px; font-family: inherit; color: #274472;
}
td input:focus { outline: none; background: #f4f7ff; }
td input.heji-input { font-weight: bold; }

.table-1 th { width: 12%; }
.table-1 td { width: 15%; }

/* 管理費 = 金額 × 月份 → 總額 (複合儲存格)；與左右一般儲存格同為 table-cell，等高對齊 */
.mgmt-cell {
    padding: 8px 5px; text-align: center; vertical-align: middle; white-space: nowrap;
    min-width: 176px;
}
.mgmt-cell input { width: 46px; height: 22px; margin: 0 1px; vertical-align: middle; }
.mgmt-x, .mgmt-eq { color: #888; font-size: 13px; vertical-align: middle; }
.mgmt-total { color: #274472; font-size: 13px; min-width: 42px; text-align: left; vertical-align: middle; }

.table-2 { border-top: none; }
.table-2 th, .table-2 td { border-top: none; }
.table-2 tr.heji-row th { font-weight: bold; background: #eef2f8; }
.vertical-text {
    writing-mode: vertical-lr; text-orientation: upright;
    letter-spacing: 5px; font-weight: bold; padding: 20px 5px;
}
.calc-hint { margin-top: 12px; font-size: 12px; color: #888; }

/* ======== 收款統計明細視窗 ======== */
.modal {
    position: fixed; inset: 0; background: rgba(33, 40, 52, 0.55);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 40px 16px; overflow: auto;
}
.modal[hidden] { display: none; }
.pay-box {
    background: #fff; border-radius: 12px; width: 900px; max-width: 100%;
    box-shadow: 0 14px 46px rgba(0,0,0,0.30);
    padding: 22px 24px 18px;
}
.pay-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.pay-title { font-size: 18px; font-weight: bold; color: #274472; }
.pay-title b { color: #c0392b; text-decoration: underline; cursor: help; }
.btn-close {
    background: #eee; border: none; border-radius: 6px; width: 30px; height: 30px;
    font-size: 15px; cursor: pointer; color: #666;
}
.btn-close:hover { background: #d7dde5; }
.pay-gen {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    background: #f4f7fc; padding: 10px; border-radius: 8px; margin-bottom: 12px;
}
.pay-gen input {
    padding: 7px 8px; border: 1px solid #ccd4e0; border-radius: 6px; font-size: 13px;
    width: 6.5em;
}
.pay-gen .btn-ghost-dark {
    border: 1px solid #274472; background: #fff; color: #274472;
    border-radius: 6px; padding: 7px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.pay-gen .btn-ghost-dark:hover { background: #eef2f8; }
.pay-gen .btn-primary { padding: 8px 16px; font-size: 13px; }
.pay-table { width: 100%; border-collapse: collapse; }
.pay-table th, .pay-table td { border: 1px solid #dfe4ec; padding: 7px 6px; text-align: center; font-size: 13px; }
.pay-table th { background: #f2f5fa; font-weight: 600; }
.pay-table td input {
    width: 90%; border: 1px solid transparent; background: #fff; text-align: center;
    font-size: 13px; padding: 4px; border-radius: 4px;
}
.pay-table td input:focus { border-color: #274472; outline: none; background: #f4f7ff; }
.pay-table td input.wide { width: 180px; text-align: left; }
.pay-table td.paid { color: #27ae60; font-weight: bold; }
.pay-table td.due { color: #c0392b; font-weight: bold; }
.pay-table tbody tr.stale td { background: #fbf5f0; }
.pay-table td.del { width: 42px; }
.btn-del { border: none; background: transparent; color: #c0392b; cursor: pointer; font-size: 15px; }
.btn-del:hover { color: #922b21; }
.pay-table tfoot td { font-weight: bold; background: #eaf0f8; color: #274472; }
.pay-hint { margin-top: 10px; font-size: 12px; color: #888; }