:root {
  --bg: #0b0d10;
  --panel: #11151a;
  --panel-2: #161b22;
  --border: #1f2630;
  --fg: #e9eef2;
  --muted: #9aa6b2;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --good: #10b981;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#auth {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
}

main {
  padding: 24px;
  display: grid;
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
}

.signed-out {
  padding: 80px 24px;
  text-align: center;
  color: var(--muted);
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.card h2 {
  margin: 0 0 12px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
}

.muted { color: var(--muted); font-size: 12px; }

.controls {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-end;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

select, input[type="number"], input[type="month"] {
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  min-width: 180px;
  color-scheme: dark;
}

select:focus, input:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: background 0.15s;
}

button:hover { background: var(--accent-hover); }
button.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
button.secondary:hover { color: var(--fg); border-color: var(--muted); }

.table-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel-2);
}

th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 13px;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 500;
  background: var(--panel);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
}

tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(59, 130, 246, 0.05); }

tfoot td {
  font-weight: 600;
  background: var(--panel);
  color: var(--fg);
}

.price-group {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.price-group:last-child { border-bottom: 0; }
.price-group-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--fg);
}

.price-row {
  display: grid;
  grid-template-columns: 110px 140px auto auto;
  gap: 10px;
  align-items: center;
  padding: 4px 0 4px 12px;
}
.price-row .plan-label { font-weight: 400; color: var(--muted); font-size: 12px; }
.price-row .saved { color: var(--good); font-size: 12px; opacity: 0; transition: opacity 0.2s; }
.price-row .saved.show { opacity: 1; }

.app-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.app-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--panel-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}
.app-icon-placeholder {
  background: var(--border);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0;
}

.price-group-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.price-group-title .app-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}

#totals h2 .app-name {
  vertical-align: middle;
}
#totals h2 .app-icon {
  width: 20px;
  height: 20px;
  border-radius: 5px;
}

.plan-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
}
.plan-badge.plan-monthly { color: #93c5fd; border-color: #1e3a8a; background: rgba(59, 130, 246, 0.12); }
.plan-badge.plan-yearly { color: #fcd34d; border-color: #78350f; background: rgba(245, 158, 11, 0.12); }
.plan-badge.plan-oneTime { color: var(--muted); }

#totals table { background: transparent; }
#totals .grand { color: var(--good); }
#totals tr.app-subtotal td {
  font-weight: 500;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
  text-align: right;
}
#totals tr.app-subtotal td:nth-last-child(2),
#totals tr.app-subtotal td:last-child { color: var(--fg); }

#totals td.all-time-cell {
  border-left: 1px solid var(--border);
  background: rgba(16, 185, 129, 0.04);
}
#totals th:last-child { border-left: 1px solid var(--border); }

.all-time-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  margin: 0 0 14px 0;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.08), rgba(59, 130, 246, 0.06));
  border: 1px solid var(--border);
  border-radius: 10px;
}
.all-time-banner-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 500;
}
.all-time-banner-meta { margin-top: 2px; }
.all-time-banner-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--good);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 600px) {
  main { padding: 12px; }
  .price-row { grid-template-columns: 1fr 1fr; }
  .price-row .saved { grid-column: 1 / -1; }
  .controls { flex-direction: column; align-items: stretch; }
  select, input[type="month"], input[type="number"] { min-width: 0; width: 100%; }
}
