/* --- Light Theme --- */
:root {
  color-scheme: light;
  --bg: #eef1f6;
  --surface: #f4f6fa;
  --surface-raised: #f8f9fc;
  --surface-sunken: #e8edf4;
  --text: #252a31;
  --muted: #7b8491;
  --line: rgba(255, 255, 255, 0.86);
  --soft-line: rgba(164, 176, 196, 0.38);
  --accent: #2f7f6b;
  --accent-2: #6a8fdc;
  --danger: #b42318;
  --shadow-raised: 14px 14px 32px rgba(174, 182, 197, 0.42), -12px -12px 28px rgba(255, 255, 255, 0.92);
  --shadow-soft: 8px 8px 20px rgba(174, 182, 197, 0.32), -8px -8px 20px rgba(255, 255, 255, 0.86);
  --shadow-inset: inset 5px 5px 12px rgba(174, 182, 197, 0.28), inset -5px -5px 12px rgba(255, 255, 255, 0.84);
  --shadow-pressed: inset 4px 4px 10px rgba(174, 182, 197, 0.34), inset -4px -4px 10px rgba(255, 255, 255, 0.82);
  --hover-shadow: 18px 18px 38px rgba(160, 170, 190, 0.42), -12px -12px 28px rgba(255, 255, 255, 0.9);
  --skeleton-bg: #e2e7ef;
  --skeleton-shine: #f8fafd;
  --chart-input: rgba(106, 143, 220, 0.42);
  --chart-output: rgba(47, 127, 107, 0.42);
  --chart-input-border: #6a8fdc;
  --chart-output-border: #2f7f6b;
  --row-alt: rgba(255, 255, 255, 0.42);
  --row-hover: rgba(255, 255, 255, 0.58);
}

/* --- Dark Theme --- */
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #18191a;
  --surface: #242526;
  --text: #e4e6eb;
  --muted: #b0b3b8;
  --line: #3e4042;
  --soft-line: rgba(255, 255, 255, 0.08);
  --surface-raised: #2a2c30;
  --surface-sunken: #1f2022;
  --accent: #2dd4a8;
  --accent-2: #6b9fff;
  --danger: #f25c54;
  --shadow-raised: 10px 10px 24px rgba(0, 0, 0, 0.34), -8px -8px 20px rgba(255, 255, 255, 0.03);
  --shadow-soft: 6px 6px 16px rgba(0, 0, 0, 0.32), -6px -6px 14px rgba(255, 255, 255, 0.03);
  --shadow-inset: inset 4px 4px 10px rgba(0, 0, 0, 0.3), inset -4px -4px 10px rgba(255, 255, 255, 0.03);
  --shadow-pressed: inset 4px 4px 10px rgba(0, 0, 0, 0.38), inset -4px -4px 10px rgba(255, 255, 255, 0.04);
  --hover-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  --skeleton-bg: #3a3b3c;
  --skeleton-shine: #4a4b4c;
  --chart-input: rgba(107, 159, 255, 0.4);
  --chart-output: rgba(45, 212, 168, 0.4);
  --chart-input-border: #6b9fff;
  --chart-output-border: #2dd4a8;
  --row-alt: #2a2b2c;
  --row-hover: #303134;
}

* {
  box-sizing: border-box;
}

[v-cloak] {
  display: none;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transition: background 0.3s, color 0.3s;
}

button,
input,
select {
  font: inherit;
}

/* --- Layout --- */
.shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 32px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.topbar-left p {
  color: var(--muted);
  margin-top: 4px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.1;
  font-weight: 700;
}

h2 {
  font-size: 18px;
  font-weight: 600;
}

/* --- Controls --- */
.controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

select,
input,
button {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-raised);
  color: var(--text);
  padding: 0 16px;
  box-shadow: var(--shadow-soft);
  transition: border-color 0.2s, box-shadow 0.2s, color 0.2s, background 0.2s;
}

select:hover,
input:hover,
button:hover {
  border-color: var(--accent);
}

select:focus,
input:focus,
button:focus-visible {
  outline: 2px solid rgba(47, 127, 107, 0.26);
  outline-offset: 3px;
}

button {
  background: var(--surface-raised);
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
}

button:hover {
  opacity: 1;
  box-shadow: var(--hover-shadow);
}

button:active {
  box-shadow: var(--shadow-pressed);
}

/* --- Theme Toggle --- */
.theme-btn {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--line);
  width: 42px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.3s, box-shadow 0.3s;
  box-shadow: inset -4px 0 0 0 var(--surface);
}

[data-theme="dark"] .theme-icon {
  box-shadow: inset -6px 0 0 0 var(--surface), 0 0 0 2px var(--muted);
  background: var(--muted);
}

