:root {
    --bg: #f3efe8;
    --bg-soft: #fbf8f2;
    --surface: rgba(255, 252, 247, 0.92);
    --surface-strong: #fffdfa;
    --surface-muted: #f5f0e8;
    --sidebar: #31433e;
    --sidebar-strong: #24322f;
    --sidebar-muted: #d2ddd4;
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --text: #26322d;
    --text-soft: #6b766f;
    --text-strong: #1f2824;
    --primary: #4f8c7a;
    --primary-strong: #3c7564;
    --secondary: #db8b55;
    --accent: #d8b44a;
    --success: #3f8a59;
    --danger: #bd6460;
    --warning: #c99942;
    --info: #427f94;
    --border: #ded6ca;
    --shadow-lg: 0 22px 52px rgba(49, 57, 52, 0.12);
    --shadow-md: 0 12px 28px rgba(49, 57, 52, 0.08);
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 10px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
}

body {
    font-family: "Noto Sans Thai", "Tahoma", "Segoe UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(79, 140, 122, 0.18), transparent 30%),
        radial-gradient(circle at 85% 18%, rgba(219, 139, 85, 0.17), transparent 20%),
        radial-gradient(circle at bottom right, rgba(216, 180, 74, 0.14), transparent 24%),
        linear-gradient(180deg, var(--bg-soft) 0%, var(--bg) 100%);
    line-height: 1.6;
}

a {
    color: inherit;
}

.app-body {
    min-height: 100vh;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px 1fr;
    transition: grid-template-columns 0.24s ease;
}

.app-body.sidebar-collapsed .app-shell {
    grid-template-columns: 92px 1fr;
}

.app-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 28px 22px;
    background:
        radial-gradient(circle at top right, rgba(255, 255, 255, 0.12), transparent 22%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 18%),
        linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-strong) 100%);
    color: #f8f4ef;
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    gap: 28px;
    z-index: 40;
    transition: width 0.24s ease, padding 0.24s ease, transform 0.24s ease;
}

.sidebar-topbar {
    display: flex;
    justify-content: flex-end;
}

.sidebar-toggle {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.06));
    color: inherit;
    box-shadow: 0 10px 18px rgba(11, 20, 18, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    position: relative;
    overflow: hidden;
}

.sidebar-toggle span {
    display: block;
    position: absolute;
    left: 50%;
    width: 16px;
    height: 2px;
    background: currentColor;
    border-radius: 999px;
    transform: translateX(-50%);
    transition: transform 0.22s ease, width 0.22s ease, opacity 0.18s ease, background-color 0.18s ease;
}

.sidebar-toggle span:nth-child(1) {
    top: 14px;
}

.sidebar-toggle span:nth-child(2) {
    top: 21px;
}

.sidebar-toggle span:nth-child(3) {
    top: 28px;
}

.sidebar-toggle:hover {
    transform: translateY(-1px);
    border-color: rgba(255, 255, 255, 0.22);
}

.sidebar-toggle:hover span:nth-child(1),
.sidebar-toggle:hover span:nth-child(3) {
    width: 18px;
}

.sidebar-toggle:focus-visible {
    outline: none;
    box-shadow:
        0 10px 18px rgba(11, 20, 18, 0.16),
        inset 0 1px 0 rgba(255, 255, 255, 0.10),
        0 0 0 3px rgba(216, 180, 74, 0.24);
}

.sidebar-toggle-desktop {
    display: inline-flex;
}

.sidebar-toggle-mobile {
    display: none;
    margin-bottom: 8px;
    color: var(--text-strong);
    background: rgba(255, 253, 250, 0.9);
    border-color: var(--border);
    box-shadow: 0 8px 18px rgba(35, 48, 43, 0.08);
}

.sidebar-toggle-mobile:hover {
    border-color: #d3c7b8;
}

.app-body.sidebar-collapsed .sidebar-toggle-desktop {
    background: linear-gradient(135deg, rgba(216, 180, 74, 0.18), rgba(255, 255, 255, 0.08));
}

.app-body.sidebar-collapsed .sidebar-toggle-desktop span:nth-child(1) {
    width: 11px;
    top: 16px;
    transform: translateX(-50%) translateX(-2px) rotate(45deg);
}

.app-body.sidebar-collapsed .sidebar-toggle-desktop span:nth-child(2) {
    opacity: 0;
    width: 0;
}

.app-body.sidebar-collapsed .sidebar-toggle-desktop span:nth-child(3) {
    width: 11px;
    top: 24px;
    transform: translateX(-50%) translateX(-2px) rotate(-45deg);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-badge {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    font-size: 1.25rem;
    font-weight: 800;
    color: #fffdfa;
    background: linear-gradient(135deg, #e3a56c 0%, #4f8c7a 100%);
    box-shadow: 0 14px 28px rgba(24, 39, 31, 0.22);
}

.brand-title {
    font-size: 1.05rem;
    font-weight: 700;
}

.brand-subtitle {
    color: var(--sidebar-muted);
    font-size: 0.88rem;
}

.sidebar-nav {
    display: grid;
    gap: 10px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    color: #e4ece7;
    text-decoration: none;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.sidebar-nav a:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    transform: translateX(2px);
}

.sidebar-nav a span:last-child,
.brand-title,
.brand-subtitle,
.sidebar-user-name,
.sidebar-user-role,
.sidebar-logout {
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.sidebar-nav a.active {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(216, 180, 74, 0.10));
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.nav-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    font-size: 0.72rem;
    font-weight: 700;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.08));
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 14px;
}

.sidebar-user-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.12);
}

.sidebar-user-name {
    font-weight: 600;
}

.sidebar-user-role {
    color: var(--sidebar-muted);
    font-size: 0.88rem;
}

.sidebar-logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border-radius: 12px;
    background: rgba(213, 126, 116, 0.14);
    color: #f7d9d3;
    text-decoration: none;
    font-weight: 600;
}

.app-body.sidebar-collapsed .app-sidebar {
    padding-left: 14px;
    padding-right: 14px;
}

.app-body.sidebar-collapsed .sidebar-brand,
.app-body.sidebar-collapsed .sidebar-user-card {
    justify-content: center;
}

.app-body.sidebar-collapsed .sidebar-topbar {
    justify-content: center;
}

.app-body.sidebar-collapsed .sidebar-nav a {
    justify-content: center;
    padding-left: 10px;
    padding-right: 10px;
}

.app-body.sidebar-collapsed .sidebar-nav a span:last-child,
.app-body.sidebar-collapsed .brand-title,
.app-body.sidebar-collapsed .brand-subtitle,
.app-body.sidebar-collapsed .sidebar-user-name,
.app-body.sidebar-collapsed .sidebar-user-role,
.app-body.sidebar-collapsed .sidebar-logout {
    opacity: 0;
    transform: translateX(-8px);
    width: 0;
    overflow: hidden;
    pointer-events: none;
}

.app-main {
    padding: 30px;
}

.content-container {
    max-width: 1320px;
    margin: 0 auto;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 26px;
}

.page-title-block {
    display: grid;
    gap: 6px;
}

.app-sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(31, 40, 36, 0.30);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.24s ease;
    z-index: 30;
}

.app-body.sidebar-open .app-sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.page-kicker {
    color: var(--primary-strong);
    font-size: 0.82rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.page-kicker::before {
    content: "";
    width: 28px;
    height: 2px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
}

.page-title {
    font-size: 2rem;
    line-height: 1.15;
    color: var(--text-strong);
}

.page-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.container,
main {
    width: 100%;
}

.card,
.stat-card,
.invoice-container {
    background: var(--surface);
    border: 1px solid rgba(222, 214, 202, 0.9);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(10px);
    position: relative;
}

.card::before,
.stat-card::before,
.invoice-container::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    background: linear-gradient(90deg, var(--primary) 0%, var(--secondary) 55%, var(--accent) 100%);
    opacity: 0.92;
}

