:root {
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-muted: #f8f9fd;
  --sidebar-from: #14162b;
  --sidebar-to: #1f2246;
  --sidebar-text: #b7bad6;
  --sidebar-text-active: #ffffff;
  --primary: #5b5bf0;
  --primary-dark: #4444d6;
  --primary-light: #eef0ff;
  --success: #16a34a;
  --success-light: #e3f9ea;
  --danger: #e11d48;
  --danger-light: #fde8ee;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --info: #0891b2;
  --info-light: #e0f7fb;
  --text: #171a2b;
  --text-muted: #767a94;
  --border: #e7e8f2;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(23, 26, 43, 0.05), 0 1px 1px rgba(23, 26, 43, 0.04);
  --shadow-md: 0 10px 30px -12px rgba(23, 26, 43, 0.18);
  --shadow-lg: 0 20px 45px -18px rgba(23, 26, 43, 0.28);
}

* { box-sizing: border-box; }

html, body, #root {
  height: 100%;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: "Inter", "Segoe UI", "Noto Sans Bengali", "Hind Siliguri", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* Smooth page-to-page navigation: only the main content area transitions,
   so the sidebar/topbar chrome (already on screen) never re-flashes on
   every click. On browsers that support cross-document View Transitions
   (Chromium), this also crossfades outgoing/incoming content instead of
   the plain browser navigation flash; unsupported browsers just get the
   .content fade-in below. */
@view-transition {
  navigation: auto;
}

::view-transition-image-pair(root),
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
h1, h2, h3, p { margin: 0; }

.btn, .nav-item, .stat-card, .loan-card, input, select, textarea {
  transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .1s ease;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d3d5e4; border-radius: 4px; }

/* ---------- Login / Setup pages ---------- */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(circle at 15% 15%, rgba(91, 91, 240, 0.35), transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(91, 91, 240, 0.25), transparent 45%),
    linear-gradient(150deg, #14162b 0%, #1f2246 55%, #2c2f66 100%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}

.auth-brand {
  text-align: center;
  margin-bottom: 26px;
}

.auth-brand .logo-mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  box-shadow: var(--shadow-md);
}

.auth-brand h1 {
  font-size: 21px;
  color: var(--text);
  font-weight: 700;
}

.auth-brand p {
  margin: 5px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

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

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.field input, .field select, .field textarea {
  padding: 12px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  background: var(--surface-muted);
  color: var(--text);
  outline: none;
  transition: border-color .15s ease, background .15s ease;
  width: 100%;
}

.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  background: var(--surface);
}

.field input:disabled { opacity: .65; }

.field .hint { font-size: 12px; color: var(--text-muted); }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
}
.checkbox-row input { width: auto; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .05s ease, background .15s ease, box-shadow .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 8px 18px -8px rgba(91, 91, 240, 0.6); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--primary-light); color: var(--primary-dark); }
.btn-secondary:hover { background: #e2e3ff; }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: #fbd7e2; }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-muted); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 13px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.alert {
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  display: none;
  margin-bottom: 4px;
}
.alert.show { display: block; }
.alert-error { background: var(--danger-light); color: #9f1239; }
.alert-success { background: var(--success-light); color: #14532d; }

.demo-note {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
}
.demo-note a { color: var(--primary); font-weight: 600; }

/* ---------- App shell ---------- */

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

.sidebar {
  width: 252px;
  flex-shrink: 0;
  background: linear-gradient(185deg, var(--sidebar-from), var(--sidebar-to));
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
}

.sidebar-brand {
  padding: 24px 20px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand h1 { font-size: 16px; color: #fff; font-weight: 700; }
.sidebar-brand span { display: block; font-size: 11px; color: #8b8fc0; margin-top: 2px; }

.sidebar-user {
  padding: 15px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 13px;
}
.sidebar-user .name {
  color: #fff;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-user .role {
  display: inline-block;
  margin-top: 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(91,91,240,0.3);
  color: #c7c9ff;
}

.nav {
  flex: 1;
  padding: 14px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: var(--sidebar-text);
}
.nav-item .icon { flex-shrink: 0; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-item.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 6px 16px -6px rgba(91, 91, 240, 0.8);
}
.nav-item.active .icon { opacity: 1; }

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-logout {
  color: #d7d8ee !important;
  border-color: rgba(255,255,255,0.16) !important;
}
.sidebar-logout:hover { background: rgba(255,255,255,0.07) !important; }

.main {
  flex: 1;
  margin-left: 252px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: calc(100% - 252px);
  min-width: 0;
}

.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar .logo-row { font-weight: 700; }
.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  display: flex;
}

.content {
  padding: 28px;
  flex: 1;
  max-width: 1280px;
  width: 100%;
  view-transition-name: main-content;
  animation: contentFadeIn .22s ease both;
}

@keyframes contentFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

::view-transition-old(main-content) {
  animation: contentFadeOut .12s ease both;
}
::view-transition-new(main-content) {
  animation: contentFadeIn .22s ease both;
}

@keyframes contentFadeOut {
  to { opacity: 0; transform: translateY(-6px); }
}

@media (prefers-reduced-motion: reduce) {
  .content { animation: none; }
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 22px;
}
.view-header h2 { font-size: 22px; font-weight: 700; }
.view-header p { margin: 4px 0 0; color: var(--text-muted); font-size: 13.5px; }
.view-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Cards */

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 26px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 14px;
}
.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-light);
  color: var(--primary-dark);
  flex-shrink: 0;
}
.stat-card .label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.stat-card .value { font-size: 22px; font-weight: 700; margin-top: 3px; letter-spacing: -0.01em; }
.stat-card.balance .stat-icon { background: var(--success-light); color: var(--success); }
.stat-card.expense .stat-icon { background: var(--danger-light); color: var(--danger); }
.stat-card.payable .stat-icon { background: var(--warning-light); color: var(--warning); }
.stat-card.income .stat-icon { background: var(--info-light); color: var(--info); }

.panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
  margin-bottom: 20px;
  min-width: 0;
}
.panel h3 { margin: 0 0 14px; font-size: 15.5px; font-weight: 700; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 20px;
  align-items: start;
}

