/* ============================================================
   RENTAL PORTFOLIO — STYLESHEET
   Clean, readable, works on desktop and tablet.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #ffffff;
  --bg2:         #f7f7f5;
  --bg3:         #efefeb;
  --border:      rgba(0,0,0,0.10);
  --border2:     rgba(0,0,0,0.18);
  --text:        #1a1a18;
  --text2:       #5a5a55;
  --text3:       #8a8a85;
  --accent:      #1a6ef5;
  --accent-bg:   #e8f0fe;
  --green:       #2d7a3a;
  --green-bg:    #e8f5ea;
  --red:         #a32020;
  --red-bg:      #fceaea;
  --amber:       #7a5200;
  --amber-bg:    #fef3db;
  --purple:      #4a3ab5;
  --purple-bg:   #eeeefe;
  --radius:      8px;
  --radius-lg:   12px;
  --shadow:      0 1px 3px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg2);
  min-height: 100vh;
}

/* ── Layout ───────────────────────────────────────────────── */

#app { display: flex; flex-direction: column; min-height: 100vh; }

header {
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

nav { display: flex; gap: 2px; }

nav button {
  padding: 6px 14px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text2);
  border-radius: var(--radius);
  transition: background 0.1s, color 0.1s;
}
nav button:hover  { background: var(--bg2); color: var(--text); }
nav button.active { background: var(--bg3); color: var(--text); font-weight: 500; }

.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

#sync-status { font-size: 12px; color: var(--text3); }

main { flex: 1; padding: 1.5rem; max-width: 1100px; margin: 0 auto; width: 100%; }

.page { display: none; }
.page.active { display: block; }

/* ── Cards ────────────────────────────────────────────────── */

.card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.card-title { font-size: 14px; font-weight: 500; }

/* ── Metric grid ──────────────────────────────────────────── */

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 1.25rem;
}

#rep-metrics {
  grid-template-columns: repeat(3, 1fr);
}

.metric {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.metric .m-label  { font-size: 11px; color: var(--text3); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.04em; }
.metric .m-value  { font-size: 22px; font-weight: 500; line-height: 1.2; }
.metric .m-sub    { font-size: 11px; color: var(--text3); margin-top: 3px; }

/* ── Apt cards ────────────────────────────────────────────── */

.apt-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 1.25rem; }

.apt-card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

.apt-card .apt-name  { font-size: 15px; font-weight: 500; margin-bottom: 2px; }
.apt-card .apt-addr  { font-size: 12px; color: var(--text2); margin-bottom: 10px; }
.apt-card .apt-stats { display: flex; gap: 1.5rem; }
.apt-card .stat      { font-size: 12px; color: var(--text3); }
.apt-card .stat strong { display: block; font-size: 14px; font-weight: 500; color: var(--text); }

/* ── Badges ───────────────────────────────────────────────── */

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 500;
  margin-bottom: 8px;
}

.badge-dk     { background: var(--accent-bg); color: var(--accent); }
.badge-pl     { background: var(--green-bg);  color: var(--green);  }
.badge-model  { background: var(--bg3);       color: var(--text2);  }
.badge-info   { background: var(--accent-bg); color: var(--accent); }

/* ── Tags (transaction type labels) ──────────────────────── */

.tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 20px;
  white-space: nowrap;
}
.tag-income   { background: var(--green-bg);  color: var(--green);  }
.tag-expense  { background: var(--red-bg);    color: var(--red);    }
.tag-deposit  { background: var(--purple-bg); color: var(--purple); }
.tag-transfer { background: var(--bg3);       color: var(--text2);  }
.tag-auto     { background: var(--amber-bg);  color: var(--amber);  font-size: 10px; }
.tag-split    { background: var(--bg3);       color: var(--text2);  font-size: 10px; }
.tx-chevron-btn { background:none; border:none; cursor:pointer; color:var(--text3); font-size:11px; padding:2px 4px; line-height:1; }
.tx-chevron-btn:hover { color:var(--text1); }
.tx-split-child td { background: var(--bg2); }
.tx-child-prefix { color: var(--text3); margin-right: 4px; }
.split-row-amt::-webkit-outer-spin-button,
.split-row-amt::-webkit-inner-spin-button,
.sr-tmpl-amt::-webkit-outer-spin-button,
.sr-tmpl-amt::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.split-row-amt, .sr-tmpl-amt { -moz-appearance: textfield; }

/* ── Tables ───────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text3);
  border-bottom: 0.5px solid var(--border);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
td { padding: 9px 10px; border-bottom: 0.5px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg2); }
.amount-cell { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.muted { color: var(--text3); }
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: var(--accent); }
.sort-asc::after  { content: ' ↑'; color: var(--accent); }
.sort-desc::after { content: ' ↓'; color: var(--accent); }
.clickable-row { cursor: pointer; }

/* ── Forms ────────────────────────────────────────────────── */

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.span-2 { grid-column: span 2; }
.form-group.span-3 { grid-column: span 3; }

label { font-size: 12px; color: var(--text2); font-weight: 500; }

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.15s;
}

