:root {
  --primary: #4F46E5;
  --accent: #4F46E5;
  --sidebar-bg: #FFFFFF;
  --btn: #4F46E5;
  --btn-hover: #4338CA;
  --bg: #FFFFFF;
  --text: #0F172A;
  --muted: #64748B;
  --card: #F8FAFC;
  --border: #E2E8F0;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

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

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

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--text);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 0 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.sidebar-brand strong {
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

.sidebar-brand span {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 1.25rem;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.92rem;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.nav-link:hover {
  background: var(--card);
  color: var(--text);
  text-decoration: none;
}

.nav-link.active {
  background: #EEF2FF;
  border-left-color: var(--primary);
  color: var(--primary);
}

.nav-link svg {
  width: 20px;
  height: 20px;
  opacity: 0.9;
}

.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid #e5e7eb;
  padding: 0.85rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-sm);
}

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.global-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg);
  border: 1px solid #e5e7eb;
  border-radius: var(--radius);
  padding: 0.35rem 0.65rem;
  min-width: 220px;
}

.global-search input {
  border: none;
  background: transparent;
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
}

.content {
  padding: 1.5rem 1.75rem 2.5rem;
  flex: 1;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid #eef2f6;
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.25rem;
}

.card-title {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.settings-page {
  max-width: 720px;
}

.settings-accordion {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.settings-panel-actions {
  margin-top: 0.25rem;
}

.settings-accordion > details {
  border: 1px solid #d1d9e0;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 1px 2px rgba(8, 47, 48, 0.06);
  overflow: hidden;
}

.settings-accordion > details > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.9rem 1.1rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  user-select: none;
}

.settings-accordion > details > summary::-webkit-details-marker {
  display: none;
}

.settings-accordion > details > summary::after {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  flex-shrink: 0;
  transition: transform 0.2s ease;
  margin-top: -0.15rem;
}

.settings-accordion > details[open] > summary {
  border-bottom-color: var(--border);
  background: var(--bg);
}

.settings-accordion > details[open] > summary::after {
  transform: rotate(45deg);
  margin-top: 0.1rem;
}

.settings-accordion .accordion-body {
  padding: 1.15rem 1.2rem 1.35rem;
  background: #fff;
  border-top: 1px solid var(--border);
}

.settings-accordion .accordion-body > p.help {
  margin: 0 0 1rem;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.45;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--btn);
  color: #fff;
}
.btn-primary:hover {
  background: var(--btn-hover);
  color: #fff;
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: #f1f5f9;
  text-decoration: none;
  color: var(--text);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
}

.btn-danger {
  background: #b91c1c;
  color: #fff;
}
.btn-danger:hover {
  background: #991b1b;
  color: #fff;
  text-decoration: none;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.85rem 1rem;
}

.form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  font-size: 0.92rem;
  background: #fff;
  color: var(--text);
}

.form-group textarea {
  min-height: 72px;
  resize: vertical;
}

.table-wrap {
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid #e5e7eb;
  max-height: calc(100vh - 220px);
}

table.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
}

table.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--card);
  color: var(--text);
  text-align: left;
  padding: 0.65rem 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

table.data-table tbody td {
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid #eef2f6;
  vertical-align: middle;
}

table.data-table tbody tr:nth-child(even) td {
  background: #f8fafc;
}

table.data-table tbody tr:hover td {
  background: #f1f5f9;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-new {
  background: #dbeafe;
  color: #1e40af;
}
.badge-warn {
  background: #fef3c7;
  color: #92400e;
}
.badge-ok {
  background: #d1fae5;
  color: #065f46;
}
.badge-bad {
  background: #fee2e2;
  color: #991b1b;
}
.badge-muted {
  background: #f3f4f6;
  color: #4b5563;
}

.row-highlight-soon td:first-child {
  box-shadow: inset 3px 0 0 var(--primary);
}
.row-highlight-overdue td:first-child {
  box-shadow: inset 3px 0 0 #dc2626;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  border: 1px solid #eef2f6;
}

.stat-card .label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-card .value {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--accent);
  margin-top: 0.25rem;
  letter-spacing: -0.02em;
}

.stat-card .value.money::before {
  content: "₹ ";
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
}

.section-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-size: 1.05rem;
  font-weight: 800;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: var(--radius);
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 25px 50px rgba(8, 47, 48, 0.18);
  border: 1px solid #e5e7eb;
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-body {
  padding: 1.25rem;
}

.modal-footer {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(145deg, #0F172A 0%, #312E81 45%, #4F46E5 100%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2);
  padding: 2rem;
}

.auth-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  color: var(--text);
}

.auth-card .sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.alert {
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  font-size: 0.88rem;
  margin-bottom: 1rem;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
}

.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

/* Mobile UI Extensions */
.mobile-nav-toggle {
  display: none;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 0.5rem;
  cursor: pointer;
}

.mobile-nav-toggle svg {
  width: 24px;
  height: 24px;
}

@media (max-width: 900px) {
  .mobile-nav-toggle {
    display: block;
  }

  .layout {
    flex-direction: column;
  }

  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    width: 260px;
    z-index: 1000;
    transition: transform 0.3s ease;
    box-shadow: 10px 0 30px rgba(0,0,0,0.2);
  }

  .sidebar.open {
    transform: translateX(280px);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 999;
  }

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

  .topbar {
    padding: 0.75rem 1rem;
  }

  .topbar h1 {
    font-size: 1.15rem;
  }

  .topbar-actions .global-search {
    min-width: 140px;
  }

  .content {
    padding: 1rem;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .toolbar .form-group {
    min-width: 0 !important;
    width: 100%;
  }

  .toolbar .btn {
    width: 100%;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .modal {
    margin: 0;
    max-height: 100vh;
    border-radius: 0;
  }
}

@media (max-width: 500px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .topbar-actions .global-search {
    display: none; /* Hide global search on very small screens to favor title */
  }
}
