/*
 * JetLegal Styles
 */

:root {
  --primary: #4A90A4;
  --primary-dark: #3d7a8c;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
}

/* Header */
.header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
  text-decoration: none;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  gap: 24px;
}

.nav-link {
  color: var(--gray-700);
  text-decoration: none;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
  background: var(--gray-100);
  color: var(--primary);
}

/* Main Content */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* Page Header */
.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--gray-900);
}

.page-subtitle {
  color: var(--gray-500);
  margin-top: 4px;
}

/* Table */
.table-container {
  background: white;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  background: var(--primary);
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: white;
  border-bottom: 1px solid var(--gray-200);
}

.data-table td {
  padding: 16px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}

.data-table tbody tr.loan-row:nth-child(4n+1) {
  background: var(--gray-100);
}

.data-table tbody tr.loan-row:nth-child(4n+3) {
  background: white;
}

.data-table tbody tr.loan-row:hover {
  background: var(--gray-200);
}

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

.table-link {
  color: var(--primary);
  text-decoration: none;
}

.table-link:hover {
  text-decoration: underline;
}

/* Status Badge */
.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.status-badge.issued {
  background: #dcfce7;
  color: #166534;
}

.status-badge.terminated {
  background: #fee2e2;
  color: #991b1b;
}

.status-badge.repaid {
  background: #dbeafe;
  color: #1e40af;
}

/* Pagination */
.pagination-container {
  padding: 16px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: center;
}

.pagy {
  display: flex;
  gap: 4px;
  list-style: none;
}

.pagy a, .pagy span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  font-size: 0.875rem;
  text-decoration: none;
  color: var(--gray-700);
  background: white;
  border: 1px solid var(--gray-200);
  transition: all 0.15s;
}

.pagy a:hover {
  background: var(--gray-100);
  border-color: var(--gray-300);
}

.pagy .current {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.pagy .disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Filters */
.filters-container {
  background: white;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  padding: 20px;
  margin-bottom: 24px;
}

.filters-form {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
}


.filter-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
}

.filter-input,
.filter-select {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--gray-700);
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.filter-input:focus,
.filter-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 16px;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: white;
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
}

.btn-secondary:hover {
  background: var(--gray-50);
  border-color: var(--gray-300);
}

.btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 0.75rem;
}

/* Tom Select Overrides */
.ts-wrapper {
  min-width: 180px;
}

/* When Tom Select is active, override filter-select styles on wrapper */
.ts-wrapper.filter-select {
  height: auto;
  padding: 0;
  border: none;
  background: transparent;
}

.ts-wrapper.multi .ts-control {
  min-height: 40px;
  padding: 4px 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.ts-control {
  border: 1px solid var(--gray-200) !important;
  border-radius: 6px !important;
  background: white !important;
}

.ts-control:focus,
.ts-wrapper.focus .ts-control {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1) !important;
}

.ts-control input {
  min-width: 60px;
}

.ts-dropdown {
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  margin-top: 4px;
}

.ts-dropdown .option {
  padding: 8px 12px;
}

.ts-dropdown .option.active {
  background: var(--primary);
  color: white;
}

.ts-wrapper.multi .ts-control > .item {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 2px 6px;
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
}

.ts-wrapper.multi .ts-control > .item .remove {
  color: white;
  border-left: 1px solid rgba(255,255,255,0.3);
  margin-left: 6px;
  padding-left: 6px;
}

.ts-wrapper.multi .ts-control > .item .remove:hover {
  background: transparent;
  color: white;
}

/* Show Page Styles */
.page-header-top {
  margin-bottom: 16px;
}

.back-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
}

.back-link:hover {
  text-decoration: underline;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
  margin-bottom: 24px;
}

.detail-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  padding: 24px;
}

.detail-card.full-width {
  grid-column: 1 / -1;
  margin-bottom: 24px;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gray-700);
  background: var(--gray-200);
  margin: -24px -24px 16px -24px;
  padding: 12px 24px;
  border-radius: 8px 8px 0 0;
}

.detail-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.detail-row dt {
  font-size: 0.875rem;
  color: var(--gray-500);
  font-weight: 500;
}

.detail-row dd {
  font-size: 0.875rem;
  color: var(--gray-900);
  text-align: right;
  max-width: 60%;
}

