:root {
  --bg: #eaf6ff;
  --bg-2: #edf8f7;
  --card: rgba(255, 255, 255, 0.92);
  --card-solid: #ffffff;
  --ink: #111827;
  --muted: #60708a;
  --line: #d7e3f5;
  --blue: #2563eb;
  --blue-2: #0ea5e9;
  --cyan: #06b6d4;
  --green: #128a4a;
  --red: #dc2626;
  --orange: #c25a00;
  --shadow: 0 22px 60px rgba(31, 71, 136, 0.16);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(22, 163, 184, 0.32), transparent 34rem),
    radial-gradient(circle at top right, rgba(37, 99, 235, 0.24), transparent 34rem),
    linear-gradient(135deg, var(--bg), var(--bg-2));
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

.page-shell {
  width: min(1480px, calc(100% - 28px));
  margin: 16px auto 56px;
}

.hero-card {
  min-height: 300px;
  padding: clamp(28px, 4vw, 48px);
  border-radius: 28px;
  color: white;
  background:
    linear-gradient(135deg, rgba(12, 30, 69, 0.98), rgba(37, 99, 235, 0.95) 58%, rgba(13, 188, 202, 0.92)),
    radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.16), transparent 22rem);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 32px;
  align-items: center;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hero-card .eyebrow,
.hero-control-card label {
  color: rgba(255, 255, 255, 0.9);
}

.hero-copy h1 {
  margin: 0;
  font-size: clamp(3rem, 7vw, 5.2rem);
  line-height: 0.95;
  letter-spacing: -0.07em;
}

.hero-text {
  width: min(840px, 100%);
  margin: 18px 0 0;
  font-size: 1.06rem;
  line-height: 1.75;
  color: rgba(255, 255, 255, 0.88);
}

.hero-control-card {
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(12px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.15);
}

.hero-control-card label {
  display: block;
  margin-bottom: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.76rem;
}

select,
input[type="search"],
.api-form input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  color: var(--ink);
  padding: 0 14px;
  outline: none;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

select:focus,
input:focus {
  border-color: var(--blue-2);
  box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.14);
}

