/* ----------------------------------------------------------------
   Rental Manager — refined, calm, dense.
   ---------------------------------------------------------------- */
:root {
  /* Palette */
  --bg:            #f6f7f9;
  --surface:       #ffffff;
  --surface-2:     #fafbfc;
  --border:        #e5e7eb;
  --border-strong: #d1d5db;
  --row-hover:     #f3f6fc;

  --text:          #0f172a;
  --text-2:        #334155;
  --muted:         #64748b;
  --muted-2:       #94a3b8;

  --accent:        #2563eb;
  --accent-2:      #1d4ed8;
  --accent-soft:   #eff4ff;
  --accent-ring:   rgba(37, 99, 235, 0.18);

  --green:         #047857;
  --green-soft:    #ecfdf5;
  --amber:         #b45309;
  --amber-soft:    #fffbeb;
  --red:           #b91c1c;
  --red-soft:      #fef2f2;
  --slate-soft:    #f1f5f9;

  --radius:   8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow:    0 1px 2px rgba(15, 23, 42, 0.05),
               0 4px 12px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
               Roboto, Helvetica, Arial, "Apple Color Emoji",
               "Segoe UI Emoji", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); text-decoration: underline; }

/* Icons */
.ico {
  width: 16px; height: 16px;
  stroke-width: 2;
  flex-shrink: 0;
  vertical-align: -3px;
}
.ico-xs { width: 13px; height: 13px; vertical-align: -2px; }
.ico-sm { width: 14px; height: 14px; }
.ico-lg { width: 20px; height: 20px; vertical-align: -4px; }
.ico-xl { width: 28px; height: 28px; }
.ico.muted { color: var(--muted-2); }

/* ----------------------------------------------------------------
   Top bar
   ---------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 28px;
  background: #0f172a;
  background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
  color: #e5e7eb;
  padding: 0 22px;
  height: 52px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
  position: sticky; top: 0; z-index: 50;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; letter-spacing: -0.01em;
}
.brand a {
  color: #ffffff;
  display: flex; align-items: center; gap: 8px;
  font-size: 14.5px;
}
.brand a:hover { text-decoration: none; color: #ffffff; }
.brand .ico { color: #60a5fa; }

.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a {
  color: #cbd5e1;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px;
  font-weight: 500;
  transition: background 80ms ease, color 80ms ease;
}
.topnav a:hover { background: rgba(255, 255, 255, 0.06); color: #ffffff; text-decoration: none; }
.topnav a.active { background: rgba(96, 165, 250, 0.18); color: #ffffff; }

.useractions { display: flex; align-items: center; gap: 14px; }
.username {
  color: #cbd5e1; font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px;
}
.linkish {
  background: none; border: none; color: #cbd5e1; cursor: pointer;
  font: inherit; padding: 6px 10px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; gap: 6px;
}
.linkish:hover { color: #ffffff; background: rgba(255, 255, 255, 0.06); text-decoration: none; }
.inline { display: inline; }

/* ----------------------------------------------------------------
   Layout & messages
   ---------------------------------------------------------------- */
.content { padding: 22px 28px 60px 28px; max-width: 1600px; margin: 0 auto; }

.messages { padding: 12px 28px 0; max-width: 1600px; margin: 0 auto; }
.msg {
  padding: 9px 14px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.msg-success { background: var(--green-soft); border-color: #a7f3d0; color: var(--green); }
.msg-error   { background: var(--red-soft);   border-color: #fecaca; color: var(--red); }

/* Page header */
.page-header {
  display: flex; align-items: baseline; gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-header h1 {
  margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.015em;
}
.page-header .crumbs {
  color: var(--muted); font-size: 12px;
  display: flex; align-items: center; gap: 4px;
}
.page-header .crumbs a { color: var(--muted); }
.page-header .grow { flex: 1; }

/* ----------------------------------------------------------------
   Cards & surfaces
   ---------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card + .card { margin-top: 14px; }
.card .body { padding: 18px 20px; }

/* ----------------------------------------------------------------
   Toolbar (filters + search + actions)
   ---------------------------------------------------------------- */
.toolbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
}
.input,
.toolbar input[type="search"],
.toolbar input[type="text"],
.toolbar select,
.form input[type="text"],
.form input[type="number"],
.form input[type="date"],
.form input[type="password"],
.form input[type="email"],
.form input[type="file"],
.form select,
.form textarea {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  border-radius: var(--radius-sm);
  transition: border-color 80ms ease, box-shadow 80ms ease;
}
.input:focus,
.toolbar input:focus, .toolbar select:focus,
.form input:focus, .form select:focus, .form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.toolbar .grow { flex: 1; min-width: 220px; }
.spacer { flex: 1; }

/* Search input with icon */
.search-wrap { position: relative; flex: 1; min-width: 220px; }
.search-wrap .ico {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--muted-2); pointer-events: none;
}
.search-wrap input { padding-left: 34px; width: 100%; }

/* ----------------------------------------------------------------
   Buttons
   ---------------------------------------------------------------- */
.btn,
.btn-primary, .btn-secondary, .btn-danger, .btn-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: background 80ms ease, border-color 80ms ease, color 80ms ease, box-shadow 80ms ease, transform 80ms ease;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted-2); text-decoration: none; color: var(--text); }
.btn:active { transform: translateY(0.5px); }

