:root {
    --ink: #071327;
    --muted: #667085;
    --line: #e5eaf2;
    --green: #13a463;
    --green2: #20d68b;
    --bg: #f5fbf8;
    --card: #ffffff;
    --danger: #e11d48;
    --warn: #d97706;
    --soft: #f3f6fa;
    --soft-green: #e9f9f2;
    --radius: 16px;
    --shadow: 0 14px 36px rgba(7, 19, 39, 0.06);
}

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

body {
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: linear-gradient(180deg, #f4fbf8 0%, #f7f9fc 45%, #fff 100%);
    color: var(--ink);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.shell {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 16px 24px;
}

.shell-main {
    min-height: 40vh;
}

.powered-by {
    margin: 28px 0 8px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    letter-spacing: 0.01em;
}

/* ── Mobile bottom nav (from Sunpal WordPress / portal-bottom-nav) ── */
.bottom {
    display: none;
}

@media (pointer: coarse) {
    .bottom a {
        min-height: 44px;
    }
}

@media (max-width: 720px) {
    .shell {
        padding-bottom: calc(88px + env(safe-area-inset-bottom));
    }

    body.is-login .shell {
        padding-bottom: calc(24px + env(safe-area-inset-bottom));
    }

    .nav a.hide-sm {
        display: none;
    }

    .bottom {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        display: flex;
        justify-content: space-around;
        align-items: center;
        min-height: calc(56px + env(safe-area-inset-bottom));
        padding: 4px 8px calc(8px + env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
        border-top: 1px solid var(--line);
        box-shadow: 0 -4px 16px rgba(7, 19, 39, 0.06);
    }

    .bottom a {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        padding: 6px 12px;
        border-radius: 10px;
        color: var(--muted);
        font-size: 10px;
        font-weight: 700;
        letter-spacing: 0.02em;
        text-decoration: none;
        transition: color 0.15s;
        -webkit-tap-highlight-color: transparent;
    }

    .bottom a svg {
        width: 22px;
        height: 22px;
        stroke-width: 1.8;
    }

    .bottom a.active,
    .bottom a:hover {
        color: var(--green);
    }
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    margin: 0 -16px;
    padding: 0 16px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(18px);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 900;
    letter-spacing: -0.04em;
    font-size: 18px;
}

.brand span {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, var(--green), var(--green2));
    font-size: 13px;
}

.nav {
    display: flex;
    gap: 8px;
    align-items: center;
}

.nav a,
.nav button {
    border: 0;
    background: transparent;
    cursor: pointer;
    font: inherit;
    font-weight: 800;
    padding: 8px 12px;
    border-radius: 999px;
    color: var(--ink);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 12px;
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 800;
    font: inherit;
    font-size: 13px;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, #06934f, var(--green));
    color: #fff;
    box-shadow: 0 10px 24px rgba(19, 164, 99, 0.22);
}

.btn-dark { background: var(--ink); color: #fff; }
.btn-soft {
    background: var(--soft-green);
    color: #067647;
    border-color: #b7eed4;
}
.btn-ghost {
    background: #fff;
    color: var(--ink);
    border-color: var(--line);
}
.btn-danger {
    background: #fff;
    color: var(--danger);
    border-color: #fecdd3;
}
.btn-sm {
    min-height: 36px;
    padding: 0 12px;
    font-size: 12px;
    border-radius: 10px;
}

.card {
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.kicker {
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 11px;
    font-weight: 900;
    color: var(--green);
}

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

.pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 9px;
    border-radius: 999px;
    background: var(--soft);
    font-size: 11px;
    font-weight: 850;
    color: #4b5563;
    text-transform: lowercase;
    letter-spacing: 0.01em;
}

.pill.ok,
.pill.paid { background: var(--soft-green); color: var(--green); }
.pill.warn,
.pill.processing { background: #fff7ed; color: var(--warn); }
.pill.bad,
.pill.unpaid,
.pill.overdue { background: #ffeef3; color: var(--danger); }
.pill.voided { background: var(--soft); color: var(--muted); }

.page-head {
    margin: 18px 0 14px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.page-head h1 {
    margin: 6px 0 0;
    font-size: clamp(28px, 5vw, 40px);
    letter-spacing: -0.06em;
    line-height: 1;
}

.filters {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: end;
    margin-bottom: 14px;
}

.field { margin-bottom: 0; }

.stack {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

label {
    display: block;
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    font-weight: 900;
    color: #7b8794;
    margin-bottom: 6px;
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0 12px;
    font: inherit;
    font-weight: 700;
    background: #fff;
    color: var(--ink);
}

input[type="checkbox"],
input[type="radio"] {
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    padding: 0;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--green);
}

input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus {
    outline: 2px solid #b7eed4;
    border-color: var(--green);
}

.login-wrap {
    display: flex;
    justify-content: center;
    padding: 28px 0 8px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 24px 22px 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-card h1 {
    margin: 0;
    font-size: clamp(28px, 5vw, 36px);
    letter-spacing: -0.06em;
    line-height: 1;
}

.login-lead {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    font-weight: 650;
    line-height: 1.45;
}

.login-remember {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 10px;
    margin: 2px 0 0;
    text-transform: none;
    letter-spacing: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--ink);
    cursor: pointer;
}

.login-remember span {
    color: var(--ink);
    text-transform: none;
    letter-spacing: 0;
    font-size: 14px;
    font-weight: 700;
}

.login-card input[type="checkbox"] {
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    max-width: 18px;
    appearance: auto;
    -webkit-appearance: checkbox;
}

.login-submit {
    width: 100%;
    min-height: 48px;
}

.login-demo {
    margin: 4px 0 0;
    padding: 14px;
    border: 1px dashed #b7eed4;
    border-radius: 14px;
    background: var(--soft-green);
}

.login-demo .kicker {
    margin: 0 0 4px;
}

.login-demo-title {
    margin: 0 0 10px;
    font-size: 14px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.login-demo-creds {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 0 0 12px;
}

.login-demo-creds dt {
    margin: 0;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 900;
    color: #7b8794;
}

.login-demo-creds dd {
    margin: 4px 0 0;
}

.login-demo-creds code {
    display: block;
    padding: 8px 10px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid var(--line);
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.01em;
}

.login-demo-fill {
    width: 100%;
}

body.is-login .shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

body.is-login .shell-main {
    flex: 1;
}

/* ── Admin bill list ─────────────────────────────────────────── */

.bill-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bill-item {
    min-width: 0;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 14px;
    box-shadow: 0 8px 24px rgba(7, 19, 39, 0.04);
    animation: bill-in 0.35s ease both;
}

.bill-item:nth-child(2) { animation-delay: 0.04s; }
.bill-item:nth-child(3) { animation-delay: 0.08s; }
.bill-item:nth-child(4) { animation-delay: 0.12s; }
.bill-item:nth-child(5) { animation-delay: 0.16s; }

@keyframes bill-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.bill-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}

.bill-period {
    font-size: 13px;
    font-weight: 850;
    color: var(--muted);
    letter-spacing: -0.01em;
}

.bill-unit {
    margin: 0;
    font-size: 16px;
    font-weight: 900;
    letter-spacing: -0.03em;
    line-height: 1.25;
    color: var(--ink);
}

.bill-due {
    margin-top: 4px;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
}

.bill-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.bill-tenant {
    font-size: 14px;
    font-weight: 800;
    letter-spacing: -0.02em;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bill-amount {
    font-size: 18px;
    font-weight: 1000;
    letter-spacing: -0.04em;
    white-space: nowrap;
}

.bill-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.bill-actions form {
    display: inline;
    margin: 0;
}

/* Desktop table view */
.bill-table-wrap {
    display: none;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

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

.bill-table th,
.bill-table td {
    text-align: left;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.bill-table tr:last-child td { border-bottom: 0; }

.bill-table th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    background: #fafbfd;
    font-weight: 850;
}

.bill-table .cell-unit {
    font-weight: 900;
    letter-spacing: -0.02em;
    line-height: 1.3;
}

.bill-table .cell-unit small {
    display: block;
    margin-top: 3px;
    font-weight: 700;
    color: var(--muted);
    font-size: 12px;
}

.bill-table .cell-amount {
    font-weight: 1000;
    letter-spacing: -0.03em;
    white-space: nowrap;
}

.bill-table .cell-actions {
    white-space: nowrap;
}

.bill-table .cell-actions .bill-actions {
    margin-top: 0;
    flex-wrap: nowrap;
}

.empty {
    text-align: center;
    color: var(--muted);
    font-weight: 750;
    padding: 36px 12px;
}

/* Users list reuses bill card/table patterns */
.user-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.user-table-wrap {
    display: none;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.user-delete-form {
    display: inline;
    margin: 0;
}

.flash {
    margin: 14px 0;
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--soft-green);
    color: #067647;
    font-weight: 800;
    font-size: 14px;
}

.flash.error {
    background: #ffeef3;
    color: #be123c;
}

@media (min-width: 860px) {
    .shell {
        padding: 0 28px 40px;
    }

    .topbar {
        height: auto;
        min-height: 64px;
        margin: 0 -28px;
        padding: 10px 28px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .nav {
        flex-wrap: wrap;
        justify-content: flex-end;
        max-width: min(100%, 820px);
    }

    .bill-list {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
        gap: 14px;
    }

    /* Keep compact cards off screen when a real table exists. */
    .bill-list:has(+ .bill-table-wrap),
    .user-list:has(+ .user-table-wrap) {
        display: none;
    }

    .bill-table-wrap,
    .user-table-wrap {
        display: block;
        overflow-x: auto;
    }

    .filters {
        grid-template-columns: 1.4fr 180px 140px auto;
    }

    .filters:has(select#role) {
        grid-template-columns: 1.4fr 180px auto;
    }
}

@media (max-width: 859px) {
    .nav a.hide-sm { display: none; }

    .filters {
        grid-template-columns: 1fr;
    }

    .filters .btn {
        width: 100%;
    }
}

/* ── Agreement signatures ─────────────────────────────────────── */
.agreement-doc {
    margin-bottom: 14px;
}

.agreement-body {
    font-size: 14px;
    line-height: 1.55;
    color: var(--ink);
}

.agreement-body h2,
.agreement-body h3 {
    margin: 1.2em 0 0.45em;
    font-size: 15px;
    letter-spacing: -0.02em;
}

.agreement-body p {
    margin: 0 0 0.85em;
}

.agreement-signatures {
    margin-top: 28px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.agreement-signatures h2,
.signature-summary-title,
.sign-pad h2 {
    margin: 0 0 8px;
    font-size: 16px;
    letter-spacing: -0.02em;
}

.agreement-signatures-note,
.sign-pad-note {
    margin: 0 0 16px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
    font-weight: 600;
}

.signature-marks {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

@media (min-width: 640px) {
    .signature-marks {
        grid-template-columns: 1fr 1fr;
    }
}

.signature-mark {
    margin: 0;
}

.signature-mark-canvas {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 112px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}

.signature-mark-canvas img {
    display: block;
    width: 100%;
    max-width: 320px;
    height: auto;
    max-height: 120px;
    object-fit: contain;
}

.signature-typed {
    font-family: "Segoe Script", "Apple Chancery", "Comic Sans MS", cursive;
    font-size: 28px;
    line-height: 1.2;
    color: var(--ink);
    transform: rotate(-4deg);
}

.signature-mark figcaption {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--muted);
    font-weight: 700;
}

.signature-mark figcaption strong {
    color: var(--ink);
    font-weight: 850;
}

.signature-empty {
    margin: 0;
    color: var(--muted);
    font-weight: 700;
    font-size: 13px;
}

.signature-summary {
    margin-bottom: 14px;
}

.signature-summary-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.signature-summary-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
    padding: 10px 0;
    border-top: 1px solid var(--line);
    font-size: 13px;
}

.signature-summary-list li:first-child {
    border-top: 0;
    padding-top: 4px;
}

.signature-summary-list .muted {
    color: var(--muted);
    font-weight: 650;
}

.signature-summary-list time {
    color: var(--muted);
    font-weight: 700;
    white-space: nowrap;
}

.sign-pad {
    margin-bottom: 14px;
}

.sign-pad-frame {
    border: 1px dashed #b7c2d0;
    border-radius: 14px;
    overflow: hidden;
    background: #fff;
    touch-action: none;
}

.sign-pad-frame canvas {
    display: block;
    width: 100%;
    height: auto;
    cursor: crosshair;
    touch-action: none;
}

.sign-pad-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.field-error {
    margin: 10px 0 0;
    color: var(--danger);
    font-size: 13px;
    font-weight: 750;
}

.agreement-footer-nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 8px 0 20px;
}

[x-cloak] { display: none !important; }

/* ── MyKad / NRIC scan ─────────────────────────────────────────── */
.ic-scan {
    margin-bottom: 16px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--soft);
}

.ic-scan-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.ic-scan h2 {
    margin: 0 0 6px;
    font-size: 15px;
    letter-spacing: -0.02em;
}

.ic-scan-note,
.field-hint,
.ic-scan-status {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
    font-weight: 650;
}

.ic-scan-preview {
    margin-top: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    background: #fff;
}

.ic-scan-preview img {
    display: block;
    width: 100%;
    max-height: 220px;
    object-fit: contain;
}

.ic-scan-status {
    margin-top: 10px;
    color: #067647;
    font-weight: 750;
}

.field-hint {
    margin-top: 6px;
}

.invite-share h2 {
    margin: 0 0 6px;
    font-size: 16px;
    letter-spacing: -0.02em;
}

.invite-link {
    width: 100%;
    margin: 12px 0 4px;
    font-size: 13px;
}

/* SESCO pay instructions (tenant) */
.sesco-pay-card {
    margin: 0 0 16px;
    padding: 16px;
    border-radius: 16px;
    border: 1px solid #cfe8d8;
    background: linear-gradient(180deg, #f3fbf6 0%, #ffffff 70%);
}
.sesco-kicker {
    margin: 0 0 4px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #13a463;
}
.sesco-pay-card h2 {
    margin: 0 0 6px;
    font-size: 1.2rem;
    letter-spacing: -0.03em;
}
.sesco-lead {
    margin: 0 0 14px;
    color: var(--muted);
    font-size: 0.95rem;
}
.sesco-account-block {
    margin: 0 0 12px;
    padding: 12px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--line);
}
.sesco-unit-label {
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 6px;
}
.sesco-number-label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
}
.sesco-number {
    display: block;
    font-size: clamp(1.35rem, 4vw, 1.7rem);
    letter-spacing: 0.04em;
    font-variant-numeric: tabular-nums;
    color: #071327;
    word-break: break-all;
}
.sesco-copy { margin-top: 10px; }
.sesco-steps {
    margin: 14px 0 0;
    padding-left: 1.2rem;
    color: var(--ink);
    display: grid;
    gap: 6px;
    font-size: 0.95rem;
}
.sesco-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}
.sesco-owner-form {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}
.sesco-owner-label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
}
.sesco-owner-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.sesco-owner-row input {
    flex: 1;
    min-width: 0;
}
