:root {
  --bg: #f2efe8;
  --bg-accent: #e9dbc2;
  --card: #fffefb;
  --text: #2d261d;
  --muted: #6a5d4e;
  --primary: #145f4b;
  --primary-hover: #0f4a3b;
  --border: #d7c5ab;
  --sidebar: #efe3cc;
  --sidebar-soft: #d8c7aa;
  --table-cell-py: 4px;
  --table-cell-px: 5px;
  --table-font-size: 0.82rem;
  --table-head-font-size: 0.8rem;
  --table-wrap-gap: 10px;
  --table-action-gap: 4px;
  --control-radius: 5px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Outfit", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 0% 0%, var(--bg-accent), transparent 34%),
    radial-gradient(circle at 100% 100%, #dfeee3, transparent 26%),
    var(--bg);
}

.app-shell {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 0;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  position: relative;
  align-self: stretch;
  background: linear-gradient(180deg, var(--sidebar), #e7d8be);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 16px 14px;
  color: var(--text);
  height: 100vh;
  overflow-y: auto;
}

.brand h1 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: 0.3px;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.side-nav {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.nav-link {
  display: block;
  text-decoration: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.4);
  border: 1px solid #dbc9ae;
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 0.93rem;
  transition: 0.2s ease;
}

.nav-link:hover {
  background: #fff7e8;
}

.nav-link.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.nav-link.nav-link-warn {
  background: #f8ece6;
  border-color: #e8c2b4;
  color: #8a3528;
}

.sidebar-note {
  margin-top: 12px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #d8c3a4;
  background: #fff8ed;
  color: #5d4f3f;
  font-size: 0.84rem;
  line-height: 1.35;
}

.auth-page {
  min-height: 100vh;
  margin: 0;
  position: relative;
  overflow: hidden;
}

.auth-page::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.2;
  background-repeat: no-repeat, no-repeat;
  background-position:
    left -40px top 40px,
    right -30px bottom 20px;
  background-size:
    340px 220px,
    320px 210px;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 360 240'%3E%3Cdefs%3E%3ClinearGradient id='a' x1='0' y1='0' x2='1' y2='1'%3E%3Cstop offset='0%25' stop-color='%23145f4b'/%3E%3Cstop offset='100%25' stop-color='%230f4a3b'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect x='52' y='94' width='256' height='122' rx='12' fill='%23f2e5cb' stroke='%23d7c5ab'/%3E%3Cpolygon points='40,104 180,36 320,104' fill='url(%23a)'/%3E%3Crect x='162' y='144' width='36' height='72' rx='6' fill='%23145f4b'/%3E%3Crect x='88' y='128' width='48' height='34' rx='4' fill='%23d9efe7' stroke='%2399c7b9'/%3E%3Crect x='224' y='128' width='48' height='34' rx='4' fill='%23d9efe7' stroke='%2399c7b9'/%3E%3Ccircle cx='300' cy='52' r='20' fill='%23e2f1ea'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 360 240'%3E%3Crect x='78' y='48' width='204' height='148' rx='14' fill='%23fff7e8' stroke='%23d7c5ab'/%3E%3Crect x='106' y='80' width='148' height='12' rx='6' fill='%23145f4b'/%3E%3Crect x='106' y='106' width='104' height='10' rx='5' fill='%23b6a184'/%3E%3Crect x='106' y='126' width='126' height='10' rx='5' fill='%23b6a184'/%3E%3Crect x='106' y='146' width='90' height='10' rx='5' fill='%23b6a184'/%3E%3Ccircle cx='260' cy='162' r='16' fill='%23e2f1ea'/%3E%3Cpath d='M252 162l6 6 12-12' fill='none' stroke='%23145f4b' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E");
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  position: relative;
  z-index: 1;
}

.auth-card {
  width: min(460px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: 0 12px 28px rgba(45, 38, 29, 0.08);
  border-radius: 12px;
}

.auth-card h1 {
  margin: 0;
  font-size: 1.35rem;
}

.auth-card p {
  margin: 6px 0 14px;
  color: var(--muted);
}

.auth-form {
  grid-template-columns: 1fr;
}

.auth-form input[type="text"],
.auth-form input[type="password"] {
  text-transform: none;
}

#login-message {
  margin-top: 8px;
}

.content {
  display: grid;
  gap: 16px;
  height: 100vh;
  overflow-y: auto;
  padding: 0;
}

section {
  scroll-margin-top: 24px;
}

section[hidden] {
  display: none !important;
}

.overview-stack {
  display: grid;
  gap: 3px;
  grid-template-columns: minmax(0, 1fr);
}

.overview-info-panel,
.overview-tables-panel {
  min-width: 0;
}

.overview-tables-panel {
  display: grid;
  gap: 3px;
  grid-template-columns: minmax(0, 1fr);
  padding-top: 5px;
}

.overview-tables-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.overview-tables-toolbar #pending-rent-summary {
  margin: 0;
  flex: 1 1 auto;
  min-width: 320px;
}

