/* P2P Lend PK — professional responsive shell (client design, live LFE data) */
:root {
  --p2p-safe-top: env(safe-area-inset-top, 0px);
  --p2p-safe-right: env(safe-area-inset-right, 0px);
  --p2p-safe-bottom: env(safe-area-inset-bottom, 0px);
  --p2p-safe-left: env(safe-area-inset-left, 0px);
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  padding-left: var(--p2p-safe-left);
  padding-right: var(--p2p-safe-right);
}

.sidebar {
  padding-top: var(--p2p-safe-top);
  padding-bottom: var(--p2p-safe-bottom);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 20, 28, 0.45);
  z-index: 999;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.show {
  display: block;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  margin-top: var(--p2p-safe-top);
}

.lfe-modal-auth {
  align-items: center;
  justify-content: center;
  padding: max(1rem, var(--p2p-safe-top)) 1rem max(1rem, var(--p2p-safe-bottom));
}

.lfe-modal-auth .panel {
  width: min(420px, 100%);
  max-height: min(92vh, 720px);
  overflow: auto;
  border-radius: 16px;
}

.lfe-modal-auth input,
.form-control,
select.form-control,
textarea.form-control {
  min-height: 44px;
  font-size: 16px;
}

.deal-footer {
  gap: 0.5rem;
  flex-wrap: wrap;
}

.table-wrap {
  -webkit-overflow-scrolling: touch;
}

.app-footer {
  padding-bottom: max(1.5rem, var(--p2p-safe-bottom));
}

@media (max-width: 1199px) {
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 992px) {
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
  .lfe-report .psychometric {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: min(88vw, 300px);
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.28);
  }
  .main {
    margin-left: 0;
    padding: 0.85rem 0.85rem 2.5rem;
    width: 100%;
  }
  .hamburger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
  }
  .topbar {
    padding: 0.55rem 0.75rem;
    gap: 0.6rem;
  }
  .topbar h1 {
    font-size: 1.05rem;
  }
  .topbar-actions {
    width: 100%;
    justify-content: flex-end;
  }
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
  }
  .stat-card .stat-value {
    font-size: 1.25rem;
  }
  .card {
    padding: 1.1rem;
  }
  .modal {
    padding: 1.25rem;
    max-height: min(92vh, 100%);
    border-radius: 14px;
  }
  .deal-card .deal-meta {
    gap: 0.45rem 0.9rem;
  }
  .info-grid {
    grid-template-columns: 1fr;
  }
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .form-actions .btn {
    width: 100%;
    justify-content: center;
  }
  .status-timeline {
    gap: 0.25rem;
  }
  .status-timeline .connector {
    width: 10px;
  }
  .toast-container {
    left: 0.75rem;
    right: 0.75rem;
    top: calc(0.75rem + var(--p2p-safe-top));
    max-width: none;
  }
}

@media (max-width: 560px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .topbar-actions .btn span {
    display: none;
  }
  .topbar-actions .btn {
    min-width: 44px;
    padding-left: 0.7rem;
    padding-right: 0.7rem;
  }
  .sidebar-brand {
    font-size: 1.25rem;
    padding: 1.4rem 1.2rem 1.2rem;
  }
  .page-content .card-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  #page-listings .flex-between {
    flex-direction: column;
    align-items: stretch;
  }
  #filterStatus,
  #filterRisk,
  #filterCategory {
    width: 100% !important;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 15px;
  }
  .deal-title {
    font-size: 0.98rem;
  }
  .app-footer span {
    display: inline-block;
    margin: 0.15rem 0.35rem;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar {
    width: 240px;
  }
  .main {
    margin-left: 240px;
    padding: 1.15rem 1.25rem 2.5rem;
  }
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (hover: none) and (pointer: coarse) {
  .sidebar-nav a,
  .btn,
  .stat-card,
  .deal-card {
    -webkit-tap-highlight-color: transparent;
  }
  .sidebar-nav a {
    min-height: 44px;
  }
}
