/* ============================================================
   RentFlow — Design System
   Premium SaaS UI — Bootstrap 5 base
   ============================================================ */

:root {
  --rf-primary:       #1a56db;
  --rf-primary-dark:  #1344b8;
  --rf-primary-light: #e8f0fe;
  --rf-accent:        #0ea5e9;
  --rf-dark:          #0f1729;
  --rf-sidebar-bg:    #0f1729;
  --rf-sidebar-w:     260px;
  --rf-topbar-h:      64px;
  --rf-card-shadow:   0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.05);
  --rf-border:        #e2e8f0;
  --rf-text:          #1e293b;
  --rf-text-muted:    #64748b;
  --rf-bg:            #f1f5f9;
  --rf-success:       #16a34a;
  --rf-warning:       #ca8a04;
  --rf-danger:        #dc2626;
  --rf-info:          #0284c7;
  --rf-radius:        10px;
  --rf-radius-lg:     16px;
}

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

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--rf-bg);
  color: var(--rf-text);
  font-size: 14px;
  line-height: 1.6;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ============================================================
   AUTH LAYOUT
   ============================================================ */

.auth-body {
  background: var(--rf-dark);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.auth-body::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 20% 50%, rgba(26,86,219,.25) 0%, transparent 60%),
              radial-gradient(ellipse at 80% 20%, rgba(14,165,233,.15) 0%, transparent 50%);
}

.auth-card {
  background: #fff;
  border-radius: var(--rf-radius-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  position: relative;
  z-index: 1;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}

.auth-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-logo .brand-icon {
  width: 52px; height: 52px;
  background: var(--rf-primary);
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: #fff;
  margin-bottom: .75rem;
}

.auth-logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--rf-dark);
  margin: 0;
}

.auth-logo p {
  font-size: .875rem;
  color: var(--rf-text-muted);
  margin: .25rem 0 0;
}

/* ============================================================
   APP LAYOUT — Sidebar + Topbar
   ============================================================ */

.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--rf-sidebar-w);
  min-height: 100vh;
  background: var(--rf-sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-brand {
  height: var(--rf-topbar-h);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
  text-decoration: none;
  gap: .75rem;
}

.sidebar-brand .brand-icon {
  width: 34px; height: 34px;
  background: var(--rf-primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: .9rem;
  flex-shrink: 0;
}

.sidebar-brand .brand-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.02em;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: .75rem 0;
}

.nav-section-label {
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.3);
  padding: .875rem 1.25rem .4rem;
}

.nav-item-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1.25rem;
  color: rgba(255,255,255,.65);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  border-radius: 0;
  transition: background .15s, color .15s;
  position: relative;
  margin: 1px 0;
}

.nav-item-link i {
  font-size: 1.05rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.nav-item-link:hover {
  background: rgba(255,255,255,.06);
  color: #fff;
}

.nav-item-link.active {
  background: rgba(26,86,219,.3);
  color: #fff;
}

.nav-item-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--rf-primary);
  border-radius: 0 2px 2px 0;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.06);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: .75rem;
  text-decoration: none;
  color: rgba(255,255,255,.75);
  padding: .5rem;
  border-radius: 8px;
  transition: background .15s;
}

.sidebar-user:hover {
  background: rgba(255,255,255,.06);
  color: #fff;
}