.overview-tables-toolbar .header-controls {
  margin-left: 0;
  flex: 0 0 auto;
}

#refresh-overview {
  margin-right: 5px;
}

@media (min-width: 1200px) {
  #overview.overview-stack {
    grid-template-columns: minmax(0, 15%) minmax(0, 85%);
    align-items: start;
  }
}

.overview-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.overview-kpi-card {
  border: 1px solid var(--border);
  background: #f8f4ee;
  padding: 8px;
  min-height: 74px;
  display: grid;
  gap: 4px;
}

.overview-kpi-title {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.overview-kpi-value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.15;
}

.overview-kpi-sub {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
}

.overview-kpi-card.kpi-neutral .overview-kpi-value {
  color: var(--primary);
}

.overview-kpi-card.kpi-warning {
  border-color: #d9a149;
  background: #fff6e9;
}

.overview-kpi-card.kpi-warning .overview-kpi-value,
.overview-kpi-card.kpi-warning .overview-kpi-sub {
  color: #c27803;
}

.overview-kpi-card.kpi-danger {
  border-color: #e2a4a0;
  background: #fff0ef;
}

.overview-kpi-card.kpi-danger .overview-kpi-value,
.overview-kpi-card.kpi-danger .overview-kpi-sub {
  color: #b42318;
}

.overview-kpi-card.kpi-good {
  border-color: #7fb8a3;
  background: #ecf7f2;
}

.overview-kpi-card.kpi-good .overview-kpi-value,
.overview-kpi-card.kpi-good .overview-kpi-sub {
  color: #145f4b;
}

.overview-header-line {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.overview-header-line h2 {
  margin: 0;
}

.overview-header-line button {
  margin-left: auto;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}

.header-controls select {
  width: auto;
  min-width: 180px;
}

.header-controls button {
  margin-left: 0;
}

#monthly-closing-report .header-controls {
  flex-wrap: nowrap;
}

#monthly-closing-report .header-controls input[type="month"] {
  width: auto;
  min-width: 160px;
}

.ledger-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ledger-tabs .ledger-tab {
  margin-left: 0;
}

.ledger-tabs .ledger-tab.active {
  background: var(--primary);
  color: #fff;
}

.ledger-panel {
  margin-top: 6px;
}

.hero h2 {
  margin: 0;
  font-size: 1.75rem;
}

.hero p {
  margin: 6px 0 0;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 16px;
}

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

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 16px;
  box-shadow: 0 10px 24px rgba(48, 39, 28, 0.06);
}

.card h2 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 1.08rem;
}

.form {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 10px 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 5px;
  font-size: 0.92rem;
  grid-column: span 12;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--control-radius);
  background: #fff;
  padding: 6px 12px;
}

input[type="text"],
textarea {
  text-transform: uppercase;
}

input[type="email"] {
  text-transform: lowercase;
}

input[type="file"] {
  color: var(--muted);
}

