:root {
  --bg: #f4efe7;
  --bg-strong: #efe3d2;
  --card: rgba(255, 252, 247, 0.88);
  --card-strong: #fffaf4;
  --ink: #1c140d;
  --muted: #64584d;
  --line: rgba(45, 29, 11, 0.12);
  --accent: #c96d36;
  --accent-deep: #8d3e16;
  --success: #1f8b62;
  --shadow: 0 24px 70px rgba(72, 41, 14, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(246, 190, 132, 0.45), transparent 30%),
    linear-gradient(135deg, #f7f0e7 0%, #efe4d6 45%, #f5f1ec 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

.ambient {
  position: fixed;
  z-index: 0;
  border-radius: 999px;
  filter: blur(30px);
  opacity: 0.5;
}

.ambient-one {
  top: 40px;
  left: -60px;
  width: 220px;
  height: 220px;
  background: rgba(210, 127, 61, 0.35);
}

.ambient-two {
  right: 40px;
  bottom: 40px;
  width: 260px;
  height: 260px;
  background: rgba(143, 194, 166, 0.28);
}

.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  padding: 28px;
}

.login-panel,
.dashboard {
  min-height: calc(100vh - 56px);
}

.hidden {
  display: none !important;
}

.login-panel {
  display: grid;
  place-items: center;
}

.login-card,
.panel-card,
.sidebar,
.topbar {
  backdrop-filter: blur(18px);
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: var(--shadow);
}

.login-card {
  width: min(100%, 440px);
  border-radius: 28px;
  padding: 36px;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent-deep);
}

.login-card h1,
.topbar h1,
.brand-block h2,
.panel-head h3,
.empty-state h3 {
  margin: 0;
  line-height: 1;
}

.subcopy,
.panel-head p,
.empty-state p,
.table-meta,
.helper-text {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 18px;
  margin-top: 26px;
}

.login-form label {
  display: grid;
  gap: 8px;
}

.login-form input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
}

.login-form button,
.ghost-button,
.nav-link,
.logout-link {
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.login-form button {
  padding: 14px 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
}

.login-form button:hover,
.ghost-button:hover,
.nav-link:hover,
.logout-link:hover {
  transform: translateY(-1px);
}

.error-text {
  min-height: 1.25rem;
  margin: 0;
  color: #c23f3f;
}

.dashboard {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 22px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  border-radius: 28px;
}

.sidebar-nav {
  display: grid;
  gap: 10px;
}

.nav-link,
.logout-link {
  padding: 14px 16px;
  text-align: left;
  background: rgba(255, 255, 255, 0.56);
  color: var(--ink);
}

.nav-link.active {
  background: linear-gradient(135deg, rgba(201, 109, 54, 0.18), rgba(141, 62, 22, 0.18));
  color: var(--accent-deep);
}

.logout-link {
  margin-top: auto;
}

.dashboard-main {
  display: grid;
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px;
  border-radius: 24px;
}

.status-chip {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(31, 139, 98, 0.12);
  color: var(--success);
  white-space: nowrap;
}

.panel-card {
  border-radius: 28px;
  padding: 24px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.search-bar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
  gap: 14px;
  margin: 18px 0 12px;
}

.search-bar label {
  display: grid;
  gap: 8px;
}

.search-bar span {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.search-bar input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
}

.search-bar select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
}

.search-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.ghost-button {
  padding: 12px 16px;
  background: #fff;
  color: var(--accent-deep);
  border: 1px solid rgba(201, 109, 54, 0.18);
}

.ghost-button.secondary {
  color: var(--muted);
}

.inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mini-button {
  padding: 8px 10px;
  min-height: auto;
  border-radius: 10px;
  border: 1px solid rgba(201, 109, 54, 0.18);
  background: #fff;
  color: var(--accent-deep);
  cursor: pointer;
}

.mini-button.minus {
  color: #b14b31;
}

.mini-button.ledger-crystal-button {
  color: var(--muted);
}