/* --- Metric Cards --- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow-raised), inset 1px 1px 0 rgba(255, 255, 255, 0.82);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.3s, background 0.3s;
}

.metric {
  min-height: 108px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.metric:hover,
.panel:hover {
  transform: translateY(-1px);
  box-shadow: var(--hover-shadow);
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.metric strong {
  font-size: 28px;
  line-height: 1.15;
  word-break: break-word;
  font-variant-numeric: tabular-nums;
}

/* --- Dimension Tabs --- */
.dim-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.dim-tabs button {
  background: var(--surface-raised);
  color: var(--muted);
  border: 1px solid var(--line);
  height: 34px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 999px;
  box-shadow: var(--shadow-soft);
}

.dim-tabs button:hover {
  border-color: var(--accent);
  color: var(--text);
}

.dim-tabs button.active {
  background: var(--surface-sunken);
  color: var(--text);
  border-color: var(--line);
  box-shadow: var(--shadow-pressed);
}

/* --- Chart --- */
.chart-panel {
  margin-bottom: 16px;
  padding: 24px;
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head span {
  color: var(--muted);
  font-size: 14px;
}

/* --- Rank --- */
.rank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  padding: 22px;
}

.rank-list {
  display: grid;
  grid-template-columns: 28px minmax(84px, 11ch) minmax(96px, 1fr) max-content;
  column-gap: 10px;
  row-gap: 12px;
}

.rank-row {
  display: contents;
}

.rank-row > * {
  align-self: center;
  min-width: 0;
}

.rank-idx {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.rank-idx.top {
  color: var(--accent);
}

.rank-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.rank-track {
  height: 8px;
  width: 100%;
  border-radius: 999px;
  background: var(--surface-sunken);
  overflow: hidden;
  box-shadow: var(--shadow-inset);
}

.rank-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.6s ease;
  box-shadow: 0 0 10px rgba(47, 127, 107, 0.18);
}

.cost-fill {
  background: linear-gradient(90deg, #d3a055, var(--accent));
}

.rank-row strong {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  justify-self: end;
  text-align: right;
  white-space: nowrap;
}

.rank-list > .empty {
  grid-column: 1 / -1;
}

/* --- Heatmap --- */
.heatmap-panel {
  --heatmap-cell-size: 14px;
  --heatmap-cell-gap: 4px;
  --heatmap-label-width: 28px;
  --heatmap-week-count: 12;
  margin-bottom: 16px;
  padding: 22px 24px;
  position: relative;
}

.activity-content {
  display: grid;
  grid-template-columns: minmax(260px, 0.42fr) minmax(0, 1fr);
  align-items: center;
  gap: 24px;
  min-height: 142px;
}

.activity-summary {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 1fr));
  gap: 12px;
}

.activity-stat {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 12px;
  background: var(--surface-sunken);
  box-shadow: var(--shadow-inset);
}