/* Checkboxes and radios must not inherit the full-width rule above */
input[type="checkbox"],
input[type="radio"] {
  width: auto;
  padding: 0;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26,110,245,0.1);
}

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

.note-hint { font-size: 11px; color: var(--text3); margin-top: 2px; }
.required-note { color: var(--red); font-size: 11px; }

/* ── Buttons ──────────────────────────────────────────────── */

.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  border: 0.5px solid var(--border2);
  transition: opacity 0.1s, background 0.1s;
  white-space: nowrap;
}
.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; pointer-events: none; }

.btn-primary   { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-secondary { background: transparent; color: var(--text); }
.btn-danger    { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.btn-sm        { padding: 5px 12px; font-size: 12px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Login screen ──────────────────────────────────────────── */

#login-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.login-card {
  background: var(--bg);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  text-align: center;
  max-width: 320px;
  width: 90%;
}

.login-card h1 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.login-card p {
  color: var(--text2);
  margin-bottom: 0;
}

.login-card .btn {
  width: 100%;
  border: none;
}

/* ── Filter bar ───────────────────────────────────────────── */

.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}

.filter-bar select, .filter-bar input { width: auto; min-width: 130px; }
.filter-bar input[type=search] { min-width: 180px; }
.filter-bar input[type=date]   { min-width: 130px; }

/* ── Pill filters ─────────────────────────────────────────── */

.pill-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 1rem; }

.pill {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  border: 0.5px solid var(--border2);
  background: transparent;
  color: var(--text2);
  font-family: inherit;
  transition: background 0.1s, color 0.1s;
}
.pill:hover  { background: var(--bg3); color: var(--text); }
.pill.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ── Import area ──────────────────────────────────────────── */

.import-zone {
  border: 1.5px dashed var(--border2);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-align: center;
  color: var(--text3);
  margin-bottom: 1rem;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s;
}
.import-zone:hover       { background: var(--bg3); }
.import-zone--active     { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.import-zone strong      { display: block; font-size: 14px; color: var(--text); margin-bottom: 4px; }
.import-zone .file-name  { display: inline-block; margin-top: 6px; font-size: 12px; color: var(--accent); font-weight: 500; }
.import-paste-toggle     { font-size: 12px; color: var(--text3); text-align: center; margin-bottom: 0.75rem; }
.import-paste-toggle a   { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* ── Transactions DataTable card ── */

.tx-card {
  padding: 0;
  overflow: hidden;
}

#tx-table-wrap {
  height: calc(100vh - var(--nav-h, 52px) - 4rem); /* 3rem main padding + 1rem card margin-bottom */
}

/* ── Sticky import preview header + column headers ────────── */

/* Sticky wrapper holds card-header + toggles row as one unit */
#import-preview-sticky,
#import-static-header {
  position: sticky;
  top: 52px;
  z-index: 20;
  background: var(--bg);
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

/* Toggles row inside the sticky wrapper */
#import-preview-toggles {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.25rem;
  padding: 0.5rem 0.75rem 0.6rem;
  border-top: 1px solid var(--border);
}

.toggle-no-selection {
  opacity: 0.45;
}
.toggle-no-selection,
.toggle-no-selection * {
  cursor: default !important;
  pointer-events: none;
}

#import-table-scroll {
  overflow: auto;
  max-height: calc(100vh - 220px);
}

#import-table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 19;
  background: var(--bg);
  box-shadow: 0 1px 0 var(--border);
}

/* ── Preview table (import) ───────────────────────────────── */