.no-data {
  color: var(--gray-500);
  font-size: 0.875rem;
  font-style: italic;
}

.active-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 9999px;
  background: #dcfce7;
  color: #166534;
}

.inactive-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 9999px;
  background: var(--gray-100);
  color: var(--gray-500);
}

@media (max-width: 768px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

/* Main Content Full (no header) */
.main-content-full {
  min-height: 100vh;
}

/* Auth Styles */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 24px;
}

.auth-logo .logo {
  font-size: 2rem;
}

.auth-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
  text-align: center;
  margin-bottom: 8px;
}

.auth-subtitle {
  color: var(--gray-500);
  text-align: center;
  margin-bottom: 24px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-form .form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-form label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-700);
}

.auth-form input[type="email"],
.auth-form input[type="password"],
.auth-form input[type="text"] {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 1rem;
  color: var(--gray-900);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.auth-form .form-actions {
  margin-top: 8px;
}

.auth-form .btn {
  width: 100%;
  height: 44px;
}

.auth-links {
  margin-top: 20px;
  text-align: center;
  font-size: 0.875rem;
}

.auth-links a {
  color: var(--primary);
  text-decoration: none;
}

.auth-links a:hover {
  text-decoration: underline;
}

.auth-links .separator {
  color: var(--gray-300);
  margin: 0 8px;
}

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 0.875rem;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

/* Logout Button */
.logout-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--gray-500);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.logout-btn:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

/* Debt Groups */
.debt-groups {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

.debt-group {
  padding: 16px;
  background: var(--gray-50);
  border-radius: 8px;
}

.debt-group-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.date-picker-container {
  margin-bottom: 16px;
}

.date-picker-container .filter-input {
  width: auto;
}

/* Expandable Rows */
.loan-row {
  cursor: pointer;
}

.loan-row:hover {
  background: var(--gray-50);
}

.expand-cell {
  width: 30px;
  text-align: center;
}

.expand-icon {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--gray-500);
  transition: transform 0.2s;
}

.expand-icon.expanded {
  transform: rotate(90deg);
}

/* Collapsible sections */
.collapsible-header {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.collapsible-header:hover {
  color: var(--primary);
}

.collapse-icon {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--gray-500);
  transition: transform 0.2s;
}

.collapse-icon.expanded {
  transform: rotate(90deg);
}

.invoices-row {
  background: var(--gray-50);
}

.invoices-row:hover {
  background: var(--gray-50) !important;
}

.invoices-container {
  padding: 16px;
}

.invoices-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.invoices-table th {
  background: var(--primary);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: white;
  border-bottom: 1px solid var(--gray-200);
}

.invoices-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  font-size: 0.875rem;
}

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

.invoices-table tbody tr:nth-child(odd) {
  background: var(--gray-100);
}

.invoices-table tbody tr:nth-child(even) {
  background: white;
}

.invoices-table tbody tr:hover {
  background: var(--gray-200);
}

.loading-text {
  color: var(--gray-500);
  font-size: 0.875rem;
  font-style: italic;
}

.bank-transactions-container {
  padding: 0;
}

.payment-info-cell {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Substatus form */
.substatus-form {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--gray-200);
}

.substatus-form .form-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.substatus-form .filter-input {
  flex: 1;
}

/* Upload form */
.upload-form {
  margin-bottom: 16px;
}

.upload-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.upload-input {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.875rem;
}

.upload-input::file-selector-button {
  padding: 6px 12px;
  margin-right: 12px;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  background: var(--gray-100);
  cursor: pointer;
  font-size: 0.875rem;
}

.upload-input::file-selector-button:hover {
  background: var(--gray-200);
}

/* Modal */
.modal-dialog {
  padding: 0;
  border: none;
  border-radius: 12px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  max-width: 90vw;
  max-height: 90vh;
  width: 900px;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}

.modal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  display: flex;
  flex-direction: column;
  height: 80vh;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
  border-radius: 12px 12px 0 0;
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gray-900);
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--gray-500);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close:hover {
  color: var(--gray-700);
}

.modal-body {
  flex: 1;
  padding: 0;
  overflow: hidden;
}

.modal-iframe {
  width: 100%;
  height: 100%;
  border: none;
}
