:root {
  --navy: #16324f;
  --navy-deep: #10263c;
  --sidebar: #16324f;
  --sidebar-deep: #10263c;
  --sidebar-active: rgba(255, 255, 255, 0.14);
  --accent: #2b6cb0;
  --page-bg: #f3f6f9;
  --text: #1a202c;
  --muted: #5b6775;
  --card: #ffffff;
  --line: #d9e2ec;
  --topbar-name: #1d4ed8;
}

html {
  font-size: 15px;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--page-bg);
}

.btn-primary {
  background: var(--accent);
  border-color: #245ea0;
}

.btn-primary:hover {
  background: #245ea0;
  border-color: #1f528c;
}

.public-shell {
  min-height: 100vh;
}

.public-header {
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.public-header-inner,
.public-content,
.public-footer {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
}

.public-header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.public-header-inner nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-link-public {
  color: var(--muted);
  text-decoration: none;
}

.public-content {
  padding-top: 2.5rem;
  padding-bottom: 3rem;
}

.public-footer {
  color: var(--muted);
  font-size: 0.9rem;
}

.hero-kicker,
.page-kicker,
.auth-brand,
.sidebar-brand,
.navbar-brand {
  letter-spacing: 0.06em;
  font-weight: 700;
}

.hero-title {
  font-size: 2.4rem;
  margin: 0.4rem 0 1rem;
}

.hero-lead,
.page-lead,
.auth-lead {
  color: var(--muted);
  max-width: 40rem;
}

.page-lead {
  font-size: 0.88rem;
  margin: 0.4rem 0 0;
}

.feature-card,
.panel,
.stat-card,
.auth-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(16, 38, 60, 0.04);
}

.feature-card {
  padding: 1.4rem;
  height: 100%;
}

.feature-card h2 {
  font-size: 1.15rem;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* 後台殼層：深藍側欄＋白頂欄。側欄 active 用白色半透明圓角；頂欄社區名深藍、「切換社區」藍框。 */
.app-sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sidebar-brand {
  display: block;
  color: #fff;
  text-decoration: none;
  font-size: 1.15rem;
  letter-spacing: 0.12em;
  padding: 1rem 1.15rem;
  background: var(--sidebar-deep);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-brand:hover {
  color: #fff;
}

.sidebar-user {
  padding: 0.85rem 1.15rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-user-line {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.sidebar-user-role {
  font-size: 0.92rem;
  font-weight: 600;
}

.sidebar-user-badge {
  display: inline-block;
  border-radius: 4px;
  padding: 0.05rem 0.4rem;
  font-size: 0.72rem;
  background: #8b93a7;
  color: #fff;
  line-height: 1.4;
}

.sidebar-user-name {
  margin-top: 0.25rem;
  color: #c9c6d9;
  font-size: 0.8rem;
}

.sidebar-nav {
  flex: 1;
  padding: 0.35rem 0.45rem 0.7rem;
  overflow: auto;
}

.sidebar-link,
.sidebar-group-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: #f3f1ff;
  text-decoration: none;
  /* 上下各約半行，相鄰項目約一行高，比先前半行距再鬆一些 */
  padding: 0.55em 0.5rem;
  border-radius: 4px;
  margin-bottom: 0;
  line-height: 1.25;
  font-size: 0.88rem;
}

.sidebar-link:hover,
.sidebar-group-title:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.sidebar-link.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
  box-shadow: inset 3px 0 0 #93c5fd;
}

.sidebar-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: currentColor;
}

.sidebar-group {
  margin-bottom: 0.15rem;
}

.sidebar-group-title {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.sidebar-group.is-active > .sidebar-group-title {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-weight: 600;
  box-shadow: inset 3px 0 0 #93c5fd;
}

.sidebar-group-title::-webkit-details-marker {
  display: none;
}

.sidebar-group-title::before {
  content: "▸";
  width: 0.7rem;
  font-size: 0.7rem;
  opacity: 0.8;
}

.sidebar-group[open] > .sidebar-group-title::before {
  content: "▾";
}

.sidebar-sublink {
  margin-left: 1.2rem;
  padding: 0.55em 0.45rem;
  font-size: 0.86rem;
  line-height: 1.25;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  background: #fff;
  border-bottom: 1px solid #e6e8ee;
  min-height: 56px;
  padding: 0.55rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.app-topbar .topbar-left,
.app-topbar .topbar-right {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.topbar-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.topbar-tenant-name {
  color: var(--topbar-name);
  font-weight: 700;
}

.topbar-tenant-inactive {
  display: inline-block;
  background: #fff4e5;
  color: #7a4b00;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.tenant-inactive-banner {
  background: #fff4e5;
  color: #7a4b00;
  border-bottom: 1px solid #f0d9a8;
  padding: 0.45rem 1.5rem;
  font-size: 0.88rem;
}

.tenant-plan-banner {
  background: #eef4ff;
  color: #1d3f7a;
  border-bottom: 1px solid #c5d4f0;
  padding: 0.45rem 1.5rem;
  font-size: 0.88rem;
}

.topbar-tenant-empty {
  color: var(--muted);
}

.btn-switch-tenant {
  display: inline-block;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: #fff;
  border-radius: 4px;
  font-size: 0.82rem;
  padding: 0.18rem 0.7rem;
  line-height: 1.4;
  text-decoration: none;
}

.btn-switch-tenant:hover,
.btn-switch-tenant:focus {
  background: #eef5fc;
  color: var(--accent);
}

.btn-switch-tenant::after {
  margin-left: 0.25rem;
}

.topbar-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}

.topbar-link:hover {
  color: #1f528c;
  text-decoration: underline;
}

.topbar-logout-form {
  margin: 0;
}

.topbar-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #4b5563;
}

.topbar-logout svg {
  width: 20px;
  height: 20px;
}

.topbar-logout:hover {
  color: #111827;
}

.app-content {
  padding: 1.75rem 2rem 3rem;
}

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.page-heading-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-wrap: nowrap !important;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.1rem;
}

.page-heading-tools form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: nowrap !important;
  min-width: 0;
  margin: 0;
  justify-content: flex-end;
}