.primary-btn,
.secondary-btn,
.ghost-btn {
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.primary-btn {
  margin-top: 12px;
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  box-shadow: 0 16px 32px rgba(37, 99, 235, 0.28);
}

.secondary-btn {
  color: white;
  background: linear-gradient(135deg, #0f172a, #2563eb);
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.2);
}

.ghost-btn {
  color: var(--blue);
  background: #eef6ff;
  border: 1px solid var(--line);
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.62;
  cursor: not-allowed;
  transform: none;
}

.sheet-link {
  display: block;
  margin-top: 14px;
  color: white;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}

.setup-panel,
.status-box,
.panel {
  border: 1px solid rgba(215, 227, 245, 0.95);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.setup-panel {
  margin-top: 22px;
  padding: 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 520px;
  gap: 22px;
  align-items: center;
}

.setup-panel h2,
.panel h2 {
  margin: 0;
  font-size: clamp(1.55rem, 2.4vw, 2rem);
  letter-spacing: -0.05em;
}

.setup-panel p:not(.eyebrow) {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.api-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
}

.api-form input {
  min-width: 220px;
}

.api-form .secondary-btn,
.api-form .ghost-btn {
  width: auto;
  white-space: nowrap;
  padding: 0 18px;
}

.status-box {
  margin-top: 20px;
  padding: 17px 20px;
  color: var(--orange);
  background: #fff3df;
  border-color: #fed7aa;
  font-weight: 600;
  line-height: 1.55;
}

.status-box.success {
  color: #166534;
  background: #dcfce7;
  border-color: #86efac;
}

.status-box.error {
  color: #991b1b;
  background: #fee2e2;
  border-color: #fca5a5;
}

.dashboard-grid {
  margin-top: 22px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}

.panel {
  padding: clamp(22px, 3vw, 28px);
}

.full-width {
  grid-column: 1 / -1;
}

.panel-heading {
  margin-bottom: 18px;
}

.split-heading,
.tenant-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
}

.right-meta {
  display: grid;
  gap: 8px;
  color: var(--muted);
  text-align: right;
  font-size: 0.9rem;
}

.kpi-grid {
  display: grid;
  gap: 14px;
}

.four-cols {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.three-cols {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.kpi-card {
  min-height: 142px;
  padding: 20px 18px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue-2);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
}

.kpi-label {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.77rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.kpi-value {
  display: block;
  margin-bottom: 12px;
  font-size: clamp(2rem, 4vw, 2.6rem);
  line-height: 1;
  letter-spacing: -0.06em;
  font-weight: 700;
}

.kpi-note {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.kpi-note.up {
  color: var(--red);
  font-weight: 600;
}

.change.up {
  color: var(--red);
  font-weight: 500;
}

.kpi-note.down {
  color: var(--green);
  font-weight: 600;
}

.change.down {
  color: var(--green);
  font-weight: 500;
}

.kpi-note.neutral,
.change.neutral {
  color: var(--muted);
  font-weight: 700;
}

.insight-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.insight-item {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
}

.insight-item strong {
  color: var(--ink);
}

.bar-chart,
.chart-card {
  min-height: 310px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.62);
  padding: 18px;
}

.bar-chart {
  display: grid;
  align-content: center;
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: 150px 1fr 110px;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-weight: 600;
}

.bar-track {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2eaf7;
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), #f97316);
}

.bar-value {
  color: var(--ink);
  text-align: right;
}

.tenant-header {
  margin-bottom: 20px;
  align-items: center;
}

.tenant-header input {
  max-width: 54%;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

th,
td {
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: #0f2d62;
  background: #e5efff;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

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

.money-value {
  display: inline-block;
  white-space: nowrap;
  word-break: keep-all;
}

td:nth-child(4),
td:nth-child(5),
td:nth-child(6),
td:nth-child(7),
td:nth-child(8) {
  white-space: nowrap;
}

.amount-positive-due {
  color: var(--red);
  font-weight: 700;
}

.amount-negative-due {
  color: var(--green);
  font-weight: 700;
}

.amount-zero-due {
  color: var(--muted);
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge.due {
  color: var(--red);
  background: #fee2e2;
}

.badge.advance {
  color: var(--green);
  background: #dcfce7;
}

.badge.clear,
.badge.unknown {
  color: var(--muted);
  background: #eef2ff;
}

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.chart-title {
  margin: 0 0 14px;
  color: var(--ink);
  font-weight: 700;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.legend span {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.legend i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.legend .primary,
.chart-line-primary,
.chart-dot-primary {
  --series-color: #2563eb;
}

.legend .secondary,
.chart-line-secondary,
.chart-dot-secondary {
  --series-color: #06b6d4;
}

.legend .third,
.chart-line-third,
.chart-dot-third {
  --series-color: #f97316;
}

.legend i.primary {
  background: #2563eb;
}

.legend i.secondary {
  background: #06b6d4;
}

.legend i.third {
  background: #f97316;
}

.svg-chart {
  width: 100%;
  min-width: 600px;
  height: auto;
}

.grid-line {
  stroke: #e6edf8;
  stroke-width: 1;
}

.axis-label {
  fill: #60708a;
  font-size: 13px;
  font-weight: 600;
}

.chart-line-primary,
.chart-line-secondary,
.chart-line-third {
  fill: none;
  stroke: var(--series-color);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-dot-primary,
.chart-dot-secondary,
.chart-dot-third {
  fill: var(--series-color);
  stroke: white;
  stroke-width: 3;
}

.empty-state {
  min-height: 240px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
}

.setup-panel.hidden {
  display: none;
}

@media (max-width: 1100px) {

  .hero-card,
  .setup-panel,
  .dashboard-grid,
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .four-cols,
  .three-cols {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .api-form .secondary-btn,
  .api-form .ghost-btn {
    width: 100%;
  }

  .tenant-header {
    display: grid;
  }

  .tenant-header input {
    max-width: none;
  }
}

@media (max-width: 680px) {
  .page-shell {
    width: min(100% - 18px, 1480px);
    margin-top: 9px;
  }

  .hero-card,
  .panel,
  .setup-panel {
    border-radius: 18px;
  }

  .hero-copy h1 {
    font-size: 2.7rem;
  }

  .four-cols,
  .three-cols {
    grid-template-columns: 1fr;
  }

  .split-heading {
    display: grid;
  }

  .right-meta {
    text-align: left;
  }

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

  .bar-value {
    text-align: left;
  }
}

/* ---------------------------------------------------------
   Subtle hover effects and animations
   Added only in CSS to make the dashboard feel more alive.
--------------------------------------------------------- */

@keyframes pageFadeIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cardFloatIn {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes softGlow {

  0%,
  100% {
    box-shadow: var(--shadow);
  }

  50% {
    box-shadow: 0 28px 80px rgba(37, 99, 235, 0.22);
  }
}

@keyframes barGrow {
  from {
    width: 0;
  }
}

@keyframes chartDraw {
  from {
    stroke-dashoffset: 900;
  }

  to {
    stroke-dashoffset: 0;
  }
}

@keyframes dotPop {
  0% {
    opacity: 0;
    transform: scale(0.4);
  }

  80% {
    opacity: 1;
    transform: scale(1.15);
  }

  100% {
    transform: scale(1);
  }
}

body {
  animation: pageFadeIn 0.55s ease both;
}

.hero-card {
  position: relative;
  overflow: hidden;
  animation: cardFloatIn 0.7s ease both;
  transition: transform 0.35s ease, box-shadow 0.35s ease, filter 0.35s ease;
}

.hero-card::before {
  content: "";
  position: absolute;
  inset: -45%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.18), transparent 34%);
  transform: translateX(-18%) translateY(-12%) rotate(12deg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease, transform 0.65s ease;
}

.hero-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 30px 80px rgba(31, 71, 136, 0.24);
}

.hero-card:hover::before {
  opacity: 1;
  transform: translateX(8%) translateY(4%) rotate(12deg);
}

.hero-copy,
.hero-control-card {
  position: relative;
  z-index: 1;
}

.hero-control-card {
  transition: transform 0.3s ease, background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.hero-control-card:hover {
  transform: translateY(-4px);
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.42);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.2);
}

.panel,
.setup-panel,
.status-box {
  animation: cardFloatIn 0.55s ease both;
  transition: transform 0.28s ease, box-shadow 0.28s ease, border-color 0.28s ease, background 0.28s ease;
}

.panel:hover,
.setup-panel:hover {
  transform: translateY(-4px);
  border-color: rgba(14, 165, 233, 0.35);
  box-shadow: 0 28px 70px rgba(31, 71, 136, 0.2);
}

.selected-panel {
  animation-delay: 0.05s;
}


.due-panel {
  animation-delay: 0.1s;
}

.tenant-panel {
  animation-delay: 0.15s;
}

.chart-section {
  animation-delay: 0.2s;
}

.snapshot-panel {
  animation-delay: 0.25s;
}

.kpi-card,
.insight-item,
.chart-card,
.bar-chart {
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}

.kpi-card:hover {
  transform: translateY(-5px) scale(1.012);
  border-color: rgba(14, 165, 233, 0.45);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 18px 42px rgba(37, 99, 235, 0.13);
}

.kpi-card:hover .kpi-value {
  transform: translateX(2px);
}

.kpi-value {
  transition: transform 0.25s ease, color 0.25s ease;
}

.insight-item:hover {
  transform: translateX(5px);
  border-color: rgba(37, 99, 235, 0.32);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 28px rgba(31, 71, 136, 0.1);
}

.chart-card:hover,
.bar-chart:hover {
  border-color: rgba(14, 165, 233, 0.35);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 18px 40px rgba(31, 71, 136, 0.11);
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.sheet-link {
  position: relative;
  overflow: hidden;
}

.primary-btn::after,
.secondary-btn::after,
.ghost-btn::after {
  content: "";
  position: absolute;
  top: 0;
  left: -80%;
  width: 55%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.38), transparent);
  transform: skewX(-20deg);
  transition: left 0.55s ease;
}

.primary-btn:hover,
.secondary-btn:hover,
.ghost-btn:hover {
  transform: translateY(-3px);
}

.primary-btn:hover::after,
.secondary-btn:hover::after,
.ghost-btn:hover::after {
  left: 125%;
}

.primary-btn:active,
.secondary-btn:active,
.ghost-btn:active {
  transform: translateY(0) scale(0.985);
}

.sheet-link {
  transition: transform 0.25s ease, opacity 0.25s ease, letter-spacing 0.25s ease;
}

.sheet-link:hover {
  transform: translateY(-2px);
  opacity: 0.92;
  letter-spacing: 0.02em;
}

select,
input[type="search"],
.api-form input {
  transition: border 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

select:hover,
input[type="search"]:hover,
.api-form input:hover {
  border-color: rgba(14, 165, 233, 0.45);
  box-shadow: 0 8px 24px rgba(31, 71, 136, 0.08);
}

select:focus,
input:focus {
  transform: translateY(-1px);
}

.table-wrap {
  transition: box-shadow 0.25s ease, border-color 0.25s ease;
}

.table-wrap:hover {
  border-color: rgba(37, 99, 235, 0.3);
  box-shadow: 0 14px 34px rgba(31, 71, 136, 0.09);
}

tbody tr {
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

tbody tr:hover {
  background: #f8fbff;
  transform: translateX(3px);
  box-shadow: inset 4px 0 0 var(--blue-2);
}

.badge {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.badge:hover {
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 8px 18px rgba(31, 71, 136, 0.12);
}

.amount-positive-due,
.amount-negative-due,
.amount-zero-due,
.money-value {
  transition: transform 0.2s ease, text-shadow 0.2s ease;
}

.amount-positive-due:hover,
.amount-negative-due:hover,
.amount-zero-due:hover,
.money-value:hover {
  transform: scale(1.04);
}

.bar-row {
  transition: transform 0.22s ease, color 0.22s ease;
}

.bar-row:hover {
  transform: translateX(5px);
  color: var(--ink);
}

.bar-fill {
  animation: barGrow 0.85s ease both;
  transition: filter 0.25s ease, transform 0.25s ease;
  transform-origin: left center;
}

.bar-row:hover .bar-fill {
  filter: brightness(1.08) saturate(1.12);
  transform: scaleY(1.18);
}

.chart-line-primary,
.chart-line-secondary,
.chart-line-third {
  stroke-dasharray: 900;
  animation: chartDraw 1.05s ease both;
}

.chart-line-secondary {
  animation-delay: 0.12s;
}

.chart-line-third {
  animation-delay: 0.22s;
}

.chart-dot-primary,
.chart-dot-secondary,
.chart-dot-third {
  transform-box: fill-box;
  transform-origin: center;
  animation: dotPop 0.45s ease both;
  transition: r 0.2s ease, filter 0.2s ease;
}

.chart-dot-primary:hover,
.chart-dot-secondary:hover,
.chart-dot-third:hover {
  filter: drop-shadow(0 4px 8px rgba(31, 71, 136, 0.25));
}

.status-box.success {
  animation: cardFloatIn 0.45s ease both, softGlow 2.8s ease-in-out 0.5s 1;
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------------------------------------------------------
   Mobile and cross-device layout fixes
   Only CSS changes. No HTML or JavaScript changes needed.
--------------------------------------------------------- */

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.page-shell {
  max-width: 1480px;
  overflow-x: hidden;
}

.hero-card,
.status-box,
.panel,
.setup-panel {
  width: 100%;
}

/* Keep charts from forcing the full page wider than the phone screen */
.chart-card {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.svg-chart {
  display: block;
}

/* Keep table scrolling contained inside the table area on medium screens */
.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Tablet/mobile hero correction */
@media (max-width: 1100px) {
  .hero-card {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .hero-control-card {
    width: 100%;
    max-width: 420px;
  }

  .status-box {
    width: 100%;
  }
}

/* Phone layout: make the top area full-width and prevent side blank space */
@media (max-width: 760px) {
  body {
    background:
      radial-gradient(circle at top left, rgba(22, 163, 184, 0.26), transparent 22rem),
      linear-gradient(135deg, var(--bg), var(--bg-2));
  }

  .page-shell {
    width: 100%;
    max-width: 100%;
    margin: 0 auto 32px;
    padding: 8px;
  }

  .hero-card {
    min-height: auto;
    padding: 24px 20px;
    border-radius: 18px;
    gap: 22px;
  }

  .hero-copy h1 {
    font-size: clamp(2.45rem, 12vw, 3.3rem);
    letter-spacing: -0.06em;
  }

  .hero-text {
    font-size: 0.96rem;
    line-height: 1.65;
  }

  .hero-control-card {
    max-width: 100%;
    padding: 18px;
    border-radius: 18px;
  }

  .status-box {
    margin-top: 12px;
    padding: 14px 16px;
    border-radius: 16px;
    font-size: 0.9rem;
  }

  .dashboard-grid {
    margin-top: 14px;
    gap: 14px;
  }

  .panel {
    padding: 18px 16px;
    border-radius: 18px;
  }

  .panel h2,
  .setup-panel h2 {
    font-size: 1.45rem;
    line-height: 1.18;
  }

  .eyebrow {
    font-size: 0.7rem;
    letter-spacing: 0.12em;
  }

  .kpi-card {
    min-height: auto;
    padding: 18px 16px;
  }

  .kpi-value {
    font-size: 2rem;
  }

  .tenant-header {
    gap: 14px;
  }

  .tenant-header input {
    width: 100%;
    height: 46px;
  }

  .chart-card,
  .bar-chart {
    min-height: 280px;
    padding: 14px;
  }

  .svg-chart {
    width: 640px;
    min-width: 640px;
  }

  .bar-row {
    gap: 8px;
  }
}

/* Phone table view: turn wide tables into readable stacked cards */
@media (max-width: 640px) {

  .tenant-panel .table-wrap,
  .snapshot-panel .table-wrap {
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .tenant-panel table,
  .snapshot-panel table {
    width: 100%;
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 12px;
  }

  .tenant-panel thead,
  .snapshot-panel thead {
    display: none;
  }

  .tenant-panel tbody,
  .snapshot-panel tbody,
  .tenant-panel tr,
  .snapshot-panel tr {
    display: block;
    width: 100%;
  }

  .tenant-panel tr,
  .snapshot-panel tr {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: white;
    box-shadow: 0 10px 28px rgba(31, 71, 136, 0.08);
  }

  .tenant-panel tr:hover,
  .snapshot-panel tr:hover {
    transform: none;
    box-shadow: 0 14px 34px rgba(31, 71, 136, 0.12);
  }

  .tenant-panel td,
  .snapshot-panel td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    width: 100%;
    padding: 11px 14px;
    border-bottom: 1px solid #eef3fb;
    text-align: right;
    white-space: normal;
  }

  .tenant-panel td:last-child,
  .snapshot-panel td:last-child {
    border-bottom: 0;
  }

  .tenant-panel td::before,
  .snapshot-panel td::before {
    flex: 0 0 45%;
    color: #0f2d62;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1.35;
    text-align: left;
    text-transform: uppercase;
  }

  .tenant-panel td:nth-child(1)::before {
    content: "User";
  }

  .tenant-panel td:nth-child(2)::before {
    content: "Sub-meter Unit";
  }

  .tenant-panel td:nth-child(3)::before {
    content: "Usage vs Prev.";
  }

  .tenant-panel td:nth-child(4)::before {
    content: "Meter Bill";
  }

  .tenant-panel td:nth-child(5)::before {
    content: "Common Space Bill";
  }

  .tenant-panel td:nth-child(6)::before {
    content: "Total Bill";
  }

  .tenant-panel td:nth-child(7)::before {
    content: "Paid";
  }

  .tenant-panel td:nth-child(8)::before {
    content: "Due";
  }

  .tenant-panel td:nth-child(9)::before {
    content: "Status";
  }

  .snapshot-panel td:nth-child(1)::before {
    content: "Sheet";
  }

  .snapshot-panel td:nth-child(2)::before {
    content: "Total Monthly Usage";
  }

  .snapshot-panel td:nth-child(3)::before {
    content: "Total Monthly Recharge";
  }

  .snapshot-panel td:nth-child(4)::before {
    content: "Per Unit Price";
  }

  .snapshot-panel td:nth-child(5)::before {
    content: "Total Common Bill";
  }

  .snapshot-panel td:nth-child(6)::before {
    content: "Total Tenant Bill";
  }

  .snapshot-panel td:nth-child(7)::before {
    content: "Total Paid";
  }

  .snapshot-panel td:nth-child(8)::before {
    content: "Total Due";
  }

  .snapshot-panel td:nth-child(9)::before {
    content: "Users";
  }

  .tenant-panel td>*,
  .snapshot-panel td>* {
    max-width: 55%;
  }

  .money-value,
  .amount-positive-due,
  .amount-negative-due,
  .amount-zero-due {
    white-space: nowrap;
  }

  .change {
    display: inline-block;
    line-height: 1.35;
  }
}

/* Extra small phones */
@media (max-width: 420px) {
  .page-shell {
    padding: 7px;
  }

  .hero-card {
    padding: 22px 18px;
  }

  .hero-copy h1 {
    font-size: 2.35rem;
  }

  .panel {
    padding: 16px 14px;
  }

  .kpi-value {
    font-size: 1.85rem;
  }

  .tenant-panel td,
  .snapshot-panel td {
    gap: 12px;
    padding: 10px 12px;
  }

  .tenant-panel td::before,
  .snapshot-panel td::before {
    flex-basis: 43%;
  }

  .tenant-panel td>*,
  .snapshot-panel td>* {
    max-width: 57%;
  }

  .svg-chart {
    width: 600px;
    min-width: 600px;
  }
}

/* ---------------------------------------------------------
   Phase 2 typography cleanup
   Softer font weights and color-only comparison emphasis.
--------------------------------------------------------- */

.change,
.kpi-note {
  font-weight: 500;
}

.change.up,
.change.down,
.change.neutral {
  font-weight: 500;
}

.kpi-note.up,
.kpi-note.down {
  font-weight: 600;
}

.kpi-note.neutral {
  font-weight: 500;
}

th,
.badge,
.legend,
.axis-label,
.bar-row,
.empty-state,
.status-box,
.insight-item,
.kpi-label {
  font-weight: 600;
}

.amount-positive-due,
.amount-negative-due,
.amount-zero-due {
  font-weight: 700;
}

/* ---------------------------------------------------------
   Phase 3 tenant table horizontal-scroll fix
   Keeps the page from shifting sideways while preserving table readability.
--------------------------------------------------------- */

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

.page-shell,
.dashboard-grid,
.panel,
.tenant-panel,
.snapshot-panel {
  max-width: 100%;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.tenant-panel table {
  width: 100%;
  min-width: 860px;
}

.tenant-panel th,
.tenant-panel td {
  padding-left: 12px;
  padding-right: 12px;
}

.tenant-panel th:nth-child(1),
.tenant-panel td:nth-child(1) {
  min-width: 130px;
}

.tenant-panel th:nth-child(3),
.tenant-panel td:nth-child(3) {
  min-width: 155px;
}

.tenant-panel th:nth-child(5),
.tenant-panel td:nth-child(5) {
  min-width: 150px;
}

/* The previous row translate hover could create a tiny page-level horizontal scroll. */
tbody tr:hover {
  transform: none;
  box-shadow: inset 4px 0 0 var(--blue-2);
}

.money-value,
.amount-positive-due,
.amount-negative-due,
.amount-zero-due {
  white-space: nowrap;
}

/* Medium screens: keep the scroll inside the table box, not the whole page. */
@media (max-width: 900px) {
  .tenant-panel table {
    min-width: 820px;
  }

  .tenant-panel th,
  .tenant-panel td {
    padding-left: 10px;
    padding-right: 10px;
  }
}

/* Phones already use the stacked-card layout. This prevents any leftover table width from pushing the viewport. */
@media (max-width: 640px) {

  .tenant-panel .table-wrap,
  .snapshot-panel .table-wrap {
    width: 100%;
    max-width: 100%;
    overflow: visible;
  }

  .tenant-panel table,
  .snapshot-panel table {
    min-width: 0;
    max-width: 100%;
  }

  .tenant-panel td,
  .snapshot-panel td {
    min-width: 0;
    word-break: normal;
    overflow-wrap: anywhere;
  }

  .tenant-panel td>*,
  .snapshot-panel td>* {
    min-width: 0;
  }

  .tenant-panel td .money-value,
  .snapshot-panel td .money-value,
  .tenant-panel td .amount-positive-due,
  .tenant-panel td .amount-negative-due,
  .tenant-panel td .amount-zero-due {
    overflow-wrap: normal;
    word-break: keep-all;
  }
}

/* ---------------------------------------------------------
   Phase 7 dark mode
   Frontend-only theme switch with saved preference.
--------------------------------------------------------- */

.theme-toggle-btn {
  margin-top: 12px;
}

body.dark-mode {
  --bg: #07111f;
  --bg-2: #0f172a;
  --card: rgba(15, 23, 42, 0.92);
  --card-solid: #111c2e;
  --ink: #e8f1ff;
  --muted: #a9bad4;
  --line: #2b3f5f;
  --blue: #60a5fa;
  --blue-2: #38bdf8;
  --cyan: #22d3ee;
  --green: #4ade80;
  --red: #fb7185;
  --orange: #fbbf24;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
  background:
    radial-gradient(circle at top left, rgba(34, 211, 238, 0.18), transparent 30rem),
    radial-gradient(circle at top right, rgba(96, 165, 250, 0.16), transparent 30rem),
    linear-gradient(135deg, var(--bg), var(--bg-2));
}

body.dark-mode .hero-card {
  background:
    linear-gradient(135deg, rgba(3, 7, 18, 0.98), rgba(15, 23, 42, 0.96) 48%, rgba(8, 47, 73, 0.95)),
    radial-gradient(circle at 80% 20%, rgba(56, 189, 248, 0.16), transparent 22rem);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
}

body.dark-mode .hero-text,
body.dark-mode .hero-card .eyebrow,
body.dark-mode .hero-control-card label {
  color: rgba(232, 241, 255, 0.9);
}

body.dark-mode .hero-control-card {
  border-color: rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.48);
}

body.dark-mode .hero-control-card:hover {
  background: rgba(15, 23, 42, 0.62);
  border-color: rgba(56, 189, 248, 0.42);
}

body.dark-mode select,
body.dark-mode input[type="search"],
body.dark-mode .api-form input {
  color: var(--ink);
  background: #0b1525;
  border-color: var(--line);
}

body.dark-mode select option {
  color: var(--ink);
  background: #0b1525;
}

body.dark-mode select:focus,
body.dark-mode input:focus {
  border-color: var(--blue-2);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.16);
}

body.dark-mode .setup-panel,
body.dark-mode .panel {
  border-color: rgba(43, 63, 95, 0.95);
  background: var(--card);
  box-shadow: var(--shadow);
}

body.dark-mode .setup-panel p:not(.eyebrow),
body.dark-mode .right-meta,
body.dark-mode .kpi-label,
body.dark-mode .kpi-note,
body.dark-mode .insight-item,
body.dark-mode .bar-row,
body.dark-mode .axis-label,
body.dark-mode .legend,
body.dark-mode .empty-state {
  color: var(--muted);
}

body.dark-mode .kpi-card,
body.dark-mode .insight-item,
body.dark-mode .bar-chart,
body.dark-mode .chart-card {
  border-color: var(--line);
  background: rgba(17, 28, 46, 0.78);
}

body.dark-mode .kpi-card:hover,
body.dark-mode .insight-item:hover,
body.dark-mode .chart-card:hover,
body.dark-mode .bar-chart:hover {
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(17, 28, 46, 0.94);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.24);
}

body.dark-mode .table-wrap {
  border-color: var(--line);
  background: #0b1525;
}

body.dark-mode table {
  color: var(--ink);
}

body.dark-mode th {
  color: #dbeafe;
  background: #13233a;
}

body.dark-mode td {
  border-bottom-color: var(--line);
}

body.dark-mode tbody tr:hover {
  background: rgba(56, 189, 248, 0.08);
  box-shadow: inset 4px 0 0 var(--blue-2);
}

body.dark-mode .status-box {
  color: #fde68a;
  background: rgba(120, 53, 15, 0.52);
  border-color: rgba(251, 191, 36, 0.34);
}

body.dark-mode .status-box.success {
  color: #bbf7d0;
  background: rgba(20, 83, 45, 0.42);
  border-color: rgba(74, 222, 128, 0.34);
}

body.dark-mode .status-box.error {
  color: #fecdd3;
  background: rgba(127, 29, 29, 0.42);
  border-color: rgba(251, 113, 133, 0.34);
}

body.dark-mode .ghost-btn {
  color: #dbeafe;
  background: rgba(15, 23, 42, 0.9);
  border-color: rgba(56, 189, 248, 0.34);
}

body.dark-mode .ghost-btn:hover {
  background: rgba(30, 41, 59, 0.96);
}

body.dark-mode .primary-btn {
  background: linear-gradient(135deg, #2563eb, #0891b2);
  box-shadow: 0 16px 32px rgba(14, 165, 233, 0.18);
}

body.dark-mode .secondary-btn {
  background: linear-gradient(135deg, #0f172a, #1d4ed8);
}

body.dark-mode .amount-positive-due,
body.dark-mode .kpi-note.up,
body.dark-mode .change.up {
  color: #fb7185;
}

body.dark-mode .amount-negative-due,
body.dark-mode .kpi-note.down,
body.dark-mode .change.down {
  color: #4ade80;
}

body.dark-mode .amount-zero-due,
body.dark-mode .kpi-note.neutral,
body.dark-mode .change.neutral {
  color: #a9bad4;
}

body.dark-mode .badge.due {
  color: #fecdd3;
  background: rgba(127, 29, 29, 0.56);
}

body.dark-mode .badge.advance {
  color: #bbf7d0;
  background: rgba(20, 83, 45, 0.52);
}

body.dark-mode .badge.clear,
body.dark-mode .badge.unknown {
  color: #dbeafe;
  background: rgba(30, 41, 59, 0.9);
}

body.dark-mode .bar-track {
  background: #1e2f4a;
}

body.dark-mode .bar-fill {
  background: linear-gradient(90deg, #fb7185, #fbbf24);
}

body.dark-mode .bar-value {
  color: var(--ink);
}

body.dark-mode .grid-line {
  stroke: #263a58;
}

body.dark-mode .axis-label {
  fill: #a9bad4;
}

body.dark-mode .chart-line-primary,
body.dark-mode .chart-dot-primary {
  --series-color: #60a5fa;
}

body.dark-mode .chart-line-secondary,
body.dark-mode .chart-dot-secondary {
  --series-color: #22d3ee;
}

body.dark-mode .chart-line-third,
body.dark-mode .chart-dot-third {
  --series-color: #fbbf24;
}

body.dark-mode .legend i.primary {
  background: #60a5fa;
}

body.dark-mode .legend i.secondary {
  background: #22d3ee;
}

body.dark-mode .legend i.third {
  background: #fbbf24;
}

body.dark-mode .chart-dot-primary,
body.dark-mode .chart-dot-secondary,
body.dark-mode .chart-dot-third {
  stroke: #0b1525;
}

@media (max-width: 640px) {

  body.dark-mode .tenant-panel tr,
  body.dark-mode .snapshot-panel tr {
    border-color: var(--line);
    background: #0b1525;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  }

  body.dark-mode .tenant-panel td,
  body.dark-mode .snapshot-panel td {
    border-bottom-color: var(--line);
  }

  body.dark-mode .tenant-panel td::before,
  body.dark-mode .snapshot-panel td::before {
    color: #bfdbfe;
  }
}

@media print {
  .theme-toggle-btn {
    display: none !important;
  }

  body.dark-mode {
    background: white;
    color: #111827;
  }
}

/* ---------------------------------------------------------
   Phase 7 dark mode refinement
   More vibrant dark palette while keeping contrast strong.
--------------------------------------------------------- */

body.dark-mode {
  --bg: #071525;
  --bg-2: #0a1830;
  --card: rgba(11, 26, 44, 0.92);
  --card-solid: #0d2035;
  --ink: #eef6ff;
  --muted: #b7c8df;
  --line: #294766;
  --blue: #6aa8ff;
  --blue-2: #38d4ff;
  --cyan: #3ce6d8;
  --green: #52e58f;
  --red: #ff7c93;
  --orange: #ffc85a;
  --shadow: 0 24px 64px rgba(0, 0, 0, 0.36);
  background:
    radial-gradient(circle at 10% 8%, rgba(56, 212, 255, 0.22), transparent 24rem),
    radial-gradient(circle at 92% 10%, rgba(106, 168, 255, 0.18), transparent 26rem),
    radial-gradient(circle at 50% 100%, rgba(60, 230, 216, 0.10), transparent 28rem),
    linear-gradient(135deg, #071525 0%, #0b1730 45%, #0d2740 100%);
}

body.dark-mode .hero-card {
  background:
    radial-gradient(circle at 15% 18%, rgba(56, 212, 255, 0.16), transparent 20rem),
    radial-gradient(circle at 84% 18%, rgba(60, 230, 216, 0.12), transparent 18rem),
    linear-gradient(135deg, rgba(3, 13, 29, 0.98) 0%, rgba(8, 25, 58, 0.97) 42%, rgba(10, 52, 84, 0.95) 100%);
  border: 1px solid rgba(68, 153, 255, 0.16);
  box-shadow:
    0 26px 72px rgba(0, 0, 0, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

body.dark-mode .hero-text {
  color: rgba(238, 246, 255, 0.88);
}

body.dark-mode .hero-control-card {
  border-color: rgba(80, 163, 255, 0.24);
  background:
    linear-gradient(180deg, rgba(9, 26, 51, 0.68), rgba(11, 28, 52, 0.56));
  box-shadow:
    0 18px 42px rgba(0, 0, 0, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

body.dark-mode .hero-control-card:hover {
  background:
    linear-gradient(180deg, rgba(12, 31, 60, 0.78), rgba(12, 30, 56, 0.66));
  border-color: rgba(56, 212, 255, 0.42);
}

body.dark-mode .setup-panel,
body.dark-mode .panel {
  background:
    linear-gradient(180deg, rgba(11, 26, 44, 0.94), rgba(13, 29, 49, 0.92));
  border-color: rgba(55, 84, 118, 0.95);
  box-shadow:
    0 18px 46px rgba(0, 0, 0, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

body.dark-mode .kpi-card,
body.dark-mode .insight-item,
body.dark-mode .bar-chart,
body.dark-mode .chart-card {
  background:
    linear-gradient(180deg, rgba(14, 32, 54, 0.86), rgba(12, 28, 47, 0.82));
  border-color: rgba(52, 86, 121, 0.96);
}

body.dark-mode .kpi-card:hover,
body.dark-mode .insight-item:hover,
body.dark-mode .chart-card:hover,
body.dark-mode .bar-chart:hover {
  border-color: rgba(56, 212, 255, 0.46);
  background:
    linear-gradient(180deg, rgba(17, 38, 64, 0.96), rgba(14, 32, 55, 0.94));
  box-shadow:
    0 18px 46px rgba(0, 0, 0, 0.28),
    0 0 0 1px rgba(56, 212, 255, 0.08);
}

body.dark-mode .table-wrap {
  background:
    linear-gradient(180deg, rgba(9, 23, 40, 0.98), rgba(10, 24, 40, 0.98));
}

body.dark-mode th {
  background: #16304e;
  color: #e8f3ff;
}

body.dark-mode tbody tr:hover {
  background: rgba(56, 212, 255, 0.08);
}

body.dark-mode .ghost-btn {
  color: #eef6ff;
  background: linear-gradient(180deg, rgba(9, 24, 45, 0.96), rgba(10, 26, 48, 0.94));
  border-color: rgba(56, 212, 255, 0.28);
}

body.dark-mode .ghost-btn:hover {
  background: linear-gradient(180deg, rgba(12, 30, 56, 0.98), rgba(12, 31, 60, 0.96));
  border-color: rgba(56, 212, 255, 0.42);
}

body.dark-mode .primary-btn {
  background: linear-gradient(135deg, #2f6fff 0%, #18a8de 55%, #20c8c8 100%);
  box-shadow: 0 16px 34px rgba(36, 127, 255, 0.24);
}

body.dark-mode .secondary-btn {
  background: linear-gradient(135deg, #163c7a, #1187bc);
}

body.dark-mode .bar-track {
  background: #183553;
}

body.dark-mode .grid-line {
  stroke: #274764;
}

body.dark-mode .legend i.primary {
  background: #6aa8ff;
}

body.dark-mode .legend i.secondary {
  background: #3ce6d8;
}

body.dark-mode .legend i.third {
  background: #ffc85a;
}

/* ---------------------------------------------------------
   Phase 2B chart rebuild
   New analytics charts and due chart moved after tenant details.
--------------------------------------------------------- */

.analytics-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.matrix-card {
  grid-column: 1 / -1;
}

.split-chart,
.highest-chart {
  display: grid;
  gap: 12px;
}

.split-row,
.highest-row {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.58);
}

.highest-row {
  grid-template-columns: 160px minmax(0, 1fr) 120px;
  align-items: center;
}

.highest-row div {
  display: grid;
  gap: 4px;
}

.highest-row span {
  color: var(--muted);
  font-size: 0.86rem;
}

.highest-row b {
  text-align: right;
  white-space: nowrap;
  font-weight: 600;
}

.split-row>strong,
.highest-row strong {
  color: var(--ink);
  font-weight: 600;
}

.split-bars {
  display: grid;
  gap: 8px;
}

.split-bar-line {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) 105px;
  gap: 10px;
  align-items: center;
}

.split-bar-label,
.split-bar-value {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.split-bar-value {
  text-align: right;
  white-space: nowrap;
}

.split-bar-track,
.highest-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2eaf7;
}

.split-bar-fill,
.highest-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  animation: barGrow 0.85s ease both;
}

.split-bar-fill.primary {
  background: linear-gradient(90deg, var(--blue), var(--blue-2));
}

.split-bar-fill.secondary {
  background: linear-gradient(90deg, var(--cyan), #14b8a6);
}

.split-bar-fill.third {
  background: linear-gradient(90deg, #f97316, var(--orange));
}

.highest-fill {
  background: linear-gradient(90deg, var(--blue), var(--cyan));
}

.matrix-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 500;
}

.matrix-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.matrix-legend i {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
}

.matrix-legend i.due {
  background: var(--red);
}

.matrix-legend i.advance {
  background: var(--green);
}

.matrix-legend i.clear {
  background: var(--muted);
}

.matrix-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
  -webkit-overflow-scrolling: touch;
}

.matrix-table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
}

.matrix-table th,
.matrix-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.matrix-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.matrix-table th:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
}

.matrix-table tbody th {
  background: #f8fbff;
  color: var(--ink);
  font-weight: 600;
}

.matrix-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 600;
}

.matrix-pill.due {
  color: var(--red);
  background: #fee2e2;
}

.matrix-pill.advance {
  color: var(--green);
  background: #dcfce7;
}

.matrix-pill.clear {
  color: var(--muted);
  background: #eef2ff;
}

body.dark-mode .split-row,
body.dark-mode .highest-row {
  border-color: var(--line);
  background: rgba(14, 32, 54, 0.62);
}

body.dark-mode .split-bar-track,
body.dark-mode .highest-track {
  background: #183553;
}

body.dark-mode .matrix-wrap {
  border-color: var(--line);
  background: #0b1525;
}

body.dark-mode .matrix-table tbody th {
  background: #10243b;
  color: var(--ink);
}

body.dark-mode .matrix-pill.due {
  color: #fecdd3;
  background: rgba(127, 29, 29, 0.56);
}

body.dark-mode .matrix-pill.advance {
  color: #bbf7d0;
  background: rgba(20, 83, 45, 0.52);
}

body.dark-mode .matrix-pill.clear {
  color: #dbeafe;
  background: rgba(30, 41, 59, 0.9);
}

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

@media (max-width: 680px) {
  .split-row {
    grid-template-columns: 1fr;
  }

  .highest-row {
    grid-template-columns: 1fr;
  }

  .highest-row b {
    text-align: left;
  }

  .split-bar-line {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .split-bar-value {
    grid-column: 2;
    text-align: left;
  }

  .matrix-table {
    min-width: 720px;
  }
}

/* ---------------------------------------------------------
   Phase 2B refinement fixes
   Compact due chart, non-scrolling due/advance cards, better chart sizing,
   and newest-to-oldest ordering support.
--------------------------------------------------------- */

.analytics-grid {
  align-items: start;
}

.analytics-panel .chart-card {
  min-height: auto;
}

.due-panel {
  grid-column: 1 / -1;
}

.due-panel .bar-chart {
  min-height: 170px;
  padding: 18px;
}

.due-panel .empty-state {
  min-height: 120px;
}

#unitPriceTrendChart,
#billSplitChart {
  align-self: start;
}

#highestUsageChart,
#dueAdvanceMatrix {
  grid-column: 1 / -1;
}

.chart-hint,
.chart-subtitle {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
}

.chart-dot-primary,
.chart-dot-secondary,
.chart-dot-third {
  cursor: pointer;
}

.usage-comparison-chart,
.due-advance-list {
  display: grid;
  gap: 14px;
}

.usage-month-card,
.due-user-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.58);
}

.usage-month-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.usage-month-head strong,
.due-user-card>strong {
  color: var(--ink);
  font-weight: 600;
}

.usage-month-head span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}

.usage-user-list {
  display: grid;
  gap: 9px;
}

.usage-user-row {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) 130px;
  gap: 12px;
  align-items: center;
}

.usage-user-row>span:first-child {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}

.usage-user-row em {
  margin-left: 6px;
  color: var(--blue);
  font-style: normal;
  font-size: 0.72rem;
  font-weight: 600;
}

.usage-user-row b {
  text-align: right;
  white-space: nowrap;
  font-weight: 600;
}

.usage-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2eaf7;
}

.usage-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--cyan));
  animation: barGrow 0.85s ease both;
}

.usage-user-row.highest .usage-fill {
  background: linear-gradient(90deg, var(--blue), var(--cyan), #14b8a6);
}

.due-user-card {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.due-month-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
}

.due-month-cell {
  display: grid;
  gap: 5px;
  min-height: 62px;
  padding: 10px 11px;
  border-radius: 14px;
  border: 1px solid transparent;
}

.due-month-cell small {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.due-month-cell b {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
}

.due-month-cell.due {
  color: var(--red);
  background: #fee2e2;
  border-color: #fecaca;
}

.due-month-cell.advance {
  color: var(--green);
  background: #dcfce7;
  border-color: #bbf7d0;
}

.due-month-cell.clear {
  color: var(--muted);
  background: #eef2ff;
  border-color: #dbeafe;
}

.due-month-cell.due small,
.due-month-cell.advance small,
.due-month-cell.clear small {
  color: currentColor;
  opacity: 0.78;
}

.matrix-wrap,
.matrix-table {
  min-width: 0;
  overflow: visible;
}

body.dark-mode .usage-month-card,
body.dark-mode .due-user-card {
  border-color: var(--line);
  background: rgba(14, 32, 54, 0.62);
}

body.dark-mode .usage-track {
  background: #183553;
}

body.dark-mode .due-month-cell.due {
  color: #fecdd3;
  background: rgba(127, 29, 29, 0.56);
  border-color: rgba(251, 113, 133, 0.24);
}

body.dark-mode .due-month-cell.advance {
  color: #bbf7d0;
  background: rgba(20, 83, 45, 0.52);
  border-color: rgba(74, 222, 128, 0.24);
}

body.dark-mode .due-month-cell.clear {
  color: #dbeafe;
  background: rgba(30, 41, 59, 0.9);
  border-color: rgba(148, 163, 184, 0.18);
}

@media (max-width: 900px) {
  .usage-user-row {
    grid-template-columns: 130px minmax(0, 1fr) 112px;
  }

  .due-user-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .due-panel .bar-chart {
    min-height: 150px;
  }

  .usage-month-head {
    display: grid;
  }

  .usage-user-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .usage-user-row b {
    text-align: left;
  }

  .due-month-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------------------------------------------------------
   Phase 2B second refinement
   Moves per-unit trend beside due chart, reduces empty space,
   and improves chart interaction/spacing.
--------------------------------------------------------- */

.due-price-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 18px;
  align-items: stretch;
}

.due-chart-block,
.price-trend-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.62);
  padding: 18px;
}

.due-chart-block .panel-heading {
  margin-bottom: 16px;
}

.due-chart-block .bar-chart {
  min-height: 170px;
  padding: 16px;
}

.due-chart-block .empty-state {
  min-height: 115px;
}

.price-trend-card {
  min-height: auto;
}

.price-trend-card .svg-chart {
  min-width: 520px;
}

.price-trend-card .chart-hint {
  margin-top: 8px;
}

.chart-dot-primary,
.chart-dot-secondary,
.chart-dot-third {
  outline: none;
  transition: r 0.2s ease, filter 0.2s ease, stroke-width 0.2s ease;
}

.chart-dot-primary:hover,
.chart-dot-secondary:hover,
.chart-dot-third:hover,
.chart-dot-primary:focus,
.chart-dot-secondary:focus,
.chart-dot-third:focus {
  filter: drop-shadow(0 0 8px rgba(96, 165, 250, 0.65));
  stroke-width: 4;
}

#unitPriceTrendChart {
  align-self: stretch;
}

#billSplitChart {
  align-self: start;
}

#highestUsageChart .chart-subtitle {
  display: block;
  margin: 12px 0 18px;
  line-height: 1.6;
}

body.dark-mode .due-chart-block,
body.dark-mode .price-trend-card {
  border-color: var(--line);
  background:
    linear-gradient(180deg, rgba(14, 32, 54, 0.86), rgba(12, 28, 47, 0.82));
}

body.dark-mode .chart-dot-primary:hover,
body.dark-mode .chart-dot-secondary:hover,
body.dark-mode .chart-dot-third:hover,
body.dark-mode .chart-dot-primary:focus,
body.dark-mode .chart-dot-secondary:focus,
body.dark-mode .chart-dot-third:focus {
  filter: drop-shadow(0 0 9px rgba(56, 212, 255, 0.7));
}

@media (max-width: 1100px) {
  .due-price-grid {
    grid-template-columns: 1fr;
  }

  .price-trend-card .svg-chart {
    min-width: 600px;
  }
}

@media (max-width: 680px) {

  .due-chart-block,
  .price-trend-card {
    padding: 14px;
  }

  .due-chart-block .bar-chart {
    min-height: 145px;
  }

  .price-trend-card .svg-chart {
    min-width: 560px;
  }
}

/* ---------------------------------------------------------
   Phase 2B third refinement
   Aligns Per-unit heading style, pairs Highest Usage with Bill Split,
   and changes positive due bar to orange-to-red.
--------------------------------------------------------- */

.price-trend-card .chart-panel-heading {
  margin-bottom: 16px;
}

.price-trend-card .chart-panel-heading h2 {
  margin: 0;
  font-size: clamp(1.55rem, 2.4vw, 2rem);
  letter-spacing: -0.05em;
}

#highestUsageChart {
  grid-column: auto;
}

#dueAdvanceMatrix {
  grid-column: 1 / -1;
}

.bar-fill {
  background: linear-gradient(90deg, #f97316 0%, #ef4444 55%, #dc2626 100%);
}

body.dark-mode .bar-fill {
  background: linear-gradient(90deg, #fb923c 0%, #fb7185 58%, #ef4444 100%);
}

@media (max-width: 1100px) {

  #highestUsageChart,
  #dueAdvanceMatrix {
    grid-column: 1 / -1;
  }
}

/* ---------------------------------------------------------
   Phase 2B fourth refinement
   Equal height for Bill Split and Highest Usage cards.
--------------------------------------------------------- */

@media (min-width: 1101px) {

  #billSplitChart,
  #highestUsageChart {
    height: 720px;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
  }

  #billSplitChart::-webkit-scrollbar,
  #highestUsageChart::-webkit-scrollbar {
    width: 9px;
  }

  #billSplitChart::-webkit-scrollbar-track,
  #highestUsageChart::-webkit-scrollbar-track {
    background: rgba(96, 112, 138, 0.14);
    border-radius: 999px;
  }

  #billSplitChart::-webkit-scrollbar-thumb,
  #highestUsageChart::-webkit-scrollbar-thumb {
    background: rgba(14, 165, 233, 0.45);
    border-radius: 999px;
  }

  #billSplitChart::-webkit-scrollbar-thumb:hover,
  #highestUsageChart::-webkit-scrollbar-thumb:hover {
    background: rgba(14, 165, 233, 0.65);
  }

  body.dark-mode #billSplitChart::-webkit-scrollbar-track,
  body.dark-mode #highestUsageChart::-webkit-scrollbar-track {
    background: rgba(183, 200, 223, 0.12);
  }

  body.dark-mode #billSplitChart::-webkit-scrollbar-thumb,
  body.dark-mode #highestUsageChart::-webkit-scrollbar-thumb {
    background: rgba(56, 212, 255, 0.42);
  }

  body.dark-mode #billSplitChart::-webkit-scrollbar-thumb:hover,
  body.dark-mode #highestUsageChart::-webkit-scrollbar-thumb:hover {
    background: rgba(56, 212, 255, 0.62);
  }
}

