:root {
    --bg: #f4f6f5;
    --panel: #ffffff;
    --text: #18201d;
    --muted: #65706b;
    --line: #d8dedb;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --danger: #b42318;
    --warn-bg: #fff7ed;
    --success-bg: #ecfdf3;
    --error-bg: #fff1f2;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, "Noto Sans HK", "Microsoft JhengHei", sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 22px;
    min-height: 56px;
    padding: 0 24px;
    background: #17211e;
    color: #fff;
    border-bottom: 3px solid #c7a03c;
}

.brand {
    color: #fff;
    font-weight: 700;
    white-space: nowrap;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-right: auto;
}

.nav a,
.user-menu a {
    color: #e8f3ef;
    padding: 8px 10px;
    border-radius: 6px;
}

.nav a:hover,
.user-menu a:hover {
    background: rgba(255, 255, 255, .1);
    text-decoration: none;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.page {
    width: min(1400px, calc(100vw - 32px));
    margin: 24px auto 40px;
}

.page-head,
.panel-head,
.toolbar,
.actions,
.form-actions,
.print-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.page-head {
    margin-bottom: 16px;
}

h1,
h2 {
    margin: 0;
    line-height: 1.2;
}

h1 {
    font-size: 28px;
}

h2 {
    font-size: 18px;
}

.muted,
.subline {
    color: var(--muted);
}

.subline {
    display: block;
    font-size: 12px;
}

.panel,
.metric,
.module {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}

.panel {
    padding: 18px;
    margin-bottom: 16px;
}

.warning-panel {
    border-color: #d6a20f;
    background: #fff8e6;
}

.metric-grid,
.module-grid,
.grid {
    display: grid;
    gap: 16px;
    margin-bottom: 16px;
}

.metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.module-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metric {
    padding: 16px;
}

.metric span,
.module span {
    display: block;
    color: var(--muted);
}

.metric strong {
    display: block;
    margin-top: 8px;
    font-size: 26px;
}

.module {
    display: block;
    padding: 18px;
}

.module strong {
    display: block;
    margin-bottom: 6px;
    color: var(--text);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    background: #eef3f1;
    color: #3b4642;
    font-weight: 700;
}

.row-actions {
    white-space: nowrap;
}

.row-actions a {
    margin-right: 8px;
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 22px;
}

.toolbar {
    justify-content: flex-start;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
}

label {
    display: grid;
    gap: 6px;
    font-weight: 700;
}

input,
select,
textarea,
button {
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid #cbd5d1;
    border-radius: 6px;
    padding: 9px 10px;
    background: #fff;
    color: var(--text);
}

textarea {
    resize: vertical;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 14px;
    border: 1px solid #b9c4bf;
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.button:hover {
    text-decoration: none;
    background: #f8faf9;
}

.button.primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.button.primary:hover {
    background: var(--primary-dark);
}

.button.danger {
    border-color: var(--danger);
    color: var(--danger);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.span-2 {
    grid-column: 1 / -1;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 400;
}

.check input {
    width: auto;
}

.document-counts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.department-picker {
    display: grid;
    gap: 12px;
}

.department-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.department-option {
    position: relative;
    display: grid;
    gap: 4px;
    min-height: 76px;
    padding: 14px 16px 14px 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8faf9;
    cursor: pointer;
}

.department-option input {
    position: absolute;
    top: 17px;
    left: 15px;
    width: auto;
}

.department-option span {
    font-size: 18px;
    font-weight: 800;
    color: var(--text);
}

.department-option small {
    color: var(--muted);
}

.department-option.is-selected,
.department-option:has(input:checked) {
    border-color: var(--primary);
    background: #eef7f1;
    box-shadow: inset 0 0 0 1px var(--primary);
}

.nested {
    border-top: 1px solid var(--line);
    padding-top: 16px;
}

.table-form {
    display: grid;
    grid-template-columns: repeat(5, minmax(120px, 1fr)) 44px;
    gap: 8px;
    align-items: center;
}

.compact-grid {
    margin-top: 12px;
}


.inline-search {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: min(460px, 100%);
}

.inline-search input {
    min-width: 260px;
}

.table-form-head {
    color: var(--muted);
    font-weight: 700;
    font-size: 13px;
}

output {
    min-height: 39px;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8faf9;
}

.totals {
    display: flex;
    justify-content: flex-end;
    gap: 18px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.totals span {
    color: var(--muted);
    margin-right: 5px;
}

.details {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 10px 14px;
}

.details dt {
    color: var(--muted);
    font-weight: 700;
}

.details dd {
    margin: 0;
}

.tag {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    background: #e7f5f1;
    color: #0f5f58;
    font-size: 12px;
    white-space: nowrap;
}

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    border: 1px solid var(--line);
}

.alert-success {
    background: var(--success-bg);
}

.alert-warning {
    background: var(--warn-bg);
}

.alert-error {
    background: var(--error-bg);
}

.auth-shell {
    display: grid;
    place-items: center;
    min-height: calc(100vh - 140px);
}

.login-panel {
    width: min(420px, 100%);
}

.diagnostics {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 24px;
    padding: 10px;
    border: 1px dashed #c7a03c;
    border-radius: 8px;
    background: #fffaf0;
    color: #51421f;
    font-size: 12px;
}

.diag-warn {
    color: var(--danger);
}

.report-number,
.report-money {
    font-size: 28px;
    font-weight: 700;
    margin: 8px 0 0;
}

.total-row td {
    font-weight: 700;
    background: #f8faf9;
}


.print-document,
.public-page {
    background: #fff;
    border: 1px solid var(--line);
    padding: 28px;
    border-radius: 8px;
}

.doc-head {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    border-bottom: 2px solid #17211e;
    padding-bottom: 16px;
    margin-bottom: 18px;
}

.standard-company,
.modern-company,
.classic-company {
    line-height: 1.35;
}

.standard-company h1,
.modern-company h1,
.classic-company h1 {
    margin: 0 0 6px;
    font-size: 24px;
    letter-spacing: 0;
}

.standard-company p,
.modern-company p,
.classic-company p {
    margin: 2px 0;
}

.doc-box {
    border: 1px solid var(--line);
    padding: 14px;
    margin-bottom: 18px;
}

.doc-table th,
.doc-table td {
    border: 1px solid var(--line);
}

.doc-total {
    width: min(360px, 100%);
    margin-left: auto;
    margin-top: 18px;
}

.doc-total div {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    padding: 7px 0;
}

.doc-foot {
    margin-top: 28px;
}

.signature {
    margin-left: auto;
    margin-top: 40px;
    width: 240px;
    border-top: 1px solid #333;
    text-align: center;
    padding-top: 8px;
}

.work-box div {
    height: 96px;
    border: 1px solid var(--line);
}

.classic-doc {
    font-family: "Courier New", "PMingLiU", monospace;
    color: #111;
    border-color: #777;
}

.classic-head {
    display: grid;
    grid-template-columns: 1fr 230px;
    gap: 18px;
    align-items: start;
    border-bottom: 1px dashed #333;
    padding-bottom: 10px;
}

.classic-company {
    text-align: center;
}

.classic-meta {
    text-align: right;
}

.classic-meta p,
.classic-company p,
.classic-customer div,
.classic-machine div {
    margin: 2px 0;
}

.classic-title {
    text-align: center;
    margin: 12px 0;
    text-decoration: underline;
}

.classic-customer,
.classic-machine,
.classic-work,
.classic-note {
    border-bottom: 1px dashed #333;
    padding: 10px 0;
}

.classic-machine {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 16px;
}

.classic-table {
    margin-top: 14px;
    border-collapse: collapse;
    width: 100%;
}

.classic-table th,
.classic-table td {
    border: 0;
    border-bottom: 1px dashed #333;
    padding: 7px 6px;
}

.classic-table th {
    background: transparent;
    color: #111;
}

.classic-work h3,
.modern-band h3,
.modern-grid h3 {
    margin: 0 0 10px;
}

.classic-work pre {
    min-height: 52px;
    white-space: pre-wrap;
    margin: 8px 0;
    font: inherit;
}

.classic-two-col {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 18px;
}

.classic-total {
    width: min(360px, 100%);
    margin: 18px 0 0 auto;
    text-align: right;
    font-weight: 700;
}

.classic-foot,
.modern-signatures {
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 24px;
    margin-top: 22px;
    break-inside: avoid;
}

.signature-line {
    border-top: 1px solid #333;
    margin-top: 26px;
    padding-top: 5px;
}

/* 蓋印參考框：跟客戶提供嘅實物尺寸（高 4.5cm／闊 6cm），
   左邊留 25mm 對齊公司名，等每次蓋印位置一致。 */
.chop-box {
    width: 60mm;
    height: 45mm;
    max-width: 100%;
    margin: 8px 0 0 25mm;
    border: 1px dashed #999;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 11px;
    letter-spacing: .1em;
}

/* 入數資料精簡版：印埋落同一張單度，唔使開多一版。 */
.payment-inline {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px dashed #999;
    font-size: 12.5px;
    line-height: 1.6;
    break-inside: avoid;
}

.payment-inline p { margin: 3px 0; }



.modern-head {
    display: grid;
    grid-template-columns: 1fr 330px;
    gap: 24px;
    align-items: start;
    border-bottom: 3px solid #17211e;
    padding-bottom: 18px;
    margin-bottom: 20px;
}

.modern-doc-meta {
    border-left: 1px solid var(--line);
    padding-left: 18px;
}

.modern-doc-meta dl {
    display: grid;
    grid-template-columns: 82px 1fr;
    gap: 8px 12px;
    margin: 12px 0 0;
}

.modern-doc-meta dt {
    color: var(--muted);
    font-weight: 700;
}

.modern-doc-meta dd {
    margin: 0;
}

.modern-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    margin-bottom: 18px;
}

.modern-band {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.wide-details {
    grid-template-columns: 130px 1fr;
}

.modern-signatures {
    grid-template-columns: repeat(3, 1fr);
}

.modern-signatures > div {
    min-height: 48px;
    border-top: 1px solid #333;
    padding-top: 6px;
}

.modern-signatures span {
    display: block;
    color: var(--muted);
}

.label-sheet {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.label {
    display: grid;
    gap: 4px;
    min-height: 120px;
    padding: 12px;
    border: 1px dashed #555;
    background: #fff;
}

@media screen and (max-width: 900px) {
    .topbar,
    .page-head,
    .panel-head {
        align-items: flex-start;
    }

    .topbar {
        position: static;
        flex-direction: column;
        padding: 14px;
        gap: 8px;
    }

    .metric-grid,
    .module-grid,
    .grid.two,
    .form-grid,
    .department-options,
    .lookup-grid,
    .label-sheet {
        grid-template-columns: 1fr;
    }

    .page {
        width: min(100vw - 20px, 1400px);
        margin-top: 14px;
    }


    .classic-head,
    .classic-machine,
    .classic-two-col,
    .classic-foot,
    .modern-head,
    .modern-grid,
    .modern-signatures {
        grid-template-columns: 1fr;
    }

    .modern-doc-meta {
        border-left: 0;
        padding-left: 0;
    }
}

@media print {
    @page {
        size: A4;
        margin: 12mm;
    }

    .topbar,
    .diagnostics,
    .print-actions,
    .page-head,
    .toolbar,
    .button {
        display: none !important;
    }

    body,
    .page {
        background: #fff;
        margin: 0;
        width: auto;
    }

    .panel,
    .print-document,
    .label {
        box-shadow: none;
        border: 0;
        border-radius: 0;
    }

    .print-document {
        padding: 0;
        page-break-after: always;
    }

    .print-document:last-child {
        page-break-after: auto;
    }

    .label-sheet {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ==========================================================================
   2026 易用性改版：導覽、列表、表單、分頁、可加行表格
   ========================================================================== */

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: #fff;
    padding: 10px 14px;
    z-index: 100;
}
.skip-link:focus { left: 8px; top: 8px; }

/* ── 導覽列 ───────────────────────────────────────────────────────────── */
.nav a.is-active {
    background: rgba(255, 255, 255, .16);
    font-weight: 700;
}

.nav-toggle {
    display: none;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .35);
    color: #fff;
    border-radius: 6px;
    padding: 7px 12px;
    cursor: pointer;
}

.topbar-search {
    flex: 0 1 320px;
    margin-left: auto;
}

.topbar-search input {
    background: rgba(255, 255, 255, .12);
    border-color: rgba(255, 255, 255, .28);
    color: #fff;
    padding: 7px 10px;
}

.topbar-search input::placeholder { color: rgba(255, 255, 255, .6); }
.topbar-search input:focus {
    background: #fff;
    color: var(--text);
    outline: 2px solid var(--primary);
}

.user-menu { position: relative; }

.user-button {
    display: grid;
    gap: 1px;
    text-align: left;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .25);
    border-radius: 6px;
    color: #fff;
    padding: 6px 12px;
    cursor: pointer;
    line-height: 1.25;
}
.user-button small { color: rgba(255, 255, 255, .7); font-size: 11px; }

/* hidden 屬性要贏過下面嘅 display，否則個選單一開始就會展開遮住其他掣。 */
.user-dropdown[hidden] {
    display: none;
}

.user-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 190px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .14);
    padding: 6px;
    z-index: 40;
    display: grid;
    gap: 2px;
}

.user-dropdown a,
.user-dropdown .linklike {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 12px;
    border-radius: 6px;
    color: var(--text);
}
.user-dropdown a:hover,
.user-dropdown .linklike:hover { background: #f1f5f4; text-decoration: none; }

.linklike {
    background: none;
    border: 0;
    color: var(--primary);
    cursor: pointer;
    font: inherit;
    padding: 0;
}

.app-foot {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    padding: 16px 24px 28px;
    color: var(--muted);
    font-size: 13px;
}

kbd {
    border: 1px solid var(--line);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 1px 5px;
    background: #fff;
    font-size: 11px;
}

/* ── 提示訊息 ─────────────────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.alert-close {
    background: none;
    border: 0;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    color: inherit;
    opacity: .55;
}
.alert-close:hover { opacity: 1; }

/* ── 指標卡 ───────────────────────────────────────────────────────────── */
a.metric { color: inherit; }
a.metric:hover { border-color: var(--primary); text-decoration: none; }
.metric.is-alert { border-color: var(--danger); background: #fff6f5; }
.metric.is-alert strong { color: var(--danger); }
.metric-grid.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric-grid.compact .metric { padding: 12px 14px; }
.metric-grid.compact strong { font-size: 20px; }

/* ── 表格 ─────────────────────────────────────────────────────────────── */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

th.num, td.num { text-align: right; }

.strong-link { font-weight: 700; }

tr.is-archived { opacity: .55; }
tr.is-archived td { background: #fafafa; }
tr.is-highlight td { background: #fff8e6; }

.text-danger { color: var(--danger); }
.text-warn { color: #9a6b00; }

.sort-link { color: inherit; white-space: nowrap; }
.sort-link.is-active { color: var(--primary); }

tfoot .total-row td { border-top: 2px solid var(--line); }

/* ── 分頁 ─────────────────────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding-top: 14px;
    margin-top: 6px;
    border-top: 1px solid var(--line);
    font-size: 14px;
}

.pagination-info { color: var(--muted); }
.pagination-size label { display: flex; align-items: center; gap: 6px; font-weight: 400; }
.pagination-size select { width: auto; padding: 5px 8px; }

.pagination-links {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.page-num {
    min-width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
}
.page-num:hover { background: #f1f5f4; text-decoration: none; }
.page-num.is-current {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 700;
}
.page-gap { padding: 0 4px; color: var(--muted); }
.button.is-disabled { opacity: .45; pointer-events: none; }

/* ── 表單 ─────────────────────────────────────────────────────────────── */
.narrow-form {
    width: min(560px, 100%);
    display: grid;
    gap: 16px;
}

.hint {
    font-weight: 400;
    font-size: 12px;
    color: var(--muted);
}

.field-error {
    display: block;
    font-weight: 400;
    font-size: 12px;
    color: var(--danger);
}

label.has-error input,
label.has-error select,
label.has-error textarea {
    border-color: var(--danger);
    background: #fffafa;
}

.inline-field {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
}
.inline-field input { width: auto; }

.toolbar-end { margin-left: auto; }

.sticky-actions {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to bottom, rgba(255, 255, 255, .6), #fff 40%);
    padding: 12px 0 2px;
    margin-top: 4px;
    z-index: 5;
}

.result-summary { color: var(--muted); margin: 0 0 12px; }

/* ── 可加行表格 ───────────────────────────────────────────────────────── */
.repeatable { display: grid; gap: 8px; }

.repeat-head { color: var(--muted); }
.repeat-row { align-items: center; }

.invoice-items,
.print-lines { display: grid; gap: 8px; }

.invoice-row {
    display: grid;
    grid-template-columns: minmax(200px, 2fr) minmax(120px, 1fr) 90px 110px 120px 44px;
    gap: 8px;
    align-items: center;
}

.print-line {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) 100px 120px 120px 44px;
    gap: 8px;
    align-items: center;
}

.lookup-rows { gap: 8px; }

.lookup-row {
    display: grid;
    grid-template-columns: minmax(140px, 1fr) 96px auto;
    gap: 8px;
    align-items: center;
}

.usage-count { font-size: 12px; color: var(--muted); white-space: nowrap; }

.icon-button {
    min-height: 34px;
    min-width: 34px;
    padding: 4px 8px;
    color: var(--muted);
}
.icon-button:hover { color: var(--danger); border-color: var(--danger); }

[data-add-row] { justify-self: start; margin-top: 4px; }

/* ── 可搜尋下拉 ───────────────────────────────────────────────────────── */
.searchable-select { display: grid; gap: 4px; }

.searchable-filter {
    font-size: 13px;
    padding: 6px 9px;
    background: #f8faf9;
}
.searchable-filter.has-no-match { border-color: var(--danger); }

/* ── 合計 ─────────────────────────────────────────────────────────────── */
.totals {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 22px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.total-line { display: flex; align-items: baseline; gap: 8px; }
.total-line span { color: var(--muted); }
.total-line strong { font-size: 16px; }
.total-line.big strong { font-size: 22px; }

/* ── 危險操作 / 作廢 ──────────────────────────────────────────────────── */
.danger-zone { border-color: #f0c4c0; background: #fffaf9; }
.danger-zone h2 { color: var(--danger); }

.void-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 10px;
}
.void-form input { width: min(360px, 100%); }

.inline-void summary { cursor: pointer; color: var(--danger); }
.inline-void form {
    display: grid;
    gap: 6px;
    margin-top: 8px;
    min-width: 220px;
}

.inline-form { display: inline; }

.plain-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.archived-block { margin-top: 14px; }
.archived-block summary { cursor: pointer; color: var(--muted); }

.empty-state { text-align: center; padding: 40px 20px; }
.empty-state .actions { justify-content: center; margin-top: 16px; }

.small { font-size: 12px; }

/* ── 公開 CMS 頁 ──────────────────────────────────────────────────────── */
.public-topbar {
    display: flex;
    align-items: center;
    min-height: 56px;
    padding: 0 24px;
    background: #17211e;
    border-bottom: 3px solid #c7a03c;
}

.public-page { max-width: 760px; margin: 0 auto; }
.public-body p { line-height: 1.8; }

/* ── 手機 ─────────────────────────────────────────────────────────────── */
@media screen and (max-width: 900px) {
    .nav-toggle { display: block; }

    .nav {
        display: none;
        width: 100%;
        flex-direction: column;
    }
    .nav.is-open { display: flex; }

    .topbar-search { flex: 1 1 100%; margin-left: 0; }
    .user-menu { width: 100%; }
    .user-button { width: 100%; }

    .invoice-row,
    .print-line,
    .table-form,
    .lookup-row {
        grid-template-columns: 1fr 1fr;
    }

    .invoice-row > *:first-child,
    .print-line > *:first-child,
    .table-form > *:first-child {
        grid-column: 1 / -1;
    }

    .repeat-head { display: none; }

    .repeat-row {
        border: 1px solid var(--line);
        border-radius: 8px;
        padding: 10px;
        background: #fbfdfc;
    }

    /* 列表變成卡片，唔使打橫捲 */
    .data-table thead { display: none; }
    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td { display: block; width: 100%; }

    .data-table tr {
        border: 1px solid var(--line);
        border-radius: 8px;
        margin-bottom: 10px;
        padding: 6px 10px;
        background: #fff;
    }

    .data-table td {
        border: 0;
        padding: 6px 0;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: baseline;
        gap: 4px 12px;
        text-align: right;
    }

    .data-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 12px;
        text-align: left;
        flex: 0 0 auto;
        white-space: nowrap;
    }

    /* 副標題（區份、聯絡人等）自己佔一行，唔好被擠成直行 */
    .data-table td .subline {
        flex: 1 0 100%;
        text-align: right;
    }

    .data-table td .tag {
        flex: 0 0 auto;
    }

    .data-table td:not([data-label]) { justify-content: flex-end; }
    .data-table td.num { text-align: right; }
    .data-table tfoot tr { background: #f8faf9; }

    .pagination { flex-direction: column; align-items: stretch; }
    .sticky-actions { position: static; }
}

@media print {
    .no-print,
    .app-foot,
    .public-topbar,
    .pagination,
    .alert,
    .skip-link,
    .doc-meta-bar,
    .danger-zone {
        display: none !important;
    }
}

/* ==========================================================================
   列印：一張單盡量印一張紙
   ========================================================================== */

.tight th,
.tight td { padding: 5px 7px; }

.meter-band .meter-head { margin-bottom: 8px; }
.meter-table td,
.meter-table th { white-space: nowrap; }

.modern-footnote {
    margin: 10px 0 0;
    font-size: 12px;
    color: var(--muted);
}

@media print {
    @page {
        size: A4;
        margin: 10mm;
    }

    html, body {
        background: #fff;
        font-size: 11.5px;
        line-height: 1.32;
    }

    .page {
        width: 100%;
        margin: 0;
    }

    .print-document {
        border: 0;
        padding: 0;
        border-radius: 0;
    }

    /* 區塊之間收窄，唔好無端端逼到第二頁 */
    .modern-head {
        gap: 14px;
        padding-bottom: 8px;
        margin-bottom: 10px;
        border-bottom-width: 2px;
    }

    .modern-grid {
        gap: 14px;
        margin-bottom: 8px;
    }

    .modern-band {
        margin-top: 8px;
        padding-top: 7px;
    }

    .modern-band h3,
    .modern-grid h3 {
        margin-bottom: 4px;
        font-size: 12.5px;
    }

    .modern-doc-meta dl,
    .details {
        gap: 2px 10px;
    }

    .details { grid-template-columns: 74px 1fr; }
    .wide-details { grid-template-columns: 92px 1fr; }

    .modern-doc-meta { padding-left: 12px; }

    .standard-company h1,
    .modern-company h1,
    .classic-company h1 { font-size: 17px; margin-bottom: 3px; }

    .modern-doc-meta h2 { font-size: 15px; }

    th, td { padding: 4px 6px; }

    /* 表格同區塊唔好喺中間斷開 */
    .modern-band,
    .modern-grid,
    .classic-machine,
    .classic-customer,
    .meter-band,
    table { page-break-inside: avoid; }

    tr { page-break-inside: avoid; }

    .modern-signatures,
    .classic-foot {
        margin-top: 14px;
        gap: 16px;
        page-break-inside: avoid;
    }

    .modern-signatures > div { min-height: 40px; padding-top: 4px; }

    /* 蓋章框保持實物尺寸（高 4.5cm／闊 6cm），列印先夾到實際印章。 */
    .chop-box { font-size: 9.5px; }

    .payment-inline {
        margin-top: 10px;
        padding-top: 8px;
        font-size: 10.5px;
    }

    .classic-work pre { min-height: 40px; }
    .classic-customer,
    .classic-machine,
    .classic-work,
    .classic-note { padding: 6px 0; }
    .classic-title { margin: 8px 0; }
    .signature-line { margin-top: 20px; }

    /* 列印一定要保持雙欄同表格外觀（唔可以跌落手機版卡片式）*/
    .modern-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .label-sheet { grid-template-columns: repeat(3, 1fr); }

    .data-table thead { display: table-header-group; }
    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: revert;
        width: auto;
    }
    .data-table tr { border: 0; margin: 0; padding: 0; background: transparent; }
    .data-table td { border-bottom: 1px solid var(--line); text-align: left; }
    .data-table td.num { text-align: right; }
    .data-table td::before { content: none; }
    .data-table td .subline { display: block; text-align: left; }

    /* 最後一段唔好孤零零帶起新一頁 */
    h3 { break-after: avoid; }
}

/* ── 抄錶收費 ─────────────────────────────────────────────────────────── */
.meter-input-grid {
    display: grid;
    grid-template-columns: 56px repeat(6, minmax(0, 1fr));
    gap: 8px;
    align-items: center;
}

.meter-row-label {
    font-weight: 700;
    color: var(--muted);
}

.meter-input-grid output {
    text-align: right;
    background: #f1f5f4;
}

.meter-warning {
    margin: 12px 0 0;
    padding: 10px 12px;
    border-radius: 6px;
    background: var(--warn-bg);
    border: 1px solid #d6a20f;
    color: #7a5200;
}

.meter-totals { margin-top: 14px; }

.check-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
    align-items: center;
}

.doc-hint {
    grid-column: 1 / -1;
    margin: 0;
    padding: 10px 12px;
    border-radius: 6px;
    background: #eef7f4;
    border: 1px solid #bcdcd4;
    color: #16544c;
    font-size: 13px;
}

@media screen and (max-width: 900px) {
    .meter-input-grid {
        grid-template-columns: 1fr 1fr;
    }
    .meter-row-label {
        grid-column: 1 / -1;
        margin-top: 8px;
        color: var(--text);
    }
}

/* ── 發票 ↔ 單據關聯提示 ─────────────────────────────────────────────── */
.note-banner {
    margin: 0 0 16px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #eef7f4;
    border: 1px solid #bcdcd4;
    color: #16544c;
    font-size: 14px;
}
.note-banner a { font-weight: 700; }
.note-banner.is-muted {
    background: #f1f4f3;
    border-color: var(--line);
    color: var(--muted);
}
