:root {
  color-scheme: light;
  --ink: #172027;
  --muted: #64707b;
  --line: #d8dee4;
  --surface: #ffffff;
  --page: #f3f5f2;
  --green: #176b55;
  --red: #a13f3f;
  --gold: #b27a22;
  --blue: #315f87;
  --shadow: 0 18px 45px rgba(25, 35, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  background: var(--page);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
select,
input {
  font: inherit;
}

.sidebar {
  min-height: 100vh;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #142326;
  color: #f4f7f3;
}

.eyebrow {
  margin: 0 0 8px;
  color: #77918e;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.05;
}

h2 {
  font-size: 30px;
}

h3 {
  font-size: 18px;
}

nav {
  display: grid;
  gap: 8px;
  margin-top: 34px;
}

.nav {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  background: transparent;
  color: #e8efec;
  cursor: pointer;
  text-align: left;
  padding: 10px 12px;
}

.nav:hover,
.nav.active {
  background: #f4f7f3;
  color: #142326;
}

.source {
  display: grid;
  gap: 6px;
  color: #b7c6c2;
  font-size: 12px;
}

.source strong {
  color: #fff;
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.filters {
  display: flex;
  gap: 12px;
  align-items: center;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

select {
  min-width: 210px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

input {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 18px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
}

.metrics article,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 18px;
  display: grid;
  gap: 10px;
}

.metrics span,
.detail-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metrics strong {
  font-size: 25px;
}

.grid.two {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: 18px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

.panel-head span {
  color: var(--muted);
  font-size: 13px;
}

.chart {
  min-height: 270px;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 8px;
  align-items: end;
  padding-top: 18px;
}

.bar {
  min-width: 0;
  display: grid;
  gap: 8px;
  align-items: end;
  justify-items: center;
}

.bar i {
  width: 100%;
  max-width: 34px;
  min-height: 4px;
  border-radius: 5px 5px 2px 2px;
  background: var(--green);
}

.bar.negative i {
  background: var(--red);
}

.bar span {
  color: var(--muted);
  font-size: 11px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.excel-wrap table {
  min-width: 1580px;
}

.excel-input {
  width: 100%;
  min-width: 120px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  padding: 6px 7px;
}

.excel-input:hover,
.excel-input:focus {
  border-color: var(--blue);
  background: #fff;
  outline: none;
}

td.num .excel-input {
  text-align: right;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  background: #edf1ef;
  color: #3c474d;
  font-size: 12px;
  text-transform: uppercase;
}

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

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

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 10px;
  background: #fbfcfb;
}

.card h4 {
  margin: 0;
  font-size: 15px;
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.card footer {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.detail-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 7px;
  background: #fbfcfb;
}

.history-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

.purchase-section,
.expense-section {
  border-top: 1px solid var(--line);
  margin: 0 0 18px;
  padding-top: 16px;
}

.purchase-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(170px, 240px));
  gap: 12px;
}

.purchase-form label,
.expense-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.expense-section .table-wrap {
  margin-top: 14px;
}

.expense-form {
  display: grid;
  grid-template-columns: minmax(140px, 0.75fr) minmax(160px, 0.9fr) minmax(210px, 1.4fr) minmax(130px, 0.7fr) minmax(180px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.expense-form select {
  min-width: 0;
}

.panel-note {
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.contract-form {
  grid-template-columns: repeat(7, minmax(130px, 1fr)) auto;
}

.history-section {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 8px;
}

.section-title h4 {
  margin: 0;
  font-size: 15px;
}

.section-title span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.agreement-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.report-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.action-status {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.agreement-output {
  width: 100%;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink);
  background: #fff;
  resize: vertical;
}

.action-button,
.mini-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
}

.action-button {
  min-height: 40px;
  padding: 0 14px;
}

.mini-button {
  min-height: 30px;
  padding: 5px 9px;
}

.muted-cell {
  color: var(--muted);
}

.rent-collection-panel { margin-bottom: 20px; }
.rent-collection-editor { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 10px; align-items: end; margin-top: 14px; padding: 14px; background: #f7f8f5; border-radius: 8px; }
.rent-status { font-weight: 700; }
.rent-status-received { color: #18733c; }
.rent-status-overdue { color: #b42318; }
.rent-status-partial, .rent-status-due { color: #9a6700; }
.rent-received { background: #18733c; color: white; }

.print-agreement-content,
.print-report-content {
  display: none;
}

.issues {
  display: grid;
  gap: 10px;
}

.issue {
  border-left: 4px solid var(--gold);
  background: #fff9ec;
  padding: 12px 14px;
  border-radius: 6px;
}

.issue strong,
.issue span {
  display: block;
}

.issue span {
  color: var(--muted);
  margin-top: 4px;
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: 0;
    gap: 18px;
  }

  nav {
    grid-template-columns: repeat(6, 1fr);
    margin-top: 18px;
  }

  .topbar,
  .filters {
    align-items: stretch;
    flex-direction: column;
  }

  select {
    width: 100%;
  }

  .metrics,
  .grid.two,
  .detail-grid,
  .purchase-form,
    .history-form,
    .expense-form,
.rent-collection-editor {
    grid-template-columns: 1fr;
  }
}

.register-filters, .expense-quick-entry { align-items: end; }
.register-filters input, .register-filters select { min-width: 9rem; }

@media (max-width: 640px) {
  main {
    padding: 18px;
  }

  nav {
    grid-template-columns: 1fr 1fr;
  }

  .metrics strong {
    font-size: 22px;
  }
}

@media print {
  body {
    display: block;
    background: #fff;
  }

  .sidebar,
  .topbar,
  main > section,
  .agreement-panel {
    display: none !important;
  }

  main {
    padding: 0;
  }

  body.print-agreement-mode .print-agreement-content,
  body.print-report-mode .print-report-content {
    display: block;
    white-space: pre-wrap;
    color: #111;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12pt;
    line-height: 1.45;
  }
}
.action-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.action-card { border: 1px solid #d8ddd9; background: #fff; border-radius: 12px; padding: 14px; text-align: left; cursor: pointer; }
.action-card strong, .action-card span { display: block; }