.preview-row-ok   { }
.preview-row-warn td:nth-child(2) { border-left: 3px solid var(--amber); }
.preview-row-err  td { color: var(--text3); font-style: italic; }
.preview-row-ignored { opacity: 0.35; }
.preview-row-ignored td { text-decoration: line-through; }
.tag-mapping { background: var(--accent-bg); color: var(--accent); font-size: 10px; }
.preview-row-dup td { background: var(--amber-bg); }
.import-section-hdr td { background: var(--bg2); font-weight: 600; font-size: 12px; cursor: pointer; padding: 5px 8px; border-top: 2px solid var(--border); user-select: none; position: sticky; top: var(--import-thead-h, 33px); z-index: 4; }
.import-section-hdr:hover td { background: var(--bg3); }
.import-section-hdr .chevron { display: inline-block; width: 14px; font-size: 10px; }
.tag-dup { background: var(--amber); color: #fff; font-size: 10px; cursor: default; }
.dup-badge { position: relative; display: inline-flex; align-items: center; }
.dup-badge-tip {
  display: none; position: absolute; left: 0; top: calc(100% + 4px);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 8px; font-size: 11px; white-space: nowrap; z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15); min-width: 200px; line-height: 1.5;
  color: var(--text1);
}
.dup-badge:hover .dup-badge-tip { display: block; }
.preview-row-locked td { background: var(--bg2) !important; }
.tx-reconciled { opacity: 0.6; }
.btn-reconcile { background: none; border: none; padding: 0.3rem 0.6rem; cursor: pointer; font-size: 16px; color: var(--text3); border-radius: 3px; line-height: 1; }
.btn-reconcile:hover { background: var(--bg2, #f0f0f0); }
.btn-reconcile.is-reconciled { color: var(--success, #2a7a2a); }
.original-value-hint { font-size: 11px; color: var(--text3); margin-top: 2px; }
.preview-row-locked td:nth-child(2) { border-left: none !important; }
.import-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.import-sortable:hover { background: var(--bg3); }
.import-sort-ind { font-size: 9px; margin-left: 3px; color: var(--text3); }

/* ── Foldable tree (static preview) ──────────────────────── */

.tree-group { margin-bottom: 0.5rem; border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.tree-group-header { display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 1rem; background: var(--bg2); cursor: pointer; user-select: none; font-size: 14px; font-weight: 600; }
.tree-group-header:hover { background: var(--bg3); }
.tree-cat { border-top: 1px solid var(--border); }
.tree-cat-header { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 1rem 0.45rem 2rem; cursor: pointer; user-select: none; font-size: 13px; background: var(--bg); }
.tree-cat-header:hover { background: var(--bg2); }
.tree-cat-body { padding: 0 0 0.5rem 0; }
.tree-toggle { font-size: 10px; color: var(--text3); width: 12px; flex-shrink: 0; }
.tree-meta { margin-left: auto; font-size: 12px; color: var(--text3); font-weight: normal; }
.tree-table { width: 100%; font-size: 12px; }
.tree-table th { font-size: 11px; }

/* ── Empty state ──────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text3);
  font-size: 13px;
}
.empty-state strong { display: block; font-size: 14px; color: var(--text2); margin-bottom: 4px; }

/* ── Toast notifications ──────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  max-width: 380px;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
  white-space: pre-line;
}
.toast-success { background: var(--green-bg); color: var(--green); border: 0.5px solid var(--green); }
.toast-error   { background: var(--red-bg);   color: var(--red);   border: 0.5px solid var(--red);   }
.toast-info    { background: var(--accent-bg); color: var(--accent); border: 0.5px solid var(--accent); }

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

/* ── Loading overlay ──────────────────────────────────────── */

#loading {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 9998;
  font-size: 14px; color: var(--text2);
}
#loading.hidden { display: none; }

/* ── User Avatar and Dropdown Menu ────────────────────────── */

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  border: none;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.1s, transform 0.1s;
  position: relative;
}

.user-avatar:hover {
  opacity: 0.85;
  transform: scale(1.05);
}

.user-avatar:active {
  transform: scale(0.98);
}

.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 200px;
  display: none;
  flex-direction: column;
  z-index: 1000;
}

.user-menu.open {
  display: flex;
}

.user-menu-item {
  padding: 10px 14px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background 0.1s;
  border-bottom: 0.5px solid var(--border);
}

.user-menu-item:last-child {
  border-bottom: none;
}

.user-menu-item:hover:not(:disabled) {
  background: var(--bg2);
}

.user-menu-item:active:not(:disabled) {
  background: var(--bg3);
}

.user-menu-item:disabled {
  color: var(--text3);
  cursor: not-allowed;
}

.user-menu-item.info {
  cursor: default;
  font-size: 12px;
  color: var(--text3);
  padding: 8px 14px;
}

.user-menu-item.info:hover {
  background: transparent;
}

.user-menu-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

/* ── Generic modal shell (used by account modals) ────────── */

.modal-content {
  background: var(--bg);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-width: 95vw;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
  flex-shrink: 0;
}
.modal-title { font-weight: 600; font-size: 15px; }
.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text3);
  line-height: 1;
  padding: 0 2px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 0 1.25rem 1rem; flex: 1; overflow-y: auto; min-height: 0; }
.modal-body > :first-child { margin-top: 1rem; }
.modal-footer {
  padding: 0.75rem 1.25rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-body .data-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}

/* ── Account tree ────────────────────────────────────────── */

.account-node {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-top: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.account-node:last-child { border-bottom: none; }
.account-name { font-weight: 500; }
.account-tree-prefix {
  font-family: monospace;
  color: var(--text3);
  white-space: pre;
  flex-shrink: 0;
  font-size: 12px;
}

.row-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  text-decoration: underline;
  text-decoration-color: transparent;
}
.btn-link:hover { text-decoration-color: var(--accent); }

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 700px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .apt-grid    { grid-template-columns: 1fr; }
  .form-grid   { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  header       { gap: 1rem; padding: 0 1rem; }
  main         { padding: 1rem; }
}

/* ── Print ─────────────────────────────────────────────────── */

@media print {
  header, nav, .filter-bar, #rep-currency-btn,
  .datatable-controls, .datatable-footer,
  .col-vis-toggle, .btn { display: none !important; }

  body  { background: #fff; color: #000; font-size: 11pt; }
  main  { padding: 0; }

  #page-reports { display: block !important; }

  .card { border: 0.5px solid #ccc; box-shadow: none; break-inside: avoid; }

  #rep-metrics { grid-template-columns: repeat(3, 1fr); }

  .amount-cell.positive { color: #1a7a3c; }
  .amount-cell.negative { color: #b33; }
}