.page-heading-tools .d-flex {
  flex-wrap: nowrap !important;
}

.page-heading-tools > *,
.page-heading-tools form > * {
  flex-shrink: 0;
}

.page-heading-tools .form-check,
.page-heading-tools .btn {
  flex-shrink: 0;
}

.page-heading-tools .form-check-label {
  white-space: nowrap;
}

.page-heading-tools .form-select {
  width: 7.5rem;
  min-width: 0;
}

.page-heading-tools .form-control {
  width: 10rem;
  min-width: 0;
}

.page-heading h1,
.page-title,
.panel-header h2 {
  margin: 0;
}

.page-title,
.page-title-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.page-title-row h1 {
  margin: 0;
  font-size: 1.75rem;
}

.page-help-body {
  font-size: 0.88rem;
  line-height: 1.55;
  color: #374151;
}

.page-help-modal-dialog {
  max-width: min(75vw, 1120px);
}

.page-help-body h3 {
  font-size: 0.92rem;
  font-weight: 700;
  margin: 0.75rem 0 0.3rem;
  color: #111827;
}

.page-help-body h3:first-child {
  margin-top: 0;
}

.page-help-body p,
.page-help-body li {
  font-size: 0.88rem;
  margin-bottom: 0.35rem;
}

.page-help-body ol {
  padding-left: 1.15rem;
  margin-bottom: 0;
}

.manual-body h2 {
  font-size: 1.05rem;
  margin: 1.1rem 0 0.4rem;
}

.manual-body h3 {
  font-size: 0.95rem;
  margin: 0.7rem 0 0.25rem;
}

.manual-body p,
.manual-body li {
  font-size: 0.9rem;
  color: #374151;
}

.manual-body ol {
  padding-left: 1.2rem;
}

.page-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  flex-shrink: 0;
}

.page-help svg {
  width: 0.95rem;
  height: 0.95rem;
}

.page-help:hover,
.page-help:focus {
  background: #eef5fc;
  color: #1f528c;
}

.stat-card {
  padding: 1.1rem 1.2rem;
}