.card {
    padding: 22px;
    margin-bottom: 18px;
}

.card-header {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-strong);
}

.card-body {
    padding: 0;
}

.section-grid,
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.dashboard-grid > * {
    grid-column: span 3;
}

.dashboard-grid.dashboard-summary > * {
    grid-column: span 4;
}

.stat-card {
    position: relative;
    overflow: hidden;
    padding: 22px;
    min-height: 148px;
}

.stat-card::after {
    content: "";
    position: absolute;
    inset: auto -18px -18px auto;
    width: 92px;
    height: 92px;
    border-radius: 999px;
    opacity: 0.08;
    background: currentColor;
}

.stat-card h3 {
    color: var(--text-soft);
    font-size: 0.88rem;
    margin-bottom: 12px;
}

.stat-number {
    font-size: clamp(2rem, 3vw, 2.8rem);
    line-height: 1;
    font-weight: 800;
    color: inherit;
}

.stat-card.tenants {
    color: #4f8c7a;
}

.stat-card.invoices {
    color: #db8b55;
}

.stat-card.paid {
    color: #3f8a59;
}

.stat-card.unpaid {
    color: #bd6460;
}

button,
.btn,
a.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 16px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.96rem;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease, color 0.18s ease;
}

button:hover,
.btn:hover,
a.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
    color: #fffdfa;
    box-shadow: 0 10px 18px rgba(90, 118, 104, 0.18);
}