/* ---------------------------------------------------------
   Phase 2B fifth refinement
   Keeps breathing space at the top and bottom of scrollable chart cards.
--------------------------------------------------------- */

@media (min-width: 1101px) {

  #billSplitChart,
  #highestUsageChart {
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  #billSplitChart .split-chart,
  #highestUsageChart .usage-comparison-chart {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 8px 22px 0;
    scroll-padding-top: 12px;
    scroll-padding-bottom: 22px;
    scrollbar-gutter: stable;
  }

  #billSplitChart .split-chart::after,
  #highestUsageChart .usage-comparison-chart::after {
    content: "";
    display: block;
    height: 10px;
  }

  #billSplitChart .split-chart::-webkit-scrollbar,
  #highestUsageChart .usage-comparison-chart::-webkit-scrollbar {
    width: 9px;
  }

  #billSplitChart .split-chart::-webkit-scrollbar-track,
  #highestUsageChart .usage-comparison-chart::-webkit-scrollbar-track {
    background: rgba(96, 112, 138, 0.14);
    border-radius: 999px;
  }

  #billSplitChart .split-chart::-webkit-scrollbar-thumb,
  #highestUsageChart .usage-comparison-chart::-webkit-scrollbar-thumb {
    background: rgba(14, 165, 233, 0.45);
    border-radius: 999px;
  }

  #billSplitChart .split-chart::-webkit-scrollbar-thumb:hover,
  #highestUsageChart .usage-comparison-chart::-webkit-scrollbar-thumb:hover {
    background: rgba(14, 165, 233, 0.65);
  }

  body.dark-mode #billSplitChart .split-chart::-webkit-scrollbar-track,
  body.dark-mode #highestUsageChart .usage-comparison-chart::-webkit-scrollbar-track {
    background: rgba(183, 200, 223, 0.12);
  }

  body.dark-mode #billSplitChart .split-chart::-webkit-scrollbar-thumb,
  body.dark-mode #highestUsageChart .usage-comparison-chart::-webkit-scrollbar-thumb {
    background: rgba(56, 212, 255, 0.42);
  }

  body.dark-mode #billSplitChart .split-chart::-webkit-scrollbar-thumb:hover,
  body.dark-mode #highestUsageChart .usage-comparison-chart::-webkit-scrollbar-thumb:hover {
    background: rgba(56, 212, 255, 0.62);
  }
}

