:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #dee2e6;
  --text: #212529;
  --text-muted: #6c757d;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 6px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* Nav */
.topnav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.nav-links { display: flex; align-items: center; gap: 1.25rem; }
.nav-links a { color: var(--text-muted); text-decoration: none; font-size: 0.9rem; }
.nav-links a:hover { color: var(--text); }
.nav-user { color: var(--text-muted); font-size: 0.85rem; }

/* Main */
main { max-width: 960px; margin: 0 auto; padding: 1.5rem 1rem; }

/* Page header */
.page-header { margin-bottom: 1.5rem; }
.page-header h2 { margin-bottom: 0.25rem; }
.page-header .address { color: var(--text-muted); font-size: 0.9rem; }
.back-link { color: var(--text-muted); text-decoration: none; font-size: 0.85rem; display: block; margin-bottom: 0.25rem; }
.back-link:hover { color: var(--primary); }

.badge {
  display: inline-block;
  background: var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  vertical-align: middle;
}

/* Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.data-table th {
  text-align: left;
  padding: 0.6rem 1rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  background: var(--bg);
}

.data-table td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.clickable-row { cursor: pointer; }
.clickable-row:hover { background: #f0f4ff; }

.unit-number { font-weight: 600; font-family: monospace; font-size: 0.95rem; }

/* Status badges */
.status-badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-weight: 500;
}
.status-resident { background: #dcfce7; color: #166534; }
.status-second_home { background: #dbeafe; color: #1e40af; }
.status-rented { background: #fef9c3; color: #854d0e; }
.status-unknown { background: #f3f4f6; color: #6b7280; }
.status-for_sale { background: #fce7f3; color: #9d174d; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card h3 { margin-bottom: 0.75rem; font-size: 1rem; }

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

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-group { display: flex; flex-direction: column; gap: 0.25rem; }
.form-group.full-width { grid-column: 1 / -1; }

.form-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

input[type="text"],
input[type="email"],
textarea,
select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

input:disabled {
  background: var(--bg);
  color: var(--text-muted);
}

textarea { resize: vertical; }

.role-select {
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.45rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.5;
  text-align: center;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
}
.btn-secondary:hover { background: var(--bg); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: transparent;
  font-size: 0.8rem;
}
.btn-danger:hover { background: #fef2f2; }

.btn-sm { padding: 0.2rem 0.6rem; font-size: 0.8rem; }

/* Form actions */
.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.right-actions { display: flex; gap: 0.5rem; }
.inline-form { display: inline; }

/* Dialog */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}

dialog::backdrop { background: rgba(0,0,0,0.3); }

dialog h3 { margin-bottom: 1rem; }
dialog .form-group { margin-bottom: 0.75rem; }
dialog .form-group label { display: block; margin-bottom: 0.25rem; }
dialog input, dialog select { width: 100%; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.login-card h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.login-card .subtitle { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.9rem; }

.login-card form { text-align: left; }
.login-card label { display: block; margin-bottom: 0.25rem; font-size: 0.85rem; font-weight: 500; }
.login-card input[type="email"] { width: 100%; margin-bottom: 0.75rem; }
.login-card .checkbox-label { margin-bottom: 1rem; font-size: 0.85rem; }
.login-card .btn { width: 100%; }

.dev-banner {
  background: #fef3c7;
  color: #92400e;
  padding: 0.5rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.dev-logins { display: flex; flex-direction: column; gap: 0.5rem; }

.dev-login-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
}
.dev-login-btn:hover { border-color: var(--primary); background: #f0f4ff; }
.dev-login-btn strong { display: block; font-size: 0.9rem; }
.dev-login-btn small { color: var(--text-muted); font-size: 0.8rem; }

/* Alerts */
.alert {
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* Reports */
.reports-list { display: grid; gap: 1rem; }

.report-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s;
}
.report-card:hover { border-color: var(--primary); }
.report-card h3 { margin-bottom: 0.25rem; }
.report-card p { color: var(--text-muted); font-size: 0.9rem; }

/* Filter bar */
.filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--border);
}

.building-tabs, .status-tabs {
  display: flex;
  gap: 0.25rem;
  padding-bottom: 0;
}

.tab {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-weight: 500;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Nav row (prev/next + back links) */
.nav-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.back-links { display: flex; gap: 1rem; }

.prev-next { display: flex; gap: 0.25rem; }
.prev-next .disabled { opacity: 0.3; pointer-events: none; }

/* Toast */
.toast {
  position: fixed;
  top: 68px;
  right: 1rem;
  background: #166534;
  color: white;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 100;
  transition: opacity 0.4s;
}
.toast.fade-out { opacity: 0; }

/* Error page */
.error-page { text-align: center; padding: 3rem 1rem; }
.error-page p { margin: 1rem 0; color: var(--text-muted); }

/* Responsive */
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-group.full-width { grid-column: 1; }
  main { padding: 1rem 0.75rem; }
  .topnav { padding: 0 0.75rem; }
  .data-table th, .data-table td { padding: 0.5rem 0.6rem; }
}