.btn-secondary {
    background: linear-gradient(135deg, #e19b68 0%, #cf7f49 100%);
    color: #fffdfa;
}

.btn-success {
    background: linear-gradient(135deg, #58a16e 0%, #3f8a59 100%);
    color: #fffdfa;
}

.btn-danger {
    background: linear-gradient(135deg, #d77b76 0%, #bd6460 100%);
    color: #fffdfa;
}

.btn-warning {
    background: linear-gradient(135deg, #e1bf67 0%, #c99942 100%);
    color: #473318;
}

.btn-light {
    background: rgba(255, 253, 250, 0.95);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-sm {
    min-height: 38px;
    padding: 0 12px;
    font-size: 0.88rem;
    border-radius: 10px;
}

.btn-group,
.toolbar-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.inline-form {
    display: inline-flex;
    margin: 0;
}

.bulk-selection-bar,
.bulk-print-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.bulk-selection-summary {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.selection-pill {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 14px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(79, 140, 122, 0.16), rgba(219, 139, 85, 0.14));
    color: var(--text-strong);
    font-weight: 700;
}

.bulk-selection-text {
    color: var(--text-soft);
    font-size: 0.95rem;
}

.checkbox-cell {
    width: 48px;
    text-align: center;
}

.checkbox-cell input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

.bulk-mode-select {
    width: 150px;
    min-width: 150px;
    max-width: 150px;
}

.invoice-stack {
    display: grid;
    gap: 24px;
}

.invoice-sheet {
    margin-bottom: 0;
}

.form-group {
    margin-bottom: 18px;
}

label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-strong);
    font-weight: 600;
}

input[type="text"],
input[type="email"],
input[type="phone"],
input[type="number"],
input[type="date"],
input[type="month"],
input[type="password"],
select,
textarea {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 0.98rem;
    font-family: inherit;
    background: var(--surface-strong);
    color: var(--text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #9eb5a7;
    box-shadow: 0 0 0 4px rgba(136, 161, 146, 0.18);
}

textarea {
    min-height: 120px;
    resize: vertical;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 18px;
}

.form-grid .col-6 {
    grid-column: span 6;
}

.form-grid .col-12 {
    grid-column: span 12;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: #f1ebe2;
}

th {
    padding: 14px 16px;
    text-align: left;
    font-size: 0.84rem;
    font-weight: 700;
    color: #5f675f;
}

td {
    padding: 16px;
    border-top: 1px solid #ece4d9;
    vertical-align: top;
}

tbody tr:nth-child(even) {
    background: rgba(250, 247, 242, 0.7);
}

tbody tr:hover {
    background: linear-gradient(90deg, rgba(79, 140, 122, 0.06), rgba(219, 139, 85, 0.05));
}

.table-wrap {
    overflow-x: auto;
}

.alert {
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-success {
    background: #edf5ee;
    color: #2f5f3a;
    border-color: #c7dec9;
}

.alert-danger {
    background: #fbefee;
    color: #8a3e38;
    border-color: #e7c1bc;
}

.alert-warning {
    background: #faf3e6;
    color: #875f20;
    border-color: #e8d2aa;
}

.alert-info {
    background: #edf4f6;
    color: #315f6e;
    border-color: #c8dade;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0 12px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
}

.badge-success {
    background: linear-gradient(135deg, #d8f0df, #e8f6ec);
    color: #2f6b42;
}

.badge-danger {
    background: linear-gradient(135deg, #f6dedd, #fbebea);
    color: #93443e;
}

.badge-primary {
    background: linear-gradient(135deg, #ddeee8, #edf7f4);
    color: #3e7361;
}

.badge-secondary {
    background: linear-gradient(135deg, #f6e3d4, #fbefe5);
    color: #98633a;
}

.empty-state {
    text-align: center;
    padding: 44px 18px;
    color: var(--text-soft);
}

.empty-state-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 12px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-strong);
    background: linear-gradient(135deg, #f4e6d5, #e4efe9);
}

.empty-state p {
    font-size: 1rem;
    margin-bottom: 14px;
}

.stack {
    display: grid;
    gap: 18px;
}

.list-plain {
    list-style: none;
    display: grid;
    gap: 10px;
}

.list-plain li {
    padding: 12px 14px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.invoice-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 28px;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: flex-start;
    padding-bottom: 16px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e6ddd1;
}

.invoice-title {
    color: var(--primary-strong);
    font-size: 1.8rem;
    font-weight: 800;
}

.invoice-subtitle {
    color: var(--text-soft);
    margin-top: 0.45rem;
}

.invoice-header-side {
    text-align: right;
    min-width: 180px;
}

.invoice-header-label {
    color: var(--text-soft);
    font-size: 0.82rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.invoice-header-number {
    color: var(--text-strong);
    font-size: 1.05rem;
    font-weight: 800;
}

.invoice-header-date {
    color: var(--text-soft);
    font-size: 0.9rem;
    margin-top: 6px;
}

.invoice-qr {
    width: 108px;
    height: 108px;
    padding: 10px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #f7ecdf, #edf4ef);
    color: var(--text-soft);
    border: 1px dashed #d8cdbd;
    overflow: hidden;
}

.invoice-qr img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 14px;
}

.invoice-meta-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.invoice-meta-card {
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255, 253, 250, 0.78);
}

.invoice-meta-row {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 12px;
    align-items: start;
    padding: 7px 0;
    border-bottom: 1px solid rgba(222, 214, 202, 0.66);
}

.invoice-meta-row:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.invoice-meta-label {
    color: var(--primary-strong);
    font-size: 0.83rem;
    font-weight: 700;
}

.invoice-meta-value {
    color: var(--text-strong);
    font-weight: 600;
}

.invoice-summary-box {
    margin: 18px 0;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    background: var(--surface-muted);
}

.invoice-summary-row {
    display: grid;
    grid-template-columns: 140px 1fr 140px 1fr;
    gap: 12px;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(222, 214, 202, 0.72);
}

.invoice-summary-row:last-child {
    border-bottom: 0;
}

.invoice-summary-status-only {
    grid-template-columns: 140px 1fr;
}

.invoice-summary-label {
    color: var(--text-strong);
    font-weight: 700;
}

.invoice-summary-value {
    color: var(--text-strong);
    font-weight: 700;
}

.invoice-items-table th:last-child,
.invoice-items-table td:last-child {
    text-align: right;
}

.invoice-items-table th:nth-child(2),
.invoice-items-table td:nth-child(2),
.invoice-items-table th:nth-child(3),
.invoice-items-table td:nth-child(3) {
    text-align: right;
}

.invoice-payment-block {
    margin-top: 24px;
    padding: 22px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: linear-gradient(135deg, rgba(244, 236, 223, 0.72), rgba(237, 244, 239, 0.72));
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 20px;
}

.invoice-payment-copy {
    max-width: 360px;
}

.invoice-payment-copy h4 {
    color: var(--primary-strong);
    font-size: 1.15rem;
    margin-bottom: 8px;
}

.invoice-payment-copy p {
    color: var(--text-soft);
}

.invoice-payment-copy .qr-tab-group {
    justify-content: center;
}

.invoice-qr-large {
    width: 380px;
    height: 380px;
    padding: 20px;
    background: #fffdfa;
    border-style: solid;
    box-shadow: 0 12px 28px rgba(49, 57, 52, 0.10);
    display: flex;
    align-items: center;
    justify-content: center;
}

.invoice-qr-large img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 16px;
    display: block;
}

.invoice-qr-large > div {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.invoice-qr-large canvas,
.invoice-qr-large img[src*="data:"] {
    display: block;
    max-width: 100%;
    max-height: 100%;
}

.invoice-info,
.invoice-details-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.invoice-info-item h4 {
    color: var(--primary-strong);
    font-size: 0.84rem;
    margin-bottom: 6px;
}

.invoice-details {
    margin: 22px 0;
    padding: 18px;
    background: var(--surface-muted);
    border-radius: 14px;
    border: 1px solid var(--border);
}

.invoice-detail-item {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.invoice-total {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 2px solid #e6ddd1;
    text-align: right;
    color: var(--primary-strong);
    font-size: 1.5rem;
    font-weight: 800;
}

.invoice-footer {
    margin-top: 24px;
    text-align: center;
    color: var(--text-soft);
}

.invoice-container.invoice-export-paper {
    width: 794px !important;
    max-width: 794px !important;
    min-height: 1123px !important;
    margin: 0 !important;
    padding: 30px !important;
    box-sizing: border-box !important;
    background: #ffffff !important;
    color: #4f4b59 !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    --text: #1f2937;
    --text-strong: #111827;
    --text-soft: #4b5563;
    --surface-muted: #ffffff;
    --border: #c9c3d8;
}

.invoice-export-paper::before {
    display: none !important;
}

.invoice-export-paper .invoice-title,
.invoice-export-paper .invoice-payment-copy h4,
.invoice-export-paper .invoice-meta-label,
.invoice-export-paper .invoice-total {
    color: #4b3f94 !important;
    text-shadow: none !important;
}

.invoice-export-paper .invoice-subtitle,
.invoice-export-paper .invoice-header-label,
.invoice-export-paper .invoice-payment-copy p {
    color: #374151 !important;
}

.invoice-export-paper .invoice-details h4,
.invoice-export-paper .invoice-details p {
    color: #000000 !important;
}

.invoice-export-paper .invoice-header,
.invoice-export-paper .invoice-total {
    border-color: #ded9ea !important;
}

.invoice-export-paper .invoice-meta-card,
.invoice-export-paper .invoice-summary-box,
.invoice-export-paper .invoice-payment-block,
.invoice-export-paper .invoice-details {
    background: #ffffff !important;
    border-color: #ded9ea !important;
    box-shadow: none !important;
}

.invoice-export-paper .invoice-meta-row,
.invoice-export-paper td {
    border-color: #ded9ea !important;
}

.invoice-export-paper thead {
    background: #ffffff !important;
}

.invoice-export-paper th,
.invoice-export-paper td,
.invoice-export-paper .invoice-meta-value,
.invoice-export-paper .invoice-summary-label,
.invoice-export-paper .invoice-summary-value {
    color: #4f4b59 !important;
}

.invoice-export-paper tbody tr,
.invoice-export-paper tbody tr:nth-child(even),
.invoice-export-paper tbody tr:hover {
    background: #ffffff !important;
}

.invoice-export-paper .invoice-qr-large {
    width: 360px !important;
    height: 360px !important;
    padding: 12px !important;
    background: #ffffff !important;
    border-color: #ded9ea !important;
    box-shadow: none !important;
}

.invoice-export-paper .invoice-qr-large img,
.invoice-export-paper .invoice-qr-large canvas {
    image-rendering: crisp-edges;
    image-rendering: pixelated;
}

.invoice-export-paper .invoice-payment-block {
    margin-top: 16px !important;
    padding: 16px !important;
    gap: 10px !important;
}

.invoice-export-paper .invoice-details {
    margin: 16px 0 0 !important;
    padding: 14px !important;
}

.invoice-export-paper .invoice-total {
    margin-top: 14px !important;
    padding-top: 14px !important;
    font-size: 1.35rem !important;
}

.print-button {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 18px;
}

.dashboard-currency {
    font-size: 2rem;
    font-weight: 800;
}

.dashboard-currency.paid {
    color: var(--success);
}

.dashboard-currency.unpaid {
    color: var(--danger);
}

.dashboard-currency.total {
    color: var(--primary-strong);
}

@media (max-width: 1100px) {
    .dashboard-grid > * {
        grid-column: span 6;
    }

    .dashboard-grid.dashboard-summary > * {
        grid-column: span 6;
    }
}

@media (max-width: 900px) {
    html,
    body {
        overflow-x: hidden;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(86vw, 310px);
        height: 100vh;
        height: 100dvh;
        overflow-y: auto;
        overscroll-behavior: contain;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

    .app-body.sidebar-open {
        overflow: hidden;
    }

    .app-body.sidebar-open .app-sidebar {
        transform: translateX(0);
    }

    .sidebar-toggle-desktop {
        display: none;
    }

    .sidebar-toggle-mobile {
        display: inline-flex;
    }

    .app-main {
        min-width: 0;
        padding: 20px;
    }

    .content-container {
        min-width: 0;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .dashboard-grid > *,
    .dashboard-grid.dashboard-summary > * {
        grid-column: span 12;
    }

    .form-grid .col-6,
    .form-grid .col-12 {
        grid-column: span 12;
    }

    .invoice-info,
    .invoice-details-grid,
    .invoice-meta-grid {
        grid-template-columns: 1fr;
    }

    .invoice-summary-row {
        grid-template-columns: 1fr 1fr;
    }

    .invoice-payment-block {
        flex-direction: column;
        align-items: center;
    }

    .invoice-qr-large {
        width: min(100%, 340px);
        height: auto;
        aspect-ratio: 1 / 1;
    }
}

@media (max-width: 640px) {
    .app-main {
        padding:
            max(12px, env(safe-area-inset-top))
            max(12px, env(safe-area-inset-right))
            max(18px, env(safe-area-inset-bottom))
            max(12px, env(safe-area-inset-left));
    }

    .content-container {
        width: 100%;
        max-width: 100%;
    }

    .card,
    .stat-card,
    .invoice-container {
        padding: 15px;
    }

    .page-header {
        gap: 12px;
        margin-bottom: 14px;
        padding-bottom: 12px;
    }

    .page-title-block {
        width: 100%;
        display: grid;
        grid-template-columns: 44px minmax(0, 1fr);
        column-gap: 12px;
        row-gap: 2px;
        align-items: center;
    }

    .sidebar-toggle-mobile {
        grid-column: 1;
        grid-row: 1 / span 2;
        width: 44px;
        margin: 0;
    }

    .page-kicker,
    .page-title {
        grid-column: 2;
        min-width: 0;
    }

    .page-kicker {
        font-size: 0.76rem;
    }

    .page-kicker::before {
        width: 18px;
    }

    .page-title {
        font-size: clamp(1.25rem, 6vw, 1.55rem);
        overflow-wrap: anywhere;
    }

    .card {
        margin-bottom: 12px;
        border-radius: 15px;
    }

    .card-header {
        margin-bottom: 12px;
        padding-bottom: 10px;
        font-size: 1rem;
    }

    th,
    td {
        padding: 12px;
    }

    .print-button,
    .page-actions,
    .btn-group,
    .toolbar-group,
    .bulk-selection-bar,
    .bulk-selection-summary,
    .bulk-print-summary {
        flex-direction: column;
        align-items: stretch;
    }

    .btn,
    a.btn,
    button.btn {
        width: 100%;
    }

    .btn,
    a.btn,
    button.btn,
    input,
    select,
    textarea {
        font-size: 16px;
    }

    .page-actions {
        width: 100%;
        gap: 8px;
    }

    .page-actions > * {
        width: 100%;
    }

    .bulk-selection-text {
        font-size: 0.9rem;
        line-height: 1.5;
    }

    .bulk-mode-select {
        width: 100%;
        min-width: 0;
        max-width: none;
    }

    .inline-form {
        width: 100%;
    }

    .toolbar-group {
        width: 100%;
        gap: 8px;
    }

    .table-wrap {
        overflow: visible;
    }

    #recentInvoicesTable,
    #recentInvoicesTable thead,
    #recentInvoicesTable tbody,
    #recentInvoicesTable th,
    #recentInvoicesTable td,
    #recentInvoicesTable tr,
    #tenantsTable,
    #tenantsTable thead,
    #tenantsTable tbody,
    #tenantsTable th,
    #tenantsTable td,
    #tenantsTable tr,
    #usersTable,
    #usersTable thead,
    #usersTable tbody,
    #usersTable th,
    #usersTable td,
    #usersTable tr,
    #invoicesTable,
    #invoicesTable thead,
    #invoicesTable tbody,
    #invoicesTable th,
    #invoicesTable td,
    #invoicesTable tr {
        display: block;
    }

    #recentInvoicesTable thead,
    #tenantsTable thead,
    #usersTable thead,
    #invoicesTable thead {
        display: none;
    }

    #recentInvoicesTable tbody,
    #tenantsTable tbody,
    #usersTable tbody,
    #invoicesTable tbody {
        display: grid;
        gap: 12px;
    }

    #recentInvoicesTable tbody tr,
    #tenantsTable tbody tr,
    #usersTable tbody tr,
    #invoicesTable tbody tr {
        background: rgba(255, 253, 250, 0.92);
        border: 1px solid var(--border);
        border-radius: 14px;
        padding: 9px 11px;
        box-shadow: 0 6px 18px rgba(49, 57, 52, 0.05);
    }

    #recentInvoicesTable tbody tr:nth-child(even),
    #recentInvoicesTable tbody tr:hover,
    #tenantsTable tbody tr:nth-child(even),
    #tenantsTable tbody tr:hover,
    #usersTable tbody tr:nth-child(even),
    #usersTable tbody tr:hover,
    #invoicesTable tbody tr:nth-child(even),
    #invoicesTable tbody tr:hover {
        background: rgba(255, 253, 250, 0.92);
    }

    #recentInvoicesTable td,
    #tenantsTable td,
    #usersTable td,
    #invoicesTable td {
        border-top: 0;
        padding: 7px 0;
        display: grid;
        grid-template-columns: minmax(82px, 96px) minmax(0, 1fr);
        gap: 8px;
        align-items: start;
        word-break: break-word;
    }

    #recentInvoicesTable td::before,
    #tenantsTable td::before,
    #usersTable td::before,
    #invoicesTable td::before {
        color: var(--text-soft);
        font-size: 0.8rem;
        font-weight: 700;
    }

    #recentInvoicesTable td:nth-child(1)::before { content: "เลขที่บิล"; }
    #recentInvoicesTable td:nth-child(2)::before { content: "ผู้เช่า"; }
    #recentInvoicesTable td:nth-child(3)::before { content: "ตู้"; }
    #recentInvoicesTable td:nth-child(4)::before { content: "เดือน/ปี"; }
    #recentInvoicesTable td:nth-child(5)::before { content: "จำนวนเงิน"; }
    #recentInvoicesTable td:nth-child(6)::before { content: "สถานะ"; }
    #recentInvoicesTable td:nth-child(7)::before { content: "จัดการ"; }

    #tenantsTable td:nth-child(1)::before { content: "ชื่อผู้เช่า"; }
    #tenantsTable td:nth-child(2)::before { content: "เบอร์โทร"; }
    #tenantsTable td:nth-child(3)::before { content: "อีเมล"; }
    #tenantsTable td:nth-child(4)::before { content: "เลขห้อง"; }
    #tenantsTable td:nth-child(5)::before { content: "ค่าเช่า/เดือน"; }
    #tenantsTable td:nth-child(6)::before { content: "สถานะ"; }
    #tenantsTable td:nth-child(7)::before { content: "จัดการ"; }

    #usersTable td:nth-child(1)::before { content: "ชื่อ - นามสกุล"; }
    #usersTable td:nth-child(2)::before { content: "ชื่อผู้ใช้"; }
    #usersTable td:nth-child(3)::before { content: "สิทธิ์"; }
    #usersTable td:nth-child(4)::before { content: "วันที่เพิ่ม"; }
    #usersTable td:nth-child(5)::before { content: "จัดการ"; }

    #invoicesTable td:nth-child(1)::before { content: "เลือก"; }
    #invoicesTable td:nth-child(2)::before { content: "เลขที่บิล"; }
    #invoicesTable td:nth-child(3)::before { content: "ผู้เช่า"; }
    #invoicesTable td:nth-child(4)::before { content: "เลขห้อง"; }
    #invoicesTable td:nth-child(5)::before { content: "เดือน/ปี"; }
    #invoicesTable td:nth-child(6)::before { content: "จำนวนเงิน"; }
    #invoicesTable td:nth-child(7)::before { content: "สถานะ"; }
    #invoicesTable td:nth-child(8)::before { content: "วันที่สร้าง"; }
    #invoicesTable td:nth-child(9)::before { content: "จัดการ"; }

    #recentInvoicesTable td:nth-child(1)::before { content: "เลขที่บิล"; }
    #recentInvoicesTable td:nth-child(2)::before { content: "ผู้เช่า"; }
    #recentInvoicesTable td:nth-child(3)::before { content: "ห้อง"; }
    #recentInvoicesTable td:nth-child(4)::before { content: "เดือน/ปี"; }
    #recentInvoicesTable td:nth-child(5)::before { content: "จำนวนเงิน"; }
    #recentInvoicesTable td:nth-child(6)::before { content: "สถานะ"; }
    #recentInvoicesTable td:nth-child(7)::before { content: "จัดการ"; }

    #tenantsTable td:nth-child(1)::before { content: "ชื่อผู้เช่า"; }
    #tenantsTable td:nth-child(2)::before { content: "เบอร์โทร"; }
    #tenantsTable td:nth-child(3)::before { content: "อีเมล"; }
    #tenantsTable td:nth-child(4)::before { content: "เลขห้อง"; }
    #tenantsTable td:nth-child(5)::before { content: "ค่าเช่า/เดือน"; }
    #tenantsTable td:nth-child(6)::before { content: "สถานะ"; }
    #tenantsTable td:nth-child(7)::before { content: "จัดการ"; }

    #usersTable td:nth-child(1)::before { content: "ชื่อ - นามสกุล"; }
    #usersTable td:nth-child(2)::before { content: "ชื่อผู้ใช้"; }
    #usersTable td:nth-child(3)::before { content: "สิทธิ์"; }
    #usersTable td:nth-child(4)::before { content: "วันที่เพิ่ม"; }
    #usersTable td:nth-child(5)::before { content: "จัดการ"; }

    #invoicesTable td:nth-child(1)::before { content: "เลือก"; }
    #invoicesTable td:nth-child(2)::before { content: "เลขที่บิล"; }
    #invoicesTable td:nth-child(3)::before { content: "ผู้เช่า"; }
    #invoicesTable td:nth-child(4)::before { content: "เลขห้อง"; }
    #invoicesTable td:nth-child(5)::before { content: "เดือน/ปี"; }
    #invoicesTable td:nth-child(6)::before { content: "จำนวนเงิน"; }
    #invoicesTable td:nth-child(7)::before { content: "สถานะ"; }
    #invoicesTable td:nth-child(8)::before { content: "วันที่สร้าง"; }
    #invoicesTable td:nth-child(9)::before { content: "จัดการ"; }

    .checkbox-cell {
        width: auto;
        text-align: left;
    }

    .checkbox-cell input[type="checkbox"] {
        margin-top: 2px;
    }

    .selection-pill,
    .badge {
        justify-content: center;
    }

    .dashboard-grid {
        gap: 10px;
        margin-bottom: 10px;
    }

    .dashboard-grid:not(.dashboard-summary) > * {
        grid-column: span 6;
        min-height: 116px;
    }

    .dashboard-grid.dashboard-summary > * {
        grid-column: span 12;
    }

    .stat-card h3 {
        margin-bottom: 8px;
        font-size: 0.8rem;
        line-height: 1.45;
    }

    .stat-number {
        font-size: 2rem;
    }

    .dashboard-currency {
        font-size: 1.55rem;
        overflow-wrap: anywhere;
    }

    .empty-state {
        padding: 30px 10px;
    }
}

/* Dark staking-style theme applied across the app. */
:root {
    color-scheme: dark;
    --bg: #060712;
    --bg-soft: #0a0b17;
    --surface: rgba(17, 18, 32, 0.86);
    --surface-strong: #141526;
    --surface-muted: #0d0e1a;
    --sidebar: #080913;
    --sidebar-strong: #05060d;
    --sidebar-muted: #8d91aa;
    --sidebar-border: rgba(151, 128, 255, 0.16);
    --text: #d9dbee;
    --text-soft: #8e93ad;
    --text-strong: #f6f4ff;
    --primary: #9f88ff;
    --primary-strong: #bba8ff;
    --secondary: #6f5cff;
    --accent: #ff5e8a;
    --success: #38e27a;
    --danger: #ff5e6c;
    --warning: #ffd166;
    --info: #50d6ff;
    --border: rgba(157, 150, 205, 0.16);
    --shadow-lg: 0 28px 70px rgba(0, 0, 0, 0.42);
    --shadow-md: 0 18px 46px rgba(0, 0, 0, 0.28);
    --radius-lg: 18px;
    --radius-md: 14px;
    --radius-sm: 10px;
}

body {
    background:
        radial-gradient(circle at 18% 12%, rgba(111, 92, 255, 0.20), transparent 26%),
        radial-gradient(circle at 82% 18%, rgba(255, 94, 138, 0.14), transparent 20%),
        radial-gradient(circle at 70% 88%, rgba(80, 214, 255, 0.10), transparent 28%),
        linear-gradient(180deg, #070813 0%, #05060d 100%);
}

.app-shell {
    grid-template-columns: 260px 1fr;
}

.app-body.sidebar-collapsed .app-shell {
    grid-template-columns: 86px 1fr;
}

.app-sidebar {
    padding: 22px 18px;
    background:
        linear-gradient(180deg, rgba(151, 128, 255, 0.08), transparent 18%),
        linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-strong) 100%);
    box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.03);
}

.sidebar-toggle,
.sidebar-user-card,
.sidebar-nav a.active {
    border-color: rgba(151, 128, 255, 0.20);
    background: rgba(255, 255, 255, 0.045);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.brand-badge,
.brand-mark {
    color: #fff;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 35%),
        linear-gradient(135deg, #7b61ff 0%, #ff5e8a 100%);
    box-shadow: 0 16px 34px rgba(111, 92, 255, 0.32);
}

.brand-title,
.sidebar-user-name {
    color: #f7f4ff;
}

.sidebar-nav a {
    color: #aeb2c9;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    color: #fff;
    background: linear-gradient(135deg, rgba(151, 128, 255, 0.18), rgba(255, 255, 255, 0.04));
}

.nav-icon {
    background: rgba(255, 255, 255, 0.06);
    color: #cfc4ff;
}

.sidebar-logout {
    background: rgba(255, 94, 108, 0.12);
    color: #ffb3bd;
}

.app-main {
    padding: 26px;
}

.content-container {
    max-width: 1380px;
}

.page-header {
    align-items: center;
    padding: 8px 0 18px;
    margin-bottom: 18px;
    border-bottom: 1px solid rgba(157, 150, 205, 0.12);
}

.page-kicker {
    color: #a49aff;
}

.page-kicker::before {
    background: linear-gradient(90deg, #7b61ff, #ff5e8a);
}

.page-title {
    color: var(--text-strong);
    font-weight: 700;
}

.card,
.stat-card,
.invoice-container,
.modal-content {
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.018)),
        var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.card::before,
.stat-card::before,
.invoice-container::before {
    height: 1px;
    background: linear-gradient(90deg, rgba(151, 128, 255, 0.04), rgba(151, 128, 255, 0.72), rgba(255, 94, 138, 0.48), rgba(151, 128, 255, 0.04));
}

.card-header {
    color: #f3f0ff;
    border-bottom-color: rgba(157, 150, 205, 0.12);
}

.stat-card {
    min-height: 138px;
}

.stat-card h3,
.invoice-subtitle,
.invoice-header-date,
.invoice-payment-copy p,
.empty-state,
.bulk-selection-text {
    color: var(--text-soft);
}

.stat-number,
.dashboard-currency {
    color: #f8f5ff;
    text-shadow: 0 0 24px rgba(151, 128, 255, 0.16);
}

.stat-card.tenants,
.dashboard-currency.total {
    color: #a994ff;
}

.stat-card.invoices {
    color: #ffd166;
}

.stat-card.paid,
.dashboard-currency.paid {
    color: #38e27a;
}

.stat-card.unpaid,
.dashboard-currency.unpaid {
    color: #ff5e8a;
}

.btn-primary,
.submit-btn {
    background: linear-gradient(135deg, #b8a3ff 0%, #7b61ff 100%);
    color: #080913;
    box-shadow: 0 14px 28px rgba(123, 97, 255, 0.28);
}

.btn-secondary {
    background: linear-gradient(135deg, #6f5cff 0%, #4a3bd4 100%);
    color: #fff;
}

.btn-success {
    background: linear-gradient(135deg, #44e88a 0%, #16a85f 100%);
    color: #06110b;
}

.btn-danger {
    background: linear-gradient(135deg, #ff6c83 0%, #d33854 100%);
    color: #fff;
}

.btn-warning {
    background: linear-gradient(135deg, #ffd166 0%, #c8912f 100%);
    color: #161006;
}

.btn-light {
    background: rgba(255, 255, 255, 0.055);
    color: #e5e1ff;
    border: 1px solid rgba(157, 150, 205, 0.16);
}

button:disabled,
.btn:disabled {
    opacity: 0.48;
    cursor: not-allowed;
    transform: none;
}

.selection-pill,
.badge-primary,
.badge-secondary {
    background: rgba(151, 128, 255, 0.14);
    color: #d8ceff;
    border: 1px solid rgba(151, 128, 255, 0.20);
}

.badge-success {
    background: rgba(56, 226, 122, 0.12);
    color: #7cf2aa;
    border: 1px solid rgba(56, 226, 122, 0.20);
}

.badge-danger {
    background: rgba(255, 94, 138, 0.13);
    color: #ff9db4;
    border: 1px solid rgba(255, 94, 138, 0.22);
}

input[type="text"],
input[type="email"],
input[type="phone"],
input[type="number"],
input[type="date"],
input[type="month"],
input[type="password"],
input[type="datetime-local"],
select,
textarea,
.field-input {
    background: rgba(5, 6, 13, 0.72);
    border-color: rgba(157, 150, 205, 0.18);
    color: #f4f1ff;
}

input::placeholder,
textarea::placeholder {
    color: #757b97;
}

input:focus,
select:focus,
textarea:focus,
.field-input:focus {
    border-color: rgba(184, 163, 255, 0.74);
    box-shadow: 0 0 0 4px rgba(123, 97, 255, 0.18);
}

label,
.invoice-summary-label,
.invoice-summary-value,
.invoice-meta-value {
    color: #ede9ff;
}

thead {
    background: rgba(255, 255, 255, 0.045);
}

th {
    color: #aeb2c9;
}

td {
    border-top-color: rgba(157, 150, 205, 0.12);
    color: #dfe1f3;
}

tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.018);
}

tbody tr:hover {
    background: linear-gradient(90deg, rgba(123, 97, 255, 0.10), rgba(255, 94, 138, 0.045));
}

.alert-success,
.alert-danger,
.alert-warning,
.alert-info {
    background: rgba(255, 255, 255, 0.055);
    color: #f3f0ff;
    border-color: rgba(157, 150, 205, 0.16);
}

.alert-success {
    border-color: rgba(56, 226, 122, 0.24);
}

.alert-danger {
    border-color: rgba(255, 94, 108, 0.24);
}

.alert-warning {
    border-color: rgba(255, 209, 102, 0.24);
}

.empty-state-icon,
.invoice-qr,
.invoice-meta-card,
.invoice-summary-box,
.invoice-details,
.invoice-payment-block,
.list-plain li {
    background: rgba(5, 6, 13, 0.48);
    border-color: rgba(157, 150, 205, 0.14);
    color: #cfc4ff;
}

.invoice-title,
.invoice-payment-copy h4,
.invoice-info-item h4,
.invoice-meta-label,
.invoice-total {
    color: #bba8ff;
}

.invoice-header,
.invoice-total {
    border-color: rgba(157, 150, 205, 0.16);
}

.invoice-qr-large {
    background: #fff;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 90;
    padding: 24px;
    background: rgba(3, 4, 10, 0.72);
    backdrop-filter: blur(8px);
}

.modal-content {
    width: min(560px, 100%);
    margin: 8vh auto 0;
    border-radius: var(--radius-lg);
}

.modal-header,
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid rgba(157, 150, 205, 0.12);
}

.modal-header h3 {
    color: #f5f2ff;
}

.modal-body {
    padding: 20px;
    color: var(--text);
}

.modal-footer {
    border-top: 1px solid rgba(157, 150, 205, 0.12);
    border-bottom: 0;
    justify-content: flex-end;
}

.close-modal-btn {
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    padding: 0;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.055);
    color: #f4f1ff;
    border: 1px solid rgba(157, 150, 205, 0.14);
    font-size: 1.4rem;
}

.app-sidebar-backdrop {
    background: rgba(3, 4, 10, 0.72);
}

@media (max-width: 640px) {
    #recentInvoicesTable tbody tr,
    #tenantsTable tbody tr,
    #usersTable tbody tr,
    #invoicesTable tbody tr {
        background: rgba(17, 18, 32, 0.90);
        border-color: rgba(157, 150, 205, 0.16);
        box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
    }

    #recentInvoicesTable tbody tr:nth-child(even),
    #recentInvoicesTable tbody tr:hover,
    #tenantsTable tbody tr:nth-child(even),
    #tenantsTable tbody tr:hover,
    #usersTable tbody tr:nth-child(even),
    #usersTable tbody tr:hover,
    #invoicesTable tbody tr:nth-child(even),
    #invoicesTable tbody tr:hover {
        background: rgba(17, 18, 32, 0.90);
    }

    .app-sidebar {
        padding:
            max(18px, env(safe-area-inset-top))
            16px
            max(18px, env(safe-area-inset-bottom));
        gap: 18px;
    }

    .sidebar-brand {
        gap: 11px;
    }

    .brand-badge {
        width: 46px;
        height: 46px;
        border-radius: 14px;
    }

    .brand-title {
        font-size: 0.96rem;
    }

    .brand-subtitle,
    .sidebar-user-role {
        font-size: 0.8rem;
    }

    .sidebar-nav {
        gap: 6px;
    }

    .sidebar-nav a {
        min-height: 48px;
        padding: 8px 10px;
    }

    .sidebar-footer {
        gap: 10px;
    }

    .sidebar-user-card {
        padding: 10px;
    }

    .modal {
        padding:
            max(12px, env(safe-area-inset-top))
            max(12px, env(safe-area-inset-right))
            max(12px, env(safe-area-inset-bottom))
            max(12px, env(safe-area-inset-left));
        overflow-y: auto;
    }

    .modal-content {
        margin: 0 auto;
        border-radius: 16px;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 15px;
    }

    .modal-header {
        align-items: flex-start;
    }

    .modal-header h3 {
        padding-top: 5px;
        font-size: 1.05rem;
    }

    .modal-footer {
        flex-direction: column-reverse;
        align-items: stretch;
    }

    .close-modal-btn {
        width: 42px;
        min-width: 42px;
        height: 42px;
        min-height: 42px;
        flex: 0 0 42px;
    }

    .invoice-header {
        flex-direction: column;
        gap: 12px;
    }

    .invoice-title {
        font-size: 1.35rem;
    }

    .invoice-header-side {
        min-width: 0;
        width: 100%;
        text-align: left;
    }

    .invoice-meta-card {
        padding: 12px;
    }

    .invoice-meta-row {
        grid-template-columns: minmax(88px, 104px) minmax(0, 1fr);
        gap: 8px;
    }

    .invoice-summary-row,
    .invoice-summary-status-only {
        grid-template-columns: minmax(88px, 104px) minmax(0, 1fr);
        gap: 8px;
        padding: 10px 12px;
    }

    .invoice-items-table {
        min-width: 520px;
    }

    .invoice-container > .invoice-items-table {
        display: table;
    }

    .invoice-container {
        overflow-x: auto;
    }

    .invoice-payment-block {
        padding: 15px;
    }

    .invoice-qr-large {
        width: min(100%, 280px);
        height: auto;
        aspect-ratio: 1;
        padding: 12px;
    }

    .invoice-total {
        font-size: 1.25rem;
    }
}

@media (max-width: 390px) {
    .dashboard-grid:not(.dashboard-summary) > * {
        min-height: 106px;
        padding: 13px;
    }

    #recentInvoicesTable td,
    #tenantsTable td,
    #usersTable td,
    #invoicesTable td {
        grid-template-columns: minmax(74px, 86px) minmax(0, 1fr);
        gap: 7px;
    }
}

/* Clean indigo admin theme */
:root {
    color-scheme: light;
    --bg: #f3f4f6;
    --bg-soft: #f8fafc;
    --surface: #ffffff;
    --surface-strong: #ffffff;
    --surface-muted: #f9fafb;
    --sidebar: #ffffff;
    --sidebar-strong: #ffffff;
    --sidebar-muted: #6b7280;
    --sidebar-border: #eef0f4;
    --text: #374151;
    --text-soft: #6b7280;
    --text-muted: #6b7280;
    --text-strong: #1f2937;
    --primary: #4f46e5;
    --primary-strong: #4338ca;
    --secondary: #6366f1;
    --accent: #8b5cf6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --border: #e5e7eb;
    --shadow-lg: 0 20px 45px rgba(31, 41, 55, 0.10);
    --shadow-md: 0 8px 24px rgba(31, 41, 55, 0.055);
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 9px;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}

body {
    font-family: "Inter", "Noto Sans Thai", sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app-shell {
    grid-template-columns: 256px minmax(0, 1fr);
}

.app-body.sidebar-collapsed .app-shell {
    grid-template-columns: 84px minmax(0, 1fr);
}

.app-sidebar {
    padding: 0 16px 18px;
    gap: 0;
    color: var(--text);
    background: #fff;
    border-right: 1px solid #eef0f4;
    box-shadow: 2px 0 12px rgba(31, 41, 55, 0.025);
}

.sidebar-brand {
    min-height: 80px;
    margin: 0 -16px 22px;
    padding: 14px 20px;
    gap: 12px;
    border-bottom: 1px solid #f0f1f4;
}

.brand-badge,
.brand-mark {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border-radius: 12px;
    color: var(--primary);
    background: #eef2ff;
    box-shadow: none;
}

.brand-title,
.sidebar-user-name {
    color: var(--text-strong);
}

.brand-title {
    font-size: 0.9rem;
}

.brand-subtitle {
    margin-top: 2px;
    color: #9ca3af;
    font-size: 0.68rem;
    line-height: 1.4;
}

.sidebar-nav {
    gap: 5px;
}

.sidebar-nav a {
    min-height: 48px;
    padding: 8px 12px;
    gap: 9px;
    border-radius: 12px;
    color: #6b7280;
    font-size: 0.92rem;
    font-weight: 500;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    color: var(--primary);
    background: #eef2ff;
    box-shadow: none;
    transform: none;
}

.nav-icon {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    color: inherit;
    background: transparent;
    font-size: 0.98rem;
}

.sidebar-footer {
    gap: 10px;
    padding-top: 18px;
    border-top: 1px solid #f0f1f4;
}

.sidebar-user-card {
    padding: 11px;
    gap: 10px;
    background: #f9fafb;
    border: 1px solid #eef0f4;
    box-shadow: none;
}

.sidebar-user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    color: #6b7280;
    background: #e5e7eb;
}

.sidebar-user-role {
    color: #9ca3af;
    font-size: 0.75rem;
}

.sidebar-logout {
    gap: 8px;
    color: var(--danger);
    background: #fff;
    border: 1px solid #fee2e2;
}

.sidebar-logout:hover {
    color: #fff;
    background: var(--danger);
}

.app-main {
    padding: 0 30px 32px;
}

.content-container {
    max-width: 1380px;
}

.page-header {
    position: sticky;
    top: 0;
    z-index: 25;
    min-height: 80px;
    margin: 0 -30px 28px;
    padding: 14px 30px;
    align-items: center;
    background: rgba(255, 255, 255, 0.88);
    border-bottom: 1px solid #eef0f4;
    backdrop-filter: blur(12px);
}

.page-title-block {
    gap: 2px;
}

.page-kicker {
    color: #6b7280;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.page-kicker::before {
    width: 6px;
    height: 6px;
    background: var(--primary);
}

.page-title {
    color: var(--text-strong);
    font-size: 1.55rem;
    font-weight: 700;
}

.header-notification {
    position: relative;
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    color: #6b7280;
    background: #f9fafb;
    border: 1px solid #eef0f4;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(31, 41, 55, 0.04);
}

.header-notification span {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 9px;
    height: 9px;
    background: var(--danger);
    border: 2px solid #fff;
    border-radius: 50%;
}

.card,
.stat-card,
.invoice-container,
.modal-content {
    color: var(--text);
    background: #fff;
    border: 1px solid #eef0f4;
    box-shadow: var(--shadow-md);
    backdrop-filter: none;
}

.card::before,
.stat-card::before,
.invoice-container::before {
    display: none;
}

.card-header {
    color: var(--text-strong);
    border-bottom-color: #eef0f4;
}

.dashboard-grid {
    gap: 20px;
    margin-bottom: 22px;
}

.stat-card {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    min-height: 126px;
    padding: 22px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 30px rgba(31, 41, 55, 0.08);
}

.stat-card::after {
    top: -24px;
    right: -24px;
    bottom: auto;
    width: 96px;
    height: 96px;
}

.stat-card h3 {
    margin-bottom: 8px;
    color: #6b7280;
    font-size: 0.86rem;
    font-weight: 500;
}

.stat-number,
.dashboard-currency {
    color: var(--text-strong);
    text-shadow: none;
}

.stat-number {
    font-size: 2rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    flex: 0 0 48px;
    border-radius: 12px;
    font-size: 1.2rem;
}

.stat-card.tenants { color: #4f46e5; }
.stat-card.tenants .stat-icon { background: #eef2ff; }
.stat-card.invoices { color: #3b82f6; }
.stat-card.invoices .stat-icon { background: #eff6ff; }
.stat-card.paid { color: #10b981; }
.stat-card.paid .stat-icon { background: #ecfdf5; }
.stat-card.unpaid { color: #ef4444; }
.stat-card.unpaid .stat-icon { background: #fef2f2; }
.stat-card.unpaid .stat-number { color: #ef4444; }

.dashboard-money {
    min-height: 144px;
    padding: 24px;
    color: #fff;
    border: 0;
    overflow: hidden;
}

.dashboard-money.paid { background: linear-gradient(135deg, #10b981, #059669); }
.dashboard-money.unpaid { background: linear-gradient(135deg, #ef4444, #dc2626); }
.dashboard-money.total { background: linear-gradient(135deg, #6366f1, #4f46e5); }

.dashboard-money::after {
    content: "฿";
    position: absolute;
    right: 20px;
    bottom: -28px;
    color: rgba(255, 255, 255, 0.14);
    font-size: 7.5rem;
    font-weight: 800;
    line-height: 1;
}

.dashboard-money .card-header {
    position: relative;
    z-index: 1;
    margin: 0 0 10px;
    padding: 0;
    color: rgba(255, 255, 255, 0.88);
    border: 0;
    font-size: 0.94rem;
    font-weight: 500;
}

.dashboard-money .card-body {
    position: relative;
    z-index: 1;
}

.dashboard-money .dashboard-currency,
.dashboard-money .dashboard-currency.paid,
.dashboard-money .dashboard-currency.unpaid,
.dashboard-money .dashboard-currency.total {
    color: #fff;
    font-size: clamp(1.6rem, 3vw, 2.35rem);
}

.dashboard-table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.dashboard-table-header > span i {
    margin-right: 7px;
    color: var(--primary);
}

.dashboard-table-header a {
    color: var(--primary);
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
}

.dashboard-table-header a i {
    margin-left: 4px;
    font-size: 0.72rem;
}

.btn-primary,
.submit-btn,
.btn-secondary {
    color: #fff;
    background: var(--primary);
    box-shadow: 0 7px 16px rgba(79, 70, 229, 0.18);
}

.btn-success { color: #fff; background: var(--success); }
.btn-danger { color: #fff; background: var(--danger); }
.btn-warning { color: #fff; background: var(--warning); }
.btn-light {
    color: #4b5563;
    background: #fff;
    border: 1px solid #e5e7eb;
}

.badge-primary,
.badge-secondary,
.selection-pill {
    color: #4f46e5;
    background: #eef2ff;
    border-color: #e0e7ff;
}

.badge-success {
    color: #059669;
    background: #ecfdf5;
    border-color: #d1fae5;
}

.badge-danger {
    color: #dc2626;
    background: #fef2f2;
    border-color: #fee2e2;
}

input[type="text"],
input[type="email"],
input[type="phone"],
input[type="tel"],
input[type="search"],
input[type="number"],
input[type="date"],
input[type="month"],
input[type="password"],
input[type="datetime-local"],
select,
textarea,
.field-input {
    color: var(--text-strong);
    background: #fff;
    border-color: #dfe3e8;
}

input::placeholder,
textarea::placeholder { color: #9ca3af; }

input:focus,
select:focus,
textarea:focus,
.field-input:focus {
    border-color: #818cf8;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.10);
}

label,
.invoice-summary-label,
.invoice-summary-value,
.invoice-meta-value { color: var(--text); }

thead { background: #f9fafb; }
th { color: #6b7280; }
td {
    color: #374151;
    border-top-color: #f0f1f4;
}
tbody tr:nth-child(even) { background: #fff; }
tbody tr:hover { background: #f9fafb; }

.empty-state-icon,
.invoice-qr,
.invoice-meta-card,
.invoice-summary-box,
.invoice-details,
.invoice-payment-block,
.list-plain li {
    color: var(--text);
    background: #f9fafb;
    border-color: #e5e7eb;
}

.invoice-title,
.invoice-payment-copy h4,
.invoice-info-item h4,
.invoice-meta-label,
.invoice-total { color: var(--primary); }

.invoice-header,
.invoice-total { border-color: #e5e7eb; }

.alert-success,
.alert-danger,
.alert-warning,
.alert-info {
    color: var(--text-strong);
    background: #fff;
    border-color: #e5e7eb;
}

.modal { background: rgba(15, 23, 42, 0.48); }
.modal-header h3 { color: var(--text-strong); }
.modal-body { color: var(--text); }
.close-modal-btn {
    color: #6b7280;
    background: #f9fafb;
    border-color: #e5e7eb;
}
.app-sidebar-backdrop { background: rgba(15, 23, 42, 0.42); }

:focus-visible {
    outline: 3px solid rgba(79, 70, 229, 0.28);
    outline-offset: 2px;
}

.card-header-with-count {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.record-count {
    padding: 4px 10px;
    color: #6b7280;
    background: #f3f4f6;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 600;
}

.search-control {
    position: relative;
}

.search-control input {
    padding-left: 44px;
    padding-right: 44px;
}

.search-control-icon {
    position: absolute;
    top: 50%;
    left: 16px;
    z-index: 1;
    color: #9ca3af;
    transform: translateY(-50%);
    pointer-events: none;
}

.search-clear {
    position: absolute;
    top: 50%;
    right: 7px;
    width: 34px;
    min-width: 34px;
    height: 34px;
    min-height: 34px;
    padding: 0;
    color: #6b7280;
    background: #f3f4f6;
    border-radius: 50%;
    transform: translateY(-50%);
}

.search-clear:hover {
    color: var(--primary);
    background: #eef2ff;
    transform: translateY(-50%);
}

.search-status {
    min-height: 20px;
    margin-top: 8px;
    color: #6b7280;
    font-size: 0.78rem;
}

.list-table-controls {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(210px, 260px) auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 22px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.list-table-controls .form-group {
    margin-bottom: 0;
}

.list-table-controls label {
    margin-bottom: 6px;
    color: #6b7280;
    font-size: 0.78rem;
}

.list-table-controls .search-status {
    margin-bottom: -20px;
}

.list-table-controls > .btn {
    min-height: 48px;
}

.invoice-period-panel,
.invoice-summary-item,
.tenant-invoice-row {
    background: #f9fafb !important;
}

.tenant-invoice-row:has(.tenant-checkbox:checked) {
    background: #f5f3ff !important;
    border-color: #a5b4fc !important;
}

.modal[aria-hidden="false"] .modal-content {
    animation: modal-enter 0.18s ease-out;
}

@keyframes modal-enter {
    from { opacity: 0; transform: translateY(8px) scale(.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 900px) {
    .app-main { padding: 0 18px 24px; }
    .page-header { margin: 0 -18px 22px; padding: 12px 18px; }
    .sidebar-toggle-mobile {
        color: var(--primary);
        background: #eef2ff;
        border-color: #e0e7ff;
    }
    .list-table-controls {
        grid-template-columns: minmax(220px, 1fr) minmax(190px, .7fr);
    }
    .list-table-controls > .btn {
        grid-column: 2;
    }
}

@media (max-width: 640px) {
    .list-table-controls {
        grid-template-columns: 1fr;
        margin-bottom: 16px;
        padding-bottom: 16px;
    }
    .list-table-controls > .btn {
        grid-column: auto;
    }
    .list-table-controls .search-status {
        margin-bottom: 0;
    }
    #recentInvoicesTable tbody tr,
    #tenantsTable tbody tr,
    #usersTable tbody tr,
    #invoicesTable tbody tr,
    #recentInvoicesTable tbody tr:nth-child(even),
    #recentInvoicesTable tbody tr:hover,
    #tenantsTable tbody tr:nth-child(even),
    #tenantsTable tbody tr:hover,
    #usersTable tbody tr:nth-child(even),
    #usersTable tbody tr:hover,
    #invoicesTable tbody tr:nth-child(even),
    #invoicesTable tbody tr:hover {
        background: #fff;
        border-color: #e5e7eb;
        box-shadow: 0 7px 20px rgba(31, 41, 55, 0.06);
    }

    .page-title { font-size: 1.25rem; }
    .header-notification { display: none; }
    .dashboard-table-header { align-items: flex-start; }
    .dashboard-table-header a { white-space: nowrap; }
}

@media print {
    @page {
        size: A4;
        margin: 8mm;
    }

    body {
        background: #fff;
        font-size: 12px;
        line-height: 1.35;
    }

    .app-sidebar,
    .page-actions,
    .print-button,
    .btn,
    .bulk-print-summary {
        display: none !important;
    }

    .app-shell {
        display: block;
    }

    .app-main {
        padding: 0;
    }

    .content-container,
    .invoice-container {
        max-width: 100%;
        margin: 0;
        padding: 0;
        box-shadow: none;
        border: 0;
        background: #fff;
    }

    .invoice-container {
        padding: 0 !important;
        box-shadow: none !important;
        border: 0 !important;
        break-inside: avoid;
    }

    .invoice-header {
        margin-bottom: 10px;
        padding-bottom: 10px;
    }

    .invoice-title {
        font-size: 1.45rem;
    }

    .invoice-meta-grid,
    .invoice-details-grid {
        gap: 10px;
    }

    .invoice-meta-card {
        padding: 10px 12px;
        border-radius: 10px;
    }

    .invoice-meta-row {
        grid-template-columns: 92px 1fr;
        gap: 8px;
        padding: 4px 0;
    }

    .invoice-header-side {
        min-width: 150px;
    }

    .invoice-details,
    .invoice-payment-block {
        margin: 12px 0;
        padding: 12px;
        border-radius: 12px;
    }

    .invoice-summary-box {
        margin: 10px 0;
    }

    .invoice-summary-row {
        grid-template-columns: 88px 1fr 88px 1fr;
        gap: 8px;
        padding: 8px 10px;
    }

    .invoice-payment-block {
        gap: 14px;
        align-items: center;
    }

    .invoice-payment-copy h4 {
        font-size: 1rem;
        margin-bottom: 4px;
    }

    .invoice-payment-copy p,
    .invoice-footer p {
        font-size: 0.85rem;
    }

    .invoice-qr-large {
        width: 145px;
        height: 145px;
        padding: 10px;
        box-shadow: none;
    }

    table {
        margin-top: 8px;
    }

    th,
    td {
        padding: 8px 10px;
    }

    .invoice-total {
        margin-top: 12px;
        padding-top: 12px;
        font-size: 1.2rem;
    }

    .invoice-footer {
        margin-top: 14px;
    }

    .invoice-sheet {
        page-break-after: always;
        break-after: page;
    }

    .invoice-sheet:last-child {
        page-break-after: auto;
        break-after: auto;
    }
}
