:root {
  --bg-1: #f5fbf7;
  --bg-2: #e1f1e8;
  --panel: #ffffff;
  --panel-2: #f4fff7;
  --text: #113625;
  --muted: #587264;
  --line: #d4e7dc;
  --brand: #0d8b57;
  --brand-2: #0a7449;
  --brand-soft: #dff5ea;
  --danger: #bc1d1d;
  --shadow: 0 14px 34px rgba(19, 54, 37, 0.1);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  background:
    radial-gradient(900px 500px at -5% -10%, #d4f0df 10%, transparent 65%),
    radial-gradient(1100px 600px at 110% 0%, #e9f8f0 15%, transparent 68%),
    linear-gradient(180deg, var(--bg-2), var(--bg-1));
}

main.container {
  max-width: 1100px;
  padding: 1rem 1rem 2rem;
  margin: 0 auto;
  padding-bottom: 2rem;
}

body:not(.is-authenticated) main.container {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

body:not(.is-authenticated) #authCard {
  width: min(520px, 100%);
  margin: auto;
}

body.is-authenticated #authCard {
  display: none;
}

.app-header {
  margin: 0.2rem 0 1rem;
}

article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
}

.brand {
  font-family: 'ADLaM Display', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #0a6f48;
  font-size: 1.25rem;
  margin-top: 0;
  margin-bottom: 0.2rem;
}

.brand-tag {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

#lightningFx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 40;
}

#lightningFx.flash {
  animation: lightningFlash 520ms ease-out;
}

#lightningFx.flash.success {
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 246, 200, 0.8), rgba(255, 246, 200, 0) 48%),
    linear-gradient(180deg, rgba(238, 255, 202, 0.34), rgba(238, 255, 202, 0) 65%);
}

#lightningFx.flash.logout {
  background:
    radial-gradient(circle at 50% 18%, rgba(220, 242, 255, 0.78), rgba(220, 242, 255, 0) 48%),
    linear-gradient(180deg, rgba(194, 225, 245, 0.32), rgba(194, 225, 245, 0) 65%);
}

@keyframes lightningFlash {
  0% { opacity: 0; }
  18% { opacity: 1; }
  32% { opacity: 0.25; }
  48% { opacity: 0.9; }
  100% { opacity: 0; }
}

.lookup {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
  align-items: center;
}

#acctno {
  margin: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.8rem 0.9rem;
  font: inherit;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

#acctno:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(11, 122, 11, 0.12);
}

#submit {
  margin: 0;
  border: 0;
  border-radius: 10px;
  padding: 0.8rem 1rem;
  background: linear-gradient(180deg, var(--brand), var(--brand-2));
  color: #fff;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.03em;
  min-width: 120px;
  cursor: pointer;
  transition: transform 160ms ease, filter 160ms ease;
}

#submit:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

#submit:disabled {
  opacity: 0.75;
  cursor: wait;
  transform: none;
}

#acctno[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(188, 29, 29, 0.1);
}

#alertx {
  color: var(--danger);
  display: none;
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
}

#result {
  display: none;
  margin-top: 1rem;
  animation: rise 220ms ease;
}

.account-meta {
  padding: 0.8rem 1rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 0.8rem;
  font-size: 0.92rem;
  box-shadow: var(--shadow);
}

.account-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

#logout {
  border: 1px solid #c7dbce;
  background: #ffffff;
  color: #315343;
  border-radius: 9px;
  padding: 0.32rem 0.62rem;
  font: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

#logout:hover {
  background: #eff9f3;
}

.invoice-state {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin: 0 0 0.8rem;
  padding: 0.55rem 0.75rem;
  background: #fff6e6;
  border: 1px solid #f0d39d;
  border-radius: 12px;
  color: #6b4b12;
  font-size: 0.82rem;
}

.invoice-state.show {
  display: flex;
}

#resumeInvoice {
  border: 1px solid #e5bf7a;
  background: #fef4df;
  color: #6b4b12;
  border-radius: 8px;
  padding: 0.28rem 0.55rem;
  font: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

#resumeInvoice:hover {
  background: #fdecc9;
}

.view-switch {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.view-switch button {
  margin: 0;
  border: 0;
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  background: #293529;
  color: #fff;
  cursor: pointer;
}

.view-switch button[aria-current="true"] {
  background: linear-gradient(180deg, var(--brand), var(--brand-2));
}

#tableWrap,
#chartWrap {
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 0.9rem;
  box-shadow: var(--shadow);
}

