html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
}

button,
input {
  font: inherit;
}

.dashboard-shell {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}

:root {
  --chart-checkins: #2563eb;
}

:root.dark {
  --chart-checkins: #60a5fa;
}

.range-switcher {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
}

.range-button {
  min-height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}

.range-button:hover {
  color: var(--text);
}

.range-button.active {
  background: var(--text);
  color: var(--bg);
}

.range-button.icon-range {
  width: 26px;
  padding: 0;
}

.chart-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.error-banner {
  display: none;
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 28%, var(--border));
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  color: var(--danger);
}

.error-banner.show {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric-card {
  min-width: 0;
  padding: 14px 15px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.metric-value {
  display: block;
  margin-top: 10px;
  color: var(--text);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.metric-foot {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 16px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 11px;
}

.metric-change {
  color: inherit;
  font-weight: 600;
}

.metric-change.positive {
  color: var(--ok);
}

.metric-change.negative {
  color: var(--danger);
}

.overview-grid,
.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.9fr);
  align-items: stretch;
  gap: 12px;
  margin-bottom: 12px;
}

.detail-grid {
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.9fr);
}

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

.usage-panel,
.insight-panel,
.table-panel,
.habits-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex: 0 0 auto;
  gap: 14px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.panel-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.panel-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.panel-link {
  display: inline-flex;
  align-items: center;
  padding-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.panel-link:hover {
  color: var(--text);
}

.usage-panel-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

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

.legend-swatch {
  width: 8px;
  height: 8px;
  display: inline-block;
  border-radius: 2px;
}

.active-swatch {
  background: var(--text);
}

.new-swatch {
  background: var(--muted-2);
}

.checkin-swatch {
  background: var(--chart-checkins, #2563eb);
}

.chart-wrap {
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  flex: 1;
  align-items: stretch;
  gap: 8px;
  min-height: 240px;
  padding: 16px 16px 8px 12px;
}

.chart-canvas {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.chart-y-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  padding: 0 0 22px;
  color: var(--muted-2);
  font-size: 10px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.activity-chart {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0;
  min-width: 0;
  height: 100%;
  padding: 0;
  background-image:
    linear-gradient(var(--border), var(--border)),
    linear-gradient(var(--border), var(--border));
  background-repeat: no-repeat;
  background-size: 100% 1px, 100% 1px;
  background-position: 0 0, 0 calc((100% - 22px) / 2);
}

.chart-column {
  position: relative;
  min-width: 0;
  height: 100%;
  outline: 0;
}

.chart-column:focus-visible {
  border-radius: 4px;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ring) 25%, transparent);
}

.chart-hover-line {
  position: absolute;
  top: 0;
  bottom: 22px;
  left: 50%;
  z-index: 3;
  width: 1px;
  background: color-mix(in srgb, var(--text) 42%, transparent);
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
}

.chart-wrap.is-line .chart-column.is-active .chart-hover-line,
.chart-wrap.is-line .chart-column:hover .chart-hover-line,
.chart-wrap.is-line .chart-column:focus-visible .chart-hover-line {
  opacity: 1;
}

.chart-wrap.is-line .chart-column.is-active .chart-label,
.chart-wrap.is-line .chart-column:hover .chart-label,
.chart-wrap.is-line .chart-column:focus-visible .chart-label {
  color: var(--text);
  font-weight: 600;
}

.chart-wrap.is-line .chart-column.is-active .line-dot,
.chart-wrap.is-line .chart-column:hover .line-dot,
.chart-wrap.is-line .chart-column:focus-visible .line-dot {
  width: 8px;
  height: 8px;
}

.bar-pair {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 22px;
  left: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
}

.chart-wrap.is-line .bar-pair {
  display: none;
}

.bar {
  width: min(12px, 28%);
  height: var(--bar-height, 0);
  border-radius: 2px 2px 0 0;
  transition: height 180ms ease;
}

.bar.is-empty {
  height: 0;
  visibility: hidden;
}

.bar.active-bar {
  background: var(--text);
}

.bar.new-bar {
  background: var(--muted-2);
}

.bar.checkin-bar {
  background: var(--chart-checkins, #2563eb);
}

.chart-column.today .bar.active-bar {
  outline: 1px solid color-mix(in srgb, var(--text) 35%, transparent);
  outline-offset: 1px;
}

.chart-svg {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  width: 100%;
  height: calc(100% - 22px);
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}

.chart-wrap.is-bar .chart-svg,
.chart-wrap.is-bar .line-dots {
  display: none;
}

.chart-svg path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.25;
  vector-effect: non-scaling-stroke;
}

.chart-svg .line-active {
  stroke: var(--text);
}

.chart-svg .line-new {
  stroke: var(--muted-2);
}

.chart-svg .line-checkins {
  stroke: var(--chart-checkins, #2563eb);
}

.chart-svg .fill-checkins {
  fill: color-mix(in srgb, var(--chart-checkins, #2563eb) 16%, transparent);
  stroke: none;
}

.line-dots {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 22px;
  left: 0;
  pointer-events: none;
  z-index: 2;
}

.line-dot {
  position: absolute;
  left: 50%;
  width: 7px;
  height: 7px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  transform: translate(-50%, 50%);
  box-sizing: border-box;
}

.line-dot.active-dot {
  background: var(--text);
}

.line-dot.new-dot {
  background: var(--muted-2);
}

.line-dot.checkin-dot {
  background: var(--chart-checkins, #2563eb);
}

.chart-wrap.is-dense .line-dot {
  width: 5px;
  height: 5px;
  border-width: 1px;
}

.chart-label {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 22px;
  overflow: hidden;
  color: var(--muted-2);
  font-size: 10px;
  line-height: 22px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-column.today .chart-label {
  color: var(--text);
  font-weight: 600;
}

.chart-tooltip[hidden] {
  display: none;
}

.chart-tooltip {
  position: absolute;
  z-index: 4;
  min-width: 148px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  color: var(--muted);
  font-size: 11px;
  pointer-events: none;
}

.chart-tooltip strong,
.chart-tooltip span {
  display: flex;
  align-items: center;
}

.chart-tooltip strong {
  margin-bottom: 6px;
  color: var(--text);
  font-size: 12px;
}

.chart-tooltip span {
  gap: 6px;
  min-height: 16px;
  white-space: nowrap;
}

.chart-tooltip b {
  margin-left: auto;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.tooltip-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 2px;
}

.tooltip-icon {
  width: 7px;
  color: var(--muted);
  font-size: 9px;
  text-align: center;
}

.chart-note {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  color: var(--muted-2);
  font-size: 11px;
}

.insight-list {
  flex: 1;
  padding: 2px 16px;
}

.insight-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  border-bottom: 1px solid var(--border);
}

.insight-row:last-child {
  border-bottom: 0;
}

.insight-copy {
  min-width: 0;
}

.insight-copy strong,
.insight-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.insight-copy strong {
  font-size: 13px;
  font-weight: 500;
}

.insight-copy small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.insight-value {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.coverage-block {
  margin: auto 16px 16px;
  padding: 12px 13px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
}

.coverage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.coverage-head strong {
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 6px;
  margin: 9px 0 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--border);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--text);
  transition: width 180ms ease;
}

.coverage-block p {
  margin: 0;
  color: var(--muted-2);
  font-size: 11px;
}

.table-panel,
.habits-panel {
  height: 380px;
}

.list-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
}

.table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
  box-shadow: 0 1px 0 var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

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

.user-cell {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 160px;
}

.avatar {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--text);
  font-size: 10px;
  font-weight: 600;
}

.user-copy {
  min-width: 0;
}

.user-copy strong,
.user-copy span {
  display: block;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-copy strong {
  font-size: 12px;
  font-weight: 500;
}

.user-copy span {
  margin-top: 1px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
}

.table-number {
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

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

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.status-chip.complete {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.habit-list {
  padding: 4px 16px 12px;
}

.habit-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 11px 0 10px;
  border-bottom: 1px solid var(--border);
}

.habit-row:last-child {
  border-bottom: 0;
}

.habit-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 500;
}

.habit-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.habit-track {
  flex: 1;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--border);
}

.habit-track span {
  display: block;
  width: var(--habit-width);
  height: 100%;
  border-radius: inherit;
  background: var(--text);
}

.habit-meta small {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.habit-count {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.empty-state {
  min-height: 170px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  padding: 24px 20px;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

.empty-state[hidden],
table[hidden],
.habit-list[hidden] {
  display: none !important;
}

.empty-state.compact,
.list-scroll .empty-state {
  min-height: 180px;
}

.empty-state strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}

.dashboard-footnote {
  padding-top: 4px;
  color: var(--muted-2);
  font-size: 11px;
}

@media (max-width: 1120px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .overview-grid,
  .detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .table-panel,
  .habits-panel {
    height: 320px;
  }
}

@media (max-width: 760px) {
  .sync-state {
    margin-left: auto;
  }

  .dashboard-shell {
    padding: 20px 14px 32px;
  }

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

  .metric-card:last-child {
    grid-column: span 2;
  }

  .usage-panel .panel-head {
    flex-wrap: wrap;
  }

  .usage-panel-actions {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
  }

  .chart-wrap {
    padding-right: 12px;
    padding-left: 8px;
  }
}

@media (max-width: 460px) {
  .refresh-button span {
    display: none;
  }

  .refresh-button {
    width: 32px;
    padding: 0;
  }

  .metric-grid {
    gap: 8px;
  }

  .metric-card {
    padding: 12px;
  }

  .metric-value {
    font-size: 22px;
  }
}