.btn-primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25);
}
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

.btn-danger { background: var(--surface); color: var(--red); border-color: #fecaca; }
.btn-danger:hover { background: var(--red); color: #fff; border-color: var(--red); }

.btn-ghost {
  border: 1px solid transparent;
  background: transparent;
  padding: 5px 8px;
  color: var(--text-2);
  font-size: 12.5px;
}
.btn-ghost:hover { background: var(--row-hover); color: var(--text); }
.btn-ghost.danger:hover { background: var(--red-soft); color: var(--red); }

button.btn, button.btn-primary, button.btn-danger, button.btn-ghost { font: inherit; }
button.btn-primary { padding: 7px 14px; }
.btn .ico, .btn-primary .ico, .btn-danger .ico, .btn-ghost .ico { margin-right: 0; }

/* ----------------------------------------------------------------
   Tables
   ---------------------------------------------------------------- */
.sheet {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface);
  font-size: 13px;
}
.sheet-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.sheet th, .sheet td {
  padding: 10px 14px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.sheet thead th {
  background: var(--surface-2);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border-strong);
  padding-top: 11px;
  padding-bottom: 11px;
  line-height: 1.2;
}
.sheet thead th:first-child { border-top-left-radius: var(--radius-lg); }
.sheet thead th:last-child { border-top-right-radius: var(--radius-lg); }
.sheet tbody tr { transition: background 80ms ease; }
.sheet tbody tr:hover { background: var(--row-hover); cursor: pointer; }
.sheet tbody tr:last-child td { border-bottom: none; }
.sheet td.num { text-align: right; font-variant-numeric: tabular-nums; }
.sheet td.alias { font-weight: 600; }
.sheet td .row-meta { color: var(--muted); font-size: 11.5px; }

.sort-link {
  color: inherit; text-decoration: none;
  display: inline-flex; align-items: center; gap: 4px;
}
.sort-link:hover { color: var(--accent); text-decoration: none; }

.scroll-x { overflow-x: auto; max-width: 100%; }

/* ----------------------------------------------------------------
   Pills / badges
   ---------------------------------------------------------------- */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
}
.pill .ico { width: 11px; height: 11px; }