.sidebar-user .user-avatar {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: var(--rf-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-user .user-avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
}

.sidebar-user .user-info { min-width: 0; flex: 1; }
.sidebar-user .user-name { font-size: .82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .user-role { font-size: .72rem; opacity: .6; }

/* ---- Main content ---- */
.app-main {
  margin-left: var(--rf-sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Topbar ---- */
.topbar {
  height: var(--rf-topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--rf-border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--rf-text);
  flex: 1;
}

.topbar-company-badge {
  background: var(--rf-primary-light);
  color: var(--rf-primary);
  font-size: .78rem;
  font-weight: 600;
  padding: .3rem .75rem;
  border-radius: 20px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Page content ---- */
.page-content {
  padding: 1.5rem;
  flex: 1;
}

/* ============================================================
   CARDS
   ============================================================ */

.rf-card {
  background: #fff;
  border-radius: var(--rf-radius);
  box-shadow: var(--rf-card-shadow);
  border: 1px solid var(--rf-border);
}

.rf-card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--rf-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.rf-card-header h5 {
  font-size: .9rem;
  font-weight: 600;
  color: var(--rf-text);
  margin: 0;
}

.rf-card-body { padding: 1.25rem; }

/* ---- KPI Card ---- */
.kpi-card {
  background: #fff;
  border-radius: var(--rf-radius);
  box-shadow: var(--rf-card-shadow);
  border: 1px solid var(--rf-border);
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
}

.kpi-card .kpi-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  margin-bottom: .875rem;
}

.kpi-card .kpi-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--rf-text);
  line-height: 1.2;
}

.kpi-card .kpi-label {
  font-size: .78rem;
  color: var(--rf-text-muted);
  margin-top: .25rem;
}

.kpi-card .kpi-change {
  font-size: .78rem;
  font-weight: 500;
  margin-top: .5rem;
}

.kpi-card .kpi-change.up   { color: var(--rf-success); }
.kpi-card .kpi-change.down { color: var(--rf-danger); }

.kpi-blue   .kpi-icon { background: #eff6ff; color: var(--rf-primary); }
.kpi-green  .kpi-icon { background: #f0fdf4; color: var(--rf-success); }
.kpi-red    .kpi-icon { background: #fef2f2; color: var(--rf-danger); }
.kpi-yellow .kpi-icon { background: #fefce8; color: var(--rf-warning); }
.kpi-cyan   .kpi-icon { background: #f0f9ff; color: var(--rf-info); }
.kpi-purple .kpi-icon { background: #faf5ff; color: #7c3aed; }

/* ============================================================
   TABLES
   ============================================================ */

.rf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.rf-table thead th {
  background: #f8fafc;
  color: var(--rf-text-muted);
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--rf-border);
  white-space: nowrap;
}

.rf-table tbody td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--rf-border);
  vertical-align: middle;
  color: var(--rf-text);
}

.rf-table tbody tr:hover { background: #f8fafc; }
.rf-table tbody tr:last-child td { border-bottom: none; }

/* ============================================================
   FORMS
   ============================================================ */

.form-label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--rf-text);
  margin-bottom: .35rem;
}

.form-control, .form-select {
  border: 1px solid var(--rf-border);
  border-radius: 8px;
  font-size: .875rem;
  color: var(--rf-text);
  padding: .55rem .875rem;
  transition: border-color .15s, box-shadow .15s;
}

.form-control:focus, .form-select:focus {
  border-color: var(--rf-primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
  outline: none;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  font-size: .84rem;
  font-weight: 500;
  border-radius: 8px;
  padding: .5rem 1rem;
  transition: all .15s;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--rf-primary);
  border-color: var(--rf-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--rf-primary-dark);
  border-color: var(--rf-primary-dark);
  color: #fff;
}

.btn-sm { padding: .3rem .7rem; font-size: .78rem; }

/* ============================================================
   FILTER BAR
   ============================================================ */

.filter-bar {
  background: #fff;
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

/* ============================================================
   BADGES / STATUS
   ============================================================ */

.badge {
  font-size: .72rem;
  font-weight: 600;
  padding: .3em .6em;
  border-radius: 6px;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--rf-text-muted);
}

.empty-state .empty-icon {
  font-size: 2.5rem;
  opacity: .35;
  margin-bottom: 1rem;
}

.empty-state h6 {
  font-size: .95rem;
  color: var(--rf-text);
  margin-bottom: .375rem;
}

/* ============================================================
   TOAST / ALERTS
   ============================================================ */

.rf-alert {
  border-radius: 8px;
  padding: .75rem 1rem;
  font-size: .875rem;
  display: flex;
  align-items: flex-start;
  gap: .625rem;
  margin-bottom: 1rem;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */

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

.page-header h4 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--rf-text);
  margin: 0;
}

/* ============================================================
   AVATAR
   ============================================================ */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }

.avatar-sm  { width: 28px; height: 28px; font-size: .7rem; }
.avatar-md  { width: 36px; height: 36px; font-size: .85rem; }
.avatar-lg  { width: 56px; height: 56px; font-size: 1.2rem; }
.avatar-xl  { width: 80px; height: 80px; font-size: 1.6rem; }

/* ============================================================
   DRE TABLE
   ============================================================ */

.dre-table { font-size: .88rem; }
.dre-table .dre-group-header td {
  background: var(--rf-primary-light);
  color: var(--rf-primary);
  font-weight: 700;
  padding: .6rem 1rem;
}
.dre-table .dre-total td {
  background: #f8fafc;
  font-weight: 700;
  border-top: 2px solid var(--rf-border);
}
.dre-table .dre-highlight td {
  background: #f0fdf4;
  font-weight: 700;
  color: var(--rf-success);
}
.dre-table .dre-negative td { color: var(--rf-danger); }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .app-main {
    margin-left: 0;
  }
}

@media (max-width: 575.98px) {
  .page-content { padding: 1rem; }
  .kpi-card .kpi-value { font-size: 1.2rem; }
  .auth-card { padding: 1.75rem 1.25rem; margin: 1rem; }
}

/* ============================================================
   UTILITIES
   ============================================================ */

.cursor-pointer { cursor: pointer; }
.fw-semibold    { font-weight: 600 !important; }
.text-rf        { color: var(--rf-primary) !important; }
.bg-rf          { background: var(--rf-primary) !important; }
.text-value     { font-size: 1.15rem; font-weight: 700; }
.text-muted-sm  { font-size: .78rem; color: var(--rf-text-muted); }
.border-bottom-dashed { border-bottom: 1px dashed var(--rf-border); }

.loading-spinner {
  display: inline-block;
  width: 1rem; height: 1rem;
  border: 2px solid rgba(26,86,219,.2);
  border-top-color: var(--rf-primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