input[type="file"]::file-selector-button {
  border: 0;
  border-radius: var(--control-radius);
  background: var(--primary);
  color: #fff;
  padding: 4px 10px;
  margin-right: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  transition: 0.2s ease;
}

input[type="file"]::file-selector-button:hover {
  background: var(--primary-hover);
}

input[type="file"]::-webkit-file-upload-button {
  border: 0;
  border-radius: var(--control-radius);
  background: var(--primary);
  color: #fff;
  padding: 4px 10px;
  margin-right: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  transition: 0.2s ease;
}

input[type="file"]::-webkit-file-upload-button:hover {
  background: var(--primary-hover);
}

textarea {
  min-height: 72px;
  resize: vertical;
}

button {
  border: 0;
  border-radius: var(--control-radius);
  background: var(--primary);
  color: white;
  padding: 10px 14px;
  cursor: pointer;
  transition: 0.2s ease;
}

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

button.ghost {
  background: #ece3d5;
  color: var(--text);
}

button.ghost:hover {
  background: #e0d4c2;
}

.inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.inline > select {
  width: min(360px, 100%);
}

.table-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  margin-bottom: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
  width: 100%;
}

.table-tools input {
  width: min(280px, 100%);
}

.table-tools button {
  padding: 6px 10px;
}

.audit-tools-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.audit-tools-row #audit-summary {
  margin: 0;
  flex: 1 1 auto;
}

.audit-tools-row #audit-table-tools {
  margin: 0;
  width: auto;
  flex: 0 0 auto;
  flex-wrap: nowrap;
}

.audit-tools-row #audit-table-tools input {
  width: 240px;
}

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

.checkline input[type="checkbox"] {
  width: auto;
}

.summary {
  background: #f8f4ee;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 10px;
  margin-bottom: 10px;
  min-height: 44px;
  font-size: 0.92rem;
}

#receipt-derived-info {
  font-size: 0.75rem;
  padding: 5px;
  margin-bottom: 0;
}

#pending-rent-summary {
  border-radius: 0;
}

#not-rented-info-summary.summary-red-flag {
  background: #fff0ef;
  border-color: #e2a4a0;
  color: #b42318;
  font-weight: 700;
}

#not-rented-info-summary.summary-ok-flag {
  background: #ecf7f2;
  border-color: #7fb8a3;
  color: #145f4b;
  font-weight: 700;
}

.receipt-property-title {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

#receipt-property-caption {
  white-space: nowrap;
}

.field-sm {
  grid-column: span 3;
}

.field-xs {
  grid-column: span 2;
}

.field-md {
  grid-column: span 4;
}

.field-lg {
  grid-column: span 5;
}

.field-full {
  grid-column: 1 / -1;
}

.field-half {
  grid-column: span 6;
}

.field-two-third {
  grid-column: span 8;
}

.field-three-quarter {
  grid-column: span 9;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  justify-content: flex-start;
  margin-top: 2px;
}

.form > button {
  grid-column: 1 / -1;
  justify-self: start;
}

.hint {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8f4ee;
  color: var(--muted);
  font-size: 0.88rem;
}

#deposit-list .hint {
  border-radius: 0;
}

.table-wrap {
  overflow-x: auto;
  margin: 0;
  padding: 0;
}

.card .table-wrap {
  margin-top: var(--table-wrap-gap);
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
  line-height: 1.2;
}

th,
td {
  text-align: left;
  padding: var(--table-cell-py) var(--table-cell-px);
  border-bottom: 1px solid #e7ddcf;
  border-right: 1px solid #e7ddcf;
  vertical-align: middle;
  white-space: nowrap;
}

th:last-child,
td:last-child {
  border-right: none;
}

th {
  color: var(--text);
  background: var(--bg-accent);
  font-weight: 700;
  font-size: var(--table-head-font-size);
  padding-top: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  border-right-color: var(--border);
}

td {
  font-size: 0.85rem;
}

.amount {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
}