.stat-label,
.stat-hint {
  color: var(--muted);
  font-size: 0.88rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 0.2rem 0;
}

.panel {
  padding: 1.1rem 1.2rem 0.4rem;
}

.bill-select-box {
  max-height: 360px;
  overflow: auto;
  margin-bottom: 0.75rem;
}

.quote-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 1rem;
  padding: 0.75rem 0.9rem;
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.quote-skip-warn {
  grid-column: 1 / -1;
  color: #9a3412;
  background: #fff7ed;
  border: 1px solid #fdba74;
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
  font-size: 0.875rem;
}

.charge-item-periods {
  display: grid;
  gap: 0.5rem;
}

.charge-item-period-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
  padding: 0.7rem 0.8rem;
}

.charge-item-period-head {
  display: grid;
  grid-template-columns: 1fr 6.5rem;
  gap: 0.75rem;
  margin-bottom: 0.45rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.charge-item-period-row {
  display: grid;
  grid-template-columns: 1fr 6.5rem;
  gap: 0.75rem;
  align-items: center;
}

.charge-item-period-row .form-control {
  text-align: right;
}

.payment-paidon-inline {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: nowrap;
}

.payment-paidon-inline .form-label {
  white-space: nowrap;
  font-size: 0.86rem;
  color: var(--muted);
}

.payment-paidon-inline .form-control {
  width: 8.5rem;
}

.payment-note-inline {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: nowrap;
}

.payment-note-inline .form-label {
  white-space: nowrap;
  margin-bottom: 0;
}

.payment-note-inline .form-control {
  flex: 1;
}

.payment-options-inline {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.empty-hint,
.table-sub {
  color: var(--muted);
}

.table-sub {
  font-size: 0.8rem;
}

.required-marker {
  color: #dc2626;
  font-weight: 700;
}

/* 開立帳單：表格改為可讀欄位模式 */
.bill-list {
  table-layout: fixed;
}

.bill-list thead th {
  white-space: nowrap;
  font-size: 0.82rem;
}

.bill-list td {
  vertical-align: middle;
}

.bill-title-main {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 1px;
}

.bill-meta-row td {
  border-top: 0;
  padding-top: 0;
  padding-bottom: 0.55rem;
  font-size: 0.78rem;
}

.bill-line-no {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.bill-line-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.9rem;
}

.bill-line-main .bill-title {
  min-width: 8rem;
  flex: 1 1 10rem;
}

.billing-issue-tools {
  overflow-x: auto;
  white-space: nowrap;
}

.billing-inline-filter {
  align-items: center !important;
}

.billing-inline-filter-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.badge-status {
  display: inline-block;
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.8rem;
}

.badge-status-draft {
  background: #fff4d6;
  color: #8a6d1d;
}

.badge-status-signed {
  background: #dbeafe;
  color: #1e4b8a;
}

.badge-status-approved {
  background: #dcfce7;
  color: #166534;
}

.badge-status-rejected {
  background: #fee2e2;
  color: #991b1b;
}

.auth-wrap {
  display: flex;
  justify-content: center;
  padding: 1.5rem 0 3rem;
}

.auth-card {
  width: min(460px, 100%);
  padding: 1.8rem;
}

.auth-title {
  font-size: 1.6rem;
  margin: 0.4rem 0 0.6rem;
}

.auth-divider {
  margin: 1.3rem 0 1rem;
}

.auth-hint {
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-hint ul {
  padding-left: 1.1rem;
  margin-top: 0.4rem;
}

.tenant-multiselect {
  position: relative;
}

.tenant-multiselect-toggle {
  min-height: 2.25rem;
}

.tenant-multiselect-panel {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  margin-top: 0.2rem;
  max-height: 16rem;
  overflow: auto;
  padding: 0.5rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(16, 38, 60, 0.12);
}

.tenant-multiselect-search {
  margin-bottom: 0.45rem;
}

.tenant-multiselect-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.2rem;
  margin: 0;
  font-size: 0.9rem;
}

.tenant-multiselect-item[hidden] {
  display: none;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.btn,
.panel-header form .btn,
.form-actions .btn {
  white-space: nowrap;
}

.panel-header > form.d-flex.flex-nowrap {
  flex-wrap: nowrap !important;
  max-width: 100%;
  min-width: 0;
  overflow: visible;
  padding-bottom: 0;
}

.panel-header > form.d-flex.flex-nowrap > * {
  min-width: 0;
}

.panel-header > form.d-flex.flex-nowrap .form-check,
.panel-header > form.d-flex.flex-nowrap .btn {
  flex-shrink: 0;
}

.panel-header > form.d-flex.flex-nowrap .form-check-label {
  white-space: nowrap;
}

.panel-header > form.d-flex.flex-nowrap .form-select {
  min-width: 0;
  width: 8.5rem;
}

.panel-header > form.d-flex.flex-nowrap .form-control {
  min-width: 0;
  width: 12rem;
}

.workbench-title-block {
  flex-shrink: 0;
}

.workbench-title-block .page-title-row h1 {
  white-space: nowrap;
}

.workbench-quick-links {
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.1rem;
  gap: 0.35rem !important;
}

.workbench-quick-links .btn {
  flex-shrink: 0;
  padding: 0.18rem 0.45rem;
  font-size: 0.78rem;
  line-height: 1.2;
  white-space: nowrap;
}

.workitems-filter-form .form-select {
  min-width: 9rem;
}

.workitems-filter-form input[type="text"],
.workitems-filter-form input[type="search"],
.workitems-filter-form .form-control {
  min-width: 14rem;
}

.workitems-filter-form .form-check,
.workitems-filter-form .btn {
  flex-shrink: 0;
}

.workitems-filter-form .form-check-label {
  white-space: nowrap;
}

form.users-filter-form {
  overflow-x: visible;
  padding-bottom: 0;
}

.users-filter-form .form-select {
  min-width: 0;
  width: 8.5rem;
}

.users-filter-form .form-control {
  min-width: 0;
  width: 14rem;
}

.finance-report-actions .finance-period-form .form-control {
  width: 8.5rem;
}

.searchable-select {
  position: relative;
  z-index: 5;
}

.searchable-select-list {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  max-height: 16rem;
  overflow: auto;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 8px 20px rgba(16, 38, 60, 0.12);
}

.searchable-select-list button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0.4rem 0.75rem;
}

.searchable-select-list button:hover,
.searchable-select-list button:focus {
  background: #eef4fa;
  cursor: pointer;
}

.household-notes-banner {
  margin: 0 0 0.9rem;
  padding: 0.85rem 1rem;
  border: 2px solid #c2410c;
  background: #fff7ed;
  border-radius: 8px;
}

.household-notes-banner-title {
  margin: 0 0 0.55rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: #9a3412;
}

.household-note-card {
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.45rem;
  background: #fff;
  border-left: 4px solid #ea580c;
}

.household-note-card.is-reminder {
  border-left-color: #b91c1c;
  background: #fef2f2;
}

.household-note-card.is-expired {
  opacity: 0.72;
  border-left-color: #9aa4b2;
}

.household-note-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.7rem;
  margin-bottom: 0.25rem;
  font-size: 0.88rem;
  color: #7c2d12;
}

.household-note-flag {
  display: inline-block;
  padding: 0 0.35rem;
  border-radius: 4px;
  background: #b91c1c;
  color: #fff;
  font-size: 0.78rem;
}

.household-notes-link {
  display: inline-block;
  margin-top: 0.2rem;
  font-weight: 600;
}

.payment-receipt-frame,
.asset-action-frame {
  width: 100%;
  min-height: 76vh;
  border: 0;
  background: #fff;
}

.permission-matrix th {
  white-space: nowrap;
}

.permission-granted {
  color: #166534;
  font-weight: 700;
}

.permission-denied {
  color: #9aa4b2;
}

.role-title-highlight {
  color: #166534;
  font-weight: 800;
}

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }

  .app-sidebar {
    width: 100%;
    min-height: 0;
  }

  .app-topbar {
    flex-wrap: wrap;
    padding: 0.6rem 1rem;
  }

  .page-heading {
    flex-direction: column;
  }
}
