:root {
  --bg: #f5f5fb;
  --surface: #ffffff;
  --surface-alt: #f7f7fc;
  --border: #e7e8f0;
  --border-light: #f0f1f6;
  --text: #14161f;
  --text-secondary: #6b7080;
  --text-muted: #9296a6;

  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef0ff;
  --primary-gradient: linear-gradient(135deg, #4f46e5, #7c3aed);

  --danger: #dc2626;
  --danger-bg: #feecec;
  --success: #059669;
  --success-bg: #dff7ed;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --info: #2563eb;
  --info-bg: #e4ecfe;
  --purple: #7c3aed;
  --purple-bg: #f0ebfe;
  --neutral: #6b7080;
  --neutral-bg: #ebecf2;
  --chart-track: #dfe1ee;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 999px;
  --shadow-sm: 0 1px 3px rgba(18, 20, 43, 0.06);
  --shadow-md: 0 8px 24px rgba(18, 20, 43, 0.08);
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Auth (login) layout ---------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-gradient);
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px;
}
.auth-emblem {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  background: var(--primary-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 24px;
}
.auth-title { text-align: center; font-size: 20px; font-weight: 800; margin: 0 0 4px; }
.auth-subtitle { text-align: center; color: var(--text-secondary); margin: 0 0 24px; font-size: 13px; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.sidebar-top {
  padding: 20px 12px 12px;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 22px;
  font-weight: 800;
  font-size: 15.5px;
  letter-spacing: -0.2px;
}
.sidebar-brand-icon {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  background: var(--primary-gradient);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.28);
}
.nav-group-label {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--primary);
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  margin: 14px 0 6px;
}
.nav-group-label:first-child { margin-top: 0; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  margin-bottom: 1px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 13.5px;
  position: relative;
}
.nav-link:hover { background: var(--surface-alt); text-decoration: none; }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }
.nav-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  border-radius: 0 3px 3px 0;
  background: var(--primary-gradient);
}
.nav-icon { flex-shrink: 0; opacity: 0.9; }
.sidebar-footer {
  padding: 14px 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
}
.user-menu { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary-gradient);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px;
  flex-shrink: 0;
}
.nav-link-logout:hover { color: var(--danger); background: var(--danger-bg); }

.main { flex: 1; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--bg);
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 800; letter-spacing: -0.3px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.user-menu { display: flex; align-items: center; gap: 10px; }
.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }

.content { padding: 0 28px 40px; }

/* ---------- Flash messages ---------- */
.flash { padding: 12px 16px; border-radius: var(--radius-md); margin-bottom: 16px; font-weight: 500; font-size: 13.5px; }
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-error { background: var(--danger-bg); color: var(--danger); }

/* ---------- Cards / tiles ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.card-hero {
  background: var(--primary-gradient);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  margin-bottom: 20px;
}
.card-hero .label { color: rgba(255,255,255,0.75); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.card-hero .row { display: flex; justify-content: space-between; padding: 4px 0; }
.card-hero .row.total { border-top: 1px solid rgba(255,255,255,0.25); margin-top: 8px; padding-top: 10px; font-weight: 800; font-size: 18px; }
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.month-nav-label { flex: 1; text-align: center; }
.month-nav-btn { width: 26px; height: 26px; border-radius: var(--radius-full); background: rgba(255,255,255,0.15); color: #fff; display: flex; align-items: center; justify-content: center; text-decoration: none; font-size: 13px; flex: none; }
.month-nav-btn:hover { background: rgba(255,255,255,0.25); text-decoration: none; }
.month-nav-btn-disabled { opacity: 0.3; pointer-events: none; }
.card-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--primary); margin: 0 0 14px; }

.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile {
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: block;
  color: var(--text);
}
.tile:hover { text-decoration: none; }
.tile .icon { width: 30px; height: 30px; border-radius: var(--radius-sm); background: var(--surface); display: flex; align-items: center; justify-content: center; margin-bottom: 10px; font-size: 15px; }
.tile .value { font-size: 22px; font-weight: 800; }
.tile .label { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-top: 4px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
table.data th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 700; white-space: nowrap; }
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--border-light); font-size: 13.5px; vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover { background: var(--surface-alt); }
.table-empty { padding: 40px 20px; text-align: center; color: var(--text-secondary); }
.row-actions { display: flex; gap: 12px; justify-content: flex-end; align-items: center; }
.row-actions form { display: inline; margin: 0; }
.link-danger { background: none; border: none; padding: 0; font: inherit; font-weight: 600; color: var(--danger); cursor: pointer; }
.link-danger:hover { text-decoration: underline; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: var(--radius-full); font-size: 11px; font-weight: 700; letter-spacing: 0.3px; white-space: nowrap; }
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge-overdue, .badge-cancelled { background: var(--danger-bg); color: var(--danger); }
.badge-due { background: var(--warning-bg); color: var(--warning); }
.badge-upcoming, .badge-vacant, .badge-draft { background: var(--info-bg); color: var(--info); }
.badge-partially_paid { background: var(--purple-bg); color: var(--purple); }
.badge-paid, .badge-occupied, .badge-active { background: var(--success-bg); color: var(--success); }
.badge-waived, .badge-inactive, .badge-neutral, .badge-under_maintenance, .badge-ending_soon, .badge-expired, .badge-terminated, .badge-vacated { background: var(--neutral-bg); color: var(--neutral); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.field { margin-bottom: 4px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.field input[type="text"], .field input[type="email"], .field input[type="password"],
.field input[type="number"], .field input[type="date"], .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  background: var(--surface-alt);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.field textarea { resize: vertical; min-height: 70px; }
.field-error { color: var(--danger); font-size: 12px; margin-top: 5px; }
.field-hint { color: var(--text-muted); font-size: 12px; margin-top: 5px; }
.field-checkbox { display: flex; align-items: center; gap: 8px; }
.field-checkbox label { margin: 0; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.form-section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-muted); margin: 24px 0 12px; }
.form-section-title:first-child { margin-top: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: 13.5px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary-gradient); color: #fff; box-shadow: 0 6px 16px rgba(79,70,229,0.28); }
.btn-primary:hover { opacity: 0.92; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------- Detail rows ---------- */
.detail-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border-light); font-size: 13.5px; }
.detail-row:last-child { border-bottom: none; }
.detail-row .label { color: var(--text-secondary); font-weight: 600; }
.detail-row .value { font-weight: 700; text-align: right; }