#add-receipt table th:nth-child(7),
#add-receipt table th:nth-child(8),
#add-receipt table th:nth-child(9),
#add-receipt table td:nth-child(7),
#add-receipt table td:nth-child(8),
#add-receipt table td:nth-child(9) {
  width: 10%;
  min-width: 96px;
}

#add-agreement table th:nth-child(8),
#add-agreement table td:nth-child(8) {
  width: 6%;
  min-width: 72px;
}

#ledger-report table th:nth-child(7),
#ledger-report table th:nth-child(8),
#ledger-report table th:nth-child(9),
#ledger-report table td:nth-child(7),
#ledger-report table td:nth-child(8),
#ledger-report table td:nth-child(9) {
  width: 10%;
  min-width: 96px;
}

#pending-rent-table th:nth-child(3),
#pending-rent-table th:nth-child(4),
#pending-rent-table th:nth-child(5),
#pending-rent-table th:nth-child(6),
#pending-rent-table td:nth-child(3),
#pending-rent-table td:nth-child(4),
#pending-rent-table td:nth-child(5),
#pending-rent-table td:nth-child(6) {
  text-align: center;
}

#overview-aging-table th:nth-child(3),
#overview-aging-table td:nth-child(3) {
  text-align: center;
}

#audit-table td:last-child {
  white-space: normal;
  max-width: 520px;
  word-break: break-word;
}

table tfoot td {
  background: var(--bg-accent);
  color: var(--text);
  font-weight: 700;
  border-top: 1px solid var(--border);
  padding-top: 6px;
  padding-bottom: 6px;
  border-right-color: var(--border);
}

.row-expiring-soon td {
  color: #c27803;
  font-weight: 700;
}

.row-completed td {
  color: #b42318;
  font-weight: 700;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--table-action-gap);
  margin: 0;
  padding: 0;
}

.table-actions button {
  padding: 3px 7px;
  font-size: 0.74rem;
  border-radius: var(--control-radius);
}

.table-actions .user-role-select {
  width: auto;
  min-width: 108px;
  padding: 3px 7px;
  font-size: 0.74rem;
  border-radius: var(--control-radius);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 20, 15, 0.45);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 12px;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-card {
  width: min(560px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 18px 28px rgba(35, 30, 22, 0.2);
  display: grid;
  gap: 8px;
}

.modal-card h3 {
  margin: 0;
  font-size: 1rem;
}

.modal-subtitle {
  margin: 0 0 4px;
  font-size: 0.84rem;
  color: var(--muted);
  width: 100%;
  display: block;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

.modal-subtitle-top {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.modal-subtitle-bottom {
  display: block;
  margin-top: 4px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

body.modal-open {
  overflow: hidden;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #1f3b33;
  color: white;
  border-radius: 10px;
  padding: 10px 12px;
  opacity: 0;
  transform: translateY(12px);
  transition: 0.2s ease;
  pointer-events: none;
  z-index: 30;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1000px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
  }

  .sidebar {
    position: static;
    display: grid;
    gap: 12px;
    height: auto;
  }

  .side-nav {
    display: flex;
    flex-wrap: wrap;
  }

  .nav-link {
    width: fit-content;
  }

  .content {
    height: auto;
    padding: 0;
  }
}

@media (max-width: 900px) {
  .form {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .field-sm,
  .field-xs,
  .field-md,
  .field-lg,
  .field-half,
  .field-two-third,
  .field-three-quarter {
    grid-column: span 3;
  }

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

@media (max-width: 620px) {
  .form {
    grid-template-columns: 1fr;
  }

  .modal-subtitle-top {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .field-sm,
  .field-xs,
  .field-md,
  .field-lg,
  .field-full,
  .field-half,
  .field-two-third,
  .field-three-quarter {
    grid-column: 1 / -1;
  }

  .audit-tools-row {
    flex-wrap: wrap;
  }

  .audit-tools-row #audit-summary,
  .audit-tools-row #audit-table-tools {
    flex: 1 1 100%;
    width: 100%;
  }
}