.ledger-mode-cell,
.ledger-amount-cell {
  font-weight: 700;
}

.ledger-credit {
  color: var(--success);
}

.ledger-debit {
  color: #c23f3f;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow: auto;
  background: rgba(28, 20, 13, 0.28);
  backdrop-filter: blur(8px);
}

.modal-card {
  position: relative;
  width: min(100%, 420px);
  padding: 26px;
  border-radius: 24px;
  background: var(--card-strong);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: var(--shadow);
}

.modal-card-wide {
  width: min(100%, 1080px);
  height: max(70vh, calc(100vh - 40px));
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal-dismiss-button {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--accent-deep);
  font-size: 0;
  line-height: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
}

.modal-dismiss-button::before {
  content: "\00d7";
  font-size: 1.4rem;
  line-height: 1;
}

.modal-card h3 {
  margin: 0;
}

.modal-copy {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.modal-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.modal-form label {
  display: grid;
  gap: 8px;
}

.modal-form span {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.modal-form input,
.modal-form textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
  font: inherit;
  resize: vertical;
}

.modal-actions {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.modal-status {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.text-button {
  margin-top: 14px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-deep);
  cursor: pointer;
}

.table-meta {
  margin: 18px 0 12px;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 14px;
  color: var(--muted);
}

.modal-search-bar {
  margin-top: 18px;
}

.modal-actions-inline {
  margin-top: 8px;
}

.modal-table-wrap {
  height: 70vh;
  max-height: 70vh;
  overflow: visible;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card-strong);
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 0.92rem;
  line-height: 1.35;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

td.copyable-cell {
  cursor: pointer;
  transition: background 120ms ease;
}

td.copyable-cell:hover {
  background: rgba(201, 109, 54, 0.08);
}

td.non-copyable-cell {
  cursor: default;
}

th {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: rgba(201, 109, 54, 0.08);
}

tbody tr:hover {
  background: rgba(143, 194, 166, 0.08);
}

.thumbnail-preview {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  object-fit: cover;
  display: block;
  border: 1px solid var(--line);
  background: rgba(201, 109, 54, 0.08);
}

.thumbnail-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(201, 109, 54, 0.08);
  font-size: 0.68rem;
}

.status-date-fresh {
  color: #1f8b62;
  font-weight: 600;
}

.status-date-stale {
  color: #c23f3f;
  font-weight: 600;
}

#fomopay-body tr.collapsible-mobile {
  cursor: pointer;
}

.marquee-shell {
  display: block;
  width: 100%;
  min-width: 0;
  overflow: hidden;
}

.marquee-text {
  display: inline-block;
  min-width: max-content;
  white-space: nowrap;
}

.marquee-text.marquee-animate {
  animation: marquee-slide 6s linear infinite alternate;
  will-change: transform;
}

@keyframes marquee-slide {
  from {
    transform: translateX(0);
  }

  to {
    transform: translateX(calc(-1 * var(--marquee-distance, 0px)));
  }
}

