/* ── Fluent Design — Windows 11 ──────────────────────────────────────────── */

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

html { font-size: 19px; }

:root {
  --accent:        #0078d4;
  --accent-hover:  #006cbf;
  --accent-press:  #005da6;
  --bg:            #f3f3f3;
  --surface:       #ffffff;
  --border:        rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.18);
  --text:          rgba(0,0,0,0.90);
  --text-muted:    rgba(0,0,0,0.55);
  --hover:         rgba(0,0,0,0.04);
  --press:         rgba(0,0,0,0.07);
  --r-sm:          4px;
  --r-md:          8px;
}

body {
  font-family: 'Segoe UI Variable', 'Segoe UI', system-ui, sans-serif;
  display: grid;
  grid-template-columns: 220px 1fr;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
}

/* ── Navigation ──────────────────────────────────────────────────────────── */

nav {
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.5rem 1rem;
  overflow-y: auto;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.8rem 0.65rem 1.25rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.01em;
}
.nav-logo:hover { opacity: 0.75; }

nav a:not(.nav-logo) {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.65rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.8125rem;
  border-radius: var(--r-sm);
  transition: background 0.1s, color 0.1s;
}

nav a:not(.nav-logo) svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

nav a:not(.nav-logo):hover {
  background: var(--hover);
  color: var(--text);
}

nav a.active {
  background: rgba(0,120,212,0.09);
  color: var(--accent);
  font-weight: 600;
}

nav a.nav-inline-link {
  display: inline;
  padding: 0;
  font-size: inherit;
  color: inherit;
  border-radius: 0;
}
nav a.nav-inline-link:hover { background: none; text-decoration: underline; }

nav a.active::before {
  content: '';
  position: absolute;
  left: -0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

/* ── Shell ───────────────────────────────────────────────────────────────── */

.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */

#topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#header-lessor {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.btn-logout {
  background: transparent;
  color: #c42b1c;
  border: 1px solid rgba(196,43,28,0.35);
  padding: 0.3rem 0.75rem;
  border-radius: var(--r-sm);
  font-size: 0.8rem;
  cursor: pointer;
}
.btn-logout:hover { background: #fde7e9; color: #a92114; border-color: rgba(196,43,28,0.6); }

/* ── Main ────────────────────────────────────────────────────────────────── */

main {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1.5rem 1.5rem;
  background: var(--bg);
}

section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 1rem;
}

section.dash-collapsed {
  background: transparent;
  border-color: transparent;
  padding: 0.1rem 1rem;
}
section.dash-collapsed .section-header { margin-bottom: 0; }

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

h2 { font-size: 1rem; font-weight: 600; }
h3 { font-size: 0.9375rem; font-weight: 600; margin-bottom: 1.25rem; }

/* ── Table ───────────────────────────────────────────────────────────────── */

.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 500px; }

th, td {
  text-align: left;
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
}

th {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--hover); }

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

button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.4rem 0.85rem;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 400;
  transition: background 0.1s;
}

button:hover  { background: var(--accent-hover); }
button:active { background: var(--accent-press); }
button:disabled { opacity: 0.38; cursor: not-allowed; pointer-events: none; }