/* ---------- Misc ---------- */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input { padding: 8px 12px; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--surface); font-size: 13px; font-family: inherit; }
.pagination { display: flex; gap: 8px; justify-content: center; margin-top: 20px; }
.pagination a, .pagination span { padding: 7px 12px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; background: var(--surface); box-shadow: var(--shadow-sm); }
.pagination .current { background: var(--primary); color: #fff; }
.muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-secondary); }

/* ---------- Documents / uploads ---------- */
.doc-list { display: flex; flex-direction: column; gap: 8px; margin: 0 0 16px; }
.doc-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  padding: 8px 10px;
}
.doc-item-thumb {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.doc-item-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.3px;
}
.doc-item-icon-pdf { background: var(--danger-bg); color: var(--danger); }
.doc-item-info { flex: 1; min-width: 0; }
.doc-item-name {
  display: block;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-item-name:hover { text-decoration: underline; }
.doc-item-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }
.doc-item-delete {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.doc-item-delete:hover { background: var(--danger-bg); color: var(--danger); }

.upload-row { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; }
.upload-type {
  flex: 0 0 190px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  background: var(--surface-alt);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
}
.upload-type:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.upload-dropzone {
  position: relative;
  flex: 1 1 240px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.upload-dropzone:hover { border-color: var(--primary); background: var(--primary-soft); }
.upload-dropzone.is-dragover { border-color: var(--primary); background: var(--primary-soft); }
.upload-dropzone.has-file { border-style: solid; border-color: var(--primary); background: var(--surface); }
.upload-dropzone:focus-within { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.upload-dropzone-icon { flex-shrink: 0; color: var(--primary); display: flex; }
.upload-dropzone-text { font-size: 12.5px; color: var(--text-secondary); line-height: 1.35; }
.upload-dropzone-text strong { color: var(--primary); font-weight: 700; }
.upload-filename { display: block; font-size: 12.5px; font-weight: 700; color: var(--text); }
.upload-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.upload-submit { flex-shrink: 0; }

/* ---------- Dashboard layout ---------- */
.dashboard-hero-row { display: flex; gap: 20px; align-items: stretch; margin-bottom: 20px; flex-wrap: wrap; }
.dashboard-hero-main { flex: 2 1 380px; margin-bottom: 0; }
.dashboard-hero-side { flex: 1 1 220px; margin-bottom: 0; display: flex; flex-direction: column; justify-content: center; }
.dashboard-side-col { display: flex; flex-direction: column; gap: 20px; }
.dashboard-side-col .card { margin-bottom: 0; }

/* ---------- Charts ---------- */
.chart-row { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; align-items: start; }
.chart-card-title { font-size: 13px; font-weight: 700; color: var(--text); margin: 0 0 4px; }
.chart-card-subtitle { font-size: 12px; color: var(--text-muted); margin: 0 0 16px; }
.chart { width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: var(--border-light); stroke-width: 1; shape-rendering: crispEdges; }
.chart-axis-label { font-size: 10px; fill: var(--text-muted); font-family: inherit; }
.chart path, .chart rect { transition: opacity 0.15s ease; }
.chart path:hover, .chart-stacked rect:hover { opacity: 0.82; }
.chart-stacked { display: block; margin-bottom: 14px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12.5px; color: var(--text-secondary); }
.chart-legend-item { display: flex; align-items: center; gap: 6px; }
.chart-legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.chart-table-toggle { margin-top: 12px; }
.chart-table-toggle summary { cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--primary); list-style: none; }
.chart-table-toggle summary::-webkit-details-marker { display: none; }
.chart-table-toggle table { margin-top: 10px; }

@media (max-width: 860px) {
  .chart-row { grid-template-columns: 1fr; }
  .dashboard-hero-row { flex-direction: column; }
  .sidebar { display: none; }
  .content { padding: 0 16px 32px; }
  .topbar { padding: 14px 16px; }
}