/* ---------------------------------------------------------
   Test: theme-matched glowing gradient button border animation
   Inspired by a rotating conic-gradient border effect.
--------------------------------------------------------- */

@property --dashboard-glow-angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

@keyframes dashboardGlowRotate {
  to {
    --dashboard-glow-angle: 360deg;
  }
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.theme-toggle-btn {
  isolation: isolate;
  border: 1px solid transparent;
}

.primary-btn::before,
.secondary-btn::before,
.ghost-btn::before,
.theme-toggle-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  padding: 2px;
  border-radius: inherit;
  background:
    conic-gradient(from var(--dashboard-glow-angle),
      transparent 0deg,
      rgba(14, 165, 233, 0.12) 50deg,
      rgba(37, 99, 235, 0.85) 105deg,
      rgba(6, 182, 212, 0.95) 170deg,
      rgba(20, 184, 166, 0.78) 230deg,
      rgba(249, 115, 22, 0.75) 290deg,
      transparent 360deg);
  opacity: 0;
  pointer-events: none;
  animation: dashboardGlowRotate 3.2s linear infinite;
  transition: opacity 0.28s ease, filter 0.28s ease;
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  mask-composite: exclude;
}

.primary-btn:hover::before,
.secondary-btn:hover::before,
.ghost-btn:hover::before,
.theme-toggle-btn:hover::before,
.primary-btn:focus-visible::before,
.secondary-btn:focus-visible::before,
.ghost-btn:focus-visible::before,
.theme-toggle-btn:focus-visible::before {
  opacity: 1;
  filter: drop-shadow(0 0 10px rgba(14, 165, 233, 0.42));
}