button.danger       { background: #c42b1c; }
button.danger:hover { background: #a92114; }

button.secondary       { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
button.secondary:hover { background: var(--hover); }

button.btn-icon {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 0.25rem;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
}
button.btn-icon:hover { background: var(--hover); color: var(--text); }
button.btn-icon.danger       { background: transparent; color: #c42b1c; }
button.btn-icon.danger:hover { background: #fde8e6; color: #a92114; }

td button { margin-right: 0.35rem; }

/* ── Entity thumbnails (property photo / tenant avatar) ─────────────────── */

.entity-thumb {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  cursor: pointer;
  display: block;
  border: 1px solid var(--border-strong);
  transition: opacity 0.1s;
}
.entity-thumb:hover { opacity: 0.8; }

.entity-thumb-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--hover);
  border: 1px dashed var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.1s, color 0.1s;
}
.entity-thumb-placeholder:hover { background: var(--surface); color: var(--text); }

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

form { display: flex; flex-direction: column; gap: 0.85rem; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

input, textarea {
  padding: 0.5rem 0.65rem;
  border: none;
  border-bottom: 2px solid rgba(0,0,0,0.3);
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  background: rgba(0,0,0,0.03);
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  transition: border-bottom-color 0.15s, background 0.15s;
}

input:hover, textarea:hover { background: rgba(0,0,0,0.05); }

input:focus, textarea:focus {
  outline: none;
  border-bottom-color: var(--accent);
  background: rgba(0,0,0,0.04);
}

select {
  padding: 0.5rem 0.65rem;
  border: 1px solid rgba(0,0,0,0.2);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
}

select:focus { outline: none; border-color: var(--accent); }

textarea { resize: vertical; }

form button[type="submit"] { margin-top: 0.25rem; align-self: flex-start; }

/* ── Lessor detail table ─────────────────────────────────────────────────── */

.detail-table { border-collapse: collapse; width: 100%; margin-bottom: 1.25rem; }
.detail-table th {
  width: 140px;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.6rem 0;
  vertical-align: top;
}
.detail-table td { padding: 0.6rem 0; font-size: 0.875rem; }

/* ── Modal ───────────────────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: 0 8px 32px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.07);
  padding: 1.75rem;
  width: 780px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

#modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 0.25rem 0.5rem;
  line-height: 1;
  border-radius: var(--r-sm);
}
#modal-close:hover { background: var(--hover); color: var(--text); }

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

.badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 100px;
  letter-spacing: 0.02em;
}
.badge.active   { background: #dff6dd; color: #107c10; }
.badge.inactive { background: #fde7e9; color: #c42b1c; }
.badge.paid   { background: #dff6dd; color: #107c10; }
.badge.unpaid { background: #fff4ce; color: #7d5a00; }

/* ── Extra charges ───────────────────────────────────────────────────────── */

.charges-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0.25rem 0;
}

.charge-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.charge-row input { flex: 1; min-width: 0; }
.charge-row button { background: #c42b1c; padding: 0.35rem 0.6rem; flex-shrink: 0; }

/* ── Invoice detail ──────────────────────────────────────────────────────── */

.invoice-detail p { font-size: 0.875rem; margin-bottom: 0.4rem; }
.invoice-detail hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.invoice-detail ul { padding-left: 1.25rem; font-size: 0.875rem; }
.invoice-detail .total { font-size: 1rem; font-weight: 700; margin-top: 0.75rem; }

/* ── Wizard ───────────────────────────────────────────────────────────────── */

.wizard {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 2rem;
  z-index: 50;
  overflow-y: auto;
}

.wizard-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 2.5rem;
  width: 480px;
  max-width: 100%;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

.wizard-box h1 { font-size: 1.125rem; font-weight: 600; margin-bottom: 0.25rem; }
.wizard-box .subtitle { color: var(--text-muted); font-size: 0.8rem; margin-bottom: 2rem; }
.wizard-logo { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 2rem; }

.wizard-steps {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 2rem;
}

.wizard-step {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
}
.wizard-step.done    { background: var(--accent); }
.wizard-step.current { background: var(--accent); opacity: 0.45; }

.wizard-box h2 { font-size: 0.9375rem; font-weight: 600; margin-bottom: 1.25rem; }

.wizard-nav {
  display: flex;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* ── States ───────────────────────────────────────────────────────────────── */

.loading, .empty { color: var(--text-muted); padding: 2rem 0; font-size: 0.875rem; }
.error { color: #c42b1c; padding: 1rem 0; font-size: 0.875rem; }
.hint  { color: var(--text-muted); font-size: 0.8rem; margin-bottom: 0.5rem; }

#wizard-error {
  background: #fde7e9;
  border: 1px solid #f4b9bc;
  border-radius: var(--r-sm);
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  color: #c42b1c;
  margin-top: 0.5rem;
}
#wizard-error details { margin-top: 0.4rem; }
#wizard-error summary { cursor: pointer; font-size: 0.75rem; opacity: 0.75; }
#wizard-error pre { margin-top: 0.4rem; font-size: 0.72rem; white-space: pre-wrap; word-break: break-all; }

.new-rate-box {
  background: #fff4ce;
  border: 1px solid #f0c010;
  border-radius: var(--r-sm);
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.new-rate-box.hidden { display: none; }

.text-muted  { color: var(--text-muted); font-size: 0.8rem; }
.active-row td { font-weight: 500; }

/* ── Dashboard ───────────────────────────────────────────────────────────── */

.dashboard { display: flex; flex-direction: column; gap: 0.65rem; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0.85rem 1.25rem;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
  margin-bottom: 0.3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-of { font-size: 1rem; font-weight: 400; color: var(--text-muted); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }
.stat-sub   { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ── Sortable table headers ───────────────────────────────────────────────── */

th.th-sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.th-sortable:hover { color: var(--text); }

.th-sort-icon       { margin-left: 0.25rem; opacity: 0.3; font-size: 0.6rem; }
.th-sort-icon.active { opacity: 1; color: var(--accent); }

tfoot.report-totals td,
tr.report-totals td {
  border-top: 2px solid var(--border-strong);
  border-bottom: none;
  padding-top: 0.75rem;
}
