:root {
  --purple: #6c3ef4;
  --purple-dark: #5a2fdd;
  --white: #ffffff;
  --light-bg: #f8f6ff;
  --text: #261d4c;
  --muted: #7f74a8;
  --danger: #d62839;
  --shadow: 0 16px 40px rgba(108, 62, 244, 0.18);
  --radius: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

body {
  min-height: 100vh;
  color: var(--text);
  background: linear-gradient(135deg, #ffffff 0%, #f3efff 100%);
}

.auth-container,
.dashboard-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card,
.dashboard-card {
  width: 100%;
  max-width: 430px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  border: 1px solid rgba(108, 62, 244, 0.1);
}

.auth-title,
.dashboard-title {
  color: var(--purple);
  margin-bottom: 8px;
  font-size: 1.8rem;
}

.auth-subtitle,
.dashboard-subtitle {
  color: var(--muted);
  margin-bottom: 24px;
}

.auth-brand {
  margin-bottom: 22px;
  text-align: center;
}

.auth-brand-logo {
  width: min(260px, 80%);
  display: block;
  margin: 0 auto 12px;
}

.auth-brand .auth-subtitle {
  margin-bottom: 0;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 0.9rem;
  color: #4c3f76;
}

.input-group input {
  height: 46px;
  border: 1px solid #d7cef8;
  border-radius: 12px;
  padding: 0 12px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.22s ease, box-shadow 0.22s ease;
}

.input-group input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 4px rgba(108, 62, 244, 0.15);
}

.btn-primary {
  margin-top: 8px;
  height: 46px;
  border: none;
  border-radius: 12px;
  background: var(--purple);
  color: var(--white);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary:hover {
  background: var(--purple-dark);
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(108, 62, 244, 0.25);
}

.btn-primary:active {
  transform: translateY(0px) scale(0.99);
}

.btn-primary:disabled {
  opacity: 0.75;
  cursor: not-allowed;
}

.error-message {
  min-height: 18px;
  color: var(--danger);
  font-size: 0.9rem;
}

.role-pill {
  display: inline-block;
  margin-bottom: 20px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(108, 62, 244, 0.12);
  color: var(--purple);
  font-weight: 600;
}

@media (max-width: 480px) {
  .auth-card,
  .dashboard-card {
    padding: 24px 20px;
  }

  .auth-title,
  .dashboard-title {
    font-size: 1.5rem;
  }

  .auth-brand-logo {
    width: min(220px, 86%);
  }
}

.btn-secondary {
  height: 40px;
  border: 1px solid #d8cff8;
  border-radius: 10px;
  padding: 0 14px;
  background: #f7f5ff;
  color: #4a3d78;
  font-weight: 600;
  cursor: pointer;
}

.btn-danger {
  height: 40px;
  border: none;
  border-radius: 10px;
  padding: 0 14px;
  background: #dd3548;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.full-width {
  width: 100%;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px 1fr;
}

.sidebar {
  background: #ffffff;
  color: var(--text);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid #e8ddff;
}

.sidebar-brand {
  font-size: 1.4rem;
  margin-bottom: 6px;
}

.sidebar-brand-logo {
  width: 100%;
  max-width: 132px;
  display: block;
  margin: 0 auto 10px;
}

.sidebar-brand-text {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-bottom: 6px;
  color: #3f267d;
}

.sidebar-subtitle {
  color: #7f74a8;
  font-size: 0.9rem;
  margin: 0 0 18px;
  text-align: center;
  letter-spacing: 0.25px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-nav a {
  color: #f6f1ff;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 10px;
  transition: background 0.2s;
}

.menu-item {
  width: 100%;
  border: none;
  background: transparent;
  color: #3f267d;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background 0.2s ease, transform 0.2s ease;
}

.menu-item:hover,
.menu-item.active {
  background: var(--purple);
  color: #ffffff;
  transform: translateX(2px);
}

.logout-item {
  margin-top: 12px;
  color: #3f267d;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(255, 255, 255, 0.16);
}

.main-content {
  padding: 20px;
  background: #f6f3ff;
}

.app-shell-dashboard {
  grid-template-columns: 260px 1fr;
}

.sidebar-fixed {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.main-content-dashboard {
  min-height: 100vh;
}

.top-navbar-dashboard {
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-branding {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-logo {
  width: 108px;
  height: auto;
  display: block;
}

.topbar-actions .role-pill {
  margin-bottom: 0;
  flex-shrink: 0;
}

.topbar-actions .btn-primary {
  margin-top: 0;
  padding: 0 16px;
  white-space: nowrap;
  flex-shrink: 0;
}

.dynamic-content {
  min-height: calc(100vh - 136px);
  transition: all 0.25s ease;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.module-card {
  border: 1px solid #efe8ff;
  border-radius: 14px;
  background: #fff;
  padding: 14px;
}

.module-card h3 {
  color: #6b5a9f;
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.module-card p {
  color: #3b2a6f;
  font-size: 1.28rem;
  font-weight: 700;
}

.module-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.module-chart {
  height: 260px;
  margin-bottom: 14px;
}

.module-meta {
  color: #7f74a8;
  margin-bottom: 10px;
}

.top-navbar {
  background: #fff;
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: 0 8px 20px rgba(35, 16, 90, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.top-navbar h1 {
  color: #3c296c;
  margin-bottom: 4px;
  font-size: 1.3rem;
}

.top-navbar p {
  color: #7f74a8;
}

.content-card {
  background: #fff;
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(53, 24, 124, 0.08);
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tab-btn {
  border: 1px solid #d8cff8;
  background: #fff;
  color: #4a3d78;
  border-radius: 10px;
  padding: 9px 16px;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--purple);
  color: #fff;
  border-color: var(--purple);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.search-input {
  flex: 1;
  min-width: 220px;
  height: 40px;
  border: 1px solid #d8cff8;
  border-radius: 10px;
  padding: 0 12px;
}

.table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid #ece6ff;
  font-size: 0.92rem;
}

.data-table th {
  background: #faf8ff;
  color: #4a3d78;
}

.data-table tbody tr:hover {
  background: #f8f5ff;
}

.action-btn {
  border: none;
  padding: 7px 11px;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  margin-right: 6px;
  font-size: 0.82rem;
}

.edit-btn {
  background: var(--purple);
}

.delete-btn {
  background: var(--danger);
}

.view-only-text {
  color: #8a7eb0;
  font-weight: 600;
}

.no-data {
  text-align: center;
  color: #8173a9;
}

.pagination-row {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.summary-card {
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 22px rgba(53, 24, 124, 0.08);
}

.summary-card h3 {
  color: #6b5a9f;
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.summary-card p {
  color: #3b2a6f;
  font-size: 1.35rem;
  font-weight: 700;
}

.charts-grid {
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.chart-card {
  border: 1px solid #efe8ff;
  border-radius: 14px;
  padding: 12px;
  background: #fff;
}

.chart-card h3 {
  color: #4a3d78;
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.sortable-th {
  cursor: pointer;
  user-select: none;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(19, 6, 55, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 30;
}

.modal-content {
  width: min(620px, 95%);
  background: #fff;
  border-radius: 16px;
  padding: 18px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.icon-button {
  border: none;
  background: transparent;
  font-size: 1.6rem;
  color: #664cae;
  cursor: pointer;
}

.master-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.master-form .input-group:nth-child(6),
.master-form .form-actions {
  grid-column: 1 / -1;
}

.input-group select,
.input-group textarea {
  border: 1px solid #d7cef8;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.95rem;
  outline: none;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.loader-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.45);
  display: flex;
  justify-content: center;
  align-items: center;
}

.loader {
  width: 44px;
  height: 44px;
  border: 4px solid #ddd2ff;
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.hidden {
  display: none !important;
}

.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  min-width: 260px;
  padding: 12px 14px;
  border-radius: 12px;
  color: #fff;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.18);
}

.toast.success {
  background: #2e9f5a;
}

.toast.error {
  background: #d62839;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-radius: 0 0 16px 16px;
    gap: 16px;
  }

  .sidebar-fixed {
    position: static;
    height: auto;
  }

  .top-navbar-dashboard {
    position: static;
  }

  .module-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-grid,
  .charts-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .topbar-branding {
    gap: 8px;
  }

  .topbar-logo {
    width: 84px;
  }

  .master-form {
    grid-template-columns: 1fr;
  }

  .module-grid {
    grid-template-columns: 1fr;
  }

  .pagination-row {
    justify-content: center;
  }

  .summary-grid,
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

.invoice-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.invoice-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.invoice-customer-group {
  grid-column: span 1;
}

.helper-text {
  color: #7f74a8;
  font-size: 0.8rem;
}

.invoice-items-table .row-input {
  width: 100%;
  border: 1px solid #d7cef8;
  border-radius: 8px;
  height: 34px;
  padding: 0 8px;
}

.add-item-btn {
  width: fit-content;
}

.invoice-summary-card {
  margin-left: auto;
  width: min(360px, 100%);
  border: 1px solid #ebe4ff;
  border-radius: 14px;
  padding: 14px;
  background: #fcfbff;
}

.invoice-summary-card h3 {
  color: #4a3d78;
  margin-bottom: 10px;
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #544777;
  margin-bottom: 8px;
}

.summary-row.total {
  border-top: 1px dashed #d2c5ff;
  padding-top: 8px;
  margin-top: 8px;
  color: #2f1f61;
}

.invoice-view-card {
  background: #fff;
}

.payment-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.payment-section {
  border: 1px solid #ece4ff;
  border-radius: 14px;
  padding: 14px;
  background: #fcfbff;
}

.payment-section h3 {
  color: #4a3d78;
  margin-bottom: 10px;
  font-size: 1rem;
}

.payment-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.payment-form-grid .form-actions {
  grid-column: 1 / -1;
}

.allocation-full {
  background: rgba(46, 159, 90, 0.08);
}

.invoice-view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}

.invoice-view-header h2 {
  color: var(--purple);
  margin-bottom: 6px;
}

.invoice-action-row {
  display: flex;
  gap: 8px;
}

.invoice-customer-box {
  border: 1px solid #ece4ff;
  border-radius: 12px;
  padding: 12px;
  background: #faf8ff;
  margin-bottom: 14px;
}

.view-summary {
  margin-top: 12px;
}

@media (max-width: 900px) {
  .invoice-meta-grid {
    grid-template-columns: 1fr;
  }

  .payment-form-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  .no-print,
  .sidebar,
  .top-navbar,
  #loader,
  #toastContainer {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .main-content {
    padding: 0;
    background: #fff;
  }

  .content-card {
    box-shadow: none;
    border: none;
  }
}