.primary-btn:hover,
.secondary-btn:hover,
.ghost-btn:hover,
.theme-toggle-btn:hover {
  box-shadow:
    0 16px 34px rgba(37, 99, 235, 0.18),
    0 0 0 1px rgba(14, 165, 233, 0.12);
}

body.dark-mode .primary-btn::before,
body.dark-mode .secondary-btn::before,
body.dark-mode .ghost-btn::before,
body.dark-mode .theme-toggle-btn::before {
  background:
    conic-gradient(from var(--dashboard-glow-angle),
      transparent 0deg,
      rgba(56, 212, 255, 0.18) 45deg,
      rgba(106, 168, 255, 0.95) 100deg,
      rgba(60, 230, 216, 0.98) 170deg,
      rgba(82, 229, 143, 0.78) 230deg,
      rgba(255, 124, 147, 0.78) 295deg,
      transparent 360deg);
}

body.dark-mode .primary-btn:hover::before,
body.dark-mode .secondary-btn:hover::before,
body.dark-mode .ghost-btn:hover::before,
body.dark-mode .theme-toggle-btn:hover::before,
body.dark-mode .primary-btn:focus-visible::before,
body.dark-mode .secondary-btn:focus-visible::before,
body.dark-mode .ghost-btn:focus-visible::before,
body.dark-mode .theme-toggle-btn:focus-visible::before {
  filter: drop-shadow(0 0 12px rgba(56, 212, 255, 0.48));
}

body.dark-mode .primary-btn:hover,
body.dark-mode .secondary-btn:hover,
body.dark-mode .ghost-btn:hover,
body.dark-mode .theme-toggle-btn:hover {
  box-shadow:
    0 16px 36px rgba(56, 212, 255, 0.14),
    0 0 0 1px rgba(56, 212, 255, 0.14);
}

@media (prefers-reduced-motion: reduce) {

  .primary-btn::before,
  .secondary-btn::before,
  .ghost-btn::before,
  .theme-toggle-btn::before {
    animation: none;
  }
}

/* ---------------------------------------------------------
   Final alignment fix
   Identical title/second-line spacing for Bill Split and Highest Usage cards.
--------------------------------------------------------- */

#billSplitChart .chart-title,
#highestUsageChart .chart-title {
  margin: 0 0 14px;
}

#billSplitChart .legend,
#highestUsageChart .chart-subtitle {
  min-height: 24px;
  margin: 0 0 18px;
  display: flex;
  align-items: center;
  line-height: 1.5;
}