/* Forms inside modals */

.inline-form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Tables */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 560px;
}
table.data-table th {
  text-align: left;
  padding: 11px 12px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .02em;
  border-bottom: 1.5px solid var(--border);
  white-space: nowrap;
}
table.data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: var(--surface-muted); }

.badge {
  display: inline-block;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge-unpaid { background: var(--danger-light); color: #9f1239; }
.badge-partial { background: var(--warning-light); color: #92400e; }
.badge-paid { background: var(--success-light); color: #14532d; }

.empty-state {
  text-align: center;
  padding: 34px 10px;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* Modal */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 43, 0.55);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  backdrop-filter: blur(2px);
}
.modal-overlay.show {
  display: flex;
  animation: overlayFadeIn .18s ease both;
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalPopIn {
  from { opacity: 0; transform: scale(.96) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .modal-overlay.show { animation: none; }
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalPopIn .2s ease both;
  box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { font-size: 17px; font-weight: 700; }
.modal-x {
  background: var(--surface-muted);
  border: none;
  border-radius: 8px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
}
.modal-x:hover { background: var(--border); color: var(--text); }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }

/* Loan card list */

.loan-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-bottom: 12px;
}
.loan-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}
.loan-card .lender { font-weight: 700; font-size: 15px; }
.loan-card .reason { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.loan-card .amounts { font-size: 13px; margin-top: 10px; display: flex; gap: 22px; flex-wrap: wrap; }
.loan-card .amounts b { display: block; font-size: 16px; margin-top: 1px; }
.loan-history { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 10px; font-size: 12.5px; color: var(--text-muted); line-height: 1.7; }

/* Toast */

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  opacity: 0;
  transform: translateY(10px);
  transition: all .2s ease;
  pointer-events: none;
  max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* Loading */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(244, 245, 250, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  backdrop-filter: blur(1px);
}
.loading-overlay.show { display: flex; }

/* ---------- Responsive ---------- */

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

@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s ease;
    width: 260px;
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; width: 100%; }
  .topbar { display: flex; }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 39;
  }
  .sidebar-overlay.show { display: block; }
  .form-row { grid-template-columns: 1fr; }
  .content { padding: 18px; }
}

@media (max-width: 480px) {
  .auth-card { padding: 26px 20px; }
  .panel { padding: 16px; }
}

/* Below this width, tables stop being a wide grid you scroll sideways
   through and instead stack each row into its own card — the column
   label sits to the left of its value via the td's data-label attribute
   (set in the Blade views), read top-to-bottom with no horizontal scroll. */
@media (max-width: 680px) {
  .table-wrap { overflow-x: visible; }

  table.data-table, table.data-table thead, table.data-table tbody,
  table.data-table th, table.data-table td, table.data-table tr {
    display: block;
    width: 100%;
    min-width: 0;
  }

  table.data-table thead {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  table.data-table tbody tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 4px 14px;
    margin-bottom: 12px;
  }
  table.data-table tbody tr:last-child { margin-bottom: 0; }
  table.data-table tr:hover td { background: none; }

  table.data-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 0;
    border-bottom: 1px dashed var(--border);
    white-space: normal;
    text-align: right;
    font-weight: 600;
  }
  table.data-table td:last-child { border-bottom: none; }
  table.data-table td:empty { display: none; }

  table.data-table td::before {
    content: attr(data-label);
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .02em;
    color: var(--text-muted);
    text-align: left;
  }
  table.data-table td:not([data-label])::before { content: none; }

  table.data-table td.empty-state {
    text-align: center;
    padding: 20px 0;
  }
  table.data-table td.empty-state::before { content: none; }
}