figure {
  margin: 0;
  overflow-x: auto;
}

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

th,
td {
  text-align: left;
  border-bottom: 1px solid #edf4ef;
  padding: 0.56rem 0.45rem;
  font-size: 0.88rem;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
}

#chartWrap {
  display: none;
  overflow-x: auto;
  min-height: 420px;
}

.chart-legend {
  display: flex;
  gap: 0.45rem;
  margin-bottom: 0.55rem;
}

.chart-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.chart-toolbar .chart-legend {
  margin-bottom: 0;
}

.chart-zoom {
  display: flex;
  gap: 0.35rem;
}

.zoom-btn {
  border: 1px solid #c8ddd0;
  background: #ffffff;
  color: #244a39;
  border-radius: 10px;
  min-width: 36px;
  padding: 0.26rem 0.52rem;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.zoom-btn:hover {
  background: #eff9f2;
  border-color: #b8d7c5;
}

.reset-btn {
  background: #173d2d;
  border-color: #173d2d;
  color: #f2faf6;
}

.reset-btn:hover {
  background: #21543f;
  border-color: #21543f;
}

.chart-hint {
  margin: 0 0 0.55rem;
  color: #5b7768;
  font-size: 0.76rem;
  line-height: 1.35;
}

.legend-btn {
  border: 1px solid #c8ddd0;
  background: #f7fcf9;
  color: #325445;
  border-radius: 999px;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 0.32rem 0.62rem;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.legend-btn.active {
  background: #173d2d;
  border-color: #173d2d;
  color: #f2faf6;
}

#chart {
  width: 100%;
  min-height: 380px;
  display: block;
}

#toast {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 20;
  padding: 0.7rem 0.9rem;
  background: #173d2d;
  color: #fff;
  border-radius: 12px;
  font-size: 0.82rem;
  box-shadow: 0 14px 30px rgba(9, 28, 20, 0.25);
  transform: translateY(-14px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

#toast.show {
  transform: translateY(0);
  opacity: 1;
}

#toast.error {
  background: #7a1e1e;
}

.chart-tooltip {
  position: fixed;
  z-index: 30;
  background: rgba(17, 34, 27, 0.95);
  color: #ecf8f0;
  border: 1px solid rgba(191, 223, 208, 0.35);
  border-radius: 10px;
  padding: 0.45rem 0.55rem;
  font-size: 0.75rem;
  line-height: 1.35;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
  box-shadow: 0 12px 26px rgba(8, 19, 14, 0.28);
}

.chart-tooltip.show {
  opacity: 1;
  transform: translateY(0);
}

.empty-card {
  margin-top: 0.75rem;
  border: 1px dashed #c5dccd;
  border-radius: 12px;
  padding: 1rem;
  background: #f9fffb;
}

.empty-card h4 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
}

.empty-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.skeleton-row td {
  border-bottom: 1px solid #eef4f0;
}

.skeleton-block {
  display: block;
  width: 100%;
  height: 0.78rem;
  border-radius: 999px;
  background: linear-gradient(90deg, #edf4ef 0%, #dfece4 50%, #edf4ef 100%);
  background-size: 220% 100%;
  animation: skeleton 1.1s linear infinite;
}

@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -20% 0; }
}

.tooltip {
  min-width: 40px;
  background: #000;
  color: #fff;
  font-size: 0.65em;
  font-family: arial, sans-serif;
  line-height: 15px;
  text-align: center;
  padding: 0 2px;
  position: absolute;
}

.version {
  color: #777;
  font-size: 10px;
  text-align: center;
  margin-top: 1.2rem;
}

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

@media (max-width: 768px) {
  main.container {
    padding: 0.8rem 0.7rem 1.2rem;
  }

  article {
    padding: 0.8rem;
  }

  .app-header {
    margin-top: 0.1rem;
  }

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

  #submit {
    width: 100%;
  }

  #chart {
    min-width: 900px;
  }

  .view-switch {
    position: sticky;
    top: 0.35rem;
    z-index: 4;
    background: transparent;
  }

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

  .chart-hint {
    font-size: 0.74rem;
  }

  #toast {
    left: 0.7rem;
    right: 0.7rem;
    top: 0.7rem;
  }
}