.empty-state {
  padding: 36px 8px 20px;
}

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

  .sidebar {
    gap: 18px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 640px) {
  html,
  body {
    overflow-x: hidden;
  }

  .app-shell {
    padding: 16px;
  }

  .login-card,
  .sidebar,
  .panel-card,
  .topbar {
    border-radius: 22px;
  }

  .sidebar {
    padding: 18px;
  }

  .sidebar-nav {
    grid-template-columns: 1fr 1fr;
  }

  .nav-link,
  .logout-link,
  .ghost-button,
  .login-form button {
    min-height: 46px;
  }

  .panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  .search-bar {
    grid-template-columns: 1fr;
  }

  .search-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .modal-card-wide {
    width: min(100%, 100%);
    height: calc(100vh - 24px);
    max-height: calc(100vh - 24px);
    padding: 20px 16px 16px;
  }

  .pagination-bar {
    justify-content: stretch;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
  }

  .ghost-button {
    width: 100%;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .modal-table-wrap {
    height: auto;
    max-height: none;
    overflow: visible;
    border: 1px solid var(--line);
    background: var(--card-strong);
  }

  #crystal-ledger-modal .pagination-bar {
    grid-template-columns: 1fr;
    justify-content: stretch;
    gap: 10px;
  }

  #crystal-ledger-modal .modal-actions-inline {
    grid-template-columns: 1fr;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
  }

  table {
    min-width: 0;
    table-layout: auto;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tbody tr {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--card-strong);
    box-shadow: 0 12px 28px rgba(72, 41, 14, 0.08);
  }

  tbody tr:hover {
    background: var(--card-strong);
  }

  td {
    display: grid;
    grid-template-columns: minmax(88px, 108px) minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
    word-break: break-word;
    overflow-wrap: anywhere;
    font-size: 0.88rem;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
  }

  .thumbnail-preview,
  .thumbnail-fallback {
    width: 48px;
    height: 48px;
  }

  .inline-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
  }

  #fomopay-body tr.collapsible-mobile td.mobile-summary-cell,
  #fomopay-body tr.collapsible-mobile td.non-copyable-cell {
    display: grid;
  }

  #fomopay-body tr.collapsible-mobile td.mobile-extra-cell {
    display: none;
  }

  #fomopay-body tr.collapsible-mobile.expanded td.mobile-extra-cell {
    display: grid;
  }

  #fomopay-body tr.collapsible-mobile:not(.expanded) {
    display: grid;
    grid-template-columns: 56px minmax(0, 1.2fr) minmax(0, 0.9fr) minmax(0, 0.9fr);
    gap: 10px;
    align-items: center;
  }

  #fomopay-body tr.collapsible-mobile:not(.expanded) td.mobile-summary-cell {
    border-bottom: 0;
    padding: 0;
    min-width: 0;
  }

  #fomopay-body tr.collapsible-mobile:not(.expanded) td.mobile-summary-cell {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    line-height: 1.25;
    font-size: 0.8rem;
    overflow: hidden;
  }

  #fomopay-body tr.collapsible-mobile:not(.expanded) td.mobile-summary-cell::before {
    display: none;
  }

  #fomopay-body tr.collapsible-mobile:not(.expanded) td.mobile-summary-cell[data-label="Picture"] {
    justify-content: center;
  }

  #fomopay-body tr.collapsible-mobile td.mobile-summary-cell[data-label="SGD AMOUNT"]::after {
    content: " SGD";
    margin-left: 4px;
    color: var(--muted);
    font-size: 0.62rem;
    white-space: nowrap;
    flex: 0 0 auto;
  }

  #fomopay-body tr.collapsible-mobile td.mobile-summary-cell[data-label="CRYSTAL GAINED"]::after {
    content: " Crystal";
    margin-left: 4px;
    color: var(--muted);
    font-size: 0.62rem;
    white-space: nowrap;
    flex: 0 0 auto;
  }

  #fomopay-body tr.collapsible-mobile:not(.expanded) .thumbnail-preview,
  #fomopay-body tr.collapsible-mobile:not(.expanded) .thumbnail-fallback {
    width: 40px;
    height: 40px;
  }

  #fomopay-body tr.collapsible-mobile.expanded {
    display: block;
  }

  .mobile-row-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-toggle-column {
    display: none;
  }
}

@media (max-width: 420px) {
  .sidebar-nav {
    grid-template-columns: 1fr;
  }

  .search-actions {
    grid-template-columns: 1fr;
  }

  .inline-actions {
    grid-template-columns: 1fr;
  }

  td {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  td::before {
    margin-bottom: 2px;
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  transform: translateX(-50%);
  padding: 12px 16px;
  border-radius: 999px;
  background: rgba(28, 20, 13, 0.9);
  color: #fffaf4;
  box-shadow: 0 16px 40px rgba(28, 20, 13, 0.25);
  font-size: 0.9rem;
}