.activity-stat span,
.activity-stat small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.activity-stat strong {
  display: block;
  margin: 5px 0 3px;
  font-size: 20px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.activity-heatmap {
  justify-self: stretch;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.heatmap-scroll {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  padding-bottom: 2px;
}

.heatmap-wrapper {
  width: 100%;
  max-width: 100%;
}

.heatmap-container {
  display: grid;
  grid-template-columns: var(--heatmap-label-width) minmax(0, 1fr);
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.heatmap-labels {
  display: grid;
  grid-template-rows: repeat(7, var(--heatmap-cell-size));
  gap: var(--heatmap-cell-gap);
  padding-top: 22px;
}

.heatmap-labels span {
  font-size: 11px;
  color: var(--muted);
  line-height: var(--heatmap-cell-size);
  text-align: right;
}

.heatmap-grid-wrapper {
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
}

.heatmap-months {
  display: grid;
  grid-template-columns: repeat(var(--heatmap-week-count), var(--heatmap-cell-size));
  justify-content: space-between;
  column-gap: var(--heatmap-cell-gap);
  height: 16px;
  margin-bottom: 6px;
  width: 100%;
}

.heatmap-months span {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.heatmap-grid {
  display: grid;
  grid-template-rows: repeat(7, var(--heatmap-cell-size));
  grid-template-columns: repeat(var(--heatmap-week-count), var(--heatmap-cell-size));
  justify-content: space-between;
  gap: var(--heatmap-cell-gap);
  width: 100%;
}

.heatmap-cell {
  width: var(--heatmap-cell-size);
  height: var(--heatmap-cell-size);
  border-radius: 5px;
  background: var(--line);
  cursor: pointer;
  box-shadow: inset 1px 1px 2px rgba(255, 255, 255, 0.54), inset -1px -1px 2px rgba(160, 170, 190, 0.18);
  transition: transform 0.1s, box-shadow 0.1s;
}

.heatmap-cell:hover {
  transform: scale(1.4);
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  z-index: 2;
  position: relative;
}

.heat-level-0 { background: var(--line); }
.heat-level-1 { background: #c6ede3; }
.heat-level-2 { background: #73cfba; }
.heat-level-3 { background: #2fb898; }
.heat-level-4 { background: #147d64; }

[data-theme="dark"] .heat-level-1 { background: #1e3d35; }
[data-theme="dark"] .heat-level-2 { background: #1a5c4c; }
[data-theme="dark"] .heat-level-3 { background: #228a6f; }
[data-theme="dark"] .heat-level-4 { background: #2dd4a8; }

.heatmap-tooltip {
  position: absolute;
  z-index: 10;
  background: var(--text);
  color: var(--surface);
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow-soft);
  transform: translate(-50%, -100%);
  margin-top: -10px;
}

.heatmap-tooltip strong {
  display: block;
  font-weight: 600;
}

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  justify-content: flex-end;
  width: 100%;
}

.legend-label {
  font-size: 11px;
  color: var(--muted);
}

.legend-cell {
  cursor: default;
}

.legend-cell:hover {
  transform: none;
  outline: none;
}

/* --- Table --- */
.table-wrap {
  overflow-x: auto;
}

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

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

th {
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
}

tbody tr:nth-child(even) {
  background: var(--row-alt);
}

tbody tr {
  transition: background 0.15s;
}

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

.empty {
  color: var(--muted);
  padding: 24px 0;
  text-align: center;
}

/* --- Skeleton --- */
.skeleton-text {
  color: transparent !important;
  background: var(--skeleton-bg);
  border-radius: 10px;
  min-width: 60px;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: 200px 0; }
}

.skeleton-text {
  background: linear-gradient(90deg, var(--skeleton-bg) 25%, var(--skeleton-shine) 50%, var(--skeleton-bg) 75%);
  background-size: 400px 100%;
}

.skeleton-row td {
  padding: 14px 10px;
}

.skeleton-bar {
  height: 14px;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--skeleton-bg) 25%, var(--skeleton-shine) 50%, var(--skeleton-bg) 75%);
  background-size: 400px 100%;
  animation: shimmer 1.5s infinite;
}

/* --- Footer --- */
.footer {
  margin-top: 32px;
  padding-top: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.footer-brand {
  height: 28px;
  min-width: 0;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  font-size: 12px;
  font-weight: 500;
  opacity: 0.42;
}

.footer-brand:hover,
.footer-brand:focus-visible {
  border-color: var(--line);
  background: var(--surface-raised);
  box-shadow: var(--shadow-soft);
  opacity: 0.72;
}

.footer-brand.active {
  opacity: 0.62;
  box-shadow: var(--shadow-pressed);
}

/* --- Toast --- */
.usage-toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  z-index: 9999;
  width: min(520px, calc(100vw - 32px));
  pointer-events: none;
  transform: translateX(-50%);
}

.usage-toast-card {
  --toast-fade-ms: 1000ms;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  background: rgba(32, 32, 32, 0.96);
  color: #e5e7eb;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  padding: 14px 14px 14px 16px;
  pointer-events: auto;
  backdrop-filter: blur(12px);
}

[data-theme="light"] .usage-toast-card {
  border-color: rgba(26, 29, 33, 0.12);
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  box-shadow: 0 16px 40px rgba(23, 32, 38, 0.18);
}

.usage-toast-content {
  display: grid;
  gap: 5px;
  min-width: 0;
  flex: 1;
  font-size: 13px;
  line-height: 1.45;
}

.usage-toast-content strong {
  color: inherit;
  font-size: 14px;
  line-height: 1.25;
}

.usage-toast-content span {
  color: var(--muted);
  overflow-wrap: anywhere;
}

[data-theme="dark"] .usage-toast-content span,
:root:not([data-theme="light"]) .usage-toast-content span {
  color: #cbd5e1;
}

.usage-toast-enter-active,
.usage-toast-leave-active {
  transition:
    opacity var(--toast-fade-ms) ease,
    transform var(--toast-fade-ms) ease;
}

.usage-toast-enter-from,
.usage-toast-leave-to {
  opacity: 0;
  transform: translateY(-12px);
}

.toast-root {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
}

.toast {
  border: 1px solid #f4c7c3;
  border-radius: 18px;
  background: #fff7f6;
  color: var(--danger);
  padding: 12px 14px;
  box-shadow: 0 12px 28px rgba(23, 32, 38, 0.16);
  font-size: 14px;
  line-height: 1.4;
  animation: toast-in 0.3s ease;
}

[data-theme="dark"] .toast {
  background: #2a1a1a;
  border-color: #5c2020;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Responsive --- */
@media (max-width: 980px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .rank-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .activity-content {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .activity-heatmap {
    justify-self: stretch;
    width: 100%;
  }
  .heatmap-legend {
    justify-content: center;
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 16px;
  }
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }
  .metric-grid,
  .rank-grid {
    grid-template-columns: 1fr;
  }
  .controls {
    width: 100%;
  }
  .controls select,
  .controls button {
    flex: 1;
  }
  .controls .theme-btn {
    flex: 0 0 42px;
  }
  .toast-root {
    right: 16px;
    bottom: 16px;
  }
  .usage-toast-container {
    top: 12px;
    width: calc(100vw - 24px);
  }
  .usage-toast-card {
    padding: 12px;
  }
  .activity-summary {
    grid-template-columns: 1fr;
  }
}