.pill-occupied { background: var(--green-soft); color: var(--green); border-color: #a7f3d0; }
.pill-vacant   { background: var(--slate-soft); color: var(--muted); border-color: #cbd5e1; }
.pill-current  { background: var(--green-soft); color: var(--green); border-color: #a7f3d0; }
.pill-late     { background: var(--amber-soft); color: var(--amber); border-color: #fde68a; }
.pill-critical { background: var(--red-soft);   color: var(--red);   border-color: #fecaca; }
.pill-paid     { background: var(--green-soft); color: var(--green); border-color: #a7f3d0; }
.pill-pending  { background: var(--slate-soft); color: var(--muted); border-color: #cbd5e1; }
.pill-overdue  { background: var(--red-soft);   color: var(--red);   border-color: #fecaca; }

.flag {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10.5px; padding: 2px 6px; border-radius: 4px;
  background: var(--amber-soft); color: var(--amber);
  font-weight: 500; margin-right: 4px;
  border: 1px solid #fde68a;
}
.flag .ico { width: 10px; height: 10px; }
.flag-vacant   { background: var(--slate-soft); color: var(--muted); border-color: #cbd5e1; }
.flag-overdue  { background: var(--red-soft);   color: var(--red);   border-color: #fecaca; }
.flag-upcoming_adjustment { background: var(--accent-soft); color: var(--accent); border-color: #c7d6f7; }

/* ----------------------------------------------------------------
   Forms
   ---------------------------------------------------------------- */
.form {
  display: grid; grid-template-columns: 220px 1fr; gap: 12px 16px;
  max-width: 760px;
  align-items: center;
}
.form label {
  color: var(--text-2); font-size: 12.5px; font-weight: 500;
}
.form > div input,
.form > div select,
.form > div textarea { width: 100%; }
.form .helptext { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.form .errorlist {
  color: var(--red); font-size: 12px; margin: 4px 0 0 0; padding: 0; list-style: none;
}
.form .actions {
  grid-column: 2 / 3;
  display: flex; gap: 8px; margin-top: 8px; padding-top: 16px;
  border-top: 1px dashed var(--border);
}

/* Login card */
.login-card {
  max-width: 380px; margin: 80px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}
.login-card .brand-block {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 22px;
}
.login-card .brand-block .ico { color: var(--accent); }
.login-card h1 { margin: 0; font-size: 17px; font-weight: 600; }
.login-card .form { grid-template-columns: 1fr; gap: 8px; }
.login-card .form label { font-weight: 500; color: var(--text-2); }
.login-card .error { color: var(--red); font-size: 12.5px; margin-top: 8px; }
.login-card .actions {
  grid-column: 1 / -1; display: block; padding-top: 12px; border-top: none; margin-top: 16px;
}
.login-card button { width: 100%; justify-content: center; padding: 9px 14px; }

/* ----------------------------------------------------------------
   Unit detail
   ---------------------------------------------------------------- */
.unit-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center; gap: 18px;
  flex-wrap: wrap;
}
.unit-hero .pile { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.unit-hero h1 {
  margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -0.02em;
  display: flex; align-items: center; gap: 10px;
}
.unit-hero h1 .ico { color: var(--accent); width: 22px; height: 22px; }
.unit-hero .sub {
  color: var(--muted); font-size: 12.5px;
  display: flex; align-items: center; gap: 6px; margin-top: 2px;
}
.unit-hero .grow { flex: 1; }
.unit-hero .actions-row { display: flex; gap: 8px; flex-wrap: wrap; }

details.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
details.section > summary {
  list-style: none; cursor: pointer;
  padding: 14px 20px;
  display: flex; align-items: center; gap: 12px;
  font-weight: 600;
  font-size: 13.5px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  user-select: none;
  transition: background 80ms ease;
}
details.section[open] > summary { border-bottom-color: var(--border); }
details.section:not([open]) > summary { border-bottom-color: transparent; }
details.section > summary:hover { background: #eef2f7; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary .chev {
  width: 16px; height: 16px; color: var(--muted-2);
  transition: transform 120ms ease;
}
details.section[open] > summary .chev { transform: rotate(180deg); }
details.section > summary .summary-icon { color: var(--accent); }
details.section .body { padding: 18px 22px; }

details.section h3 {
  margin: 0 0 10px 0;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.06em;
  font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}

/* Key/value */
.kv {
  display: grid; grid-template-columns: 220px 1fr; gap: 8px 24px;
  margin: 0;
}
.kv dt {
  color: var(--muted); font-size: 12.5px;
  display: inline-flex; align-items: center; gap: 6px;
}
.kv dd { margin: 0; color: var(--text); font-size: 13px; }
.kv dd.amount { font-variant-numeric: tabular-nums; font-weight: 500; }

.empty {
  color: var(--muted); font-style: italic;
  padding: 14px; text-align: center;
  background: var(--surface-2); border-radius: var(--radius);
  border: 1px dashed var(--border);
}

/* Docs */
.docs ul { list-style: none; padding: 0; margin: 0; }
.docs li {
  padding: 8px 0;
  display: flex; gap: 10px; align-items: center;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
}
.docs li:last-child { border-bottom: none; }
.docs li .file-icon { color: var(--muted-2); }
.docs li .doc-meta { color: var(--muted); font-size: 11.5px; }
.docs .grow { flex: 1; }

/* ----------------------------------------------------------------
   Modal
   ---------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  animation: fade-in 120ms ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  min-width: 480px;
  max-width: 600px;
  padding: 24px 28px;
  box-shadow: var(--shadow-lg);
  animation: pop-in 140ms ease;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal h2 {
  margin: 0 0 4px 0; font-size: 16px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.modal h2 .ico { color: var(--accent); }
.modal .close {
  float: right; cursor: pointer; color: var(--muted-2);
  padding: 4px; border-radius: var(--radius-sm);
}
.modal .close:hover { background: var(--row-hover); color: var(--text); }
.modal p.muted { margin: 0 0 16px 0; }

/* ----------------------------------------------------------------
   Misc
   ---------------------------------------------------------------- */
.right { text-align: right; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.spacer-y { height: 16px; }

.actions-cell { white-space: nowrap; text-align: right; }
.actions-cell form { display: inline; }
.actions-cell .btn-ghost { padding: 3px 7px; font-size: 11.5px; }
.actions-cell .btn-ghost + .btn-ghost,
.actions-cell .btn-ghost + form,
.actions-cell form + .btn-ghost,
.actions-cell form + form { margin-left: 2px; }

/* Highlight overdue/critical rows subtly on the dashboard */
tr.row-overdue td { background-color: #fef9f5; }
tr.row-overdue:hover td { background-color: #fef0e6; }
tr.row-vacant .cell-tenant { color: var(--muted-2); font-style: italic; }

/* Mini stat strip on dashboard */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center; gap: 12px;
}
.stat .icon-tile {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.stat .icon-tile.green   { background: var(--green-soft); color: var(--green); }
.stat .icon-tile.amber   { background: var(--amber-soft); color: var(--amber); }
.stat .icon-tile.red     { background: var(--red-soft);   color: var(--red); }
.stat .icon-tile.slate   { background: var(--slate-soft); color: var(--muted); }
.stat .label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat .value { font-size: 19px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }

/* Property-type cell */
.type-cell { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
